26
26
*
27
27
* @note Notification events are associated with type-dependent event data.
28
28
* Receivers should not access the data directly, but instead use the
29
- * the dedicated API functions.
30
- * If the data is read directly, the receiver is responsible for setting
31
- * the @ref NETAPI_NOTIFY_FLAG_ACK flag for the sending thread.
32
- *
29
+ * the dedicated API functions to copy the data from the sender's.
30
+ * If the data is read manually, the receiver is responsible for
31
+ * calling @ref gnrc_netapi_notify_ack to unblock the sender.
33
32
*
34
33
* @author Elena Frank <[email protected] >
35
34
*/
@@ -39,23 +38,15 @@ extern "C" {
39
38
#endif
40
39
41
40
#include "net/ipv6/addr.h"
42
- #include "sched.h"
43
-
44
- /**
45
- * @brief Thread flag for acknowledging a received notify even.
46
- *
47
- * @note The flag should only be set after all event data was copied
48
- * by receiver and can be freed by the sender.
49
- */
50
- #define NETAPI_NOTIFY_FLAG_ACK (1u << 10)
41
+ #include "cond.h"
42
+ #include "mutex.h"
51
43
52
44
/**
53
45
* @brief Definition of notification event types in the network stack.
54
46
*
55
47
* @note Expand at will.
56
48
* If event data is associated with the type, a helper function must also
57
- * be added for parsing the data and setting the @ref NETAPI_NOTIFY_FLAG_ACK
58
- * on the sender.
49
+ * be added for parsing the data and calling @ref gnrc_netapi_notify_ack.
59
50
*/
60
51
typedef enum {
61
52
NETAPI_NOTIFY_L2_CONNECTED , /**< Connection established on layer 2. */
@@ -64,13 +55,23 @@ typedef enum {
64
55
NETAPI_NOTIFY_L3_UNREACHABLE , /**< Node became unreachable on the network layer. */
65
56
} netapi_notify_t ;
66
57
58
+ /**
59
+ * @brief Data structure to acknowledge netapi notification events.
60
+ */
61
+ typedef struct {
62
+ int counter ; /**< ACK counter */
63
+ cond_t cond ; /**< condition variable to signal change in count */
64
+ mutex_t lock ; /**< lock for counter */
65
+ } gnrc_netapi_notify_ack_t ;
66
+
67
67
/**
68
68
* @brief Data structure to be sent for netapi notification events.
69
69
*/
70
70
typedef struct {
71
- netapi_notify_t event ; /**< the type of event */
72
- void * _data ; /**< associated event data. */
73
- uint16_t _data_len ; /**< size of the event data */
71
+ netapi_notify_t event ; /**< the type of event */
72
+ void * _data ; /**< associated event data. */
73
+ uint16_t _data_len ; /**< size of the event data */
74
+ gnrc_netapi_notify_ack_t * ack ; /**< acknowledge event */
74
75
} gnrc_netapi_notify_t ;
75
76
76
77
/**
@@ -83,13 +84,26 @@ typedef struct {
83
84
kernel_pid_t if_pid ; /**< PID of network interface */
84
85
} netapi_notify_l2_connection_t ;
85
86
87
+ /**
88
+ * @brief Acknowledge that a notify event was received and its data read.
89
+ *
90
+ * @param[in] ack Pointer to the event's acknowledgment structure.
91
+ */
92
+ static inline void gnrc_netapi_notify_ack (gnrc_netapi_notify_ack_t * ack )
93
+ {
94
+ mutex_lock (& ack -> lock );
95
+ ack -> counter ++ ;
96
+ /* Signal that the counter changed. */
97
+ cond_signal (& ack -> cond );
98
+ mutex_unlock (& ack -> lock );
99
+ }
100
+
86
101
/**
87
102
* @brief Parse the connection event data associated with @ref NETAPI_NOTIFY_L2_CONNECTED
88
103
* and @ref NETAPI_NOTIFY_L2_DISCONNECTED events.
89
104
*
90
- * @note This will set the @ref NETAPI_NOTIFY_FLAG_ACK for the sending thread .
105
+ * @note This will call @ref gnrc_netapi_notify_ack .
91
106
*
92
- * @param[in] sender_pid PID of the netapi sender.
93
107
* @param[in] notify Pointer to the received notify event.
94
108
* @param[out] data Connection data received in the @p notify event.
95
109
* data.l2addr_len should be set to the size of the l2addr buffer.
@@ -99,24 +113,21 @@ typedef struct {
99
113
* @retval -ENOBUFS if the length of l2addr in @p data is smaller than the
100
114
* received l2addr.
101
115
*/
102
- uint8_t gnrc_netapi_notify_copy_l2_connection_data (kernel_pid_t sender_pid ,
103
- gnrc_netapi_notify_t * notify ,
116
+ uint8_t gnrc_netapi_notify_copy_l2_connection_data (gnrc_netapi_notify_t * notify ,
104
117
netapi_notify_l2_connection_t * data );
105
118
/**
106
119
* @brief Parse the ipv6 address associated with @ref NETAPI_NOTIFY_L3_DISCOVERED and
107
120
* @ref NETAPI_NOTIFY_L3_UNREACHABLE events.
108
121
*
109
- * @note This will set the @ref NETAPI_NOTIFY_FLAG_ACK for the sending thread .
122
+ * @note This will call @ref gnrc_netapi_notify_ack .
110
123
*
111
- * @param[in] sender_pid PID of the netapi sender.
112
124
* @param[in] notify Pointer to the received notify event.
113
125
* @param[out] addr IPv6 address of the remote.
114
126
*
115
127
* @retval sizeof(ipv6_addr_t) on success.
116
128
* @retval -EINVAL if @p notify is of a wrong @ref netapi_notify_t type.
117
129
*/
118
- int gnrc_netapi_notify_copy_l3_address (kernel_pid_t sender_pid , gnrc_netapi_notify_t * notify ,
119
- ipv6_addr_t * addr );
130
+ int gnrc_netapi_notify_copy_l3_address (gnrc_netapi_notify_t * notify , ipv6_addr_t * addr );
120
131
121
132
#ifdef __cplusplus
122
133
}
0 commit comments