Skip to content

Commit de57f85

Browse files
committed
Ready for 4.0.0
1 parent 8d9500b commit de57f85

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

Lib/module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int manage_fds(module *mod, m_context *c, const int flag, const bool stop
159159
}
160160

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

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

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

186186
int ret = manage_fds(mod, c, RM, stop);
187187
MOD_ASSERT(!ret, err_str, MOD_ERR);

Lib/priv.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
m_context *c = map_get(ctx, (char *)name); \
2222
MOD_ASSERT(c, "Context not found.", MOD_NO_CTX);
2323

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

35+
/* Convenience macros for exposed API */
3436
#define GET_CTX(self) _GET_CTX(self, false)
3537
#define GET_CTX_PURE(self) _GET_CTX(self, true)
3638

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

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

55+
/* Convenience macros for exposed API */
5256
#define GET_MOD(self) _GET_MOD(self, false)
5357
#define GET_MOD_PURE(self) _GET_MOD(self, true)
5458

Lib/pubsub.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static module_ret_code publish_msg(const module *mod, const char *topic,
5858
MOD_PARAM_ASSERT(message);
5959
MOD_PARAM_ASSERT(size > 0);
6060

61-
GET_CTX_PURE((&mod->self));
61+
GET_CTX_PRIV((&mod->self));
6262

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

7575
/** Private API **/
7676

77+
module_ret_code tell_system_pubsub_msg(m_context *c, enum msg_type type, const char *topic) {
78+
pubsub_msg_t m = { .topic = topic, .sender = NULL, .message = NULL, .type = type, .size = 0 };
79+
return tell_pubsub_msg(&m, NULL, c);
80+
}
81+
7782
int flush_pubsub_msg(void *data, void *m) {
7883
module *mod = (module *)m;
7984
pubsub_msg_t *mm = NULL;
@@ -178,11 +183,6 @@ module_ret_code module_unsubscribe(const self_t *self, const char *topic) {
178183
return MOD_ERR;
179184
}
180185

181-
module_ret_code tell_system_pubsub_msg(m_context *c, enum msg_type type, const char *topic) {
182-
pubsub_msg_t m = { .topic = topic, .sender = NULL, .message = NULL, .type = type, .size = 0 };
183-
return tell_pubsub_msg(&m, NULL, c);
184-
}
185-
186186
module_ret_code module_tell(const self_t *self, const self_t *recipient, const unsigned char *message,
187187
const ssize_t size) {
188188
GET_MOD(self);

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module_ref should then return a new self_t* object, add it to a stack in module.
1717
- [x] Better arrange code in module.c (ie: above internal API, below exposed API)
1818
- [x] Split module.c into module_pubsub.c and module_generic.c (?)
1919
- [x] Add a module_priv.c with various common (priv) functions?
20-
- [ ] Better macros naming (eg: GET_MOD_PURE etc etc...)
20+
- [x] Better macros naming (eg: GET_MOD_PURE etc etc...)
2121

2222
- [x] Add new tests for module_ref!
2323
- [x] Update libmodule API doc

0 commit comments

Comments
 (0)