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 "msg.h"
27 #include "net/gnrc/pkt.h"
28 #include "thread.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
37 #define GNRC_NETERR_MSG_TYPE (0x0206)
38 
42 #define GNRC_NETERR_SUCCESS (0)
43 
50 #ifdef MODULE_GNRC_NETERR
51 static inline void gnrc_neterr_report(gnrc_pktsnip_t *pkt, uint32_t err)
52 {
53  if (pkt->err_sub != KERNEL_PID_UNDEF) {
54  msg_t msg;
55 
57  msg.content.value = err;
58 
59  msg_send(&msg, pkt->err_sub);
60  }
61 }
62 #else
63 #define gnrc_neterr_report(pkt, err) (void)pkt; (void)err
64 #endif
65 
74 #ifdef MODULE_GNRC_NETERR
75 static inline int gnrc_neterr_reg(gnrc_pktsnip_t *pkt)
76 {
77  if (pkt->err_sub != KERNEL_PID_UNDEF) {
78  return EALREADY;
79  }
80  pkt->err_sub = thread_getpid();
81  return 0;
82 }
83 #else
84 #define gnrc_neterr_reg(pkt) (0)
85 #endif
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif /* NET_GNRC_NETERR_H */
int msg_send(msg_t *m, kernel_pid_t target_pid)
Send a message (blocking).
#define KERNEL_PID_UNDEF
Canonical identifier for an invalid PID.
Definition: sched.h:110
static kernel_pid_t thread_getpid(void)
Returns the process ID of the currently running thread.
Definition: thread.h:393
#define EALREADY
Connection already in progress.
Definition: errno.h:76
#define gnrc_neterr_reg(pkt)
Registers the current thread for errors on a gnrc_pktsnip_t.
Definition: neterr.h:84
#define GNRC_NETERR_MSG_TYPE
Messaging / IPC type for reporting an error.
Definition: neterr.h:37
#define gnrc_neterr_report(pkt, err)
Reports an error to all subscribers of errors to pkt.
Definition: neterr.h:63
General definitions for network packets and their helper functions.
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:108
Describes a message object which can be sent between threads.
Definition: msg.h:196
uint16_t type
Type field.
Definition: msg.h:199
union msg_t::@1 content
Content of the message.
uint32_t value
Value content field.
Definition: msg.h:202