Skip to content

Commit

Permalink
fixup! gnrc_netreg: add arbitrary callback support
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Oct 25, 2016
1 parent edf9372 commit 25d4472
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile.pseudomodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ PSEUDOMODULES += gnrc_ipv6_router
PSEUDOMODULES += gnrc_ipv6_router_default
PSEUDOMODULES += gnrc_netdev_default
PSEUDOMODULES += gnrc_neterr
PSEUDOMODULES += gnrc_netapi_callbacks
PSEUDOMODULES += gnrc_netapi_mbox
PSEUDOMODULES += gnrc_pktbuf
PSEUDOMODULES += gnrc_sixlowpan_border_router_default
Expand Down
15 changes: 15 additions & 0 deletions sys/include/net/gnrc/netapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
* USEMODULE += gnrc_netapi_mbox
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @}
*
* @defgroup net_gnrc_netapi_callbacks Callback extension
* @ingroup net_gnrc_netapi
* @brief Callback extension for @ref net_gnrc_netapi
* @{
* @details The submodule `gnrc_netapi_callbacks` provides an extension for
* callbacks to run GNRC thread-less.
*
* To use, add the module `gnrc_netapi_callbacks` to the `USEMODULE` macro in
* your application's Makefile:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk}
* USEMODULE += gnrc_netapi_callbacks
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @}
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
Expand Down
20 changes: 14 additions & 6 deletions sys/include/net/gnrc/netreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ typedef enum {
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
GNRC_NETREG_TYPE_MBOX,
#endif
#if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
GNRC_NETREG_TYPE_CB,
#endif
} gnrc_netreg_type_t;
#endif

Expand Down Expand Up @@ -78,22 +80,24 @@ typedef enum {
* for the netreg entry
* @param[in] mbox Target @ref core_mbox "mailbox" for the registry entry
*
* @note Only available with @ref net_gnrc_netreg_extra.
* @note Only available with @ref net_gnrc_netapi_mbox.
*
* @return An initialized netreg entry
*/
#define GNRC_NETREG_ENTRY_INIT_MBOX(demux_ctx, mbox) { NULL, demux_ctx, \
GNRC_NETREG_TYPE_MBOX, \
{ .mbox = mbox } }
#endif

#if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
/**
* @brief Initializes a netreg entry statically with callback
*
* @param[in] demux_ctx The @ref gnrc_netreg_entry_t::demux_ctx "demux context"
* for the netreg entry
* @param[in] cb Target callback for the registry entry
*
* @note Only available with @ref net_gnrc_netreg_extra.
* @note Only available with @ref net_gnrc_netapi_callbacks.
*
* @return An initialized netreg entry
*/
Expand All @@ -106,7 +110,7 @@ typedef enum {
*
* @pre `cmd` $\in$ { @ref GNRC_NETAPI_MSG_TYPE_RCV, @ref GNRC_NETAPI_MSG_TYPE_SND }
*
* @note Only available with @ref net_gnrc_netreg_extra.
* @note Only available with @ref net_gnrc_netapi_callbacks.
*
* @param[in] cmd @ref net_gnrc_netapi command type. Must be either
* @ref GNRC_NETAPI_MSG_TYPE_SND or
Expand All @@ -119,7 +123,7 @@ typedef void (*gnrc_netreg_entry_cb_t)(uint16_t cmd, gnrc_pktsnip_t *pkt,

/**
* @brief Callback + Context descriptor
* @note Only available with @ref net_gnrc_netreg_extra.
* @note Only available with @ref net_gnrc_netapi_callbacks.
*/
typedef struct {
gnrc_netreg_entry_cb_t cb; /**< the callback */
Expand Down Expand Up @@ -167,10 +171,11 @@ typedef struct gnrc_netreg_entry {
mbox_t *mbox;
#endif

#if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
/**
* @brief Target callback for the registry entry
*
* @note Only available with @ref net_gnrc_netreg_extra.
* @note Only available with @ref net_gnrc_netapi_callbacks.
*/
gnrc_netreg_entry_cbd_t *cbd;
#endif
Expand Down Expand Up @@ -223,6 +228,9 @@ static inline void gnrc_netreg_entry_init_mbox(gnrc_netreg_entry_t *entry,
entry->type = GNRC_NETREG_TYPE_MBOX;
entry->target.mbox = mbox;
}
#endif

#if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
/**
* @brief Initializes a netreg entry dynamically with callback
*
Expand All @@ -231,7 +239,7 @@ static inline void gnrc_netreg_entry_init_mbox(gnrc_netreg_entry_t *entry,
* for the netreg entry
* @param[in] mbox Target callback for the registry entry
*
* @note Only available with @ref net_gnrc_netreg_extra.
* @note Only available with @ref net_gnrc_netapi_callbacks.
*/
static inline void gnrc_netreg_entry_init_cb(gnrc_netreg_entry_t *entry,
uint32_t demux_ctx,
Expand Down
1 change: 1 addition & 0 deletions sys/net/gnrc/netapi/gnrc_netapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ int gnrc_netapi_dispatch(gnrc_nettype_t type, uint32_t demux_ctx,
}
break;
#endif
#ifdef MODULE_GNRC_NETAPI_CALLBACKS
case GNRC_NETREG_TYPE_CB:
sendto->target.cbd->cb(cmd, pkt, sendto->target.cbd->ctx);
break;
Expand Down

0 comments on commit 25d4472

Please sign in to comment.