Skip to content

Commit

Permalink
Ready for 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Jan 20, 2019
1 parent 8d9500b commit de57f85
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Lib/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static int manage_fds(module *mod, m_context *c, const int flag, const bool stop
}

static module_ret_code start(module *mod, const char *err_str) {
GET_CTX_PURE((&mod->self));
GET_CTX_PRIV((&mod->self));

/*
* Starting module for the first time
Expand All @@ -181,7 +181,7 @@ static module_ret_code start(module *mod, const char *err_str) {
}

static module_ret_code stop(module *mod, const char *err_str, const bool stop) {
GET_CTX_PURE((&mod->self));
GET_CTX_PRIV((&mod->self));

int ret = manage_fds(mod, c, RM, stop);
MOD_ASSERT(!ret, err_str, MOD_ERR);
Expand Down
8 changes: 6 additions & 2 deletions Lib/priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
m_context *c = map_get(ctx, (char *)name); \
MOD_ASSERT(c, "Context not found.", MOD_NO_CTX);

#define GET_CTX_PRIV(self) m_context *c = self->ctx
/*
* Convenience macro to retrieve self->ctx + doing some checks.
* Skip reference check for pure functions.
*/
#define _GET_CTX(self, pure) \
MOD_ASSERT(self, "NULL self handler.", MOD_NO_SELF); \
MOD_ASSERT(!self->is_ref || pure, "Self is a reference object. It does not own module.", MOD_REF_ERR); \
m_context *c = self->ctx; \
GET_CTX_PRIV(self); \
MOD_ASSERT(c, "Context not found.", MOD_NO_CTX);

/* Convenience macros for exposed API */
#define GET_CTX(self) _GET_CTX(self, false)
#define GET_CTX_PURE(self) _GET_CTX(self, true)

Expand All @@ -39,16 +41,18 @@
module *mod = map_get(ctx->modules, (char *)name); \
MOD_ASSERT(mod, "Module not found.", MOD_NO_MOD);

#define GET_MOD_PRIV(self) module *mod = self->mod
/*
* Convenience macro to retrieve self->mod + doing some checks.
* Skip reference check for pure functions.
*/
#define _GET_MOD(self, pure) \
MOD_ASSERT(self, "NULL self handler.", MOD_NO_SELF); \
MOD_ASSERT(!self->is_ref || pure, "Self is a reference object. It does not own module.", MOD_REF_ERR); \
module *mod = self->mod; \
GET_MOD_PRIV(self); \
MOD_ASSERT(mod, "Module not found.", MOD_NO_MOD);

/* Convenience macros for exposed API */
#define GET_MOD(self) _GET_MOD(self, false)
#define GET_MOD_PURE(self) _GET_MOD(self, true)

Expand Down
12 changes: 6 additions & 6 deletions Lib/pubsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static module_ret_code publish_msg(const module *mod, const char *topic,
MOD_PARAM_ASSERT(message);
MOD_PARAM_ASSERT(size > 0);

GET_CTX_PURE((&mod->self));
GET_CTX_PRIV((&mod->self));

void *tmp = NULL;
/*
Expand All @@ -74,6 +74,11 @@ static module_ret_code publish_msg(const module *mod, const char *topic,

/** Private API **/

module_ret_code tell_system_pubsub_msg(m_context *c, enum msg_type type, const char *topic) {
pubsub_msg_t m = { .topic = topic, .sender = NULL, .message = NULL, .type = type, .size = 0 };
return tell_pubsub_msg(&m, NULL, c);
}

int flush_pubsub_msg(void *data, void *m) {
module *mod = (module *)m;
pubsub_msg_t *mm = NULL;
Expand Down Expand Up @@ -178,11 +183,6 @@ module_ret_code module_unsubscribe(const self_t *self, const char *topic) {
return MOD_ERR;
}

module_ret_code tell_system_pubsub_msg(m_context *c, enum msg_type type, const char *topic) {
pubsub_msg_t m = { .topic = topic, .sender = NULL, .message = NULL, .type = type, .size = 0 };
return tell_pubsub_msg(&m, NULL, c);
}

module_ret_code module_tell(const self_t *self, const self_t *recipient, const unsigned char *message,
const ssize_t size) {
GET_MOD(self);
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module_ref should then return a new self_t* object, add it to a stack in module.
- [x] Better arrange code in module.c (ie: above internal API, below exposed API)
- [x] Split module.c into module_pubsub.c and module_generic.c (?)
- [x] Add a module_priv.c with various common (priv) functions?
- [ ] Better macros naming (eg: GET_MOD_PURE etc etc...)
- [x] Better macros naming (eg: GET_MOD_PURE etc etc...)

- [x] Add new tests for module_ref!
- [x] Update libmodule API doc
Expand Down

0 comments on commit de57f85

Please sign in to comment.