Skip to content

Commit

Permalink
* Avoid exposing main() and modules_pre_start() functions in modules.…
Browse files Browse the repository at this point in the history
…h interface.

They're not part of libmodule's API and should not be called like functions.
* Small examples updates.
  • Loading branch information
FedeDP committed Jul 26, 2019
1 parent 948a683 commit ce00c4e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Lib/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static int recv_events(m_context *c, int timeout);
map_t *ctx;
memhook_t memhook;

void modules_pre_start(void) {
_public_ void _ctor0_ _weak_ modules_pre_start(void) {
MODULE_DEBUG("Pre-starting libmodule.");
}

Expand Down Expand Up @@ -46,7 +46,7 @@ static map_ret_code main_loop(void *data, const char *key, void *value) {
* if ctx_num > 1 -> allocating ctx_num pthreads and each of them will loop on its context
* else -> just loops on only ctx on main thread
*/
int main(int argc, char *argv[]) {
_public_ int _weak_ main(int argc, char *argv[]) {
void *th = NULL;

/* If there is more than 1 registered ctx, alloc as many pthreads as needed */
Expand Down
2 changes: 0 additions & 2 deletions Lib/public/module/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
extern "C"{
#endif

_public_ void _ctor0_ _weak_ modules_pre_start(void);
_public_ int _weak_ main(int argc, char *argv[]);
_public_ module_ret_code modules_set_memhook(const memhook_t *hook);
_public_ module_ret_code modules_ctx_set_logger(const char *ctx_name, const log_cb logger);
_public_ module_ret_code modules_ctx_loop_events(const char *ctx_name, const int max_events);
Expand Down
9 changes: 8 additions & 1 deletion Samples/Easy/doggo.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ static void receive(const msg_t *msg, const void *userdata) {
/* Doggo should subscribe to "leaving" topic */
m_subscribe(msg->ps_msg->topic);
break;
case MODULE_STOPPED: {
char *name = NULL;
module_get_name(msg->ps_msg->sender, &name);
m_log("Module '%s' has been stopped.\n", name);
free(name);
}
break;
default:
break;
}
Expand All @@ -80,7 +87,7 @@ static void receive_sleeping(const msg_t *msg, const void *userdata) {
/* A new module has been started */
char *name = NULL;
module_get_name(new_mod, &name);
m_log("Module '%s' has been started started.\n", name);
m_log("Module '%s' has been started.\n", name);
free(name);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Samples/Poll/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* There is no need to explicitly call it.
*/
void modules_pre_start() {
printf("Started Libmodule %d.%d.%d\n", MODULE_VERSION_MAJ, MODULE_VERSION_MIN, MODULE_VERSION_PAT);
printf("Poll_Sample -> Started Libmodule %d.%d.%d\n", MODULE_VERSION_MAJ, MODULE_VERSION_MIN, MODULE_VERSION_PAT);
printf("Press 'c' to start playing with your own doggo...\n");
}

Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ conversely to module_stop that should stop module right away freeing all its enq
- [x] stop() and start() should avoid err_str parameter.
- [x] Stop looping on context when there are no RUNNING modules
- [x] Cleanup some out of date comments in examples
- [x] Avoid exposing in modules.h main() and modules_pre_start() functions: they're not part of libmodule's API and cannot be called as functions.

### Doc
- [x] module_dump
Expand Down

0 comments on commit ce00c4e

Please sign in to comment.