From 0a1c6b5565e20167d1f1f33a5a8b597f420b18b0 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Fri, 26 Jul 2019 23:20:30 +0200 Subject: [HICN-252] Add per-application policy framework to hicn-light forwarder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0531cd7a7de179581295ae34766c81cd9cf3e172 Signed-off-by: Jordan Augé Signed-off-by: Mauro Sardara Co-authored-by: Mauro Sardara --- ctrl/facemgr/src/common.h | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 ctrl/facemgr/src/common.h (limited to 'ctrl/facemgr/src/common.h') diff --git a/ctrl/facemgr/src/common.h b/ctrl/facemgr/src/common.h new file mode 100644 index 000000000..a73964b6d --- /dev/null +++ b/ctrl/facemgr/src/common.h @@ -0,0 +1,94 @@ +/* + * 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 common.h + * \file Common definitions used throughout the code + */ +#ifndef FACEMGR_COMMON_H +#define FACEMGR_COMMON_H + +#include +#include + +#include "util/types.h" +#include "util/ip_address.h" +#include "util/token.h" // XXX debug + +//#define DEBUG + +/* Return value conventions */ +#define FACEMGR_SUCCESS 0 +#define FACEMGR_FAILURE -1 +#define FACEMGR_IS_ERROR(rc) (rc < 0) + +/* Useful types and macros for comparisons */ +typedef int(*cmp_t)(const void * x, const void * y); + +#define INT_CMP(x, y) x < y ? -1 : (x == y ? 0 : 1) + +/* Dump with indent */ +#define INDENT(n, fmt) "%*s" fmt, n, "" +#define printfi(n, fmt, ...) printf(INDENT(n*4, fmt), ##__VA_ARGS__) + +/* Boilerplate code */ + +#define NO_INITIALIZE(NAME) \ +int \ +NAME ## _initialize(NAME ## _t * obj) { \ + return FACEMGR_SUCCESS; \ +} + +#define NO_FINALIZE(NAME) \ +int \ +NAME ## _finalize(NAME ## _t * obj) { \ + return FACEMGR_SUCCESS; \ +} + +#define AUTOGENERATE_CREATE_FREE(NAME) \ + \ +NAME ## _t * \ +NAME ## _create() \ +{ \ + NAME ## _t * obj = malloc(sizeof(NAME ## _t)); \ + if (!obj) \ + goto ERR_MALLOC; \ + \ + if (FACEMGR_IS_ERROR(NAME ## _initialize(obj))) \ + goto ERR_INIT; \ + \ + return obj; \ + \ +ERR_INIT: \ + free(obj); \ +ERR_MALLOC: \ + return NULL; \ +} \ + \ +void \ +NAME ## _free(NAME ## _t * obj) \ +{ \ + if (FACEMGR_IS_ERROR(NAME ## _finalize(obj))) \ + (void)0; /* XXX */ \ + free(obj); \ +} \ + +#define AUTOGENERATE_DEFS(NAME) \ +int NAME ## _initialize(NAME ## _t *); \ +int NAME ## _finalize(NAME ## _t *); \ +NAME ## _t * NAME ## _create(); \ +void NAME ## _free(NAME ## _t *); \ + +#endif /* FACEMGR_COMMON_H */ -- cgit 1.2.3-korg