annotate include/mb_backend.h @ 1295:71118bff7d61

CHange the wrong append to appendCHild
author wycc
date Sun, 16 Jan 2011 09:45:09 +0800
parents fa5f71d4aa04
children
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
1111
fa5f71d4aa04 console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1060
diff changeset
19 #ifdef CONSOLE_BACKEND
fa5f71d4aa04 console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1060
diff changeset
20 #include "mb_cons_supp.h"
fa5f71d4aa04 console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1060
diff changeset
21 #endif
fa5f71d4aa04 console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1060
diff changeset
22
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
23 struct _mb_rt;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
24 typedef struct _mb_rt mb_rt_t;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
25
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
26 struct _mb_timer_man;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
27 struct _mb_timer_factory;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
28 struct _mb_IO_man;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
29 struct _mb_IO_factory;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
30
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
31 /*! \brief Type of IO that registered with an IO manager.
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
32 */
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
33 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
34
993
5b58e74988bc Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents: 991
diff changeset
35 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
36 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
37 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
38 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
39 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
40
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
41 /*! \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
42 */
02d52058d352 Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents: 1009
diff changeset
43 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
44
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
45 /*! \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
46 * 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
47 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
48 * 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
49 * 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
50 * 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
51 * 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
52 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
53 * - keyboard event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
54 * - timer event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
55 * - image loader(?)
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
56 * - render manager(?)
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
57 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
58 typedef struct {
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
59 mb_rt_t *(*rt_new)(const char *display, int w,int h);
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
60 mb_rt_t *(*rt_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
61
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
62 void (*rt_free)(mb_rt_t *rt);
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
63 void (*rt_free_keep_win)(mb_rt_t *rt);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
64 /*! \brief Request the backend to start monitoring a file descriptor.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
65 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
66 * 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
67 */
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
68 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
69 mb_IO_cb_t f,void *arg);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
70 /*! \brief Request the backend to stop monitoring a file descriptor.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
71 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
72 * 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
73 */
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
74 void (*remove_event)(mb_rt_t *rt, int hdl);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
75 /*! \brief Event Loop
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
76 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
77 * This is called when main application does not handle event
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
78 * 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
79 * mb_IO_factory_t) with the backend.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
80 */
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
81 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
82
d5b8853767e7 Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents: 1011
diff changeset
83 /*! \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
84 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
85
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
86 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
87 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
88 mb_timer_man_t *(*timer_man)(mb_rt_t *rt);
1060
e415c55b4a0d Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents: 1041
diff changeset
89 observer_factory_t *(*observer_factory)(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
90 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
91
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 * 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
94 * 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
95 */
1022
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
96 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
97 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
98 } mb_backend_t;
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
99
1022
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
100 #define mb_runtime_new(disp, w, h) \
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
101 mb_dfl_backend.rt_new((disp), (w), (h))
1022
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
102 #define mb_runtime_new_with_win(disp, win) \
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
103 mb_dfl_backend.rt_new_with_win((disp), (win))
1037
9f8a64ac5435 Fix typo of io_fact.
Thinker K.F. Li <thinker@codemud.net>
parents: 1034
diff changeset
104 #define mb_reg_IO_factory(io_fact) \
9f8a64ac5435 Fix typo of io_fact.
Thinker K.F. Li <thinker@codemud.net>
parents: 1034
diff changeset
105 mb_dfl_backend.reg_IO_factory(io_fact)
9f8a64ac5435 Fix typo of io_fact.
Thinker K.F. Li <thinker@codemud.net>
parents: 1034
diff changeset
106 #define mb_reg_timer_factory(tm_fact) \
9f8a64ac5435 Fix typo of io_fact.
Thinker K.F. Li <thinker@codemud.net>
parents: 1034
diff changeset
107 mb_dfl_backend.reg_timer_factory(tm_fact)
1022
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
108
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
109 /*
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
110 * 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
111 * 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
112 */
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
113 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
114
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
115 #define mb_runtime_free(rt) \
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
116 mb_dfl_backend.rt_free(rt)
1041
eb3d2e3381cb Fix typo for mb_runtime_free_keep_win()
Thinker K.F. Li <thinker@codemud.net>
parents: 1037
diff changeset
117 #define mb_runtime_free_keep_win(rt) \
eb3d2e3381cb Fix typo for mb_runtime_free_keep_win()
Thinker K.F. Li <thinker@codemud.net>
parents: 1037
diff changeset
118 mb_dfl_backend.rt_free_keep_win(rt)
1022
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
119 #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
120 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
121 #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
122 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
123 #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
124 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
125 #define mb_runtime_flush(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
126 mb_dfl_backend.flush(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
127 #define mb_runtime_kbevents(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
128 mb_dfl_backend.kbevents(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
129 #define mb_runtime_rdman(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
130 mb_dfl_backend.rdman(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
131 #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
132 mb_dfl_backend.timer_man(rt)
1060
e415c55b4a0d Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents: 1041
diff changeset
133 #define mb_runtime_observer_factory(rt) \
e415c55b4a0d Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents: 1041
diff changeset
134 mb_dfl_backend.observer_factory(rt)
1022
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
135 #define mb_runtime_loader(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
136 mb_dfl_backend.loader(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
137
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
138
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
139 /*! \brief IO Manager
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
140 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
141 struct _mb_IO_man {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
142 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
143 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
144 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
145 int io_hdl);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
146 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
147
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
148 /*! \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
149 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
150 struct _mb_IO_factory {
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
151 mb_IO_man_t *(*io_man_new)(void);
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
152 void (*io_man_free)(mb_IO_man_t *io_man);
984
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
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
155 #define mb_io_man_reg(io_man, fd, type, cb, data) \
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
156 (io_man)->reg(io_man, fd, type, cb, data)
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
157 #define mb_io_man_unreg(io_man, io_hdl) \
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
158 (io_man)->unreg(io_man, io_hdl)
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
159 #define mb_io_man_new(io_fact) (io_fact)->io_man_new()
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
160 #define mb_io_man_free(io_fact, io_man) (io_fact)->io_man_free(io_man)
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
161
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
162 /*! \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
163 */
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
164 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
165 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
166 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
167 void *data);
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 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_man {
1017
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
172 /*! \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
173 *
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
174 * \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
175 */
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
176 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
177 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
178 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
179 /*! \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
180 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
181 * \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
182 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
183 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
184 };
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
185
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
186 /*! \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
187 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
188 struct _mb_timer_factory {
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
189 mb_timer_man_t *(*timer_man_new)(void);
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
190 void (*timer_man_free)(mb_timer_man_t *timer_man);
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
191 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
192
1017
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
193 #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
194 (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
195 #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
196 (tm_man)->remove((tm_man), (tm_hdl))
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
197 #define mb_timer_man_new(tm_fact) (tm_fact)->timer_man_new()
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
198 #define mb_timer_man_free(tm_fact, tm_man) (tm_fact)->timer_man_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
199
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
200 #endif /* __MB_BACKEND_H_ */