Author: richard
Date: Fri Jan 16 02:38:30 2009
New Revision: 3852
URL: http://svn.slimdevices.com?rev=3852&root=Jive&view=rev
Log:
Bug: 10296
Description:
Back-ported timer changes from 7.4. This may help address the random reboot
issues. Changes are:
3770:3771
3772:3773
3775:3776
3811:3812
Removed:
7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_timer.c
Modified:
7.3/trunk/squeezeplay/src/squeezeplay/Makefile.am
7.3/trunk/squeezeplay/src/squeezeplay/Makefile.in
7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua
7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h
7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/Makefile.am
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/Makefile.am?rev=3852&root=Jive&r1=3851&r2=3852&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/Makefile.am (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/Makefile.am Fri Jan 16 02:38:30 2009
@@ -163,7 +163,6 @@
src/ui/jive_textarea.c \
src/ui/jive_textinput.c \
src/ui/jive_tile.c \
- src/ui/jive_timer.c \
src/ui/jive_utils.c \
src/ui/jive_widget.c \
src/ui/jive_window.c \
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/Makefile.in
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/Makefile.in?rev=3852&root=Jive&r1=3851&r2=3852&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/Makefile.in (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/Makefile.in Fri Jan 16 02:38:30 2009
@@ -78,8 +78,8 @@
jive_framework_osx.lo jive_framework_linux.lo jive_group.lo \
jive_icon.lo jive_label.lo jive_menu.lo jive_slider.lo \
jive_style.lo jive_surface.lo jive_textarea.lo \
- jive_textinput.lo jive_tile.lo jive_timer.lo jive_utils.lo \
- jive_widget.lo jive_window.lo lua_jiveui.lo
+ jive_textinput.lo jive_tile.lo jive_utils.lo jive_widget.lo \
+ jive_window.lo lua_jiveui.lo
libjiveui_la_OBJECTS = $(am_libjiveui_la_OBJECTS)
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(testdir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
@@ -286,7 +286,6 @@
src/ui/jive_textarea.c \
src/ui/jive_textinput.c \
src/ui/jive_tile.c \
- src/ui/jive_timer.c \
src/ui/jive_utils.c \
src/ui/jive_widget.c \
src/ui/jive_window.c \
@@ -497,7 +496,6 @@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_textarea....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_textinput....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_tile....@am__quote@
-...@amdep_true@@am__include@ @am__qu...@./$(DEPDIR)/jive_timer....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_utils....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_widget....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_window....@am__quote@
@@ -736,13 +734,6 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/ui/jive_tile.c'
object='jive_tile.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE)
$(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS)
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS)
$(CFLAGS) -c -o jive_tile.lo `test -f 'src/ui/jive_tile.c' || echo
'$(srcdir)/'`src/ui/jive_tile.c
-
-jive_timer.lo: src/ui/jive_timer.c
-...@am__fastdepcc_true@ if $(LIBTOOL) --tag=CC --mode=compile $(CC)
$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS)
$(CFLAGS) -MT jive_timer.lo -MD -MP -MF "$(DEPDIR)/jive_timer.Tpo" -c -o
jive_timer.lo `test -f 'src/ui/jive_timer.c' || echo
'$(srcdir)/'`src/ui/jive_timer.c; \
-...@am__fastdepcc_true@ then mv -f "$(DEPDIR)/jive_timer.Tpo"
"$(DEPDIR)/jive_timer.Plo"; else rm -f "$(DEPDIR)/jive_timer.Tpo"; exit 1; fi
-...@amdep_true@@am__fastdepCC_FALSE@ source='src/ui/jive_timer.c'
object='jive_timer.lo' libtool=yes @AMDEPBACKSLASH@
-...@amdep_true@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE)
$(depcomp) @AMDEPBACKSLASH@
-...@am__fastdepcc_false@ $(LIBTOOL) --tag=CC --mode=compile $(CC)
$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS)
$(CFLAGS) -c -o jive_timer.lo `test -f 'src/ui/jive_timer.c' || echo
'$(srcdir)/'`src/ui/jive_timer.c
jive_utils.lo: src/ui/jive_utils.c
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS)
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS)
$(CFLAGS) -MT jive_utils.lo -MD -MP -MF "$(DEPDIR)/jive_utils.Tpo" -c -o
jive_utils.lo `test -f 'src/ui/jive_utils.c' || echo
'$(srcdir)/'`src/ui/jive_utils.c; \
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua?rev=3852&root=Jive&r1=3851&r2=3852&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua Fri Jan
16 02:38:30 2009
@@ -301,6 +301,7 @@
collectgarbage("step")
-- process ui event once per frame
+ Timer:_runTimer(now)
running = eventTask:resume()
-- when is the next frame due?
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua?rev=3852&root=Jive&r1=3851&r2=3852&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua Fri Jan 16
02:38:30 2009
@@ -26,15 +26,23 @@
-- stuff we use
-local _assert, string, tostring, type = _assert, string, tostring, type
+local _assert, ipairs, pcall, string, tostring, type = _assert, ipairs, pcall,
string, tostring, type
local oo = require("loop.base")
+local table = require("jive.utils.table")
+
+local Framework = require("jive.ui.Framework")
+
local debug = require("jive.utils.debug")
+local log = require("jive.utils.log").logger("ui")
-- our class
module(..., oo.class)
+
+-- sorted list of running timers
+local timers = {}
--[[
@@ -68,7 +76,10 @@
=cut
--]]
--- C implementation
+function start(self)
+ local now = Framework:getTicks()
+ self:_insertTimer(now + self.interval)
+end
--[[
@@ -80,7 +91,10 @@
=cut
--]]
--- C implementation
+function stop(self)
+ table.delete(timers, self)
+ self.expires = nil
+end
--[[
@@ -115,9 +129,10 @@
function setInterval(self, interval)
_assert(type(interval) == "number")
- self.interval = interval
- if self._timerData then
- self:restart()
+ if self.expires then
+ self:restart(interval)
+ else
+ self.interval = interval
end
end
@@ -131,9 +146,50 @@
=cut
--]]
function isRunning(self)
- return self._timerData ~= nil
-end
-
+ return self.expires ~= nil
+end
+
+
+-- insert the timer into timer queue
+function _insertTimer(self, expires)
+ if self.expires then
+ table.delete(timers, self)
+ end
+ self.expires = expires
+
+ for i, timer in ipairs(timers) do
+ if self.expires < timer.expires then
+ table.insert(timers, i, self)
+ return
+ end
+ end
+ table.insert(timers, self)
+end
+
+
+-- process timer queue
+function _runTimer(self, now)
+ if timers[1] and not timers[1].expires then
+ log:error("stopped timer in timer list")
+ debug.dump(timers)
+ end
+
+ while timers[1] and timers[1].expires <= now do
+ local timer = table.remove(timers, 1)
+
+ -- call back may modify the timer so update it first
+ if not timer.once then
+ timer:_insertTimer(timer.expires + timer.interval)
+ else
+ timer.expires = nil
+ end
+
+ local status, err = pcall(timer.callback)
+ if not status then
+ log:warn("timer error: ", err)
+ end
+ end
+end
--[[
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h?rev=3852&root=Jive&r1=3851&r2=3852&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h Fri Jan 16 02:38:30 2009
@@ -139,9 +139,9 @@
enum {
- JIVE_USER_EVENT_TIMER = 0x00000001,
- JIVE_USER_EVENT_KEY_HOLD = 0x00000002,
- JIVE_USER_EVENT_MOUSE_HOLD = 0x00000003,
+ /* reserved: 0x00000001 */
+ /* reserved: 0x00000002 */
+ /* reserved: 0x00000003 */
JIVE_USER_EVENT_EVENT = 0x00000004,
};
@@ -380,8 +380,6 @@
JiveFont *jive_style_array_font(lua_State *L, int index, const char *array,
int n, const char *key);
Uint32 jive_style_array_color(lua_State *L, int index, const char *array, int
n, const char *key, Uint32 def, bool *is_set);
-void jive_timer_dispatch_event(lua_State *L, void *param);
-
/* lua functions */
int jiveL_get_background(lua_State *L);
@@ -473,9 +471,6 @@
int jiveL_style_color(lua_State *L);
int jiveL_style_font(lua_State *L);
-int jiveL_timer_add_timer(lua_State *L);
-int jiveL_timer_remove_timer(lua_State *L);
-
#define JIVEL_STACK_CHECK_BEGIN(L) { int _sc = lua_gettop((L));
Modified: 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
URL:
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c?rev=3852&root=Jive&r1=3851&r2=3852&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c Fri Jan 16
02:38:30 2009
@@ -66,9 +66,10 @@
static JiveKey key_mask = 0;
-static SDL_TimerID key_timer = NULL;
-
-static SDL_TimerID mouse_timer = NULL;
+static Uint32 key_timeout = 0;
+
+static Uint32 mouse_timeout = 0;
+static Uint32 mouse_timeout_arg;
static Uint16 mouse_origin_x, mouse_origin_y;
@@ -84,14 +85,15 @@
{ SDLK_AudioNext, JIVE_KEY_FWD },
{ SDLK_AudioRaiseVolume,JIVE_KEY_VOLUME_UP },
{ SDLK_AudioLowerVolume,JIVE_KEY_VOLUME_DOWN },
- { SDLK_PAGEUP, JIVE_KEY_PAGE_UP },
- { SDLK_PAGEDOWN, JIVE_KEY_PAGE_DOWN },
+ { SDLK_PAGEUP, JIVE_KEY_PAGE_UP },
+ { SDLK_PAGEDOWN, JIVE_KEY_PAGE_DOWN },
{ SDLK_UNKNOWN, JIVE_KEY_NONE },
};
static int init_path(lua_State *L);
static int process_event(lua_State *L, SDL_Event *event);
+static void process_timers(lua_State *L);
static int filter_events(const SDL_Event *event);
int jiveL_update_screen(lua_State *L);
@@ -142,7 +144,7 @@
SDL_putenv("SDL_NOMOUSE=1");
/* initialise SDL */
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL_Init(V|T|A): %s\n", SDL_GetError());
SDL_Quit();
exit(-1);
@@ -322,6 +324,7 @@
}
/* process events */
+ process_timers(L);
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) > 0 ) {
r |= process_event(L, &event);
}
@@ -969,34 +972,6 @@
}
-static Uint32 keyhold_callback(Uint32 interval, void *param) {
- SDL_Event user_event;
- memset(&user_event, 0, sizeof(SDL_Event));
-
- user_event.type = SDL_USEREVENT;
- user_event.user.code = JIVE_USER_EVENT_KEY_HOLD;
- user_event.user.data1 = param;
-
- SDL_PushEvent(&user_event);
-
- return 0;
-}
-
-
-static Uint32 mousehold_callback(Uint32 interval, void *param) {
- SDL_Event user_event;
- memset(&user_event, 0, sizeof(SDL_Event));
-
- user_event.type = SDL_USEREVENT;
- user_event.user.code = JIVE_USER_EVENT_MOUSE_HOLD;
- user_event.user.data1 = param;
-
- SDL_PushEvent(&user_event);
-
- return 0;
-}
-
-
static int do_dispatch_event(lua_State *L, JiveEvent *jevent) {
int r;
@@ -1016,9 +991,10 @@
static int process_event(lua_State *L, SDL_Event *event) {
JiveEvent jevent;
+ Uint32 now;
memset(&jevent, 0, sizeof(JiveEvent));
- jevent.ticks = SDL_GetTicks();
+ jevent.ticks = now = SDL_GetTicks();
switch (event->type) {
case SDL_QUIT:
@@ -1057,16 +1033,9 @@
if (event->type == SDL_MOUSEBUTTONDOWN) {
if (mouse_state == MOUSE_STATE_NONE) {
- unsigned int * param = malloc(sizeof(unsigned
int));
-
mouse_state = MOUSE_STATE_DOWN;
-
- if (mouse_timer) {
- SDL_RemoveTimer(mouse_timer);
- }
-
- *param = (event->button.y << 16) |
event->button.x;
- mouse_timer = SDL_AddTimer(HOLD_TIMEOUT,
&mousehold_callback, param);
+ mouse_timeout_arg = (event->button.y << 16) |
event->button.x;
+ mouse_timeout = now + HOLD_TIMEOUT;
mouse_origin_x = event->button.x;
mouse_origin_y = event->button.y;
@@ -1088,11 +1057,7 @@
jive_queue_event(&up);
}
- if (mouse_timer) {
- SDL_RemoveTimer(mouse_timer);
- mouse_timer = NULL;
- }
-
+ mouse_timeout = 0;
mouse_state = MOUSE_STATE_NONE;
}
break;
@@ -1143,37 +1108,26 @@
if (entry->keysym == SDLK_UNKNOWN) {
// handle regular character keys ('a', 't', etc..)
if (event->type == SDL_KEYDOWN &&
event->key.keysym.unicode != 0) {
- JiveEvent textEvent;
-
- memset(&textEvent, 0, sizeof(JiveEvent));
- textEvent.type = JIVE_EVENT_CHAR_PRESS;
- textEvent.ticks = SDL_GetTicks();
+ jevent.type = JIVE_EVENT_CHAR_PRESS;
if (event->key.keysym.sym == SDLK_BACKSPACE) {
//special case for Backspace, where
value set is not ascii value, instead pass backspace ascii value
- textEvent.u.text.unicode = 8;
+ jevent.u.text.unicode = 8;
} else {
- textEvent.u.text.unicode =
event->key.keysym.unicode;
+ jevent.u.text.unicode =
event->key.keysym.unicode;
}
- jive_queue_event(&textEvent);
- }
- return 0;
+ }
}
/* handle pgup/upgn as repeatable keys */
- if (entry->keysym == SDLK_PAGEUP || entry->keysym ==
SDLK_PAGEDOWN) {
+ else if (entry->keysym == SDLK_PAGEUP || entry->keysym ==
SDLK_PAGEDOWN) {
if (event->type == SDL_KEYDOWN) {
- JiveEvent keypress;
-
- memset(&keypress, 0, sizeof(JiveEvent));
- keypress.type = JIVE_EVENT_KEY_PRESS;
- keypress.ticks = SDL_GetTicks();
- keypress.u.key.code = entry->keycode;
- jive_queue_event(&keypress);
- }
- return 0;
+ jevent.type = JIVE_EVENT_KEY_PRESS;
+ jevent.ticks = SDL_GetTicks();
+ jevent.u.key.code = entry->keycode;
+ }
}
- if (event->type == SDL_KEYDOWN) {
+ else if (event->type == SDL_KEYDOWN) {
if (key_mask & entry->keycode) {
// ignore key repeats
return 0;
@@ -1193,11 +1147,7 @@
jevent.type = JIVE_EVENT_KEY_DOWN;
jevent.u.key.code = entry->keycode;
- if (key_timer) {
- SDL_RemoveTimer(key_timer);
- }
-
- key_timer = SDL_AddTimer(HOLD_TIMEOUT,
&keyhold_callback, (void *)key_mask);
+ key_timeout = now + HOLD_TIMEOUT;
break;
}
@@ -1244,11 +1194,7 @@
}
}
- if (key_timer) {
- SDL_RemoveTimer(key_timer);
- key_timer = NULL;
- }
-
+ key_timeout = 0;
key_mask &= ~(entry->keycode);
if (key_mask == 0) {
key_state = KEY_STATE_NONE;
@@ -1258,34 +1204,10 @@
}
case SDL_USEREVENT:
- switch ( (int) event->user.code) {
- case JIVE_USER_EVENT_TIMER:
- JIVEL_STACK_CHECK_BEGIN(L);
- jive_timer_dispatch_event(L, event->user.data1);
- JIVEL_STACK_CHECK_END(L);
- return 0;
-
- case JIVE_USER_EVENT_KEY_HOLD:
- jevent.type = JIVE_EVENT_KEY_HOLD;
- jevent.u.key.code = (JiveKey) event->user.data1;
- key_state = KEY_STATE_SENT;
- break;
-
- case JIVE_USER_EVENT_MOUSE_HOLD:
- if (mouse_state == MOUSE_STATE_DOWN) {
- jevent.type = JIVE_EVENT_MOUSE_HOLD;
- jevent.u.mouse.x = *((unsigned int *)
event->user.data1) & 0xFFFF;
- jevent.u.mouse.y = ( *((unsigned int *)
event->user.data1) >> 16) & 0xFFFF;
- mouse_state = MOUSE_STATE_SENT;
- free(event->user.data1);
- }
- break;
-
- case JIVE_USER_EVENT_EVENT:
- memcpy(&jevent, event->user.data1, sizeof(JiveEvent));
- free(event->user.data1);
- break;
- }
+ assert(event->user.code == JIVE_USER_EVENT_EVENT);
+
+ memcpy(&jevent, event->user.data1, sizeof(JiveEvent));
+ free(event->user.data1);
break;
case SDL_VIDEORESIZE: {
@@ -1326,6 +1248,37 @@
}
return do_dispatch_event(L, &jevent);
+}
+
+
+static void process_timers(lua_State *L) {
+ JiveEvent jevent;
+ Uint32 now;
+
+ memset(&jevent, 0, sizeof(JiveEvent));
+ jevent.ticks = now = SDL_GetTicks();
+
+ if (mouse_timeout && mouse_timeout < now) {
+ if (mouse_state == MOUSE_STATE_DOWN) {
+ jevent.type = JIVE_EVENT_MOUSE_HOLD;
+ jevent.u.mouse.x = (mouse_timeout_arg >> 0) & 0xFFFF;
+ jevent.u.mouse.y = (mouse_timeout_arg >> 16) & 0xFFFF;
+ mouse_state = MOUSE_STATE_SENT;
+
+ do_dispatch_event(L, &jevent);
+ }
+ mouse_timeout = 0;
+ }
+
+ if (key_timeout && key_timeout < now) {
+ jevent.type = JIVE_EVENT_KEY_HOLD;
+ jevent.u.key.code = key_mask;
+ key_state = KEY_STATE_SENT;
+
+ do_dispatch_event(L, &jevent);
+
+ key_timeout = 0;
+ }
}
@@ -1442,12 +1395,6 @@
{ "iterate", jiveL_window_iterate },
{ "draw", jiveL_window_draw },
{ "_eventHandler", jiveL_window_event_handler },
- { NULL, NULL }
-};
-
-static const struct luaL_Reg timer_methods[] = {
- { "start", jiveL_timer_add_timer },
- { "stop", jiveL_timer_remove_timer },
{ NULL, NULL }
};
@@ -1537,10 +1484,6 @@
luaL_register(L, NULL, slider_methods);
lua_pop(L, 1);
- lua_getfield(L, 2, "Timer");
- luaL_register(L, NULL, timer_methods);
- lua_pop(L, 1);
-
lua_getfield(L, -1, "Event");
luaL_register(L, NULL, event_methods);
lua_pop(L, 1);
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins