Enable/disable plugin support using compilation flags

This commit is contained in:
suvendhu 2021-10-26 23:28:00 +05:30
parent 7f8d825a52
commit 0d04be3ad4
9 changed files with 89 additions and 5 deletions

View file

@ -16,6 +16,12 @@ AM_CONDITIONAL([LOPENSSL],[test "x$enable_libopenssl" = "xyes"])
AC_ARG_ENABLE(vendor_extension, [AS_HELP_STRING([--enable-vendor-extension], [enable vendor extension])], AC_DEFINE(BBF_VENDOR_EXTENSION),)
AM_CONDITIONAL([BBF_VENDOR_EXTENSION],[test "x$enable_vendor_extension" = "xyes"])
AC_ARG_ENABLE(json_plugin, [AS_HELP_STRING([--enable-json-plugin], [enable json plugin to extend datamodel])], AC_DEFINE(BBFDM_ENABLE_JSON_PLUGIN),)
AM_CONDITIONAL([BBFDM_ENABLE_JSON_PLUGIN],[test "x$enable_json_plugin" = "xyes"])
AC_ARG_ENABLE(shared_library, [AS_HELP_STRING([--enable-shared-library], [enable shared library support to extend datamodel])], AC_DEFINE(BBFDM_ENABLE_DOTSO_PLUGIN),)
AM_CONDITIONAL([BBFDM_ENABLE_DOTSO_PLUGIN],[test "x$enable_shared_library" = "xyes"])
AC_DEFINE_UNQUOTED(BBF_VENDOR_LIST, "$BBF_VENDOR_LIST")
AC_DEFINE_UNQUOTED(BBF_VENDOR_PREFIX, "$BBF_VENDOR_PREFIX")

View file

@ -12,6 +12,8 @@
#include "dmdynamicjson.h"
#include "dmentry.h"
#ifdef BBFDM_ENABLE_JSON_PLUGIN
#define json_object_get_string(x) (char *)json_object_get_string(x)
static LIST_HEAD(loaded_json_files);
@ -1071,3 +1073,5 @@ int load_json_dynamic_arrays(struct dmctx *ctx)
}
return 0;
}
#endif /* BBFDM_ENABLE_JSON_PLUGIN */

View file

@ -12,6 +12,8 @@
#ifndef __DMENTRYJSON_H__
#define __DMENTRYJSON_H__
#ifdef BBFDM_ENABLE_JSON_PLUGIN
#include <libbbf_api/dmcommon.h>
#define JSON_FOLDER_PATH "/etc/bbfdm/json"
@ -19,4 +21,5 @@
int load_json_dynamic_arrays(struct dmctx *ctx);
int free_json_dynamic_arrays(DMOBJ *dm_entryobj);
#endif /* BBFDM_ENABLE_JSON_PLUGIN */
#endif //__DMENTRYJSON_H__

View file

@ -11,6 +11,8 @@
#include "dmdynamiclibrary.h"
#ifdef BBFDM_ENABLE_DOTSO_PLUGIN
LIST_HEAD(loaded_library_list);
LIST_HEAD(dynamic_operate_list);
LIST_HEAD(library_memhead);
@ -310,3 +312,5 @@ int load_library_dynamic_arrays(struct dmctx *ctx)
}
return 0;
}
#endif /* BBFDM_ENABLE_DOTSO_PLUGIN */

View file

@ -12,6 +12,8 @@
#ifndef __DMENTRYLIBRARY_H__
#define __DMENTRYLIBRARY_H__
#ifdef BBFDM_ENABLE_DOTSO_PLUGIN
#include <libbbf_api/dmcommon.h>
#define LIBRARY_FOLDER_PATH "/usr/lib/bbfdm"
@ -19,4 +21,5 @@
int load_library_dynamic_arrays(struct dmctx *ctx);
void free_library_dynamic_arrays(DMOBJ *dm_entryobj);
#endif /* BBFDM_ENABLE_DOTSO_PLUGIN */
#endif //__DMENTRYLIBRARY_H__

View file

@ -22,8 +22,13 @@
LIST_HEAD(head_package_change);
LIST_HEAD(main_memhead);
#ifdef BBFDM_ENABLE_JSON_PLUGIN
static char json_hash[64] = {0};
#endif /* BBFDM_ENABLE_JSON_PLUGIN */
#ifdef BBFDM_ENABLE_DOTSO_PLUGIN
static char library_hash[64] = {0};
#endif /* BBFDM_ENABLE_DOTSO_PLUGIN */
#ifdef BBF_VENDOR_EXTENSION
static bool first_boot = false;
@ -363,9 +368,28 @@ int dm_entry_revert_changes(void)
return 0;
}
#if defined(BBFDM_ENABLE_JSON_PLUGIN) || defined(BBFDM_ENABLE_DOTSO_PLUGIN)
static char* get_folder_path(bool json_path)
{
if (json_path) {
#ifdef BBFDM_ENABLE_JSON_PLUGIN
return JSON_FOLDER_PATH;
#endif /* BBFDM_ENABLE_JSON_PLUGIN */
} else {
#ifdef BBFDM_ENABLE_DOTSO_PLUGIN
return LIBRARY_FOLDER_PATH;
#endif /* BBFDM_ENABLE_DOTSO_PLUGIN */
}
return NULL;
}
static int get_stats_folder(bool json_path, int *count, unsigned long *size)
{
const char *path = json_path ? JSON_FOLDER_PATH : LIBRARY_FOLDER_PATH;
const char *path = get_folder_path(json_path);
if (path == NULL) {
return 0;
}
if (folder_exists(path)) {
struct dirent *entry = NULL;
@ -405,27 +429,43 @@ static int check_stats_folder(bool json_path)
snprintf(buf, sizeof(buf), "count:%d,size:%lu", count, size);
if (strcmp(buf, json_path ? json_hash : library_hash) != 0) {
strncpy(json_path ? json_hash : library_hash, buf, 64);
return 1;
if (json_path) {
#ifdef BBFDM_ENABLE_JSON_PLUGIN
if (strcmp(buf, json_hash) != 0) {
strncpy(json_hash, buf, 64);
return 1;
}
#endif /* BBFDM_ENABLE_JSON_PLUGIN */
} else {
#ifdef BBFDM_ENABLE_DOTSO_PLUGIN
if (strcmp(buf, library_hash) != 0) {
strncpy(library_hash, buf, 64);
return 1;
}
#endif /* BBFDM_ENABLE_DOTSO_PLUGIN */
}
return 0;
}
#endif /* (BBFDM_ENABLE_JSON_PLUGIN || BBFDM_ENABLE_DOTSO_PLUGIN) */
void load_dynamic_arrays(struct dmctx *ctx)
{
#ifdef BBFDM_ENABLE_JSON_PLUGIN
// Load dynamic objects and parameters exposed via a JSON file
if (check_stats_folder(true)) {
free_json_dynamic_arrays(tEntry181Obj);
load_json_dynamic_arrays(ctx);
}
#endif /* BBFDM_ENABLE_JSON_PLUGIN */
#ifdef BBFDM_ENABLE_DOTSO_PLUGIN
// Load dynamic objects and parameters exposed via a library
if (check_stats_folder(false)) {
free_library_dynamic_arrays(tEntry181Obj);
load_library_dynamic_arrays(ctx);
}
#endif /* BBFDM_ENABLE_DOTSO_PLUGIN */
#ifdef BBF_VENDOR_EXTENSION
// Load objects and parameters exposed via vendor extension
@ -442,8 +482,14 @@ void free_dynamic_arrays(void)
DMOBJ *root = tEntry181Obj;
DMNODE node = {.current_object = ""};
#ifdef BBFDM_ENABLE_JSON_PLUGIN
free_json_dynamic_arrays(tEntry181Obj);
#endif /* BBFDM_ENABLE_JSON_PLUGIN */
#ifdef BBFDM_ENABLE_DOTSO_PLUGIN
free_library_dynamic_arrays(tEntry181Obj);
#endif /* BBFDM_ENABLE_DOTSO_PLUGIN */
#ifdef BBF_VENDOR_EXTENSION
free_vendor_dynamic_arrays(tEntry181Obj);
#endif

View file

@ -49,7 +49,7 @@ function install_libbbf()
fi
exec_cmd autoreconf -i
exec_cmd ./configure --enable-tr181 --enable-tr104 --enable-tr143 --enable-libopenssl --enable-vendor-extension BBF_VENDOR_LIST="$VENDOR_LIST" BBF_VENDOR_PREFIX="$VENDOR_PREFIX"
exec_cmd ./configure --enable-tr181 --enable-tr104 --enable-tr143 --enable-libopenssl --enable-json-plugin --enable-shared-library --enable-vendor-extension BBF_VENDOR_LIST="$VENDOR_LIST" BBF_VENDOR_PREFIX="$VENDOR_PREFIX"
make CFLAGS="-D_GNU_SOURCE -Wall -Werror" CFLAGS+="$COV_CFLAGS" LDFLAGS="$COV_LDFLAGS" >/dev/null 2>&1
echo "installing libbbf"

View file

@ -24,4 +24,12 @@ config BBF_TR143
bool "Enable TR-143 Data Model Support"
default y
config BBFDM_ENABLE_JSON_PLUGIN
bool "Enable json plugin to extend datamodel"
default n
config BBFDM_ENABLE_DOTSO_PLUGIN
bool "Enable shared library plugin to extend datamodel"
default n
endif

View file

@ -68,6 +68,16 @@ CONFIGURE_ARGS += \
endif ##CONFIG_BBF_VENDOR_EXTENSION
ifeq ($(CONFIG_BBFDM_ENABLE_JSON_PLUGIN),y)
CONFIGURE_ARGS += \
--enable-json-plugin
endif
ifeq ($(CONFIG_BBFDM_ENABLE_DOTSO_PLUGIN),y)
CONFIGURE_ARGS += \
--enable-shared-library
endif
define Package/libbbfdm/install
$(INSTALL_DIR) $(1)/lib
$(CP) $(PKG_BUILD_DIR)/bin/.libs/libbbfdm.so* $(1)/lib/