extern_interface/include/exint/event.h

32 lines
1.1 KiB
C
Raw Normal View History

#ifndef _INCLUDE_EVENT_H_
#define _INCLUDE_EVENT_H_
#include <stddef.h>
#define CONCAT_(prefix, suffix) prefix##suffix
/// Concatenate `prefix, suffix` into `prefixsuffix`
#define CONCAT(prefix, suffix) CONCAT_(prefix, suffix)
/// Register event handler
#define ON_EVENT_EX(name, func, data) \
static void func (const char* event_name, size_t args_size, void *args, void* user_data); \
int CONCAT(func, _register_ret) = exint_event_register(#name, func, data);\
static void func (const char* event_name, size_t args_size, void *args, void* user_data)
#define ON_EVENT(name) ON_EVENT_EX(name, CONCAT(_event_ ## name ## _handle_line_, __LINE__), NULL)
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*event_callback)(const char*, size_t, void*, void*);
void exint_event(const char *event_name, size_t args_size, void *args);
int exint_event_register(const char *event_name, event_callback callback, void* user_data);
int exint_event_unregister(const char *event_name, event_callback callback, void* user_data);
void* exint_event_thread(void*);
#ifdef __cplusplus
}
#endif
#endif