Skip to content

Commit

Permalink
Renamed userhook type to userhook_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Aug 31, 2019
1 parent 29aa0c9 commit 86a9466
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Lib/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ module_ret_code stop(mod_t *mod, const bool stop) {

/** Public API **/

module_ret_code module_register(const char *name, const char *ctx_name, self_t **self, const userhook *hook) {
module_ret_code module_register(const char *name, const char *ctx_name, self_t **self, const userhook_t *hook) {
MOD_PARAM_ASSERT(name);
MOD_PARAM_ASSERT(ctx_name);
MOD_PARAM_ASSERT(self);
Expand All @@ -281,7 +281,7 @@ module_ret_code module_register(const char *name, const char *ctx_name, self_t *
while (true) {
mod->name = name;

memcpy(&mod->hook, hook, sizeof(userhook));
memcpy(&mod->hook, hook, sizeof(userhook_t));
mod->state = IDLE;
mod->fds = NULL;

Expand Down
2 changes: 1 addition & 1 deletion Lib/priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ typedef struct {

/* Struct that holds data for each module */
struct _module {
userhook hook; // module's user defined callbacks
userhook_t hook; // module's user defined callbacks
stack_t *recvs; // Stack of recv functions for module_become/unbecome
const void *userdata; // module's user defined data
enum module_states state; // module's state
Expand Down
2 changes: 1 addition & 1 deletion Lib/public/module/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C"{
#endif

/* Module registration */
_public_ module_ret_code module_register(const char *name, const char *ctx_name, self_t **self, const userhook *hook);
_public_ module_ret_code module_register(const char *name, const char *ctx_name, self_t **self, const userhook_t *hook);
_public_ module_ret_code module_deregister(self_t **self);

/* External shared object module runtime loading */
Expand Down
2 changes: 1 addition & 1 deletion Lib/public/module/module_cmn.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ typedef struct {
evaluate_cb evaluate; // module's state changed function
recv_cb recv; // module's recv function
destroy_cb destroy; // module's destroy function
} userhook;
} userhook_t;

/* Struct that holds user defined memory functions */
typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion Lib/public/module/module_easy.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static void destroy(void); \
static const self_t *_self = NULL; \
static void _ctor3_ constructor(void) { \
if (check()) { \
userhook hook = { init, evaluate, receive, destroy }; \
userhook_t hook = { init, evaluate, receive, destroy }; \
module_register(name, ctx, (self_t **)&self(), &hook); \
} \
} \
Expand Down
4 changes: 2 additions & 2 deletions Samples/SharedSrc/mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ static self_t *selfA, *selfB;
* These modules can share some callbacks.
*/
void create_modules(const char *ctx_name) {
userhook hookA = (userhook) { A_init, evaluate, A_recv, destroy };
userhook hookB = (userhook) { B_init, evaluate, B_recv, destroy };
userhook_t hookA = (userhook_t) { A_init, evaluate, A_recv, destroy };
userhook_t hookB = (userhook_t) { B_init, evaluate, B_recv, destroy };

module_register("Pippo", ctx_name, &selfA, &hookA);
module_register("Doggo", ctx_name, &selfB, &hookB);
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ conversely to module_stop that should stop module right away freeing all its enq
- [x] Rename module_poll_t to fd_priv_t
- [x] FIX: avoid sending with MODULE_STOPPED pubsub message a not-exishtent reference to mod->self when deregistering, as module gets freed right after. Send NULL.
- [x] FIX: when deregistering, remove module from context before stopping it
- [x] Rename userhook to userhook_t, following other types

### Doc
- [x] module_dump
Expand Down
2 changes: 1 addition & 1 deletion docs/src/data_structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Types
evaluate_cb evaluate; // module's state changed function
recv_cb recv; // module's recv function
destroy_cb destroy; // module's destroy function
} userhook;
} userhook_t;
/* Struct that holds user defined memory functions */
typedef struct {
Expand Down
12 changes: 6 additions & 6 deletions tests/test_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const self_t *testSelf = NULL;
void test_module_register_NULL_name(void **state) {
(void) state; /* unused */

userhook hook = (userhook) { init, evaluate, recv, destroy };
userhook_t hook = (userhook_t) { init, evaluate, recv, destroy };
module_ret_code ret = module_register(NULL, CTX, &self, &hook);
assert_false(ret == MOD_OK);
assert_null(self);
Expand All @@ -27,7 +27,7 @@ void test_module_register_NULL_name(void **state) {
void test_module_register_NULL_ctx(void **state) {
(void) state; /* unused */

userhook hook = (userhook) { init, evaluate, recv, destroy };
userhook_t hook = (userhook_t) { init, evaluate, recv, destroy };
module_ret_code ret = module_register("testName", NULL, &self, &hook);
assert_false(ret == MOD_OK);
assert_null(self);
Expand All @@ -36,7 +36,7 @@ void test_module_register_NULL_ctx(void **state) {
void test_module_register_NULL_self(void **state) {
(void) state; /* unused */

userhook hook = (userhook) { init, evaluate, recv, destroy };
userhook_t hook = (userhook_t) { init, evaluate, recv, destroy };
module_ret_code ret = module_register("testName", CTX, NULL, &hook);
assert_false(ret == MOD_OK);
assert_null(self);
Expand All @@ -53,7 +53,7 @@ void test_module_register_NULL_hook(void **state) {
void test_module_register(void **state) {
(void) state; /* unused */

userhook hook = (userhook) { init, evaluate, recv, destroy };
userhook_t hook = (userhook_t) { init, evaluate, recv, destroy };
module_ret_code ret = module_register("testName", CTX, &self, &hook);
assert_true(ret == MOD_OK);
assert_non_null(self);
Expand All @@ -63,7 +63,7 @@ void test_module_register(void **state) {
void test_module_register_already_registered(void **state) {
(void) state; /* unused */

userhook hook = (userhook) { init, evaluate, recv, destroy };
userhook_t hook = (userhook_t) { init, evaluate, recv, destroy };
module_ret_code ret = module_register("testName", CTX, &self, &hook);
assert_false(ret == MOD_OK);
assert_non_null(self);
Expand All @@ -75,7 +75,7 @@ void test_module_register_same_name(void **state) {

self_t *self2 = NULL;

userhook hook = (userhook) { init, evaluate, recv, destroy };
userhook_t hook = (userhook_t) { init, evaluate, recv, destroy };
module_ret_code ret = module_register("testName", CTX, &self2, &hook);
assert_false(ret == MOD_OK);
assert_null(self2);
Expand Down

0 comments on commit 86a9466

Please sign in to comment.