comparison include/mb_backend.h @ 1067:7b4e80ab671a openvg

merge from default branch
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 01 Dec 2010 12:25:56 +0800
parents e415c55b4a0d
children fa5f71d4aa04
comparison
equal deleted inserted replaced
630:bd18951b51d5 1067:7b4e80ab671a
1 #ifndef __MB_BACKEND_H_
2 #define __MB_BACKEND_H_
3
4 #include "mb_redraw_man.h"
5 #include "mb_timer.h"
6 #include "mb_observer.h"
7 #include "mb_img_ldr.h"
8
9 #include "mb_config.h"
10
11 #ifdef X_BACKEND
12 #include "mb_X_supp.h"
13 #endif
14
15 #ifdef DFB_BACKEND
16 #inclde "mb_dfb_supp.h"
17 #endif
18
19 struct _mb_rt;
20 typedef struct _mb_rt mb_rt_t;
21
22 struct _mb_timer_man;
23 struct _mb_timer_factory;
24 struct _mb_IO_man;
25 struct _mb_IO_factory;
26
27 /*! \brief Type of IO that registered with an IO manager.
28 */
29 enum _MB_IO_TYPE {MB_IO_DUMMY, MB_IO_R, MB_IO_W, MB_IO_RW};
30
31 typedef struct _mb_timer_man mb_timer_man_t;
32 typedef struct _mb_timer_factory mb_timer_factory_t;
33 typedef struct _mb_IO_man mb_IO_man_t;
34 typedef struct _mb_IO_factory mb_IO_factory_t;
35 typedef enum _MB_IO_TYPE MB_IO_TYPE;
36
37 /*! \brief Function signature of callback functions for IO requests.
38 */
39 typedef void (*mb_IO_cb_t)(int hdl, int fd, MB_IO_TYPE type, void *data);
40
41 /*! \brief The backend engine mb_backend_t is used to define the
42 * interface to realize the MB.
43 *
44 * A backend is used to receive events from the system. The MB does
45 * not define the backend by itself. Instead, it define an interface
46 * which allow the lower layer to implement the event system. Each
47 * backend need to provides the following events.
48 *
49 * - keyboard event
50 * - timer event
51 * - image loader(?)
52 * - render manager(?)
53 */
54 typedef struct {
55 mb_rt_t *(*rt_new)(const char *display, int w,int h);
56 mb_rt_t *(*rt_new_with_win)(MB_DISPLAY display, MB_WINDOW win);
57
58 void (*rt_free)(mb_rt_t *rt);
59 void (*rt_free_keep_win)(mb_rt_t *rt);
60 /*! \brief Request the backend to start monitoring a file descriptor.
61 *
62 * This is used only when the backend is responsible for event loop.
63 */
64 int (*add_event)(mb_rt_t *rt, int fd, MB_IO_TYPE type,
65 mb_IO_cb_t f,void *arg);
66 /*! \brief Request the backend to stop monitoring a file descriptor.
67 *
68 * This is used only when the backend is responsible for event loop.
69 */
70 void (*remove_event)(mb_rt_t *rt, int hdl);
71 /*! \brief Event Loop
72 *
73 * This is called when main application does not handle event
74 * loop. Or, it should register an IO factory (i.e \ref
75 * mb_IO_factory_t) with the backend.
76 */
77 void (*event_loop)(mb_rt_t *rt);
78
79 /*! \brief Flush requests to screen server if existed */
80 int (*flush)(mb_rt_t *rt);
81
82 subject_t *(*kbevents)(mb_rt_t *rt);
83 redraw_man_t *(*rdman)(mb_rt_t *rt);
84 mb_timer_man_t *(*timer_man)(mb_rt_t *rt);
85 observer_factory_t *(*observer_factory)(mb_rt_t *rt);
86 mb_img_ldr_t *(*loader)(mb_rt_t *rt);
87
88 /*
89 * Following two methods are used to integrate a backend to
90 * event loop of main application.
91 */
92 void (*reg_IO_factory)(mb_IO_factory_t *io_man);
93 void (*reg_timer_factory)(mb_timer_factory_t *tm_man);
94 } mb_backend_t;
95
96 #define mb_runtime_new(disp, w, h) \
97 mb_dfl_backend.rt_new((disp), (w), (h))
98 #define mb_runtime_new_with_win(disp, win) \
99 mb_dfl_backend.rt_new_with_win((disp), (win))
100 #define mb_reg_IO_factory(io_fact) \
101 mb_dfl_backend.reg_IO_factory(io_fact)
102 #define mb_reg_timer_factory(tm_fact) \
103 mb_dfl_backend.reg_timer_factory(tm_fact)
104
105 /*
106 * This is defined by backend implementations. For example, X_supp.c
107 * or dfb_supp.c should defined a backend.
108 */
109 extern mb_backend_t mb_dfl_backend;
110
111 #define mb_runtime_free(rt) \
112 mb_dfl_backend.rt_free(rt)
113 #define mb_runtime_free_keep_win(rt) \
114 mb_dfl_backend.rt_free_keep_win(rt)
115 #define mb_runtime_add_event(rt, fd, type, cb, arg) \
116 mb_dfl_backend.add_event((rt), (fd), (type), (cb), (arg))
117 #define mb_runtime_remove_event(hdl) \
118 mb_dfl_backend.remove_event((rt), (hdl))
119 #define mb_runtime_event_loop(rt) \
120 mb_dfl_backend.event_loop(rt)
121 #define mb_runtime_flush(rt) \
122 mb_dfl_backend.flush(rt)
123 #define mb_runtime_kbevents(rt) \
124 mb_dfl_backend.kbevents(rt)
125 #define mb_runtime_rdman(rt) \
126 mb_dfl_backend.rdman(rt)
127 #define mb_runtime_timer_man(rt) \
128 mb_dfl_backend.timer_man(rt)
129 #define mb_runtime_observer_factory(rt) \
130 mb_dfl_backend.observer_factory(rt)
131 #define mb_runtime_loader(rt) \
132 mb_dfl_backend.loader(rt)
133
134
135 /*! \brief IO Manager
136 */
137 struct _mb_IO_man {
138 int (*reg)(struct _mb_IO_man *io_man,
139 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data);
140 void (*unreg)(struct _mb_IO_man *io_man,
141 int io_hdl);
142 };
143
144 /*! \brief Factory of IO managers.
145 */
146 struct _mb_IO_factory {
147 mb_IO_man_t *(*io_man_new)(void);
148 void (*io_man_free)(mb_IO_man_t *io_man);
149 };
150
151 #define mb_io_man_reg(io_man, fd, type, cb, data) \
152 (io_man)->reg(io_man, fd, type, cb, data)
153 #define mb_io_man_unreg(io_man, io_hdl) \
154 (io_man)->unreg(io_man, io_hdl)
155 #define mb_io_man_new(io_fact) (io_fact)->io_man_new()
156 #define mb_io_man_free(io_fact, io_man) (io_fact)->io_man_free(io_man)
157
158 /*! \brief Function signature of callback functions for timers.
159 */
160 typedef void (*mb_timer_cb_t)(int hdl,
161 const mb_timeval_t *tmo,
162 const mb_timeval_t *now,
163 void *data);
164
165 /*! \brief Timer manager
166 */
167 struct _mb_timer_man {
168 /*! \brief Setup a timeout callback.
169 *
170 * \return -1 for error.
171 */
172 int (*timeout)(struct _mb_timer_man *tm_man,
173 mb_timeval_t *tmout, /* tiemout (wall time) */
174 mb_timer_cb_t cb, void *data);
175 /*! \brief Remove a timeout request.
176 *
177 * \param tm_hdl is the handle returned by _mb_timer_man::timeout.
178 */
179 void (*remove)(struct _mb_timer_man *tm_man, int tm_hdl);
180 };
181
182 /*! \brief Factory of timer manager.
183 */
184 struct _mb_timer_factory {
185 mb_timer_man_t *(*timer_man_new)(void);
186 void (*timer_man_free)(mb_timer_man_t *timer_man);
187 };
188
189 #define mb_timer_man_timeout(tm_man, tmout, cb, data) \
190 (tm_man)->timeout((tm_man), (tmout), (cb), (data))
191 #define mb_timer_man_remove(tm_man, tm_hdl) \
192 (tm_man)->remove((tm_man), (tm_hdl))
193 #define mb_timer_man_new(tm_fact) (tm_fact)->timer_man_new()
194 #define mb_timer_man_free(tm_fact, tm_man) (tm_fact)->timer_man_free(tm_man)
195
196 #endif /* __MB_BACKEND_H_ */