annotate include/mb_backend.h @ 1022:84006acab6af refine_backend_if

Use macros to hide the default backend
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 22 Nov 2010 15:20:11 +0800
parents 1a3cc22ee1bd
children e9a134d75c99
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
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
9 #include "mb_config.h"
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
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;
1009
595a06fc0157 Change X_MB_add/remove_event() to match new mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents: 996
diff changeset
25 typedef enum _MB_IO_TYPE MB_IO_TYPE;
993
5b58e74988bc Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents: 991
diff changeset
26
1011
02d52058d352 Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents: 1009
diff changeset
27 /*! \brief Function signature of callback functions for IO requests.
02d52058d352 Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents: 1009
diff changeset
28 */
02d52058d352 Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents: 1009
diff changeset
29 typedef void (*mb_IO_cb_t)(int hdl, int fd, MB_IO_TYPE type, void *data);
02d52058d352 Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents: 1009
diff changeset
30
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
31 /*! \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
32 * 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
33 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
34 * 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
35 * 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
36 * 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
37 * 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
38 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
39 * - keyboard event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
40 * - timer event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
41 * - image loader(?)
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
42 * - render manager(?)
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 typedef struct {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
45 mb_rt_t *(*new)(const char *display, int w,int h);
1011
02d52058d352 Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents: 1009
diff changeset
46 mb_rt_t *(*new_with_win)(MB_DISPLAY display, MB_WINDOW win);
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
47
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
48 void (*free)(mb_rt_t *rt);
1013
d5b8853767e7 Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents: 1011
diff changeset
49 void (*free_keep_win)(mb_rt_t *rt);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
50 /*! \brief Request the backend to start monitoring a file descriptor.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
51 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
52 * 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
53 */
1009
595a06fc0157 Change X_MB_add/remove_event() to match new mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents: 996
diff changeset
54 int (*add_event)(mb_rt_t *rt, int fd, MB_IO_TYPE type,
1011
02d52058d352 Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents: 1009
diff changeset
55 mb_IO_cb_t f,void *arg);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
56 /*! \brief Request the backend to stop monitoring a file descriptor.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
57 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
58 * 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
59 */
1009
595a06fc0157 Change X_MB_add/remove_event() to match new mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents: 996
diff changeset
60 void (*remove_event)(mb_rt_t *rt, int hdl);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
61 /*! \brief Event Loop
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
62 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
63 * This is called when main application does not handle event
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
64 * 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
65 * mb_IO_factory_t) with the backend.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
66 */
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
67 void (*event_loop)(mb_rt_t *rt);
1013
d5b8853767e7 Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents: 1011
diff changeset
68
d5b8853767e7 Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents: 1011
diff changeset
69 /*! \brief Flush requests to screen server if existed */
d5b8853767e7 Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents: 1011
diff changeset
70 int (*flush)(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
71
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
72 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
73 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
74 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
75 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
76 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
77
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 * 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
80 * 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
81 */
1022
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
82 void (*reg_IO_factory)(mb_IO_factory_t *io_man);
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
83 void (*reg_timer_factory)(mb_timer_factory_t *tm_man);
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
84 } mb_backend_t;
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
85
1022
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
86 #define mb_runtime_new(disp, w, h) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
87 mb_dfl_backend.new((disp), (w), (h))
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
88 #define mb_runtime_new_with_win(disp, win) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
89 mb_dfl_backend.new_with_win((disp), (win))
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
90 #define mb_reg_IO_factory(io_man) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
91 mb_dfl_backend.reg_IO_factory(io_man)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
92 #define mb_reg_timer_factory(tm_man) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
93 mb_dfl_backend.reg_timer_factory(tm_man)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
94
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
95 /*
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
96 * This is defined by backend implementations. For example, X_supp.c
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
97 * or dfb_supp.c should defined a backend.
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
98 */
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
99 extern mb_backend_t mb_dfl_backend;
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
100
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
101 #define mb_runtime_free(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
102 mb_dfl_backend.free(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
103 #define mb_runtime_free_with_win(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
104 mb_dfl_backend.free_with_win(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
105 #define mb_runtime_add_event(rt, fd, type, cb, arg) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
106 mb_dfl_backend.add_event((rt), (fd), (type), (cb), (arg))
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
107 #define mb_runtime_remove_event(hdl) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
108 mb_dfl_backend.remove_event((rt), (hdl))
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
109 #define mb_runtime_event_loop(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
110 mb_dfl_backend.event_loop(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
111 #define mb_runtime_flush(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
112 mb_dfl_backend.flush(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
113 #define mb_runtime_kbevents(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
114 mb_dfl_backend.kbevents(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
115 #define mb_runtime_rdman(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
116 mb_dfl_backend.rdman(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
117 #define mb_runtime_timer_man(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
118 mb_dfl_backend.timer_man(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
119 #define mb_runtime_ob_factory(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
120 mb_dfl_backend.ob_factory(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
121 #define mb_runtime_loader(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
122 mb_dfl_backend.loader(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
123
984
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 /*! \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
126 */
993
5b58e74988bc Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents: 991
diff changeset
127 enum _MB_IO_TYPE {MB_IO_DUMMY, MB_IO_R, MB_IO_W, MB_IO_RW};
984
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 /*! \brief IO Manager
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
130 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
131 struct _mb_IO_man {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
132 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
133 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
134 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
135 int io_hdl);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
136 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
137
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
138 /*! \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
139 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
140 struct _mb_IO_factory {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
141 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
142 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
143 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
144
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
145 /*! \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
146 */
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
147 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
148 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
149 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
150 void *data);
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
151
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
152 /*! \brief Timer manager
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
153 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
154 struct _mb_timer_man {
1017
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
155 /*! \brief Setup a timeout callback.
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
156 *
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
157 * \return -1 for error.
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
158 */
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
159 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
160 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
161 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
162 /*! \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
163 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
164 * \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
165 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
166 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
167 };
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
168
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
169 /*! \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
170 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
171 struct _mb_timer_factory {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
172 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
173 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
174 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
175
1017
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
176 #define mb_timer_man_timeout(tm_man, tmout, cb, data) \
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
177 (tm_man)->timeout((tm_man), (tmout), (cb), (data))
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
178 #define mb_timer_man_remove(tm_man, tm_hdl) \
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
179 (tm_man)->remove((tm_man), (tm_hdl))
1019
1a3cc22ee1bd Fix testcase of animate.c for mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents: 1017
diff changeset
180 #define mb_timer_man_new(tm_fact) (tm_fact)->new()
1a3cc22ee1bd Fix testcase of animate.c for mb_timer_man_t
Thinker K.F. Li <thinker@codemud.net>
parents: 1017
diff changeset
181 #define mb_timer_man_free(tm_fact, tm_man) (tm_fact)->free(tm_man)
1017
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
182
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
183 #endif /* __MB_BACKEND_H_ */