Mercurial > MadButterfly
changeset 1060:e415c55b4a0d
Stop using ob as acronym observer
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sun, 28 Nov 2010 12:59:05 +0800 |
parents | 36aef79d68e4 |
children | 5f38974372db |
files | examples/tank/tank_main.c include/mb_backend.h include/mb_dfb_supp.h include/mb_observer.h include/mb_redraw_man.h nodejs/njs_mb_supp.h src/X_supp.c src/animate.c src/dfb_supp.c src/observer.c src/redraw_man.c |
diffstat | 11 files changed, 83 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/tank/tank_main.c Sun Nov 28 12:07:37 2010 +0800 +++ b/examples/tank/tank_main.c Sun Nov 28 12:59:05 2010 +0800 @@ -58,7 +58,7 @@ int direction; mb_progm_t *progm; mb_timeval_t start_time; - observer_t *ob_redraw; + observer_t *observer_redraw; int hit_tmr; mb_timer_man_t *timer_man; }; @@ -170,7 +170,7 @@ mb_rt_t *mb_rt = tank_rt->mb_rt; redraw_man_t *rdman; mb_timer_man_t *timer_man; - ob_factory_t *factory; + observer_factory_t *factory; /* for the program */ mb_progm_t *progm; subject_t *comp_sub; @@ -238,7 +238,7 @@ rdman = mb_runtime_rdman(mb_rt); timer_man = mb_runtime_timer_man(mb_rt); - factory = mb_runtime_ob_factory(mb_rt); + factory = mb_runtime_observer_factory(mb_rt); progm = mb_progm_new(1, rdman); tank->progm = progm;
--- a/include/mb_backend.h Sun Nov 28 12:07:37 2010 +0800 +++ b/include/mb_backend.h Sun Nov 28 12:59:05 2010 +0800 @@ -82,7 +82,7 @@ subject_t *(*kbevents)(mb_rt_t *rt); redraw_man_t *(*rdman)(mb_rt_t *rt); mb_timer_man_t *(*timer_man)(mb_rt_t *rt); - ob_factory_t *(*ob_factory)(mb_rt_t *rt); + observer_factory_t *(*observer_factory)(mb_rt_t *rt); mb_img_ldr_t *(*loader)(mb_rt_t *rt); /* @@ -126,8 +126,8 @@ mb_dfl_backend.rdman(rt) #define mb_runtime_timer_man(rt) \ mb_dfl_backend.timer_man(rt) -#define mb_runtime_ob_factory(rt) \ - mb_dfl_backend.ob_factory(rt) +#define mb_runtime_observer_factory(rt) \ + mb_dfl_backend.observer_factory(rt) #define mb_runtime_loader(rt) \ mb_dfl_backend.loader(rt)
--- a/include/mb_dfb_supp.h Sun Nov 28 12:07:37 2010 +0800 +++ b/include/mb_dfb_supp.h Sun Nov 28 12:59:05 2010 +0800 @@ -32,7 +32,7 @@ extern subject_t *X_MB_kbevents(void *xmb_rt); extern redraw_man_t *X_MB_rdman(void *xmb_rt); extern mb_tman_t *X_MB_tman(void *xmb_rt); -extern ob_factory_t *X_MB_ob_factory(void *xmb_rt); +extern observer_factory_t *X_MB_observer_factory(void *xmb_rt); extern mb_img_ldr_t *X_MB_img_ldr(void *xmb_rt); #endif
--- a/include/mb_observer.h Sun Nov 28 12:07:37 2010 +0800 +++ b/include/mb_observer.h Sun Nov 28 12:59:05 2010 +0800 @@ -10,7 +10,7 @@ typedef struct _subject subject_t; typedef struct _mouse_event mouse_event_t; typedef struct _monitor_event monitor_event_t; -typedef struct _ob_factory ob_factory_t; +typedef struct _observer_factory observer_factory_t; typedef void (*evt_handler)(event_t *event, void *arg); struct _event { @@ -55,7 +55,7 @@ int flags; subject_t *monitor_sub; /*!< \brief Monitor adding/removing * obervers on this subject. */ - ob_factory_t *factory; + observer_factory_t *factory; STAILQ(observer_t) observers; }; /*! \brief Flag that make a subject to stop propagate events to parents. */ @@ -87,13 +87,13 @@ * It provides functions for allocation of subject and observer objects, * and strategy function for getting the subject of parent coord object. */ -struct _ob_factory { - subject_t *(*subject_alloc)(ob_factory_t *factory); - void (*subject_free)(ob_factory_t *factory, subject_t *subject); - observer_t *(*observer_alloc)(ob_factory_t *factory); - void (*observer_free)(ob_factory_t *factory, observer_t *observer); +struct _observer_factory { + subject_t *(*subject_alloc)(observer_factory_t *factory); + void (*subject_free)(observer_factory_t *factory, subject_t *subject); + observer_t *(*observer_alloc)(observer_factory_t *factory); + void (*observer_free)(observer_factory_t *factory, observer_t *observer); /*! This is a strategy function to get subjects of parents. */ - subject_t *(*get_parent_subject)(ob_factory_t *factory, + subject_t *(*get_parent_subject)(observer_factory_t *factory, subject_t *cur_subject); }; @@ -105,7 +105,7 @@ EVT_MOUSE_MOVE_RAW }; -extern subject_t *subject_new(ob_factory_t *factory, +extern subject_t *subject_new(observer_factory_t *factory, void *obj, int obj_type); extern void subject_free(subject_t *subject); extern void subject_notify(subject_t *subject, event_t *evt);
--- a/include/mb_redraw_man.h Sun Nov 28 12:07:37 2010 +0800 +++ b/include/mb_redraw_man.h Sun Nov 28 12:59:05 2010 +0800 @@ -82,7 +82,7 @@ mbe_t *cr; mbe_t *backend; - ob_factory_t ob_factory; + observer_factory_t observer_factory; subject_t *redraw; /*!< \brief Notified after redrawing. */ subject_t *addrm_monitor; /*!< \brief Monitor adding/removing observers @@ -217,7 +217,7 @@ /*! \defgroup rdman_accessors Accessors of Redraw Manager * @{ */ -#define rdman_get_ob_factory(rdman) (&(rdman)->ob_factory) +#define rdman_get_observer_factory(rdman) (&(rdman)->observer_factory) #define rdman_get_redraw_subject(rdman) ((rdman)->redraw) #define rdman_get_root(rdman) ((rdman)->root_coord) #define rdman_get_cr(rdman) ((rdman)->cr)
--- a/nodejs/njs_mb_supp.h Sun Nov 28 12:07:37 2010 +0800 +++ b/nodejs/njs_mb_supp.h Sun Nov 28 12:59:05 2010 +0800 @@ -25,7 +25,7 @@ #define njs_mb_kbevents(rt) mb_runtime_kbevents((rt)->mb_rt) #define njs_mb_rdman(rt) mb_runtime_rdman((rt)->mb_rt) #define njs_mb_timer_man(rt) mb_runtime_timer_man((rt)->mb_rt) -#define njs_mb_ob_factory(rt) mb_runtime_ob_factory((rt)->mb_rt) +#define njs_mb_observer_factory(rt) mb_runtime_observer_factory((rt)->mb_rt) #define njs_mb_img_ldr(rt) mb_runtime_img_ldr((rt)->mb_rt) #endif /* __NJS_MB_SUPP_H_ */
--- a/src/X_supp.c Sun Nov 28 12:07:37 2010 +0800 +++ b/src/X_supp.c Sun Nov 28 12:59:05 2010 +0800 @@ -39,7 +39,7 @@ int ksym_per_code; KeySym *syms; subject_t *kbevents; - ob_factory_t *ob_factory; + observer_factory_t *observer_factory; }; /* @} */ @@ -286,7 +286,7 @@ static int X_kb_init(X_kb_info_t *kbinfo, Display *display, redraw_man_t *rdman) { int n_syms; - ob_factory_t *factory; + observer_factory_t *factory; int r; r = XDisplayKeycodes(display, @@ -302,12 +302,12 @@ if(kbinfo->syms == NULL) return ERR; - factory = rdman_get_ob_factory(rdman); + factory = rdman_get_observer_factory(rdman); kbinfo->kbevents = subject_new(factory, kbinfo, OBJT_KB); if(kbinfo->kbevents == NULL) return ERR; - /*! \todo Make sure ob_factory is still need. */ - kbinfo->ob_factory = factory; + /*! \todo Make sure observer_factory is still need. */ + kbinfo->observer_factory = factory; return OK; } @@ -1011,12 +1011,12 @@ return xmb_rt->timer_man; } -static ob_factory_t * -_x_supp_ob_factory(mb_rt_t *rt) { +static observer_factory_t * +_x_supp_observer_factory(mb_rt_t *rt) { X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *) rt; - ob_factory_t *factory; + observer_factory_t *factory; - factory = rdman_get_ob_factory(xmb_rt->rdman); + factory = rdman_get_observer_factory(xmb_rt->rdman); return factory; } @@ -1086,7 +1086,7 @@ _x_supp_kbevents, _x_supp_rdman, _x_supp_timer_man, - _x_supp_ob_factory, + _x_supp_observer_factory, _x_supp_img_ldr, _x_supp_reg_IO_factory,
--- a/src/animate.c Sun Nov 28 12:07:37 2010 +0800 +++ b/src/animate.c Sun Nov 28 12:59:05 2010 +0800 @@ -115,7 +115,7 @@ mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) { mb_progm_t *progm; #ifndef UNITTEST - ob_factory_t *factory; + observer_factory_t *factory; #endif /* UNITTEST */ int i; @@ -127,7 +127,7 @@ progm->rdman = rdman; #ifndef UNITTEST - factory = rdman_get_ob_factory(rdman); + factory = rdman_get_observer_factory(rdman); progm->complete = subject_new(factory, progm, OBJT_PROGM); if(progm->complete == NULL) { free(progm);
--- a/src/dfb_supp.c Sun Nov 28 12:07:37 2010 +0800 +++ b/src/dfb_supp.c Sun Nov 28 12:59:05 2010 +0800 @@ -24,7 +24,7 @@ int keycode_min, keycode_max; int ksym_per_code; subject_t *kbevents; - ob_factory_t *ob_factory; + observer_factory_t *observer_factory; }; /* @} */ @@ -458,11 +458,11 @@ return xmb_rt->tman; } -ob_factory_t *X_MB_ob_factory(void *rt) { +observer_factory_t *X_MB_observer_factory(void *rt) { X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt; - ob_factory_t *factory; + observer_factory_t *factory; - factory = rdman_get_ob_factory(xmb_rt->rdman); + factory = rdman_get_observer_factory(xmb_rt->rdman); return factory; } @@ -525,7 +525,7 @@ X_MB_kbevents, X_MB_rdman, X_MB_tman, - X_MB_ob_factory, + X_MB_observer_factory, X_MB_img_ldr };
--- a/src/observer.c Sun Nov 28 12:07:37 2010 +0800 +++ b/src/observer.c Sun Nov 28 12:59:05 2010 +0800 @@ -9,7 +9,7 @@ #define ASSERT(x) #endif -subject_t *subject_new(ob_factory_t *factory, void *obj, int obj_type) { +subject_t *subject_new(observer_factory_t *factory, void *obj, int obj_type) { subject_t *subject; subject = factory->subject_alloc(factory); @@ -28,10 +28,10 @@ } /*! - * \todo Keep ob_factory following subject objects. + * \todo Keep observer_factory following subject objects. */ void subject_free(subject_t *subject) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; observer_t *observer; monitor_event_t mevt; @@ -60,7 +60,7 @@ void subject_notify(subject_t *subject, event_t *evt) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; observer_t *observer; subject_t *old_subject; int stop_propagate = 0; @@ -114,7 +114,7 @@ */ observer_t *subject_add_event_observer(subject_t *subject, int type, evt_handler hdr, void *arg) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; observer_t *observer; monitor_event_t mevt; @@ -141,7 +141,7 @@ */ observer_t *subject_add_event_observer_head(subject_t *subject, int type, evt_handler hdr, void *arg) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; observer_t *observer; monitor_event_t mevt; @@ -166,7 +166,7 @@ void subject_remove_observer(subject_t *subject, observer_t *observer) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; monitor_event_t mevt; STAILQ_REMOVE(subject->observers, observer_t, next, observer); @@ -186,34 +186,36 @@ #include <CUnit/Basic.h> #include <stdlib.h> -static subject_t *test_subject_alloc(ob_factory_t *factory) { +static subject_t *test_subject_alloc(observer_factory_t *factory) { subject_t *subject; subject = (subject_t *)malloc(sizeof(subject_t)); return subject; } -static void test_subject_free(ob_factory_t *factory, subject_t *subject) { +static void +test_subject_free(observer_factory_t *factory, subject_t *subject) { free(subject); } -static observer_t *test_observer_alloc(ob_factory_t *factory) { +static observer_t *test_observer_alloc(observer_factory_t *factory) { observer_t *observer; observer = (observer_t *)malloc(sizeof(observer_t)); return observer; } -static void test_observer_free(ob_factory_t *factory, observer_t *observer) { +static void +test_observer_free(observer_factory_t *factory, observer_t *observer) { free(observer); } -static subject_t *test_get_parent_subject(ob_factory_t *factory, +static subject_t *test_get_parent_subject(observer_factory_t *factory, subject_t *subject) { return NULL; } -static ob_factory_t test_factory = { +static observer_factory_t test_factory = { test_subject_alloc, test_subject_free, test_observer_alloc,
--- a/src/redraw_man.c Sun Nov 28 12:07:37 2010 +0800 +++ b/src/redraw_man.c Sun Nov 28 12:59:05 2010 +0800 @@ -370,12 +370,14 @@ extern void sh_dummy_fill(shape_t *, mbe_t *); #endif /* UNITTEST */ -static subject_t *ob_subject_alloc(ob_factory_t *factory); -static void ob_subject_free(ob_factory_t *factory, subject_t *subject); -static observer_t *ob_observer_alloc(ob_factory_t *factory); -static void ob_observer_free(ob_factory_t *factory, observer_t *observer); -static subject_t *ob_get_parent_subject(ob_factory_t *factory, - subject_t *cur_subject); +static subject_t *observer_subject_alloc(observer_factory_t *factory); +static void observer_subject_free(observer_factory_t *factory, + subject_t *subject); +static observer_t *observer_observer_alloc(observer_factory_t *factory); +static void observer_observer_free(observer_factory_t *factory, + observer_t *observer); +static subject_t *observer_get_parent_subject(observer_factory_t *factory, + subject_t *cur_subject); /* Functions for children. */ #define FORCHILDREN(coord, child) \ for((child) = STAILQ_HEAD((coord)->children); \ @@ -710,16 +712,16 @@ rdman->paint_color_pool && rdman->coord_canvas_pool)) goto err; - rdman->ob_factory.subject_alloc = ob_subject_alloc; - rdman->ob_factory.subject_free = ob_subject_free; - rdman->ob_factory.observer_alloc = ob_observer_alloc; - rdman->ob_factory.observer_free = ob_observer_free; - rdman->ob_factory.get_parent_subject = ob_get_parent_subject; + rdman->observer_factory.subject_alloc = observer_subject_alloc; + rdman->observer_factory.subject_free = observer_subject_free; + rdman->observer_factory.observer_alloc = observer_observer_alloc; + rdman->observer_factory.observer_free = observer_observer_free; + rdman->observer_factory.get_parent_subject = observer_get_parent_subject; rdman->redraw = - subject_new(&rdman->ob_factory, rdman, OBJT_RDMAN); + subject_new(&rdman->observer_factory, rdman, OBJT_RDMAN); rdman->addrm_monitor = - subject_new(&rdman->ob_factory, rdman, OBJT_RDMAN); + subject_new(&rdman->observer_factory, rdman, OBJT_RDMAN); if(!(rdman->redraw && rdman->addrm_monitor)) goto err; @@ -736,7 +738,7 @@ rdman->n_coords = 1; coord_init(rdman->root_coord, NULL); mb_prop_store_init(&rdman->root_coord->obj.props, rdman->pent_pool); - rdman->root_coord->mouse_event = subject_new(&rdman->ob_factory, + rdman->root_coord->mouse_event = subject_new(&rdman->observer_factory, rdman->root_coord, OBJT_COORD); coord_set_flags(rdman->root_coord, COF_OWN_CANVAS); @@ -886,7 +888,7 @@ return ERR; geo_init(geo); - geo->mouse_event = subject_new(&rdman->ob_factory, geo, OBJT_GEO); + geo->mouse_event = subject_new(&rdman->observer_factory, geo, OBJT_GEO); subject_set_monitor(geo->mouse_event, rdman->addrm_monitor); geo_attach_coord(geo, coord); @@ -1034,7 +1036,7 @@ coord_init(coord, parent); mb_prop_store_init(&coord->obj.props, rdman->pent_pool); - coord->mouse_event = subject_new(&rdman->ob_factory, + coord->mouse_event = subject_new(&rdman->observer_factory, coord, OBJT_COORD); subject_set_monitor(coord->mouse_event, rdman->addrm_monitor); @@ -2619,48 +2621,51 @@ * Implment factory and strategy functions for observers and subjects. * @{ */ -static subject_t *ob_subject_alloc(ob_factory_t *factory) { +static subject_t *observer_subject_alloc(observer_factory_t *factory) { redraw_man_t *rdman; subject_t *subject; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); subject = elmpool_elm_alloc(rdman->subject_pool); return subject; } -static void ob_subject_free(ob_factory_t *factory, subject_t *subject) { +static void +observer_subject_free(observer_factory_t *factory, subject_t *subject) { redraw_man_t *rdman; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); elmpool_elm_free(rdman->subject_pool, subject); } -static observer_t *ob_observer_alloc(ob_factory_t *factory) { +static observer_t *observer_observer_alloc(observer_factory_t *factory) { redraw_man_t *rdman; observer_t *observer; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); observer = elmpool_elm_alloc(rdman->observer_pool); return observer; } -static void ob_observer_free(ob_factory_t *factory, observer_t *observer) { +static void +observer_observer_free(observer_factory_t *factory, observer_t *observer) { redraw_man_t *rdman; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); elmpool_elm_free(rdman->observer_pool, observer); } -static subject_t *ob_get_parent_subject(ob_factory_t *factory, - subject_t *cur_subject) { +static subject_t * +observer_get_parent_subject(observer_factory_t *factory, + subject_t *cur_subject) { redraw_man_t *rdman; coord_t *coord, *parent_coord; geo_t *geo; subject_t *parent; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); switch(cur_subject->obj_type) { case OBJT_GEO: geo = (geo_t *)cur_subject->obj;