libcortex
Event loop library following a "batteries included" approach
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
core.h File Reference

The core definitions of libcortex. More...

#include <stdint.h>
#include <regex.h>
#include "config.h"
#include "threads.h"
#include "dict.h"
#include "linkedlist.h"
#include "evloop.h"

Go to the source code of this file.

Data Structures

struct  crtx_event
 an event that is emitted by a listener crtx_listener_base More...
 
struct  crtx_task
 a task basically represents a function that will be executed for an crtx_event More...
 
struct  crtx_graph
 structure that represents a graph of tasks (crtx_task) that will be traversed with every crtx_event More...
 
struct  crtx_listener_repository
 listener repository to create new listeners of a certain type More...
 
struct  crtx_listener_base
 base structure of a listener More...
 
struct  crtx_module
 represents generic modules More...
 
struct  crtx_lstnr_plugin
 structure that represents a plugin More...
 
struct  crtx_handler_category_entry
 
struct  crtx_handler_category
 a list of crtx_handler_category_entry for a certain event type More...
 
struct  crtx_root
 core structure of libcortex More...
 

Macros

#define CRTX_TEST_MAIN(mainfct)
 
#define CRTX_EVENT_TYPE_VARTYPE   unsigned int
 
#define CRTX_EVENT_TYPE_FAMILY_MAX   (2)
 
#define CRTX_GRAPH_KEEP_GOING   1<<0
 
#define CRTX_LSTNR_STARTUP_TRIGGER   (1<<0)
 
#define CRTX_LSTNR_NO_AUTO_CLOSE   (1<<1)
 

Typedefs

typedef void(* crtx_raw_to_dict_t) (struct crtx_event *event, struct crtx_dict_item *item, void *user_data)
 

Enumerations

enum  crtx_processing_mode { CRTX_PREFER_NONE =0 , CRTX_PREFER_THREAD , CRTX_PREFER_ELOOP , CRTX_NO_PROCESSING_MODE }
 specifies how a listener should be processed More...
 
enum  crtx_listener_state {
  CRTX_LSTNR_UNKNOWN =0 , CRTX_LSTNR_STARTING , CRTX_LSTNR_STARTED , CRTX_LSTNR_PAUSED ,
  CRTX_LSTNR_STOPPING , CRTX_LSTNR_STOPPED , CRTX_LSTNR_SHUTTING_DOWN , CRTX_LSTNR_SHUTDOWN
}
 the possible states of a listener crtx_listener_base
 

Functions

void crtx_printf (char level, char const *format,...) __attribute__((format(printf
 
void char * crtx_stracpy (const char *str, size_t *str_length)
 
struct crtx_eventnew_event ()
 
void crtx_free_event (struct crtx_event *event)
 
int crtx_init ()
 
int crtx_finish ()
 
void crtx_loop ()
 start the main event loop
 
int crtx_loop_onetime ()
 
int crtx_is_shutting_down ()
 
int crtx_create_graph (struct crtx_graph **crtx_graph, const char *name)
 
int crtx_init_graph (struct crtx_graph *crtx_graph, const char *name)
 
int crtx_shutdown_graph (struct crtx_graph *egraph)
 
int crtx_free_graph (struct crtx_graph *egraph)
 
void add_task (struct crtx_graph *graph, struct crtx_task *task)
 
void crtx_add_task (struct crtx_graph *graph, struct crtx_task *task)
 add task to graph
 
int crtx_create_listener_task (struct crtx_listener_base *lstnr, crtx_handle_task_t handler, void *userdata)
 
struct crtx_taskcrtx_graph_get_task (struct crtx_graph *graph, const char *id, crtx_handle_task_t handler)
 
void add_event_type (char *event_type)
 
int crtx_find_graph_add_event (struct crtx_event *event)
 
void crtx_add_event (struct crtx_graph *graph, struct crtx_event *event)
 add a new event to a graph for processing
 
void add_event_sync (struct crtx_graph *graph, struct crtx_event *event)
 
struct crtx_graphcrtx_find_graph_for_event_description (char *event_description)
 
struct crtx_graphcrtx_find_graph_for_event_type (CRTX_EVENT_TYPE_VARTYPE event_type)
 
struct crtx_graphcrtx_get_graph_for_event_description (char *event_type, char **new_event_types)
 
struct crtx_taskcrtx_new_task ()
 
void crtx_free_task (struct crtx_task *task)
 
int crtx_wait_on_event (struct crtx_event *event)
 
int crtx_create_listener (const char *id, void *options) __attribute__((deprecated))
 
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
 
int crtx_init_listener_base (struct crtx_listener_base *lstnr)
 
struct crtx_listener_basecrtx_calloc_listener_base (void)
 
int crtx_listener_add_fd (struct crtx_listener_base *listener, int *fd_ptr, int fd, int event_flags, uint64_t timeout_us, crtx_handle_task_t event_handler, void *event_handler_data, crtx_evloop_error_cb_t error_cb, void *error_cb_data)
 
int crtx_listener_get_fd (struct crtx_listener_base *listener)
 
void crtx_shutdown_listener (struct crtx_listener_base *listener)
 release this listener
 
int crtx_create_event (struct crtx_event **event)
 
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
 
struct crtx_taskcrtx_create_task (struct crtx_graph *graph, unsigned char position, const char *id, crtx_handle_task_t handler, void *userdata)
 
struct crtx_taskcrtx_create_task_unique (struct crtx_graph *graph, unsigned char position, const char *id, crtx_handle_task_t handler, void *userdata)
 
void crtx_init_shutdown ()
 
int crtx_start_listener (struct crtx_listener_base *listener)
 start or activate a listener
 
int crtx_update_listener (struct crtx_listener_base *listener)
 trigger a listener update, e.g., to apply changes to a running listener
 
int crtx_stop_listener (struct crtx_listener_base *listener)
 deactivate a listener
 
void crtx_print_tasks (struct crtx_graph *graph)
 
void crtx_hexdump (unsigned char *buffer, size_t index)
 
void crtx_traverse_graph (struct crtx_graph *graph, struct crtx_event *event)
 
void crtx_reference_event_response (struct crtx_event *event)
 
void crtx_dereference_event_response (struct crtx_event *event)
 
void crtx_reference_event_release (struct crtx_event *event)
 
void crtx_dereference_event_release (struct crtx_event *event)
 
int crtx_graph_has_task (struct crtx_graph *graph)
 
int crtx_is_graph_empty (struct crtx_graph *graph)
 
void crtx_init_notification_listeners (void **data)
 
void crtx_finish_notification_listeners (void *data)
 
int crtx_handle_std_signals ()
 
void * crtx_process_graph_tmain (void *arg)
 
int crtx_process_one_event (struct crtx_graph *graph)
 
void crtx_event_set_raw_data (struct crtx_event *event, unsigned char type,...)
 
void crtx_event_set_dict_data (struct crtx_event *event, struct crtx_dict *data_dict, unsigned char n_additional_fields)
 
int crtx_event_raw2dict (struct crtx_event *event, void *user_data)
 
void crtx_event_get_payload (struct crtx_event *event, char *id, void **raw_pointer, struct crtx_dict **dict)
 
struct crtx_dictcrtx_event_get_dict (struct crtx_event *event)
 
struct crtx_dict_itemcrtx_event_get_item_by_key (struct crtx_event *event, char *id, char *key)
 
int crtx_event_get_value_by_key (struct crtx_event *event, char *key, char type, void *buffer, size_t buffer_size)
 
void * crtx_event_get_ptr (struct crtx_event *event)
 
char * crtx_event_get_string (struct crtx_event *event, char *key)
 
void crtx_event_set_dict (struct crtx_event *event, char *signature,...)
 
int crtx_event_get_int (struct crtx_event *event, int *value)
 
int crtx_event_get_data (struct crtx_event *event, void **data, size_t *size)
 
void crtx_register_handler_for_event_type (char *event_type, char *handler_name, crtx_handle_task_t handler_function, void *handler_data)
 
void crtx_autofill_graph_with_tasks (struct crtx_graph *graph, const char *event_type)
 
enum crtx_processing_mode crtx_get_mode (enum crtx_processing_mode local_mode)
 
void crtx_wait_on_graph_empty (struct crtx_graph *graph)
 
struct crtx_listener_repositorycrtx_get_new_listener_repo_entry ()
 
void crtx_set_main_event_loop (const char *event_loop)
 
int crtx_separate_evloop_thread ()
 
void crtx_lock_listener_source (struct crtx_listener_base *lbase)
 
void crtx_unlock_listener_source (struct crtx_listener_base *lbase)
 
void crtx_lock_listener (struct crtx_listener_base *lbase)
 
void crtx_unlock_listener (struct crtx_listener_base *lbase)
 
void crtx_trigger_event_processing (struct crtx_listener_base *lstnr)
 
void crtx_lstnr_handle_fd_closed (struct crtx_listener_base *lstnr)
 
void crtx_shutdown_after_fork ()
 
struct crtx_threadcrtx_start_detached_event_loop ()
 
int crtx_get_version (unsigned int *major, unsigned int *minor, unsigned int *revision)
 
void crtx_selfpipe_cb_free_lstnr (void *data)
 
int crtx_selfpipe_enqueue_cb (void(*cb)(void *), void *cb_data)
 
void crtx_print_event (struct crtx_event *event, FILE *f)
 
int crtx_is_fd_valid (int fd)
 

Variables

struct crtx_module static_modules []
 
struct crtx_rootcrtx_root
 

Detailed Description

The core definitions of libcortex.

Macro Definition Documentation

◆ CRTX_TEST_MAIN

#define CRTX_TEST_MAIN (   mainfct)
Value:
int main(int argc, char **argv) { \
int i; \
crtx_init(); \
crtx_handle_std_signals(); \
CRTX_DBG("entering test function\n"); \
i = mainfct(argc, argv); \
CRTX_DBG("left test function\n"); \
crtx_finish(); \
return i; \
}

Enumeration Type Documentation

◆ crtx_processing_mode

specifies how a listener should be processed

Enumerator
CRTX_PREFER_NONE 

unspecified mode

CRTX_PREFER_THREAD 

a thread should be started, e.g., for blocking calls

CRTX_PREFER_ELOOP 

a listener provides a file descriptor that can be added to the event loop

CRTX_NO_PROCESSING_MODE 

the listener requires no processing, e.g., if it depends on other listeners

Function Documentation

◆ crtx_stop_listener()

int crtx_stop_listener ( struct crtx_listener_base listener)

deactivate a listener

refuse stop if our reverse dependencies are still running