23#include "linkedlist.h"
26#define CRTX_TEST_MAIN(mainfct) \
27 int main(int argc, char **argv) { \
30 crtx_handle_std_signals(); \
31 CRTX_DBG("entering test function\n"); \
32 i = mainfct(argc, argv); \
33 CRTX_DBG("left test function\n"); \
52#ifndef CRTX_EVENT_TYPE_VARTYPE
53#define CRTX_EVENT_TYPE_VARTYPE unsigned int
56#define CRTX_EVENT_TYPE_FAMILY_MAX (2)
60 CRTX_EVENT_TYPE_VARTYPE
type;
66 char response_expected;
69 char release_in_progress;
71 unsigned char refs_before_response;
72 unsigned char refs_before_release;
73 pthread_cond_t response_cond;
74 pthread_cond_t release_cond;
78 void (*cb_before_release)(
struct crtx_event *event,
void *cb_before_release_data);
79 void *cb_before_release_data;
83 #ifndef CRTX_REDUCED_SIZE
99 crtx_handle_task_t cleanup;
105 #ifndef CRTX_REDUCED_SIZE
112#define CRTX_GRAPH_KEEP_GOING 1<<0
135 pthread_mutex_t queue_mutex;
136 pthread_cond_t queue_cond;
142 struct crtx_dll ll_hdr;
144 #ifndef CRTX_REDUCED_SIZE
157 #ifndef CRTX_REDUCED_SIZE
166 CRTX_LSTNR_UNKNOWN=0,
172 CRTX_LSTNR_SHUTTING_DOWN,
177#define CRTX_LSTNR_STARTUP_TRIGGER (1<<0)
178#define CRTX_LSTNR_NO_AUTO_CLOSE (1<<1)
202 MUTEX_TYPE source_lock;
210 void (*thread_stop)(
struct crtx_thread *thread,
void *data);
218 void *free_cb_userdata;
223 char free_after_event;
227 #ifndef CRTX_REDUCED_SIZE
258 #ifndef CRTX_REDUCED_SIZE
267 crtx_handle_task_t function;
274 struct crtx_ll *entries;
281 unsigned int n_graphs;
282 MUTEX_TYPE graphs_mutex;
287 struct crtx_dll *graph_queue;
288 MUTEX_TYPE graph_queue_mutex;
295 void *reinit_cb_data;
297 const char *chosen_event_loop;
299 struct crtx_ll *event_loops;
313 unsigned int listener_repository_length;
315 struct crtx_ll *handler_categories;
323 #ifndef CRTX_REDUCED_SIZE
334void crtx_printf(
char level,
char const *format, ...) __attribute__ ((format (printf, 2, 3)));
335char *crtx_stracpy(const
char *str,
size_t *str_length);
337void crtx_free_event(struct
crtx_event *event);
341int crtx_loop_onetime();
342int crtx_is_shutting_down();
346int crtx_shutdown_graph(struct
crtx_graph *egraph);
347int crtx_free_graph(struct
crtx_graph *egraph);
352int crtx_create_listener_task(struct
crtx_listener_base *lstnr, crtx_handle_task_t handler,
void *userdata);
353struct
crtx_task * crtx_graph_get_task(struct
crtx_graph *graph, const
char *
id, crtx_handle_task_t handler);
354void add_event_type(
char *event_type);
355int crtx_find_graph_add_event(struct
crtx_event *event);
358struct
crtx_graph *crtx_find_graph_for_event_description(
char *event_description);
359struct
crtx_graph *crtx_find_graph_for_event_type(CRTX_EVENT_TYPE_VARTYPE event_type);
360struct
crtx_graph *crtx_get_graph_for_event_description(
char *event_type,
char **new_event_types);
362void crtx_free_task(struct
crtx_task *task);
363int crtx_wait_on_event(struct
crtx_event *event);
364int crtx_create_listener(const
char *
id,
void *options) __attribute__((deprecated));
373 crtx_handle_task_t event_handler,
374 void *event_handler_data,
375 crtx_evloop_error_cb_t error_cb,
381int crtx_create_event(struct
crtx_event **event);
383 CRTX_EVENT_TYPE_VARTYPE event_type,
char *description,
384 char data_type,
char *data_key_or_sign,
386struct
crtx_task *crtx_create_task(struct
crtx_graph *graph,
unsigned char position, const
char *
id, crtx_handle_task_t handler,
void *userdata);
387struct
crtx_task *crtx_create_task_unique(struct
crtx_graph *graph,
unsigned char position, const
char *
id, crtx_handle_task_t handler,
void *userdata);
388void crtx_init_shutdown();
393void crtx_print_tasks(struct
crtx_graph *graph);
394void crtx_hexdump(
unsigned char *buffer,
size_t index);
397void crtx_reference_event_response(struct
crtx_event *event);
398void crtx_dereference_event_response(struct
crtx_event *event);
399void crtx_reference_event_release(struct
crtx_event *event);
400void crtx_dereference_event_release(struct
crtx_event *event);
403int crtx_graph_has_task(struct
crtx_graph *graph);
404int crtx_is_graph_empty(struct
crtx_graph *graph);
407void crtx_init_notification_listeners(
void **data);
408void crtx_finish_notification_listeners(
void *data);
410int crtx_handle_std_signals();
412void *crtx_process_graph_tmain(
void *arg);
413int crtx_process_one_event(struct
crtx_graph *graph);
416void crtx_event_set_raw_data(struct
crtx_event *event,
unsigned char type, ...);
417void crtx_event_set_dict_data(struct
crtx_event *event, struct
crtx_dict *data_dict,
unsigned char n_additional_fields);
418int crtx_event_raw2dict(struct
crtx_event *event,
void *user_data);
419void crtx_event_get_payload(struct
crtx_event *event,
char *
id,
void **raw_pointer, struct
crtx_dict **dict);
422int crtx_event_get_value_by_key(struct
crtx_event *event,
char *key,
char type,
void *buffer,
size_t buffer_size);
423void *crtx_event_get_ptr(struct
crtx_event *event);
424char *crtx_event_get_string(struct
crtx_event *event,
char *key);
425void crtx_event_set_dict(struct
crtx_event *event,
char *signature, ...);
426int crtx_event_get_int(struct
crtx_event *event,
int *value);
427int crtx_event_get_data(struct
crtx_event *event,
void **data,
size_t *size);
429void crtx_register_handler_for_event_type(
char *event_type,
char *handler_name, crtx_handle_task_t handler_function,
void *handler_data);
430void crtx_autofill_graph_with_tasks(struct
crtx_graph *graph, const
char *event_type);
433void crtx_wait_on_graph_empty(struct
crtx_graph *graph);
437void crtx_set_main_event_loop(const
char *event_loop);
438int crtx_separate_evloop_thread();
447void crtx_shutdown_after_fork();
449struct
crtx_thread * crtx_start_detached_event_loop();
451int crtx_get_version(
unsigned int *major,
unsigned int *minor,
unsigned int *revision);
453void crtx_selfpipe_cb_free_lstnr(
void *data);
454int crtx_selfpipe_enqueue_cb(
void (*cb)(
void*),
void *cb_data);
456void crtx_print_event(struct
crtx_event *event, FILE *f);
458int crtx_is_fd_valid(
int fd);
crtx_processing_mode
specifies how a listener should be processed
Definition core.h:39
@ CRTX_NO_PROCESSING_MODE
the listener requires no processing, e.g., if it depends on other listeners
Definition core.h:43
@ CRTX_PREFER_THREAD
a thread should be started, e.g., for blocking calls
Definition core.h:41
@ CRTX_PREFER_NONE
unspecified mode
Definition core.h:40
@ CRTX_PREFER_ELOOP
a listener provides a file descriptor that can be added to the event loop
Definition core.h:42
int crtx_update_listener(struct crtx_listener_base *listener)
trigger a listener update, e.g., to apply changes to a running listener
Definition core.c:252
int crtx_stop_listener(struct crtx_listener_base *listener)
deactivate a listener
Definition core.c:354
void crtx_shutdown_listener(struct crtx_listener_base *listener)
release this listener
Definition core.c:470
int crtx_start_listener(struct crtx_listener_base *listener)
start or activate a listener
Definition core.c:133
int crtx_push_new_event(struct crtx_listener_base *lstnr, struct crtx_event **event, CRTX_EVENT_TYPE_VARTYPE event_type, char *description, char data_type, char *data_key_or_sign,...)
helper function to create and add an event with one call
Definition core.c:852
crtx_listener_state
the possible states of a listener crtx_listener_base
Definition core.h:165
int crtx_setup_listener(const char *id, void *options)
look for a listener repo for the given id and iniitalize a listener of this type
Definition core.c:289
void crtx_add_event(struct crtx_graph *graph, struct crtx_event *event)
add a new event to a graph for processing
Definition core.c:786
void crtx_add_task(struct crtx_graph *graph, struct crtx_task *task)
add task to graph
Definition core.c:677
void crtx_loop()
start the main event loop
Definition core.c:1232
an event that is emitted by a listener crtx_listener_base
Definition core.h:59
struct crtx_dict_item data
data associated with this event
Definition core.h:63
pthread_mutex_t mutex
mutex that protects this structure
Definition core.h:81
struct crtx_listener_base * origin
the listener that generated this event
Definition core.h:76
CRTX_EVENT_TYPE_VARTYPE type
this or crtx_event::description describe the type of event
Definition core.h:60
char error
if set, event has been invalidated
Definition core.h:68
char * description
this or crtx_event::type describe the type of event
Definition core.h:61
structure that represents a graph of tasks (crtx_task) that will be traversed with every crtx_event
Definition core.h:115
unsigned int n_types
number of crtx_graph::types
Definition core.h:122
char ** descriptions
event descriptions this graph accepts
Definition core.h:124
struct crtx_listener_base * listener
listener this graph belongs to
Definition core.h:138
CRTX_EVENT_TYPE_VARTYPE * types
type of events this graph accepts
Definition core.h:121
pthread_mutex_t mutex
mutex that protects this structure
Definition core.h:127
struct crtx_dll * claimed
list of events which are currently processed
Definition core.h:134
struct crtx_task * tasks
list of tasks in this graph
Definition core.h:129
unsigned int n_descriptions
number of crtx_graph::descriptions
Definition core.h:125
enum crtx_processing_mode mode
processing mode (none, thread, eloop) of this graph
Definition core.h:131
struct crtx_dll * equeue
event queue of this graph
Definition core.h:133
a list of crtx_handler_category_entry for a certain event type
Definition core.h:272
base structure of a listener
Definition core.h:186
MUTEX_TYPE state_mutex
mutex that protects the listener's state
Definition core.h:192
void * userdata
storage for user-provided data
Definition core.h:225
MUTEX_TYPE dependencies_lock
mutex that protects the (reverse) depenency lists
Definition core.h:206
struct crtx_ll * rev_dependencies
list of listeners which depend on us
Definition core.h:205
char autolock_source
if enabled, crtx_listener_base.source_lock is acquired before calling an event handler
Definition core.h:201
struct crtx_ll ll
linked-list entry of this listener
Definition core.h:187
struct crtx_ll * dependencies
list of listeners this listener depends on
Definition core.h:204
struct crtx_graph * graph
graph that contains the tasks that will be executed on events
Definition core.h:220
enum crtx_listener_state state
the current state of this listener
Definition core.h:193
enum crtx_processing_mode mode
processing mode (none, thread, eloop) of this listener
Definition core.h:196
struct crtx_evloop_fd evloop_fd
if this listener has a file descriptor, it will be stored in this structure
Definition core.h:198
struct crtx_evloop_callback default_el_cb
contains data about what should happen if events occur
Definition core.h:199
listener repository to create new listeners of a certain type
Definition core.h:152
structure that represents a plugin
Definition core.h:244
char(* init)()
callback that initializes this plugin
Definition core.h:251
char * path
path to the library
Definition core.h:245
void(* finish)()
callback that finishes this plugin
Definition core.h:252
void * handle
library handle
Definition core.h:248
void(* get_listener_repository)(struct crtx_listener_repository **listener_repository, unsigned int *listener_repository_length)
callback that registers the listeners the plugin provides
Definition core.h:254
char * plugin_name
name of this plugin
Definition core.h:256
char * basename
filename of the library
Definition core.h:246
represents generic modules
Definition core.h:235
core structure of libcortex
Definition core.h:279
void(* reinit_cb)(void *cb_data)
callback function that is called during reinit after a fork
Definition core.h:294
struct crtx_ll * listeners
list of registered listeners
Definition core.h:284
unsigned int n_plugins
number of available plugins in crtx_root::plugins
Definition core.h:310
struct crtx_lstnr_plugin * plugins
list of available plugins
Definition core.h:309
char reinit_after_shutdown
if true, reinitialize libcortex after a fork
Definition core.h:292
MUTEX_TYPE listeners_mutex
mutex that protects the list of listeners crtx_root::listeners
Definition core.h:285
a task basically represents a function that will be executed for an crtx_event
Definition core.h:91
crtx_handle_task_t handle
function that is called with the current event
Definition core.h:98
unsigned char position
position of the task in the graph
Definition core.h:93
char * event_type_match
if 0, task receives all events passing the graph
Definition core.h:96