The friendly Operating System for the Internet of Things
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 GNRC_NETERR_H
21 #define 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 = sched_active_pid;
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 /* GNRC_NETERR_H */
93 
Types used by the kernel.
volatile kernel_pid_t sched_active_pid
Process ID of active thread.
uint32_t value
Value content field.
Definition: msg.h:190
#define gnrc_neterr_report(pkt, err)
Reports an error to all subscribers of errors to pkt.
Definition: neterr.h:64
General definitions for network packets and their helper functions.
union msg_t::@2 content
Content of the message.
int msg_send(msg_t *m, kernel_pid_t target_pid)
Send a message (blocking).
Threading API.
#define KERNEL_PID_UNDEF
Canonical identifier for an invalid PID.
Definition: kernel_types.h:63
#define EALREADY
Connection already in progress.
Definition: errno.h:76
Messaging API for inter process communication.
#define gnrc_neterr_reg(pkt)
Registers the current thread for errors on a gnrc_pktsnip_t.
Definition: neterr.h:85
Describes a message object which can be sent between threads.
Definition: msg.h:184
#define GNRC_NETERR_MSG_TYPE
Messaging / IPC type for reporting an error.
Definition: neterr.h:38
Type to represent parts (either headers or payload) of a packet, called snips.
uint16_t type
Type field.
Definition: msg.h:187