ndn-lite
face.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Zhiyi Zhang, Xinyu Ma
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v3.0. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #ifndef FORWARDER_FACE_H_
10 #define FORWARDER_FACE_H_
11 
12 #include <stdbool.h>
13 #include <stdint.h>
14 #include <stddef.h>
15 #include "../ndn-enums.h"
16 #include "../ndn-constants.h"
17 
18 #define container_of(ptr, type, member) \
19  ((type *)((char *)(1 ? (ptr) : &((type *)0)->member) - offsetof(type, member)))
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
31 struct ndn_face_intf;
32 
36 typedef int (*ndn_face_intf_up)(struct ndn_face_intf* self);
37 
41 typedef int (*ndn_face_intf_send)(struct ndn_face_intf* self,
42  const uint8_t* packet, uint32_t size);
43 
47 typedef int (*ndn_face_intf_down)(struct ndn_face_intf* self);
48 
52 typedef void (*ndn_face_intf_destroy)(struct ndn_face_intf* self);
53 
62 typedef struct ndn_face_intf {
67 
72 
77 
82 
87 
93  uint8_t state;
94 
100  uint8_t type;
102 
107 static inline int
109 {
110  if (self->state != NDN_FACE_STATE_UP)
111  return self->up(self);
112  return 0;
113 }
114 
121 static inline int
122 ndn_face_send(ndn_face_intf_t* self, const uint8_t* packet, uint32_t size)
123 {
124  if (self->state != NDN_FACE_STATE_UP)
125  self->up(self);
126  return self->send(self, packet, size);
127 }
128 
133 static inline int
135 {
136  return self->down(self);
137 }
138 
144 static inline void
146 {
147  self->destroy(self);
148 }
149 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif // #define FORWARDER_FACE_H_
int(* ndn_face_intf_down)(struct ndn_face_intf *self)
Shutdown the face temporarily.
Definition: face.h:47
static void ndn_face_destroy(ndn_face_intf_t *self)
Destructor.
Definition: face.h:145
uint8_t state
The state of the face.
Definition: face.h:93
void(* ndn_face_intf_destroy)(struct ndn_face_intf *self)
Destructor.
Definition: face.h:52
ndn_table_id_t face_id
Unique Face ID.
Definition: face.h:86
struct ndn_face_intf ndn_face_intf_t
Abstract NDN network face.
ndn_face_intf_send send
Send out a packet.
Definition: face.h:71
ndn_face_intf_destroy destroy
Destructor.
Definition: face.h:81
ndn_face_intf_up up
Turn on the face.
Definition: face.h:66
uint8_t type
The type of the face, reserved.
Definition: face.h:100
static int ndn_face_send(ndn_face_intf_t *self, const uint8_t *packet, uint32_t size)
Send out a packet.
Definition: face.h:122
static int ndn_face_up(ndn_face_intf_t *self)
Turn on the face.
Definition: face.h:108
ndn_face_intf_down down
Shutdown the face temporarily.
Definition: face.h:76
int(* ndn_face_intf_send)(struct ndn_face_intf *self, const uint8_t *packet, uint32_t size)
Send out a packet.
Definition: face.h:41
uint16_t ndn_table_id_t
Definition: ndn-constants.h:39
int(* ndn_face_intf_up)(struct ndn_face_intf *self)
Turn on the face.
Definition: face.h:36
Definition: ndn-enums.h:15
Abstract NDN network face.
Definition: face.h:62
static int ndn_face_down(ndn_face_intf_t *self)
Shutdown the face temporarily.
Definition: face.h:134