comparison include/mb_backend.h @ 984:3fe8054457a8 refine_backend_if

Change interface of mb_backend_t for more concise
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 22 Nov 2010 00:42:29 +0800
parents
children bab9c0f836b9
comparison
equal deleted inserted replaced
970:a1ebbe11354d 984:3fe8054457a8
1 #ifndef __MB_BACKEND_H_
2 #define __MB_BACKEND_H_
3
4 #ifdef X_BACKEND
5 #include "mb_X_supp.h"
6 #endif
7
8 #ifdef DFB_BACKEND
9 #inclde "mb_dfb_supp.h"
10 #endif
11
12 typedef void *MBB_WINDOW;
13 typedef void mb_rt_t;
14
15 /*! \brief The backend engine mb_backend_t is used to define the
16 * interface to realize the MB.
17 *
18 * A backend is used to receive events from the system. The MB does
19 * not define the backend by itself. Instead, it define an interface
20 * which allow the lower layer to implement the event system. Each
21 * backend need to provides the following events.
22 *
23 * - keyboard event
24 * - timer event
25 * - image loader(?)
26 * - render manager(?)
27 */
28 typedef struct {
29 mb_rt_t *(*new)(const char *display, int w,int h);
30 mb_rt_t *(*new_with_win)(const char *display, MBB_WINDOW win, int w,int h);
31
32 void (*free)(mb_rt_t *rt);
33 void (*add_event)(mb_rt_t *rt,int type, int fd, mb_eventcb_t f,void *arg);
34 void (*remove_event)(mb_rt_t *rt,int type, int fd);
35 void (*loop)(mb_rt_t *rt);
36
37 subject_t *(*kbevents)(mb_rt_t *rt);
38 redraw_man_t *(*rdman)(mb_rt_t *rt);
39 mb_timer_man_t *(*tman)(mb_rt_t *rt);
40 ob_factory_t *(*ob_factory)(mb_rt_t *rt);
41 mb_img_ldr_t *(*loader)(mb_rt_t *rt);
42
43 /*
44 * Following two methods are used to integrate a backend to
45 * event loop of main application.
46 */
47 void (*reg_IO_factory)(mb_IO_factory_t *evman);
48 void (*reg_timer_factory)(mb_timer_factory_t *evman);
49 } mb_backend_t;
50
51 extern mb_backend_t backend;
52
53 /*! \brief Type of IO that registered with an IO manager.
54 */
55 enum MB_IO_TYPE {MB_IO_R, MB_IO_W, MB_IO_RW};
56
57 /*! \brief Function signature of callback functions for IO requests.
58 */
59 typedef void (*mb_IO_cb_t)(int fd, MB_IO_TYPE type, void *data);
60
61 /*! \brief IO Manager
62 */
63 struct _mb_IO_man {
64 int (*reg)(struct _mb_IO_man *io_man,
65 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data);
66 void (*unreg)(struct _mb_IO_Man *io_man,
67 int io_hdl);
68 };
69 typedef struct _mb_IO_man mb_IO_man_t;
70
71 /*! \brief Factory of IO managers.
72 */
73 struct _mb_IO_factory {
74 mb_IO_man_t *(*new)(void);
75 void (*free)(mb_IO_man_t *io_man);
76 };
77 typedef struct _mb_IO_factory mb_IO_factory_t;
78
79 /*! \brief Function signature of callback functions for timers.
80 */
81 typedef void (*mb_timer_cb_t)(mbsec_t sec, mbusec_t usec, void *data);
82
83 /*! \brief Timer manager
84 */
85 struct _mb_timer_man {
86 int (*timeout)(struct _mb_timer_man *tm_man,
87 mbsec_t sec, mbusec_t usec, mb_timer_cb_t cb, void *data);
88 /*! \brief Remove a timeout request.
89 *
90 * \param tm_hdl is the handle returned by _mb_timer_man::timeout.
91 */
92 void (*remove)(struct _mb_timer_man *tm_man, int tm_hdl);
93 } mb_timer_man_t;
94
95 /*! \brief Factory of timer manager.
96 */
97 struct _mb_timer_factory {
98 mb_timer_man_t *(*new)(void);
99 void (*free)(mb_timer_man_t *timer_man);
100 };
101 typedef struct _mb_timer_factory mb_timer_factory_t;
102
103 #endif /* __MB_BACKEND_H_ */