annotate 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
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
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
4 #ifdef X_BACKEND
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
5 #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
6 #endif
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
7
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
8 #ifdef DFB_BACKEND
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
9 #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
10 #endif
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
11
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
12 typedef void *MBB_WINDOW;
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13 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
14
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15 /*! \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
16 * 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
17 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
18 * 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
19 * 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
20 * 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
21 * 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
22 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23 * - keyboard event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
24 * - timer event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
25 * - image loader(?)
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
26 * - render manager(?)
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
27 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
28 typedef struct {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
29 mb_rt_t *(*new)(const char *display, int w,int h);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
30 mb_rt_t *(*new_with_win)(const char *display, MBB_WINDOW win, int w,int h);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
31
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
32 void (*free)(mb_rt_t *rt);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
33 void (*add_event)(mb_rt_t *rt,int type, int fd, mb_eventcb_t f,void *arg);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
34 void (*remove_event)(mb_rt_t *rt,int type, int fd);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
35 void (*loop)(mb_rt_t *rt);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
36
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
37 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
38 redraw_man_t *(*rdman)(mb_rt_t *rt);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
39 mb_timer_man_t *(*tman)(mb_rt_t *rt);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
40 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
41 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
42
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
43 /*
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
44 * 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
45 * 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
46 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
47 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
48 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
49 } mb_backend_t;
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
50
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
51 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
52
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
53 /*! \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
54 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
55 enum MB_IO_TYPE {MB_IO_R, MB_IO_W, MB_IO_RW};
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
56
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
57 /*! \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
58 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
59 typedef void (*mb_IO_cb_t)(int fd, MB_IO_TYPE type, void *data);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
60
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
61 /*! \brief IO Manager
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
62 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
63 struct _mb_IO_man {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
64 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
65 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
66 void (*unreg)(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
67 int io_hdl);
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 typedef struct _mb_IO_man mb_IO_man_t;
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
70
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
71 /*! \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
72 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
73 struct _mb_IO_factory {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
74 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
75 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
76 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
77 typedef struct _mb_IO_factory mb_IO_factory_t;
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
78
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
79 /*! \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
80 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
81 typedef void (*mb_timer_cb_t)(mbsec_t sec, mbusec_t usec, void *data);
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 Timer manager
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
84 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
85 struct _mb_timer_man {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
86 int (*timeout)(struct _mb_timer_man *tm_man,
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
87 mbsec_t sec, mbusec_t usec, mb_timer_cb_t cb, void *data);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
88 /*! \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
89 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
90 * \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
91 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
92 void (*remove)(struct _mb_timer_man *tm_man, int tm_hdl);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
93 } mb_timer_man_t;
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 /*! \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
96 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
97 struct _mb_timer_factory {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
98 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
99 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
100 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
101 typedef struct _mb_timer_factory mb_timer_factory_t;
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 #endif /* __MB_BACKEND_H_ */