Skip to content

Commit

Permalink
fixup! gnrc_netreg: add mbox support
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Oct 25, 2016
1 parent 2fced10 commit edf9372
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ifneq (,$(filter gnrc_conn_udp,$(USEMODULE)))
USEMODULE += gnrc_udp
endif

ifneq (,$(filter gnrc_netreg_extra,$(USEMODULE)))
ifneq (,$(filter gnrc_netapi_mbox,$(USEMODULE)))
USEMODULE += core_mbox
endif

Expand Down
2 changes: 1 addition & 1 deletion Makefile.pseudomodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PSEUDOMODULES += gnrc_ipv6_router
PSEUDOMODULES += gnrc_ipv6_router_default
PSEUDOMODULES += gnrc_netdev_default
PSEUDOMODULES += gnrc_neterr
PSEUDOMODULES += gnrc_netreg_extra
PSEUDOMODULES += gnrc_netapi_mbox
PSEUDOMODULES += gnrc_pktbuf
PSEUDOMODULES += gnrc_sixlowpan_border_router_default
PSEUDOMODULES += gnrc_sixlowpan_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 @@ -21,6 +21,21 @@
* @file
* @brief Generic interface to communicate with GNRC modules
*
* @defgroup net_gnrc_netapi_mbox Mailbox IPC extension
* @ingroup net_gnrc_netapi
* @brief @ref core_mbox "Mailbox IPC" extension for @ref net_gnrc_netapi
* @{
*
* @details The submodule `gnrc_netapi_mbox` provides an extension for
* @ref core_mbox "Mailbox IPC".
*
* To use, add the module `gnrc_netapi_mbox` to the `USEMODULE` macro in your
* application's Makefile:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk}
* USEMODULE += gnrc_netapi_mbox
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @}
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
Expand Down
43 changes: 17 additions & 26 deletions sys/include/net/gnrc/netreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@
* @brief Definitions to register network protocol PIDs to use with
* @ref net_gnrc_netapi.
*
* @defgroup net_gnrc_netreg_extra Extension for alternative handlers
* @ingroup net_gnrc_netreg
* @brief Registry extension for alternative handlers
* @{
* The submodule `gnrc_netreg_extra` provides an extension for alternative
* handlers (e.g. @ref core_mbox "Mailbox IPC").
*
* To use, add the module `gnrc_netreg_extra` to the `USEMODULE` macro in your
* application's Makefile:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk}
* USEMODULE += gnrc_netreg_extra
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @}
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NETREG_H_
Expand All @@ -42,18 +27,21 @@
#include "net/gnrc/nettype.h"
#include "net/gnrc/pkt.h"

#ifdef MODULE_GNRC_NETREG_EXTRA
#ifdef MODULE_GNRC_NETAPI_MBOX
#include "mbox.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifdef MODULE_GNRC_NETREG_EXTRA
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) || \
defined(DOXYGEN)
typedef enum {
GNRC_NETREG_TYPE_DEFAULT = 0,
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
GNRC_NETREG_TYPE_MBOX,
#endif
GNRC_NETREG_TYPE_CB,
} gnrc_netreg_type_t;
#endif
Expand All @@ -74,15 +62,15 @@ typedef enum {
*
* @return An initialized netreg entry
*/
#ifdef MODULE_GNRC_NETREG_EXTRA
#ifdef MODULE_GNRC_NETAPI_MBOX
#define GNRC_NETREG_ENTRY_INIT_PID(demux_ctx, pid) { NULL, demux_ctx, \
GNRC_NETREG_TYPE_DEFAULT, \
{ pid } }
#else
#define GNRC_NETREG_ENTRY_INIT_PID(demux_ctx, pid) { NULL, demux_ctx, { pid } }
#endif

#if defined(MODULE_GNRC_NETREG_EXTRA) || defined(DOXYGEN)
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
/**
* @brief Initializes a netreg entry statically with mbox
*
Expand Down Expand Up @@ -158,23 +146,26 @@ typedef struct gnrc_netreg_entry {
* ports in UDP/TCP, or similar.
*/
uint32_t demux_ctx;
#if defined(MODULE_GNRC_NETREG_EXTRA) || defined(DOXYGEN)
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) || \
defined(DOXYGEN)
/**
* @brief Type of the registry entry
*
* @note Only available with @ref net_gnrc_netreg_extra.
* @note Only available with @ref net_gnrc_netapi_mbox or
* @ref net_gnrc_netapi_callbacks.
*/
gnrc_netreg_type_t type;
#endif
union {
kernel_pid_t pid; /**< The PID of the registering thread */
#if defined(MODULE_GNRC_NETREG_EXTRA) || defined(DOXYGEN)
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
/**
* @brief 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.
*/
mbox_t *mbox;
#endif

/**
* @brief Target callback for the registry entry
Expand Down Expand Up @@ -206,13 +197,13 @@ static inline void gnrc_netreg_entry_init_pid(gnrc_netreg_entry_t *entry,
{
entry->next = NULL;
entry->demux_ctx = demux_ctx;
#ifdef MODULE_GNRC_NETREG_EXTRA
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS)
entry->type = GNRC_NETREG_TYPE_DEFAULT;
#endif
entry->target.pid = pid;
}

#if defined(MODULE_GNRC_NETREG_EXTRA) || defined(DOXYGEN)
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
/**
* @brief Initializes a netreg entry dynamically with mbox
*
Expand All @@ -221,7 +212,7 @@ static inline void gnrc_netreg_entry_init_pid(gnrc_netreg_entry_t *entry,
* 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.
*/
static inline void gnrc_netreg_entry_init_mbox(gnrc_netreg_entry_t *entry,
uint32_t demux_ctx,
Expand Down
7 changes: 5 additions & 2 deletions sys/net/gnrc/netapi/gnrc_netapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static inline int _snd_rcv(kernel_pid_t pid, uint16_t type, gnrc_pktsnip_t *pkt)
return ret;
}

#ifdef MODULE_GNRC_NETREG_EXTRA
#ifdef MODULE_GNRC_NETAPI_MBOX
static inline int _snd_rcv_mbox(mbox_t *mbox, uint16_t type, gnrc_pktsnip_t *pkt)
{
msg_t msg;
Expand All @@ -102,7 +102,7 @@ int gnrc_netapi_dispatch(gnrc_nettype_t type, uint32_t demux_ctx,
gnrc_pktbuf_hold(pkt, numof - 1);

while (sendto) {
#ifdef MODULE_GNRC_NETREG_EXTRA
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS)
int release = 0;
switch (sendto->type) {
case GNRC_NETREG_TYPE_DEFAULT:
Expand All @@ -111,15 +111,18 @@ int gnrc_netapi_dispatch(gnrc_nettype_t type, uint32_t demux_ctx,
release = 1;
}
break;
#ifdef MODULE_GNRC_NETAPI_MBOX
case GNRC_NETREG_TYPE_MBOX:
if (_snd_rcv_mbox(sendto->target.mbox, cmd, pkt) < 1) {
/* unable to dispatch packet */
release = 1;
}
break;
#endif
case GNRC_NETREG_TYPE_CB:
sendto->target.cbd->cb(cmd, pkt, sendto->target.cbd->ctx);
break;
#endif
default:
/* unknown dispatch type */
release = 1;
Expand Down
9 changes: 4 additions & 5 deletions sys/net/gnrc/netreg/gnrc_netreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ void gnrc_netreg_init(void)

int gnrc_netreg_register(gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
{
#ifdef MODULE_GNRC_NETREG_EXTRA
#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS)
#ifdef DEVELHELP
if (entry->type == GNRC_NETREG_TYPE_DEFAULT) {
/* only threads with a message queue are allowed to register at gnrc */
assert(sched_threads[entry->target.pid]->msg_array);
}
/* only threads with a message queue are allowed to register at gnrc */
assert((entry->type != GNRC_NETREG_TYPE_DEFAULT) ||
sched_threads[entry->target.pid]->msg_array);
#endif
#else
/* only threads with a message queue are allowed to register at gnrc */
Expand Down

0 comments on commit edf9372

Please sign in to comment.