summaryrefslogtreecommitdiffstats
path: root/ctrl/facemgr/src/interface.c
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-07-26 23:20:30 +0200
committerMauro Sardara <msardara@cisco.com>2019-07-29 17:13:35 +0200
commit0a1c6b5565e20167d1f1f33a5a8b597f420b18b0 (patch)
tree98c5da8f231fbd3dc2ce6502040e29c8333d9ffc /ctrl/facemgr/src/interface.c
parent05ca0aa8f612ee48fb66d4dbebe596b7f1e03181 (diff)
[HICN-252] Add per-application policy framework to hicn-light forwarder
Change-Id: I0531cd7a7de179581295ae34766c81cd9cf3e172 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com> Signed-off-by: Mauro Sardara <msardara@cisco.com> Co-authored-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'ctrl/facemgr/src/interface.c')
-rw-r--r--ctrl/facemgr/src/interface.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/ctrl/facemgr/src/interface.c b/ctrl/facemgr/src/interface.c
new file mode 100644
index 000000000..af9f666a7
--- /dev/null
+++ b/ctrl/facemgr/src/interface.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * \file interface.c
+ * \brief Implementation of interface base class.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "event.h"
+#include "face_rules.h"
+#include "interface.h"
+#include "interface_ops_map.h"
+#include "util/map.h"
+
+static interface_ops_map_t * interface_ops_map = NULL;
+
+int
+interface_register(const interface_ops_t * ops)
+{
+ if (!interface_ops_map) {
+ interface_ops_map = interface_ops_map_create();
+ if (!interface_ops_map)
+ return FACEMGR_FAILURE;
+ }
+ interface_ops_map_add(interface_ops_map, ops->type, ops);
+ return FACEMGR_SUCCESS;
+}
+
+interface_t *
+interface_create(const char * name, const char * type)
+{
+
+ interface_ops_t * ops;
+ int rc = interface_ops_map_get(interface_ops_map, type, &ops);
+ if (FACEMGR_IS_ERROR(rc)) {
+ printf("Interface type not found %s\n", type);
+ return NULL;
+ }
+
+ interface_t * interface = malloc(sizeof(interface_t));
+ if (!interface)
+ return NULL;
+
+ interface->name = strdup(name);
+ /* this should use type */
+ interface->ops = ops;
+ interface->callback = NULL;
+ interface->callback_data = NULL;
+ interface->data = NULL;
+
+ return interface;
+}
+
+void
+interface_free(interface_t * interface)
+{
+ free(interface->name);
+ free(interface);
+}
+
+void
+_interface_set_callback(interface_t * interface, callback_t callback, void * callback_data)
+{
+ interface->callback = callback;
+ interface->callback_data = callback_data;
+}
+
+int
+interface_initialize(interface_t * interface, struct face_rules_s * rules)
+{
+ if (!interface->ops->initialize)
+ return FACEMGR_FAILURE;
+ return interface->ops->initialize(interface, rules, &interface->data);
+}
+
+int
+interface_finalize(interface_t * interface)
+{
+ if (!interface->ops->finalize)
+ return FACEMGR_FAILURE;
+ return interface->ops->finalize(interface);
+}
+
+int
+interface_on_event(interface_t * interface, const event_t * event)
+{
+ if (!interface->ops->on_event)
+ return FACEMGR_FAILURE;
+ return interface->ops->on_event(interface, event);
+}