Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
interface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
28 #ifndef FACEMGR_INTERFACE_H
29 #define FACEMGR_INTERFACE_H
30 
31 #include <stdbool.h>
32 #include <hicn/facemgr/loop.h>
33 
34 typedef enum {
35  INTERFACE_CB_TYPE_REGISTER_FD,
36  INTERFACE_CB_TYPE_UNREGISTER_FD,
37  INTERFACE_CB_TYPE_RAISE_EVENT,
38  INTERFACE_CB_TYPE_REGISTER_TIMER,
39  INTERFACE_CB_TYPE_UNREGISTER_TIMER,
40 } interface_cb_type_t;
41 
42 typedef int (*interface_cb_t)(facemgr_t * facemgr, interface_cb_type_t type, void * data);
43 
47 struct interface_s;
48 typedef struct {
50  char * type;
51  /* Constructor */
52  int (*initialize)(struct interface_s * interface, void * cfg);
53  /* Destructor */
54  int (*finalize)(struct interface_s * interface);
55  /* Callback upon file descriptor event (iif previously registered) */
56  int (*callback)(struct interface_s * interface, int fd, void * data);
57  /* Callback upon face events coming from the face manager */
58  int (*on_event)(struct interface_s * interface, struct facelet_s * facelet);
60 
61 typedef struct interface_s {
62  char * name;
63  const interface_ops_t * ops;
64 
65  interface_cb_t callback;
66  void * callback_owner;
67 
68  void * data;
69 } interface_t;
70 
78 int interface_register(const interface_ops_t * ops);
79 
81 
86 
94 interface_t * interface_create(const char * name, const char * type);
95 
100 void interface_free(interface_t * interface);
101 
102 
103 void interface_set_callback(interface_t * interface, void * callback_owner, interface_cb_t callback);
104 
105 int interface_initialize(interface_t * interface, void * cfg);
106 
107 int interface_finalize(interface_t * interface);
108 
109 int interface_on_event(interface_t * interface, struct facelet_s * facelet);
110 
118 int interface_callback(interface_t * interface, interface_cb_type_t type, void * data);
119 
120 int interface_raise_event(interface_t * interface, facelet_t * facelet);
121 
122 int interface_register_fd(interface_t * interface, int fd, void * data);
123 
124 int interface_unregister_fd(interface_t * interface, int fd);
125 
126 typedef int (*interface_fd_callback_t)(interface_t * interface, int fd, void * unused);
127 
138 int interface_register_timer(interface_t * interface, unsigned delay_ms,
139  interface_fd_callback_t callback, void * data);
140 
147 int interface_unregister_timer(interface_t * interface, int fd);
148 
149 #endif /* FACEMGR_INTERFACE_H */
interface_s
Definition: interface.h:61
interface_ops_t
Definition: interface.h:48
interface_register
int interface_register(const interface_ops_t *ops)
Registers a new interface type.
interface_unregister_timer
int interface_unregister_timer(interface_t *interface, int fd)
Unregisters a timer event.
interface_create
interface_t * interface_create(const char *name, const char *type)
Create a new instance of an interface of a given type.
interface_callback
int interface_callback(interface_t *interface, interface_cb_type_t type, void *data)
Raises a facelet event to the face manager.
interface_free
void interface_free(interface_t *interface)
Free an interface instance.
loop.h
Face manager main loop.
interface_register_timer
int interface_register_timer(interface_t *interface, unsigned delay_ms, interface_fd_callback_t callback, void *data)
Registers a timer event.
interface_ops_t::type
char * type
Definition: interface.h:50
interface_unregister_all
int interface_unregister_all()
Unregister all interface types.