Skip to content

Commit

Permalink
Dropped MODULE_PRE_START macro, and welcomed a new module_pre_start i…
Browse files Browse the repository at this point in the history
…nterface function declared by MODULE macro.
  • Loading branch information
FedeDP committed Mar 18, 2018
1 parent 4040353 commit 36ea3a1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions Lib/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

/* Interface Macros */
#define MODULE_CTX(name, ctx) \
static void _ctor1_ module_pre_start(void); \
static int init(void); \
static int check(void); \
static int evaluate(void); \
Expand All @@ -42,8 +43,6 @@
static void _dtor1_ destructor(void) { module_deregister(&self); }

#define MODULE(name) MODULE_CTX(name, DEFAULT_CTX)

#define MODULE_PRE_START() static void _ctor1_ module_pre_start(void)

/* Defines for easy API (with no need bothering with both self and ctx) */
#define m_is(x) module_is(self, x)
Expand Down
2 changes: 1 addition & 1 deletion Samples/Easy/a.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void recv_ready(const msg_t *msg, const void *userdata);
* called before registering the module. Use this to set some
* global state needed eg: in check() function
*/
MODULE_PRE_START() {
static void module_pre_start(void) {
printf("A: Not yet inited!\n");
}

Expand Down
2 changes: 1 addition & 1 deletion Samples/Easy/b.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ MODULE("B");
* called before registering the module. Use this to set some
* global state needed eg: in check() function
*/
MODULE_PRE_START() {
static void module_pre_start(void) {
printf("B: Not yet inited!\n");
}

Expand Down
12 changes: 9 additions & 3 deletions docs/src/callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
Module callbacks
================

Every module needs 5 callbacks that be must defined by developer. |br|
They are automatically declared by MODULE macro:
Every module needs 5 functions that be must defined by developer. |br|
They are automatically declared by MODULE macro. |br|
Moreover, a module_pre_start function is declared too, but it is not needed by libmodule interface, ie: it can be left undefined.

.. code::
static void module_pre_start(void);
static int init(void);
static int check(void);
static int evaluate(void);
static void recv(const msg_t *msg, const void *userdata);
static void destroy(void);
.. c:function:: module_pre_start(void)
It can be used to create a function that will be called before any module is registered. |br|
It is the per-module version of :ref:`modules_pre_start <modules_pre_start>` function. |br|

.. c:function:: init(void)
Initializes module state
Expand Down
6 changes: 0 additions & 6 deletions docs/src/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ These macros make it easy and transparent to developer all of the module's inter
It enforces correct modularity too: each module must have its own source file. |br|
Where not specified, these functions return a :ref:`module_ret_code <module_ret_code>`.

.. c:macro:: MODULE_PRE_START()
This macro can be used to create a function that will be automatically called before any module is registered.
It is the per-module version of :ref:`modules_pre_start <modules_pre_start>` function.
It does not return anything.

.. c:macro:: m_is(state)
Check current module's state
Expand Down

0 comments on commit 36ea3a1

Please sign in to comment.