-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MausTec:main' into Orgasm-Modes
- Loading branch information
Showing
7 changed files
with
242 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#ifndef __system__event_manager_h | ||
#define __system__event_manager_h | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "system/events.h" | ||
|
||
#define EVENT_DECL(evt) const char* evt | ||
#define EVENT_DEFINE(evt) const char* evt = #evt | ||
|
||
#define EVENT_HANDLER_ARG_TYPE void* | ||
|
||
EVENTS(EVENT_DECL); | ||
|
||
/** | ||
* @brief Function type for event handlers that you can registers. | ||
* | ||
*/ | ||
typedef void (*event_handler_t | ||
)(const char* event, | ||
EVENT_HANDLER_ARG_TYPE event_arg_ptr, | ||
int event_arg_int, | ||
EVENT_HANDLER_ARG_TYPE handler_arg); | ||
|
||
typedef struct event_handler_node { | ||
event_handler_t handler; | ||
EVENT_HANDLER_ARG_TYPE handler_arg; | ||
struct event_handler_node* next; | ||
} event_handler_node_t; | ||
|
||
typedef struct event_node { | ||
event_handler_node_t* handlers; | ||
struct event_node* next; | ||
char event[]; | ||
} event_node_t; | ||
|
||
/** | ||
* @brief Registers an event handler. | ||
* | ||
* Event handlers may only be registered once per event. This function will filter through the | ||
* existing event handlers, and if such an event/handler combination is found, will return an error. | ||
* | ||
* @param event Event string | ||
* @param handler Handler function pointer | ||
* @param handler_arg Argument to pass along to the handler_arg param in Handler function | ||
* invocations | ||
*/ | ||
event_handler_node_t* event_manager_register_handler( | ||
const char* event, event_handler_t handler, EVENT_HANDLER_ARG_TYPE handler_arg | ||
); | ||
|
||
/** | ||
* @brief Unregisters a handler from a specific event. | ||
* | ||
* @param event Event string | ||
* @param handler Handler function pointer | ||
*/ | ||
void event_manager_unregister_handler(const char* event, event_handler_t handler); | ||
|
||
/** | ||
* @brief Unregisters a handler from all events. | ||
* | ||
* @param handler Handler function pointer | ||
*/ | ||
void event_manager_unregister_handler_all(event_handler_t handler); | ||
|
||
/** | ||
* @brief Dispatches an event to all handlers registered to it. | ||
* | ||
* @param event Event string | ||
* @param event_arg_ptr Event arg, pointer | ||
* @param event_arg_int Event arg, integer | ||
*/ | ||
void event_manager_dispatch( | ||
const char* event, EVENT_HANDLER_ARG_TYPE event_arg_ptr, int event_arg_int | ||
); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef __system__events_h | ||
#define __system__events_h | ||
|
||
#define EVENTS(X) \ | ||
X(EVT_MODE_SET); \ | ||
X(EVT_SPEED_CHANGE); \ | ||
X(EVT_AROUSAL_CHANGE); \ | ||
X(EVT_ORGASM_DENIAL); \ | ||
X(EVT_EDGE_START); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.