1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

ng_netapi: centralize packet dispatchment for RCV and SND

This commit is contained in:
Martine Lenders 2015-04-29 22:32:06 +02:00
parent 3b814fdf05
commit 59f62e5366
2 changed files with 60 additions and 0 deletions

View File

@ -31,6 +31,7 @@
#include "kernel.h"
#include "thread.h"
#include "net/ng_netconf.h"
#include "net/ng_nettype.h"
#include "net/ng_pkt.h"
#ifdef __cplusplus
@ -83,6 +84,19 @@ typedef struct {
*/
int ng_netapi_send(kernel_pid_t pid, ng_pktsnip_t *pkt);
/**
* @brief Sends a @ref NG_NETAPI_MSG_TYPE_SND command to all subscribers to
* (@p type, @p demux_ctx).
*
* @param[in] type type of the targeted network module.
* @param[in] demux_ctx demultiplexing context for @p type.
* @param[in] pkt pointer into the packet buffer holding the data to send
*
* @return Number of subscribers to (@p type, @p demux_ctx).
*/
int ng_netapi_dispatch_send(ng_nettype_t type, uint32_t demux_ctx,
ng_pktsnip_t *pkt);
/**
* @brief Shortcut function for sending @ref NG_NETAPI_MSG_TYPE_RCV messages
*
@ -94,6 +108,19 @@ int ng_netapi_send(kernel_pid_t pid, ng_pktsnip_t *pkt);
*/
int ng_netapi_receive(kernel_pid_t pid, ng_pktsnip_t *pkt);
/**
* @brief Sends a @ref NG_NETAPI_MSG_TYPE_RCV command to all subscribers to
* (@p type, @p demux_ctx).
*
* @param[in] type type of the targeted network module.
* @param[in] demux_ctx demultiplexing context for @p type.
* @param[in] pkt pointer into the packet buffer holding the data to send
*
* @return Number of subscribers to (@p type, @p demux_ctx).
*/
int ng_netapi_dispatch_receive(ng_nettype_t type, uint32_t demux_ctx,
ng_pktsnip_t *pkt);
/**
* @brief Shortcut function for sending @ref NG_NETAPI_MSG_TYPE_GET messages and
* parsing the returned @ref NG_NETAPI_MSG_TYPE_ACK message

View File

@ -20,6 +20,8 @@
#include "kernel.h"
#include "msg.h"
#include "net/ng_netreg.h"
#include "net/ng_pktbuf.h"
#include "net/ng_netapi.h"
/**
@ -64,16 +66,47 @@ static inline int _snd_rcv(kernel_pid_t pid, uint16_t type, ng_pktsnip_t *pkt)
return msg_send(&msg, pid);
}
static inline int _snd_rcv_dispatch(ng_nettype_t type, uint32_t demux_ctx,
uint16_t cmd, ng_pktsnip_t *pkt)
{
int numof = ng_netreg_num(type, demux_ctx);
ng_netreg_entry_t *sendto;
if (numof != 0) {
sendto = ng_netreg_lookup(type, demux_ctx);
ng_pktbuf_hold(pkt, numof - 1);
while (sendto) {
_snd_rcv(sendto->pid, cmd, pkt);
sendto = ng_netreg_getnext(sendto);
}
}
return numof;
}
int ng_netapi_send(kernel_pid_t pid, ng_pktsnip_t *pkt)
{
return _snd_rcv(pid, NG_NETAPI_MSG_TYPE_SND, pkt);
}
int ng_netapi_dispatch_send(ng_nettype_t type, uint32_t demux_ctx,
ng_pktsnip_t *pkt)
{
return _snd_rcv_dispatch(type, demux_ctx, NG_NETAPI_MSG_TYPE_SND, pkt);
}
int ng_netapi_receive(kernel_pid_t pid, ng_pktsnip_t *pkt)
{
return _snd_rcv(pid, NG_NETAPI_MSG_TYPE_RCV, pkt);
}
int ng_netapi_dispatch_receive(ng_nettype_t type, uint32_t demux_ctx,
ng_pktsnip_t *pkt)
{
return _snd_rcv_dispatch(type, demux_ctx, NG_NETAPI_MSG_TYPE_RCV, pkt);
}
int ng_netapi_get(kernel_pid_t pid, ng_netconf_opt_t opt, uint16_t context,
void *data, size_t data_len)
{