annotate include/mb_backend.h @ 1071:1a75a4778515 openvg

Commont for changes of mbe
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 01 Dec 2010 14:33:57 +0800
parents e415c55b4a0d
children fa5f71d4aa04
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
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
19 struct _mb_rt;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
20 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
21
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
22 struct _mb_timer_man;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
23 struct _mb_timer_factory;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
24 struct _mb_IO_man;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
25 struct _mb_IO_factory;
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
26
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
27 /*! \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
28 */
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
29 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
30
993
5b58e74988bc Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents: 991
diff changeset
31 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
32 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
33 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
34 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
35 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
36
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
37 /*! \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
38 */
02d52058d352 Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents: 1009
diff changeset
39 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
40
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
41 /*! \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
42 * 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
43 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
44 * 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
45 * 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
46 * 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
47 * 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
48 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
49 * - keyboard event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
50 * - timer event
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
51 * - image loader(?)
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
52 * - render manager(?)
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
53 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
54 typedef struct {
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
55 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
56 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
57
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
58 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
59 void (*rt_free_keep_win)(mb_rt_t *rt);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
60 /*! \brief Request the backend to start monitoring a file descriptor.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
61 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
62 * 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
63 */
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
64 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
65 mb_IO_cb_t f,void *arg);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
66 /*! \brief Request the backend to stop monitoring a file descriptor.
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
67 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
68 * 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
69 */
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
70 void (*remove_event)(mb_rt_t *rt, int hdl);
985
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
71 /*! \brief Event Loop
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
72 *
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
73 * This is called when main application does not handle event
bab9c0f836b9 doc backend
Thinker K.F. Li <thinker@codemud.net>
parents: 984
diff changeset
74 * 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
75 * mb_IO_factory_t) with the backend.
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 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
78
d5b8853767e7 Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents: 1011
diff changeset
79 /*! \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
80 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
81
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
82 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
83 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
84 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
85 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
86 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
87
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 * 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
90 * 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
91 */
1022
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
92 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
93 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
94 } mb_backend_t;
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 #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
97 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
98 #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
99 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
100 #define mb_reg_IO_factory(io_fact) \
9f8a64ac5435 Fix typo of io_fact.
Thinker K.F. Li <thinker@codemud.net>
parents: 1034
diff changeset
101 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
102 #define mb_reg_timer_factory(tm_fact) \
9f8a64ac5435 Fix typo of io_fact.
Thinker K.F. Li <thinker@codemud.net>
parents: 1034
diff changeset
103 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
104
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
105 /*
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
106 * 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
107 * 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
108 */
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
109 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
110
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
111 #define mb_runtime_free(rt) \
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
112 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
113 #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
114 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
115 #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
116 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
117 #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
118 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
119 #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
120 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
121 #define mb_runtime_flush(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
122 mb_dfl_backend.flush(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
123 #define mb_runtime_kbevents(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
124 mb_dfl_backend.kbevents(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
125 #define mb_runtime_rdman(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
126 mb_dfl_backend.rdman(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
127 #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
128 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
129 #define mb_runtime_observer_factory(rt) \
e415c55b4a0d Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents: 1041
diff changeset
130 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
131 #define mb_runtime_loader(rt) \
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
132 mb_dfl_backend.loader(rt)
84006acab6af Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1019
diff changeset
133
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
134
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
135 /*! \brief IO Manager
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 struct _mb_IO_man {
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
138 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
139 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
140 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
141 int io_hdl);
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
142 };
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 /*! \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
145 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
146 struct _mb_IO_factory {
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
147 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
148 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
149 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
150
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
151 #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
152 (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
153 #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
154 (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
155 #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
156 #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
157
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
158 /*! \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
159 */
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
160 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
161 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
162 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
163 void *data);
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
164
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
165 /*! \brief Timer manager
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
166 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
167 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
168 /*! \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
169 *
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
170 * \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
171 */
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
172 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
173 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
174 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
175 /*! \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
176 *
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
177 * \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
178 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
179 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
180 };
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
181
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
182 /*! \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
183 */
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
184 struct _mb_timer_factory {
1034
e9a134d75c99 To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents: 1022
diff changeset
185 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
186 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
187 };
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
188
1017
9b5d4839c5bb Use mb_timer_man_t instead of mb_tman_t.
Thinker K.F. Li <thinker@codemud.net>
parents: 1013
diff changeset
189 #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
190 (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
191 #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
192 (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
193 #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
194 #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
195
984
3fe8054457a8 Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
196 #endif /* __MB_BACKEND_H_ */