1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #ifndef CRM_COMMON_MAINLOOP__H
19 # define CRM_COMMON_MAINLOOP__H
20
21
22
23
24
25
26
27 # include <glib.h>
28
29 enum mainloop_child_flags {
30
31 mainloop_leave_pid_group = 0x01,
32 };
33
34 typedef struct trigger_s crm_trigger_t;
35 typedef struct mainloop_io_s mainloop_io_t;
36 typedef struct mainloop_child_s mainloop_child_t;
37 typedef struct mainloop_timer_s mainloop_timer_t;
38
39 void mainloop_cleanup(void);
40
41 crm_trigger_t *mainloop_add_trigger(int priority, int (*dispatch) (gpointer user_data),
42 gpointer userdata);
43
44 void mainloop_set_trigger(crm_trigger_t * source);
45
46 void mainloop_trigger_complete(crm_trigger_t * trig);
47
48 gboolean mainloop_destroy_trigger(crm_trigger_t * source);
49
50 gboolean crm_signal(int sig, void (*dispatch) (int sig));
51
52 gboolean mainloop_add_signal(int sig, void (*dispatch) (int sig));
53
54 gboolean mainloop_destroy_signal(int sig);
55
56 bool mainloop_timer_running(mainloop_timer_t *t);
57
58 void mainloop_timer_start(mainloop_timer_t *t);
59
60 void mainloop_timer_stop(mainloop_timer_t *t);
61
62 guint mainloop_timer_set_period(mainloop_timer_t *t, guint period_ms);
63
64 mainloop_timer_t *mainloop_timer_add(const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata);
65
66 void mainloop_timer_del(mainloop_timer_t *t);
67
68
69 # include <crm/common/ipc.h>
70 # include <qb/qbipcs.h>
71
72 struct ipc_client_callbacks {
73 int (*dispatch) (const char *buffer, ssize_t length, gpointer userdata);
74 void (*destroy) (gpointer);
75 };
76
77 qb_ipcs_service_t *mainloop_add_ipc_server(const char *name, enum qb_ipc_type type,
78 struct qb_ipcs_service_handlers *callbacks);
79
80 void mainloop_del_ipc_server(qb_ipcs_service_t * server);
81
82 mainloop_io_t *mainloop_add_ipc_client(const char *name, int priority, size_t max_size,
83 void *userdata, struct ipc_client_callbacks *callbacks);
84
85 void mainloop_del_ipc_client(mainloop_io_t * client);
86
87 crm_ipc_t *mainloop_get_ipc_client(mainloop_io_t * client);
88
89 struct mainloop_fd_callbacks {
90 int (*dispatch) (gpointer userdata);
91 void (*destroy) (gpointer userdata);
92 };
93
94 mainloop_io_t *mainloop_add_fd(const char *name, int priority, int fd, void *userdata,
95 struct mainloop_fd_callbacks *callbacks);
96
97 void mainloop_del_fd(mainloop_io_t * client);
98
99
100
101
102
103 void mainloop_child_add(pid_t pid,
104 int timeout,
105 const char *desc,
106 void *userdata,
107 void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
108
109 void mainloop_child_add_with_flags(pid_t pid,
110 int timeout,
111 const char *desc,
112 void *userdata,
113 enum mainloop_child_flags,
114 void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
115
116 void *mainloop_child_userdata(mainloop_child_t * child);
117 int mainloop_child_timeout(mainloop_child_t * child);
118 const char *mainloop_child_name(mainloop_child_t * child);
119
120 pid_t mainloop_child_pid(mainloop_child_t * child);
121 void mainloop_clear_child_userdata(mainloop_child_t * child);
122 gboolean mainloop_child_kill(pid_t pid);
123
124 # define G_PRIORITY_MEDIUM (G_PRIORITY_HIGH/2)
125
126 #endif