pacemaker  2.0.2-debe490
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mainloop.h
Go to the documentation of this file.
1 /*
2  * Copyright 2009-2019 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef CRM_COMMON_MAINLOOP__H
11 # define CRM_COMMON_MAINLOOP__H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
23 # include <signal.h> // sighandler_t
24 # include <glib.h>
25 
27  /* don't kill pid group on timeout, only kill the pid */
29 };
30 
31 typedef struct trigger_s crm_trigger_t;
32 typedef struct mainloop_io_s mainloop_io_t;
33 typedef struct mainloop_child_s mainloop_child_t;
34 typedef struct mainloop_timer_s mainloop_timer_t;
35 
36 void mainloop_cleanup(void);
37 
38 crm_trigger_t *mainloop_add_trigger(int priority, int (*dispatch) (gpointer user_data),
39  gpointer userdata);
40 
41 void mainloop_set_trigger(crm_trigger_t * source);
42 
44 
45 gboolean mainloop_destroy_trigger(crm_trigger_t * source);
46 
47 # ifndef HAVE_SIGHANDLER_T
48 typedef void (*sighandler_t)(int);
49 # endif
50 
52 gboolean crm_signal(int sig, void (*dispatch) (int sig)); // deprecated
53 
54 gboolean mainloop_add_signal(int sig, void (*dispatch) (int sig));
55 
56 gboolean mainloop_destroy_signal(int sig);
57 
59 
61 
63 
64 guint mainloop_timer_set_period(mainloop_timer_t *t, guint period_ms);
65 
66 mainloop_timer_t *mainloop_timer_add(const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata);
67 
69 
70 
71 # include <crm/common/ipc.h>
72 # include <qb/qbipcs.h>
73 
75  int (*dispatch) (const char *buffer, ssize_t length, gpointer userdata);
76  void (*destroy) (gpointer);
77 };
78 
79 qb_ipcs_service_t *mainloop_add_ipc_server(const char *name, enum qb_ipc_type type,
80  struct qb_ipcs_service_handlers *callbacks);
81 
82 void mainloop_del_ipc_server(qb_ipcs_service_t * server);
83 
84 mainloop_io_t *mainloop_add_ipc_client(const char *name, int priority, size_t max_size,
85  void *userdata, struct ipc_client_callbacks *callbacks);
86 
88 
90 
92  int (*dispatch) (gpointer userdata);
93  void (*destroy) (gpointer userdata);
94 };
95 
96 mainloop_io_t *mainloop_add_fd(const char *name, int priority, int fd, void *userdata,
97  struct mainloop_fd_callbacks *callbacks);
98 
99 void mainloop_del_fd(mainloop_io_t * client);
100 
101 /*
102  * Create a new tracked process
103  * To track a process group, use -pid
104  */
105 void mainloop_child_add(pid_t pid,
106  int timeout,
107  const char *desc,
108  void *userdata,
109  void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
110 
111 void mainloop_child_add_with_flags(pid_t pid,
112  int timeout,
113  const char *desc,
114  void *userdata,
116  void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
117 
120 const char *mainloop_child_name(mainloop_child_t * child);
121 
122 pid_t mainloop_child_pid(mainloop_child_t * child);
124 gboolean mainloop_child_kill(pid_t pid);
125 
126 void pcmk_drain_main_loop(GMainLoop *mloop, guint timer_ms,
127  bool (*check)(guint));
128 
129 # define G_PRIORITY_MEDIUM (G_PRIORITY_HIGH/2)
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif
gboolean mainloop_add_signal(int sig, void(*dispatch)(int sig))
Definition: mainloop.c:386
mainloop_io_t * mainloop_add_fd(const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
Definition: mainloop.c:864
void mainloop_timer_start(mainloop_timer_t *t)
Definition: mainloop.c:1238
guint mainloop_timer_set_period(mainloop_timer_t *t, guint period_ms)
Definition: mainloop.c:1256
mainloop_child_flags
Definition: mainloop.h:26
void mainloop_timer_del(mainloop_timer_t *t)
Definition: mainloop.c:1294
gboolean mainloop_child_kill(pid_t pid)
Definition: mainloop.c:1096
void(* sighandler_t)(int)
Definition: mainloop.h:48
void pcmk_drain_main_loop(GMainLoop *mloop, guint timer_ms, bool(*check)(guint))
Process main loop events while a certain condition is met.
Definition: mainloop.c:1330
struct mainloop_timer_s mainloop_timer_t
Definition: mainloop.h:34
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:32
void mainloop_child_add_with_flags(pid_t pid, int timeout, const char *desc, void *userdata, enum mainloop_child_flags, void(*callback)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode))
Definition: mainloop.c:1151
struct mainloop_child_s mainloop_child_t
Definition: mainloop.h:33
void mainloop_set_trigger(crm_trigger_t *source)
Definition: mainloop.c:215
void mainloop_cleanup(void)
Definition: mainloop.c:460
int(* dispatch)(gpointer userdata)
Definition: mainloop.h:92
pid_t mainloop_child_pid(mainloop_child_t *child)
Definition: mainloop.c:924
uint32_t pid
Definition: internal.h:83
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
Definition: mainloop.c:223
void mainloop_timer_stop(mainloop_timer_t *t)
Definition: mainloop.c:1247
struct trigger_s crm_trigger_t
Definition: mainloop.h:31
void(* destroy)(gpointer)
Definition: mainloop.h:76
void * mainloop_child_userdata(mainloop_child_t *child)
Definition: mainloop.c:942
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:58
void(* destroy)(gpointer userdata)
Definition: mainloop.h:93
gboolean crm_signal(int sig, void(*dispatch)(int sig))
Definition: mainloop.c:358
sighandler_t crm_signal_handler(int sig, sighandler_t dispatch)
Definition: mainloop.c:328
crm_trigger_t * mainloop_add_trigger(int priority, int(*dispatch)(gpointer user_data), gpointer userdata)
Definition: mainloop.c:203
void mainloop_del_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:849
bool mainloop_timer_running(mainloop_timer_t *t)
Definition: mainloop.c:1230
void mainloop_child_add(pid_t pid, int timeout, const char *desc, void *userdata, void(*callback)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode))
Definition: mainloop.c:1185
void mainloop_trigger_complete(crm_trigger_t *trig)
Definition: mainloop.c:191
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:855
void mainloop_clear_child_userdata(mainloop_child_t *child)
Definition: mainloop.c:948
Wrappers for and extensions to libqb IPC.
void mainloop_del_fd(mainloop_io_t *client)
Definition: mainloop.c:908
void mainloop_del_ipc_server(qb_ipcs_service_t *server)
Definition: mainloop.c:672
mainloop_timer_t * mainloop_timer_add(const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata)
Definition: mainloop.c:1273
gboolean mainloop_destroy_signal(int sig)
Definition: mainloop.c:440
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
Definition: mainloop.c:821
qb_ipcs_service_t * mainloop_add_ipc_server(const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks)
Definition: mainloop.c:642
const char * mainloop_child_name(mainloop_child_t *child)
Definition: mainloop.c:930
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Definition: mainloop.h:75
enum crm_ais_msg_types type
Definition: internal.h:85
int mainloop_child_timeout(mainloop_child_t *child)
Definition: mainloop.c:936