pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
Data Structures | Macros | Typedefs | Enumerations | Functions
mainloop.h File Reference

Wrappers for and extensions to glib mainloop. More...

#include <signal.h>
#include <glib.h>
#include <stdbool.h>
#include <crm/common/ipc.h>
#include <qb/qbipcs.h>
#include <crm/common/mainloop_compat.h>
Include dependency graph for mainloop.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ipc_client_callbacks
 
struct  mainloop_fd_callbacks
 

Macros

#define G_PRIORITY_MEDIUM   (G_PRIORITY_HIGH/2)
 

Typedefs

typedef struct trigger_s crm_trigger_t
 
typedef struct mainloop_io_s mainloop_io_t
 
typedef struct mainloop_child_s mainloop_child_t
 
typedef struct mainloop_timer_s mainloop_timer_t
 
typedef void(* sighandler_t) (int)
 

Enumerations

enum  mainloop_child_flags { mainloop_leave_pid_group = 0x01 }
 

Functions

void mainloop_cleanup (void)
 
crm_trigger_tmainloop_add_trigger (int priority, int(*dispatch)(gpointer user_data), gpointer userdata)
 Create a trigger to be used as a mainloop source. More...
 
void mainloop_set_trigger (crm_trigger_t *source)
 
void mainloop_trigger_complete (crm_trigger_t *trig)
 
gboolean mainloop_destroy_trigger (crm_trigger_t *source)
 
sighandler_t crm_signal_handler (int sig, sighandler_t dispatch)
 
gboolean mainloop_add_signal (int sig, void(*dispatch)(int sig))
 
gboolean mainloop_destroy_signal (int sig)
 
bool mainloop_timer_running (mainloop_timer_t *t)
 
void mainloop_timer_start (mainloop_timer_t *t)
 
void mainloop_timer_stop (mainloop_timer_t *t)
 
guint mainloop_timer_set_period (mainloop_timer_t *t, guint period_ms)
 
mainloop_timer_tmainloop_timer_add (const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata)
 
void mainloop_timer_del (mainloop_timer_t *t)
 
qb_ipcs_service_t * mainloop_add_ipc_server (const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks)
 
qb_ipcs_service_t * mainloop_add_ipc_server_with_prio (const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks, enum qb_loop_priority prio)
 Start server-side API end-point, hooked into the internal event loop. More...
 
void mainloop_del_ipc_server (qb_ipcs_service_t *server)
 
mainloop_io_tmainloop_add_ipc_client (const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
 
void mainloop_del_ipc_client (mainloop_io_t *client)
 
crm_ipc_tmainloop_get_ipc_client (mainloop_io_t *client)
 
mainloop_io_tmainloop_add_fd (const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
 
void mainloop_del_fd (mainloop_io_t *client)
 
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))
 
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))
 
void * mainloop_child_userdata (mainloop_child_t *child)
 
int mainloop_child_timeout (mainloop_child_t *child)
 
const char * mainloop_child_name (mainloop_child_t *child)
 
pid_t mainloop_child_pid (mainloop_child_t *child)
 
void mainloop_clear_child_userdata (mainloop_child_t *child)
 
gboolean mainloop_child_kill (pid_t pid)
 
void pcmk_quit_main_loop (GMainLoop *mloop, unsigned int n)
 Drain some remaining main loop events then quit it. More...
 
void pcmk_drain_main_loop (GMainLoop *mloop, guint timer_ms, bool(*check)(guint))
 Process main loop events while a certain condition is met. More...
 

Detailed Description

Wrappers for and extensions to glib mainloop.

Definition in file mainloop.h.

Macro Definition Documentation

◆ G_PRIORITY_MEDIUM

#define G_PRIORITY_MEDIUM   (G_PRIORITY_HIGH/2)

Definition at line 182 of file mainloop.h.

Typedef Documentation

◆ crm_trigger_t

typedef struct trigger_s crm_trigger_t

Definition at line 32 of file mainloop.h.

◆ mainloop_child_t

typedef struct mainloop_child_s mainloop_child_t

Definition at line 34 of file mainloop.h.

◆ mainloop_io_t

typedef struct mainloop_io_s mainloop_io_t

Definition at line 33 of file mainloop.h.

◆ mainloop_timer_t

typedef struct mainloop_timer_s mainloop_timer_t

Definition at line 35 of file mainloop.h.

◆ sighandler_t

typedef void(* sighandler_t) (int)

Definition at line 49 of file mainloop.h.

Enumeration Type Documentation

◆ mainloop_child_flags

Enumerator
mainloop_leave_pid_group 

Definition at line 27 of file mainloop.h.

Function Documentation

◆ crm_signal_handler()

sighandler_t crm_signal_handler ( int  sig,
sighandler_t  dispatch 
)

Definition at line 309 of file mainloop.c.

◆ mainloop_add_fd()

mainloop_io_t* mainloop_add_fd ( const char *  name,
int  priority,
int  fd,
void *  userdata,
struct mainloop_fd_callbacks callbacks 
)

Definition at line 959 of file mainloop.c.

◆ mainloop_add_ipc_client()

mainloop_io_t* mainloop_add_ipc_client ( const char *  name,
int  priority,
size_t  max_size,
void *  userdata,
struct ipc_client_callbacks callbacks 
)

Definition at line 919 of file mainloop.c.

◆ mainloop_add_ipc_server()

qb_ipcs_service_t* mainloop_add_ipc_server ( const char *  name,
enum qb_ipc_type  type,
struct qb_ipcs_service_handlers *  callbacks 
)

Definition at line 640 of file mainloop.c.

◆ mainloop_add_ipc_server_with_prio()

qb_ipcs_service_t* mainloop_add_ipc_server_with_prio ( const char *  name,
enum qb_ipc_type  type,
struct qb_ipcs_service_handlers *  callbacks,
enum qb_loop_priority  prio 
)

Start server-side API end-point, hooked into the internal event loop.

Parameters
[in]namename of the IPC end-point ("address" for the client)
[in]typeselects libqb's IPC back-end (or use #QB_IPC_NATIVE)
[in]callbacksdefines libqb's IPC service-level handlers
[in]prioritypriority relative to other events handled in the abstract handling loop, use #QB_LOOP_MED when unsure
Returns
libqb's opaque handle to the created service abstraction
Note
For portability concerns, do not use this function if you keep priority as #QB_LOOP_MED, stick with mainloop_add_ipc_server (with exactly such semantics) instead (once you link with this new symbol employed, you can't downgrade the library freely anymore).
The intended effect will only get fully reflected when run-time linked to patched libqb: https://github.com/ClusterLabs/libqb/pull/352

Definition at line 647 of file mainloop.c.

◆ mainloop_add_signal()

gboolean mainloop_add_signal ( int  sig,
void(*)(int sig)  dispatch 
)

Definition at line 357 of file mainloop.c.

◆ mainloop_add_trigger()

crm_trigger_t* mainloop_add_trigger ( int  priority,
int(*)(gpointer user_data)  dispatch,
gpointer  userdata 
)

Create a trigger to be used as a mainloop source.

Parameters
[in]priorityRelative priority of source (lower number is higher priority)
[in]dispatchTrigger dispatch function (should return 0 to remove the trigger from the mainloop, -1 if the trigger should be kept but the job is still running and not complete, and 1 if the trigger should be kept and the job is complete)
[in]userdataPointer to pass to dispatch
Returns
Newly allocated mainloop source for trigger

Definition at line 187 of file mainloop.c.

◆ mainloop_child_add()

void mainloop_child_add ( pid_t  pid,
int  timeout,
const char *  desc,
void *  userdata,
void(*)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode)  callback 
)

Definition at line 1286 of file mainloop.c.

◆ mainloop_child_add_with_flags()

void mainloop_child_add_with_flags ( pid_t  pid,
int  timeout,
const char *  desc,
void *  userdata,
enum  mainloop_child_flags,
void(*)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode)  callback 
)

Definition at line 1255 of file mainloop.c.

◆ mainloop_child_kill()

gboolean mainloop_child_kill ( pid_t  pid)

Definition at line 1199 of file mainloop.c.

◆ mainloop_child_name()

const char* mainloop_child_name ( mainloop_child_t child)

Definition at line 1025 of file mainloop.c.

◆ mainloop_child_pid()

pid_t mainloop_child_pid ( mainloop_child_t child)

Definition at line 1019 of file mainloop.c.

◆ mainloop_child_timeout()

int mainloop_child_timeout ( mainloop_child_t child)

Definition at line 1031 of file mainloop.c.

◆ mainloop_child_userdata()

void* mainloop_child_userdata ( mainloop_child_t child)

Definition at line 1037 of file mainloop.c.

◆ mainloop_cleanup()

void mainloop_cleanup ( void  )

Definition at line 421 of file mainloop.c.

◆ mainloop_clear_child_userdata()

void mainloop_clear_child_userdata ( mainloop_child_t child)

Definition at line 1043 of file mainloop.c.

◆ mainloop_del_fd()

void mainloop_del_fd ( mainloop_io_t client)

Definition at line 1003 of file mainloop.c.

◆ mainloop_del_ipc_client()

void mainloop_del_ipc_client ( mainloop_io_t client)

Definition at line 944 of file mainloop.c.

◆ mainloop_del_ipc_server()

void mainloop_del_ipc_server ( qb_ipcs_service_t *  server)

Definition at line 684 of file mainloop.c.

◆ mainloop_destroy_signal()

gboolean mainloop_destroy_signal ( int  sig)

Definition at line 401 of file mainloop.c.

◆ mainloop_destroy_trigger()

gboolean mainloop_destroy_trigger ( crm_trigger_t source)

Definition at line 208 of file mainloop.c.

◆ mainloop_get_ipc_client()

crm_ipc_t* mainloop_get_ipc_client ( mainloop_io_t client)

Definition at line 950 of file mainloop.c.

◆ mainloop_set_trigger()

void mainloop_set_trigger ( crm_trigger_t source)

Definition at line 200 of file mainloop.c.

◆ mainloop_timer_add()

mainloop_timer_t* mainloop_timer_add ( const char *  name,
guint  period_ms,
bool  repeat,
GSourceFunc  cb,
void *  userdata 
)

Definition at line 1369 of file mainloop.c.

◆ mainloop_timer_del()

void mainloop_timer_del ( mainloop_timer_t t)

Definition at line 1390 of file mainloop.c.

◆ mainloop_timer_running()

bool mainloop_timer_running ( mainloop_timer_t t)

Definition at line 1324 of file mainloop.c.

◆ mainloop_timer_set_period()

guint mainloop_timer_set_period ( mainloop_timer_t t,
guint  period_ms 
)

Definition at line 1353 of file mainloop.c.

◆ mainloop_timer_start()

void mainloop_timer_start ( mainloop_timer_t t)

Definition at line 1333 of file mainloop.c.

◆ mainloop_timer_stop()

void mainloop_timer_stop ( mainloop_timer_t t)

Definition at line 1343 of file mainloop.c.

◆ mainloop_trigger_complete()

void mainloop_trigger_complete ( crm_trigger_t trig)

Definition at line 168 of file mainloop.c.

◆ pcmk_drain_main_loop()

void pcmk_drain_main_loop ( GMainLoop *  mloop,
guint  timer_ms,
bool(*)(guint)  check 
)

Process main loop events while a certain condition is met.

Parameters
[in,out]mloopMain loop to process
[in]timer_msDon't process longer than this amount of time
[in]checkFunction that returns true if events should be processed
Note
This function is intended to be called at shutdown if certain important events should not be missed. The caller would likely quit the main loop or exit after calling this function. The check() function will be passed the remaining timeout in milliseconds.

Definition at line 1449 of file mainloop.c.

◆ pcmk_quit_main_loop()

void pcmk_quit_main_loop ( GMainLoop *  mloop,
unsigned int  n 
)

Drain some remaining main loop events then quit it.

Parameters
[in,out]mloopMain loop to drain and quit
[in]nDrain up to this many pending events

Definition at line 1420 of file mainloop.c.