annotate include/mb_backend.h @ 985:bab9c0f836b9 refine_backend_if

doc backend
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 22 Nov 2010 00:42:29 +0800
parents 3fe8054457a8
children c39d14139ca5
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
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
4 #include "mb_config.h"
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
5
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
6 #ifdef X_BACKEND
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
7 #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
8 #endif
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
9
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
10 #ifdef DFB_BACKEND
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
11 #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
12 #endif
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
14 typedef void *MBB_WINDOW;
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15 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
16
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 /*! \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
18 * 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
19 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
20 * 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
21 * 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
22 * 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
23 * 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
24 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
25 * - keyboard event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
26 * - timer event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
27 * - image loader(?)
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
28 * - render manager(?)
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
29 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
30 typedef struct {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
31 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
32 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
33
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
34 void (*free)(mb_rt_t *rt);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
35 /*! \brief Request the backend to start monitoring a file descriptor.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
36 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
37 * This is used only when the backend is responsible for event loop.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
38 */
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
39 void (*add_event)(mb_rt_t *rt,int type, int fd, mb_eventcb_t f,void *arg);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
40 /*! \brief Request the backend to stop monitoring a file descriptor.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
41 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
42 * This is used only when the backend is responsible for event loop.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
43 */
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
44 void (*remove_event)(mb_rt_t *rt,int type, int fd);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
45 /*! \brief Event Loop
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
46 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
47 * This is called when main application does not handle event
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
48 * loop. Or, it should register an IO factory (i.e \ref
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
49 * mb_IO_factory_t) with the backend.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
50 */
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
51 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
52
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
53 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
54 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
55 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
56 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
57 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
58
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
59 /*
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
60 * 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
61 * 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
62 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
63 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
64 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
65 } mb_backend_t;
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
66
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
67 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
68
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
69 /*! \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
70 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
71 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
72
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
73 /*! \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
74 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
75 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
76
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
77 /*! \brief IO Manager
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 struct _mb_IO_man {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
80 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
81 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
82 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
83 int io_hdl);
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 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
86
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
87 /*! \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
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_factory {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
90 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
91 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
92 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
93 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
94
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
95 /*! \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
96 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
97 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
98
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
99 /*! \brief Timer manager
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 struct _mb_timer_man {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
102 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
103 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
104 /*! \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
105 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
106 * \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
107 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
108 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
109 } mb_timer_man_t;
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
110
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
111 /*! \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
112 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
113 struct _mb_timer_factory {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
114 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
115 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
116 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
117 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
118
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
119 #endif /* __MB_BACKEND_H_ */