neterr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef NET_GNRC_NETERR_H
21 #define NET_GNRC_NETERR_H
22 
23 #include <errno.h>
24 #include <stdint.h>
25 
26 #include "kernel_types.h"
27 #include "msg.h"
28 #include "net/gnrc/pkt.h"
29 #include "thread.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 #define GNRC_NETERR_MSG_TYPE (0x0206)
39 
43 #define GNRC_NETERR_SUCCESS (0)
44 
51 #ifdef MODULE_GNRC_NETERR
52 static inline void gnrc_neterr_report(gnrc_pktsnip_t *pkt, uint32_t err)
53 {
54  if (pkt->err_sub != KERNEL_PID_UNDEF) {
55  msg_t msg;
56 
58  msg.content.value = err;
59 
60  msg_send(&msg, pkt->err_sub);
61  }
62 }
63 #else
64 #define gnrc_neterr_report(pkt, err) (void)pkt; (void)err
65 #endif
66 
75 #ifdef MODULE_GNRC_NETERR
76 static inline int gnrc_neterr_reg(gnrc_pktsnip_t *pkt)
77 {
78  if (pkt->err_sub != KERNEL_PID_UNDEF) {
79  return EALREADY;
80  }
81  pkt->err_sub = thread_getpid();
82  return 0;
83 }
84 #else
85 #define gnrc_neterr_reg(pkt) (0)
86 #endif
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif /* NET_GNRC_NETERR_H */
93 
EALREADY
#define EALREADY
Connection already in progress.
Definition: errno.h:76
GNRC_NETERR_MSG_TYPE
#define GNRC_NETERR_MSG_TYPE
Messaging / IPC type for reporting an error.
Definition: neterr.h:38
gnrc_neterr_report
#define gnrc_neterr_report(pkt, err)
Reports an error to all subscribers of errors to pkt.
Definition: neterr.h:64
msg_t::type
uint16_t type
Type field.
Definition: msg.h:188
msg.h
Messaging API for inter process communication.
gnrc_neterr_reg
#define gnrc_neterr_reg(pkt)
Registers the current thread for errors on a gnrc_pktsnip_t.
Definition: neterr.h:85
thread_getpid
static kernel_pid_t thread_getpid(void)
Returns the process ID of the currently running thread.
Definition: thread.h:472
msg_t::content
union msg_t::@2 content
Content of the message.
pkt.h
General definitions for network packets and their helper functions.
msg_t::value
uint32_t value
Value content field.
Definition: msg.h:191
msg_send
int msg_send(msg_t *m, kernel_pid_t target_pid)
Send a message (blocking).
msg_t
Describes a message object which can be sent between threads.
Definition: msg.h:185
gnrc_pktsnip
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:108
kernel_types.h
Types used by the kernel.
errno.h
KERNEL_PID_UNDEF
#define KERNEL_PID_UNDEF
Canonical identifier for an invalid PID.
Definition: sched.h:105