Mercurial > MadButterfly
annotate include/mb_backend.h @ 1005:714169f33f13 refine_backend_if
Fix X_init_connection() to match modification of mb_backend_t
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 22 Nov 2010 00:42:30 +0800 |
parents | 734ba9161be4 |
children | 595a06fc0157 |
rev | line source |
---|---|
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1 #ifndef __MB_BACKEND_H_ |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
2 #define __MB_BACKEND_H_ |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
3 |
991
1882700bb4b9
Adapt mb_tman_t to mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents:
990
diff
changeset
|
4 #include "mb_redraw_man.h" |
1882700bb4b9
Adapt mb_tman_t to mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents:
990
diff
changeset
|
5 #include "mb_timer.h" |
1882700bb4b9
Adapt mb_tman_t to mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents:
990
diff
changeset
|
6 #include "mb_observer.h" |
1882700bb4b9
Adapt mb_tman_t to mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents:
990
diff
changeset
|
7 #include "mb_img_ldr.h" |
1882700bb4b9
Adapt mb_tman_t to mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents:
990
diff
changeset
|
8 |
985 | 9 #include "mb_config.h" |
10 | |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
11 #ifdef X_BACKEND |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
12 #include "mb_X_supp.h" |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
13 #endif |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
14 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
15 #ifdef DFB_BACKEND |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
16 #inclde "mb_dfb_supp.h" |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
17 #endif |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
18 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
19 typedef void mb_rt_t; |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
20 |
993
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
21 typedef struct _mb_timer_man mb_timer_man_t; |
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
22 typedef struct _mb_timer_factory mb_timer_factory_t; |
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
23 typedef struct _mb_IO_man mb_IO_man_t; |
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
24 typedef struct _mb_IO_factory mb_IO_factory_t; |
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
25 |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
26 /*! \brief The backend engine mb_backend_t is used to define the |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
27 * interface to realize the MB. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
28 * |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
29 * A backend is used to receive events from the system. The MB does |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
30 * not define the backend by itself. Instead, it define an interface |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
31 * which allow the lower layer to implement the event system. Each |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
32 * backend need to provides the following events. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
33 * |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
34 * - keyboard event |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
35 * - timer event |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
36 * - image loader(?) |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
37 * - render manager(?) |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
38 */ |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
39 typedef struct { |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
40 mb_rt_t *(*new)(const char *display, int w,int h); |
993
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
41 mb_rt_t *(*new_with_win)(const char *display, MB_WINDOW win, int w,int h); |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
42 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
43 void (*free)(mb_rt_t *rt); |
985 | 44 /*! \brief Request the backend to start monitoring a file descriptor. |
45 * | |
46 * This is used only when the backend is responsible for event loop. | |
47 */ | |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
48 void (*add_event)(mb_rt_t *rt,int type, int fd, mb_eventcb_t f,void *arg); |
985 | 49 /*! \brief Request the backend to stop monitoring a file descriptor. |
50 * | |
51 * This is used only when the backend is responsible for event loop. | |
52 */ | |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
53 void (*remove_event)(mb_rt_t *rt,int type, int fd); |
985 | 54 /*! \brief Event Loop |
55 * | |
56 * This is called when main application does not handle event | |
57 * loop. Or, it should register an IO factory (i.e \ref | |
58 * mb_IO_factory_t) with the backend. | |
59 */ | |
60 void (*event_loop)(mb_rt_t *rt); | |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
61 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
62 subject_t *(*kbevents)(mb_rt_t *rt); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
63 redraw_man_t *(*rdman)(mb_rt_t *rt); |
994
5d9def42df12
Rename mb_backend_t::tman() to mb_backend_t::timer_man()
Thinker K.F. Li <thinker@codemud.net>
parents:
993
diff
changeset
|
64 mb_timer_man_t *(*timer_man)(mb_rt_t *rt); |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
65 ob_factory_t *(*ob_factory)(mb_rt_t *rt); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
66 mb_img_ldr_t *(*loader)(mb_rt_t *rt); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
67 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
68 /* |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
69 * Following two methods are used to integrate a backend to |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
70 * event loop of main application. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
71 */ |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
72 void (*reg_IO_factory)(mb_IO_factory_t *evman); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
73 void (*reg_timer_factory)(mb_timer_factory_t *evman); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
74 } mb_backend_t; |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
75 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
76 extern mb_backend_t backend; |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
77 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
78 /*! \brief Type of IO that registered with an IO manager. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
79 */ |
993
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
80 enum _MB_IO_TYPE {MB_IO_DUMMY, MB_IO_R, MB_IO_W, MB_IO_RW}; |
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
81 typedef enum _MB_IO_TYPE MB_IO_TYPE; |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
82 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
83 /*! \brief Function signature of callback functions for IO requests. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
84 */ |
990
8dd42310dd79
Change signature of callback for IO and timer manager
Thinker K.F. Li <thinker@codemud.net>
parents:
986
diff
changeset
|
85 typedef void (*mb_IO_cb_t)(int hdl, int fd, MB_IO_TYPE type, void *data); |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
86 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
87 /*! \brief IO Manager |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
88 */ |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
89 struct _mb_IO_man { |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
90 int (*reg)(struct _mb_IO_man *io_man, |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
91 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data); |
993
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
92 void (*unreg)(struct _mb_IO_man *io_man, |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
93 int io_hdl); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
94 }; |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
95 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
96 /*! \brief Factory of IO managers. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
97 */ |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
98 struct _mb_IO_factory { |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
99 mb_IO_man_t *(*new)(void); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
100 void (*free)(mb_IO_man_t *io_man); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
101 }; |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
102 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
103 /*! \brief Function signature of callback functions for timers. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
104 */ |
996
734ba9161be4
Change signature to make const for arguments of mb_timer_cb_t
Thinker K.F. Li <thinker@codemud.net>
parents:
994
diff
changeset
|
105 typedef void (*mb_timer_cb_t)(int hdl, |
734ba9161be4
Change signature to make const for arguments of mb_timer_cb_t
Thinker K.F. Li <thinker@codemud.net>
parents:
994
diff
changeset
|
106 const mb_timeval_t *tmo, |
734ba9161be4
Change signature to make const for arguments of mb_timer_cb_t
Thinker K.F. Li <thinker@codemud.net>
parents:
994
diff
changeset
|
107 const mb_timeval_t *now, |
991
1882700bb4b9
Adapt mb_tman_t to mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents:
990
diff
changeset
|
108 void *data); |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
109 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
110 /*! \brief Timer manager |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
111 */ |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
112 struct _mb_timer_man { |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
113 int (*timeout)(struct _mb_timer_man *tm_man, |
991
1882700bb4b9
Adapt mb_tman_t to mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents:
990
diff
changeset
|
114 mb_timeval_t *tmout, /* tiemout (wall time) */ |
1882700bb4b9
Adapt mb_tman_t to mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents:
990
diff
changeset
|
115 mb_timer_cb_t cb, void *data); |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
116 /*! \brief Remove a timeout request. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
117 * |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
118 * \param tm_hdl is the handle returned by _mb_timer_man::timeout. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
119 */ |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
120 void (*remove)(struct _mb_timer_man *tm_man, int tm_hdl); |
993
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
991
diff
changeset
|
121 }; |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
122 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
123 /*! \brief Factory of timer manager. |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
124 */ |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
125 struct _mb_timer_factory { |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
126 mb_timer_man_t *(*new)(void); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
127 void (*free)(mb_timer_man_t *timer_man); |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
128 }; |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
129 |
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
130 #endif /* __MB_BACKEND_H_ */ |