Skip to content

Commit

Permalink
Renamed recv callback to receive to avoid conflicts with recv(2). Upd…
Browse files Browse the repository at this point in the history
…ated check() comments in examples.
  • Loading branch information
FedeDP committed Mar 29, 2018
1 parent 9c7edb7 commit 3b72972
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 35 deletions.
8 changes: 4 additions & 4 deletions Lib/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
static int init(void); \
static int check(void); \
static int evaluate(void); \
static void recv(const msg_t *msg, const void *userdata); \
static void receive(const msg_t *msg, const void *userdata); \
static void destroy(void); \
static const self_t *self = NULL; \
static void _ctor3_ constructor(void) { \
if (check()) { \
static userhook hook = { init, evaluate, recv, destroy }; \
static userhook hook = { init, evaluate, receive, destroy }; \
module_register(name, ctx, &self, &hook); \
} \
} \
Expand All @@ -31,8 +31,8 @@
#define m_pause() module_pause(self)
#define m_resume() module_resume(self)
#define m_stop() module_stop(self)
#define m_become(x) module_become(self, recv_##x)
#define m_unbecome() module_become(self, recv)
#define m_become(x) module_become(self, receive_##x)
#define m_unbecome() module_become(self, receive)
#define m_set_userdata(userdata) module_set_userdata(self, userdata)
#define m_update_fd(fd, close_old) module_update_fd(self, fd, close_old)
#define m_log(fmt, ...) module_log(self, fmt, ##__VA_ARGS__)
Expand Down
9 changes: 4 additions & 5 deletions Samples/Easy/doggo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <unistd.h>
#include <string.h>

static void recv_sleeping(const msg_t *msg, const void *userdata);
static void receive_sleeping(const msg_t *msg, const void *userdata);

/*
* Declare and automagically initialize
Expand All @@ -30,8 +30,7 @@ static int init(void) {

/*
* Whether this module should be actually created:
* 0 means OK -> start this module
* !0 means do not start.
* true if module must be created, !true otherwise.
*
* Use this function as a starting filter:
* you may desire that a module is not started in certain conditions.
Expand Down Expand Up @@ -63,7 +62,7 @@ static void destroy(void) {
* Our default poll callback.
* Note that message_t->msg/sender are unused for now.
*/
static void recv(const msg_t *msg, const void *userdata) {
static void receive(const msg_t *msg, const void *userdata) {
if (msg->msg) {
if (!strcmp(msg->msg->message, "ComeHere")) {
m_log("Running...\n");
Expand All @@ -83,7 +82,7 @@ static void recv(const msg_t *msg, const void *userdata) {
}
}

static void recv_sleeping(const msg_t *msg, const void *userdata) {
static void receive_sleeping(const msg_t *msg, const void *userdata) {
if (msg->msg) {
if (!strcmp(msg->msg->message, "WakeUp")) {
m_unbecome();
Expand Down
9 changes: 4 additions & 5 deletions Samples/Easy/pippo.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
MODULE("Pippo");

static void recv_ready(const msg_t *msg, const void *userdata);
static void receive_ready(const msg_t *msg, const void *userdata);

/*
* This function is automatically called before registering the module.
Expand All @@ -33,8 +33,7 @@ static int init(void) {

/*
* Whether this module should be actually created:
* 0 means OK -> start this module
* !0 means do not start.
* true if module must be created, !true otherwise.
*
* Use this function as a starting filter:
* you may desire that a module is not started in certain conditions.
Expand Down Expand Up @@ -66,7 +65,7 @@ static void destroy(void) {
* Our default poll callback.
* Note that message_t->msg/sender are unused for now.
*/
static void recv(const msg_t *msg, const void *userdata) {
static void receive(const msg_t *msg, const void *userdata) {
if (!msg->msg) {
char c;
read(msg->fd, &c, sizeof(char));
Expand Down Expand Up @@ -95,7 +94,7 @@ static void recv(const msg_t *msg, const void *userdata) {
* Secondary poll callback.
* Use m_become(ready) to start using this second poll callback.
*/
static void recv_ready(const msg_t *msg, const void *userdata) {
static void receive_ready(const msg_t *msg, const void *userdata) {
if (!msg->msg) {
char c;
read(msg->fd, &c, sizeof(char));
Expand Down
9 changes: 4 additions & 5 deletions Samples/MultiCtx/a.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void module_pre_start(void) {

}

static void recv_ready(const msg_t *msg, const void *userdata);
static void receive_ready(const msg_t *msg, const void *userdata);

/*
* Initializes this module's state;
Expand All @@ -40,8 +40,7 @@ static int init(void) {

/*
* Whether this module should be actually created:
* 0 means OK -> start this module
* !0 means do not start.
* true if module must be created, !true otherwise.
*
* Use this function as a starting filter:
* you may desire that a module is not started in certain conditions.
Expand Down Expand Up @@ -73,7 +72,7 @@ static void destroy(void) {
* Our default poll callback.
* Note that message_t->msg/sender are unused for now.
*/
static void recv(const msg_t *msg, const void *userdata) {
static void receive(const msg_t *msg, const void *userdata) {
if (!msg->msg) {
uint64_t t;
read(msg->fd, &t, sizeof(uint64_t));
Expand All @@ -93,7 +92,7 @@ static void recv(const msg_t *msg, const void *userdata) {
* Secondary poll callback.
* Use m_become(ready) to start using this second poll callback.
*/
static void recv_ready(const msg_t *msg, const void *userdata) {
static void receive_ready(const msg_t *msg, const void *userdata) {
if (!msg->msg) {
uint64_t t;
read(msg->fd, &t, sizeof(uint64_t));
Expand Down
5 changes: 2 additions & 3 deletions Samples/MultiCtx/b.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ static int init(void) {

/*
* Whether this module should be actually created:
* 0 means OK -> start this module
* !0 means do not start.
* true if module must be created, !true otherwise.
*
* Use this function as a starting filter:
* you may desire that a module is not started in certain conditions.
Expand Down Expand Up @@ -72,7 +71,7 @@ static void destroy(void) {
* Our default poll callback.
* Note that message_t->msg/sender are unused for now.
*/
static void recv(const msg_t *msg, const void *userdata) {
static void receive(const msg_t *msg, const void *userdata) {
if (!msg->msg) {
struct signalfd_siginfo fdsi;
ssize_t s = read(msg->fd, &fdsi, sizeof(struct signalfd_siginfo));
Expand Down
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Generic

- [x] update doc
- [x] rename recv to receive() to avoid issues with recv(2)
- [x] Update check() comments in examples

## Test it

Expand Down
6 changes: 3 additions & 3 deletions docs/src/callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Moreover, a module_pre_start function is declared too, but it is not needed by l
static int init(void);
static int check(void);
static int evaluate(void);
static void recv(const msg_t *msg, const void *userdata);
static void receive(const msg_t *msg, const void *userdata);
static void destroy(void);
.. c:function:: module_pre_start(void)
Expand Down Expand Up @@ -45,9 +45,9 @@ Moreover, a module_pre_start function is declared too, but it is not needed by l

:returns: true (not-0) if module is now ready to be started, else 0.

.. c:function:: recv(msg, userdata)
.. c:function:: receive(msg, userdata)
Poll callback, called when any event is ready on module's fd.
Poll callback, called when any event is ready on module's fd or when a PubSub message is received by a module.

:param: :c:type:`const msg_t *` msg: pointer to msg_t struct.
:param: :c:type:`const void *` userdata: pointer to userdata as set by m_set_userdata.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lifecycle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ When dealing with libmodule's :ref:`module_complex`, no modules is automatically
While this may seem useless, i am sure there can be some cases where you may wish to register/deregister modules yourself. |br|
When using complex API, you are responsible to register/deregister modules, and thus initing/destroying them. |br|
Note that with Complex API, module_pre_start() function is not available (it would be useless), and you won't need to define check() function. |br|
You will still have to define evaluate(), init(), recv() and destroy() functions (but you can freely name them!). |br|
You will still have to define evaluate(), init(), receive() and destroy() functions (but you can freely name them!). |br|

Everything else but module's (de)registration is same as Easy API.

18 changes: 9 additions & 9 deletions docs/src/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ Where not specified, these functions return a :ref:`module_ret_code <module_ret_

.. c:macro:: m_become(new_recv)
Change recv callback to recv_new_recv
Change receive callback to receive_new_recv

:param new_recv: new module's recv; the function has prefix \recv_ concatenated with new_recv
:param new_recv: new module's receive callback; the function has prefix \receive_ concatenated with new_recv
:type new_recv: untyped

.. c:macro:: m_unbecome(void)
Reset to default recv poll callback
Reset to default receive poll callback

.. c:macro:: m_set_userdata(userdata)
Set userdata for this module; userdata will be passed as parameter to recv callback
Set userdata for this module; userdata will be passed as parameter to receive callback

:param userdata: module's new userdata.
:type userdata: :c:type:`const void *`
Expand Down Expand Up @@ -191,18 +191,18 @@ Again, where not specified, these functions return a :ref:`module_ret_code <modu
:param self: pointer to module's handler
:type self: :c:type:`const self_t *`

.. c:function:: module_become(self, new_recv)
.. c:function:: module_become(self, new_receive)
Change recv callback to new_recv
Change receive callback to new_receive

:param self: pointer to module's handler
:param new_recv: new module's recv.
:param new_receive: new module's receive.
:type self: :c:type:`const self_t *`
:type new_recv: :c:type:`recv_cb`
:type new_receive: :c:type:`recv_cb`

.. c:function:: module_set_userdata(self, userdata)
Set userdata for this module; userdata will be passed as parameter to recv callback.
Set userdata for this module; userdata will be passed as parameter to receive callback.

:param self: pointer to module's handler
:param userdata: module's new userdata.
Expand Down

0 comments on commit 3b72972

Please sign in to comment.