comparison include/mb_observer.h @ 192:54fdc2a65242

Remove factory from observer APIs. - Save factory that used to new a subject as subject's attribute. - Get factory from subject himself instead of passing as an argument. - It make API of observer more simple and clean.
author Thinker K.F. Li <thinker@branda.to>
date Tue, 18 Nov 2008 21:42:30 +0800
parents 530bb7728546
children f9d507a3e1d9
comparison
equal deleted inserted replaced
191:18f8c3126cdb 192:54fdc2a65242
33 */ 33 */
34 struct _subject { 34 struct _subject {
35 int obj_type; /*!< \brief type of object (a.k.a. OBJT_*). */ 35 int obj_type; /*!< \brief type of object (a.k.a. OBJT_*). */
36 void *obj; /*!< \brief the object this subject for. */ 36 void *obj; /*!< \brief the object this subject for. */
37 int flags; 37 int flags;
38 ob_factory_t *factory;
38 STAILQ(observer_t) observers; 39 STAILQ(observer_t) observers;
39 }; 40 };
40 /*! \brief Flag that make a subject to propagate events to parents. */ 41 /*! \brief Flag that make a subject to propagate events to parents. */
41 #define SUBF_STOP_PROPAGATE 0x1 42 #define SUBF_STOP_PROPAGATE 0x1
42 #define SUBF_BUSY 0x2 /*!< \brief in subject_notify() */ 43 #define SUBF_BUSY 0x2 /*!< \brief in subject_notify() */
75 EVT_KB_PRESS, EVT_KB_RELEASE, EVT_PROGM_COMPLETE, 76 EVT_KB_PRESS, EVT_KB_RELEASE, EVT_PROGM_COMPLETE,
76 EVT_RDMAN_REDRAW }; 77 EVT_RDMAN_REDRAW };
77 78
78 extern subject_t *subject_new(ob_factory_t *factory, 79 extern subject_t *subject_new(ob_factory_t *factory,
79 void *obj, int obj_type); 80 void *obj, int obj_type);
80 extern void subject_free(ob_factory_t *factory, subject_t *subject); 81 extern void subject_free(subject_t *subject);
81 extern void subject_notify(ob_factory_t *factory, 82 extern void subject_notify(subject_t *subject, event_t *evt);
82 subject_t *subject, event_t *evt); 83 extern observer_t *subject_add_observer(subject_t *subject,
83 extern observer_t *subject_add_observer(ob_factory_t *factory,
84 subject_t *subject,
85 evt_handler hdr, void *arg); 84 evt_handler hdr, void *arg);
86 extern void subject_remove_observer(ob_factory_t *factory, 85 extern void subject_remove_observer(subject_t *subject,
87 subject_t *subject,
88 observer_t *observer); 86 observer_t *observer);
89 87
90 88
91 #endif /* __OBSERVER_H_ */ 89 #endif /* __OBSERVER_H_ */