# HG changeset patch # User Thinker K.F. Li # Date 1222454442 -28800 # Node ID 9870b049b7f6098ebcddbcaef35b757d4f1125c8 # Parent 2b316b5d65f992e470f1e2b13fba19aadec385a3 Make mb_progm_abort() work. diff -r 2b316b5d65f9 -r 9870b049b7f6 examples/tank/tank_main.c --- a/examples/tank/tank_main.c Fri Sep 26 17:56:08 2008 +0800 +++ b/examples/tank/tank_main.c Sat Sep 27 02:40:42 2008 +0800 @@ -108,7 +108,7 @@ if(tank->progm) { tman = X_MB_tman(xmb_rt); - mb_progm_abort(tank->progm, tman); + mb_progm_abort(tank->progm); } free(tank); } @@ -252,27 +252,31 @@ switch(xkey->sym) { case 0xff51: /* left */ direction = TD_LEFT; + tank_move(tank_rt->tank1, direction, tank_rt); break; case 0xff52: /* up */ direction = TD_UP; + tank_move(tank_rt->tank1, direction, tank_rt); break; case 0xff53: /* right */ direction = TD_RIGHT; + tank_move(tank_rt->tank1, direction, tank_rt); break; case 0xff54: /* down */ direction = TD_DOWN; + tank_move(tank_rt->tank1, direction, tank_rt); break; case 0x20: /* space */ + break; case 0xff0d: /* enter */ default: return; } - tank_move(tank_rt->tank1, direction, tank_rt); } static void init_keyboard(tank_rt_t *tank_rt) { diff -r 2b316b5d65f9 -r 9870b049b7f6 src/animate.c --- a/src/animate.c Fri Sep 26 17:56:08 2008 +0800 +++ b/src/animate.c Sat Sep 27 02:40:42 2008 +0800 @@ -98,6 +98,7 @@ int first_playing; /*!< first playing word. */ mb_tman_t *tman; subject_t *complete; /*!< notify when a program is completed. */ + mb_timer_t *cur_timer; int n_words; int max_words; @@ -290,6 +291,7 @@ timer = mb_tman_timeout(progm->tman, &next_tmo, mb_progm_step, progm); } else { + /* Make program to complete. */ #ifndef UNITTEST factory = rdman_get_ob_factory(progm->rdman); comp_evt.event.type = EVT_PROGM_COMPLETE; @@ -297,6 +299,7 @@ comp_evt.progm = progm; subject_notify(factory, progm->complete, &comp_evt.event); #endif /* UNITTEST */ + progm->cur_timer = NULL; } } @@ -329,10 +332,17 @@ timer = mb_tman_timeout(tman, &progm->words[0].abs_start, mb_progm_step, progm); ASSERT(timer != NULL); + + /* We need timer to abort it. */ + progm->cur_timer = timer; } -void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) { +void mb_progm_abort(mb_progm_t *progm) { /*! \todo Make sure abort release resources. */ + if(progm->cur_timer) { + mb_tman_remove(progm->tman, progm->cur_timer); + progm->cur_timer = NULL; + } } /*! \brief Return event subject for completion of a program. diff -r 2b316b5d65f9 -r 9870b049b7f6 src/animate.h --- a/src/animate.h Fri Sep 26 17:56:08 2008 +0800 +++ b/src/animate.h Sat Sep 27 02:40:42 2008 +0800 @@ -42,7 +42,7 @@ const mb_timeval_t *playing); extern void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, mb_timeval_t *now); -extern void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman); +extern void mb_progm_abort(mb_progm_t *progm); extern subject_t *mb_progm_get_complete(mb_progm_t *progm); /*! \defgroup ani_actions Animation Actions