bbf: update dynamic library generator

This commit is contained in:
Amin Ben Ramdhane 2020-09-03 22:34:15 +01:00
parent 99705ac5f9
commit e20b717d17
4 changed files with 128 additions and 206 deletions

View file

@ -1,23 +1,21 @@
LIB_EXAMPLE := lib/libexample.so
LIB_EXAMPLE := libexample.so
OBJS := example.o
PROG_CFLAGS = $(CFLAGS) -fstrict-aliasing
PROG_LDFLAGS = $(LDFLAGS) -lbbfdm
LIB_CFLAGS = $(CFLAGS) -fstrict-aliasing
LIB_LDFLAGS = $(LDFLAGS) -lbbf_api
FPIC := -fPIC
.PHONY: all
%.o: %.c
$(CC) $(PROG_CFLAGS) $(FPIC) -c -o $@ $<
$(CC) $(LIB_CFLAGS) $(FPIC) -c -o $@ $<
all: $(LIB_EXAMPLE)
$(LIB_EXAMPLE): $(OBJS)
$(shell mkdir -p lib)
$(CC) -shared -Wl,-soname,libexample.so $^ -o $@
$(CC) $(LIB_CFLAGS) $(LIB_LDFLAGS) -shared -o $@ $^
clean:
rm -f *.o
rm -f $(LIB_EXAMPLE)
rm -f *.o $(LIB_EXAMPLE)

View file

@ -8,13 +8,11 @@
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include <libbbfdm/dmbbf.h>
#include <libbbfdm/dmcommon.h>
#include <libbbfdm/dmuci.h>
#include <libbbfdm/dmubus.h>
#include <libbbfdm/dmjson.h>
#include <libbbfdm/dmentry.h>
#include <libbbfdm/dmoperate.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
#include "example.h"
/* ********** RootDynamicObj ********** */
@ -26,25 +24,8 @@ LIB_MAP_OBJ tRootDynamicObj[] = {
/* ********** RootDynamicOperate ********** */
LIB_MAP_OPERATE tRootDynamicOperate[] = {
/* pathname, operation */
{"Device.BBKSpeedTest", dynamicDeviceOperate},
{0}
};
/* *** Device.IP.Diagnostics. *** */
DMOBJ tdynamicIPDiagnosticsObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/
{"X_IOPSYS_EU_BBKSpeedTest", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tdynamicIPDiagnosticsX_IOPSYS_EU_BBKSpeedTestParams, NULL, BBFDM_BOTH},
{0}
};
/* *** Device.IP.Diagnostics.X_IOPSYS_EU_BBKSpeedTest. *** */
DMLEAF tdynamicIPDiagnosticsX_IOPSYS_EU_BBKSpeedTestParams[] = {
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
{"DiagnosticsState", &DMWRITE, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState, setdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState, NULL, NULL, BBFDM_BOTH},
{"Latency", &DMREAD, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Latency, NULL, NULL, NULL, BBFDM_BOTH},
{"Download", &DMREAD, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Download, NULL, NULL, NULL, BBFDM_BOTH},
{"Upload", &DMREAD, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Upload, NULL, NULL, NULL, BBFDM_BOTH},
/* pathname, operation, type */
{"Device.BBKSpeedTest", dynamicDeviceOperate, "async"},
{0}
};
@ -76,20 +57,16 @@ static inline char *bbk_speedtest_get(char *option, char *def)
{
char *tmp;
dmuci_get_varstate_string("cwmp", "@bbkspeedtest[0]", option, &tmp);
if(tmp && tmp[0] == '\0')
return dmstrdup(def);
else
return tmp;
return tmp[0] == '\0' ? dmstrdup(def) : tmp;
}
int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = bbk_speedtest_get("DiagnosticState", "None");
return 0;
}
int setdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
static int setdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *tmp;
struct uci_section *curr_section = NULL;
@ -101,9 +78,7 @@ int setdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState(char *refp
if (strcmp(value, "Requested") == 0) {
curr_section = dmuci_walk_state_section("cwmp", "bbkspeedtest", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
if (!curr_section)
{
dmuci_add_state_section("cwmp", "bbkspeedtest", &curr_section, &tmp);
}
dmuci_set_varstate_value("cwmp", "@bbkspeedtest[0]", "DiagnosticState", value);
execute_bbk_speedtest();
}
@ -112,19 +87,19 @@ int setdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState(char *refp
return 0;
}
int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Latency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Latency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = bbk_speedtest_get("Latency", "0");
return 0;
}
int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Download(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Download(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = bbk_speedtest_get("Download", "0");
return 0;
}
int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Upload(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Upload(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = bbk_speedtest_get("Upload", "0");
return 0;
@ -133,7 +108,7 @@ int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Upload(char *refparam, stru
/*************************************************************
* OPERATE
/*************************************************************/
opr_ret_t dynamicDeviceOperate(struct dmctx *dmctx, char *path, char *input)
opr_ret_t dynamicDeviceOperate(struct dmctx *dmctx, char *path, json_object *input)
{
json_object *ubus_res = NULL;
@ -149,3 +124,21 @@ opr_ret_t dynamicDeviceOperate(struct dmctx *dmctx, char *path, char *input)
return SUCCESS;
}
/* *** Device.IP.Diagnostics. *** */
DMOBJ tdynamicIPDiagnosticsObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/
{"X_IOPSYS_EU_BBKSpeedTest", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tdynamicIPDiagnosticsX_IOPSYS_EU_BBKSpeedTestParams, NULL, BBFDM_BOTH},
{0}
};
/* *** Device.IP.Diagnostics.X_IOPSYS_EU_BBKSpeedTest. *** */
DMLEAF tdynamicIPDiagnosticsX_IOPSYS_EU_BBKSpeedTestParams[] = {
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
{"DiagnosticsState", &DMWRITE, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState, setdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState, NULL, NULL, BBFDM_BOTH},
{"Latency", &DMREAD, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Latency, NULL, NULL, NULL, BBFDM_BOTH},
{"Download", &DMREAD, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Download, NULL, NULL, NULL, BBFDM_BOTH},
{"Upload", &DMREAD, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Upload, NULL, NULL, NULL, BBFDM_BOTH},
{0}
};

View file

@ -14,12 +14,6 @@
DMOBJ tdynamicIPDiagnosticsObj[];
DMLEAF tdynamicIPDiagnosticsX_IOPSYS_EU_BBKSpeedTestParams[];
int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int setdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Latency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Download(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int getdynamic_IPDiagnosticsX_IOPSYS_EU_BBKSpeedTest_Upload(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
opr_ret_t dynamicDeviceOperate(struct dmctx *dmctx, char *path, char *input);
#endif //__EXAMPLE_H

View file

@ -158,13 +158,11 @@ def cprinttopfile ( fp ):
print >> fp, " * Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>"
print >> fp, " */"
print >> fp, ""
print >> fp, "#include <libbbfdm/dmbbf.h>"
print >> fp, "#include <libbbfdm/dmcommon.h>"
print >> fp, "#include <libbbfdm/dmuci.h>"
print >> fp, "#include <libbbfdm/dmubus.h>"
print >> fp, "#include <libbbfdm/dmjson.h>"
print >> fp, "#include <libbbfdm/dmentry.h>"
print >> fp, "#include <libbbfdm/dmoperate.h>"
print >> fp, "#include <libbbf_api/dmbbf.h>"
print >> fp, "#include <libbbf_api/dmcommon.h>"
print >> fp, "#include <libbbf_api/dmuci.h>"
print >> fp, "#include <libbbf_api/dmubus.h>"
print >> fp, "#include <libbbf_api/dmjson.h>"
print >> fp, "#include \"example.h\""
print >> fp, ""
@ -184,28 +182,26 @@ def hprinttopfile ( fp ):
print >> fp, ""
def printmakefile ( fp ):
print >> fp, "LIB_EXAMPLE := lib/libexample.so"
print >> fp, "LIB_EXAMPLE := libexample.so"
print >> fp, ""
print >> fp, "OBJS := example.o"
print >> fp, ""
print >> fp, "PROG_CFLAGS = $(CFLAGS) -fstrict-aliasing"
print >> fp, "PROG_LDFLAGS = $(LDFLAGS) -lbbfdm"
print >> fp, "LIB_CFLAGS = $(CFLAGS) -fstrict-aliasing"
print >> fp, "LIB_LDFLAGS = $(LDFLAGS) -lbbf_api"
print >> fp, "FPIC := -fPIC"
print >> fp, ""
print >> fp, ".PHONY: all"
print >> fp, ""
print >> fp, "%.o: %.c"
print >> fp, " $(CC) $(PROG_CFLAGS) $(FPIC) -c -o $@ $<"
print >> fp, " $(CC) $(LIB_CFLAGS) $(FPIC) -c -o $@ $<"
print >> fp, ""
print >> fp, "all: $(LIB_EXAMPLE)"
print >> fp, ""
print >> fp, "$(LIB_EXAMPLE): $(OBJS)"
print >> fp, " $(shell mkdir -p lib)"
print >> fp, " $(CC) -shared -Wl,-soname,libexample.so $^ -o $@"
print >> fp, " $(CC) $(LIB_CFLAGS) $(LIB_LDFLAGS) -shared -o $@ $^"
print >> fp, ""
print >> fp, "clean:"
print >> fp, " rm -f *.o"
print >> fp, " rm -f $(LIB_EXAMPLE)"
print >> fp, " rm -f *.o $(LIB_EXAMPLE)"
print >> fp, ""
def hprintfootfile ( fp ):
@ -215,13 +211,13 @@ def hprintfootfile ( fp ):
def cprintAddDelObj( faddobj, fdelobj, name, mappingobj, dmobject ):
fp = open('./.objadddel.c', 'a')
print >> fp, "int %s(char *refparam, struct dmctx *ctx, void *data, char **instance)" % faddobj
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char **instance)" % faddobj
print >> fp, "{"
print >> fp, " //TODO"
print >> fp, " return 0;"
print >> fp, "}"
print >> fp, ""
print >> fp, "int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)" % fdelobj
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)" % fdelobj
print >> fp, "{"
print >> fp, " switch (del_action) {"
print >> fp, " case DEL_INST:"
@ -236,15 +232,9 @@ def cprintAddDelObj( faddobj, fdelobj, name, mappingobj, dmobject ):
print >> fp, ""
fp.close()
def hprintAddDelObj( faddobj, fdelobj ):
fp = open('./.objadddel.h', 'a')
print >> fp, "int %s(char *refparam, struct dmctx *ctx, void *data, char **instance);" % faddobj
print >> fp, "int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action);" % fdelobj
fp.close()
def cprintBrowseObj( fbrowse, name, mappingobj, dmobject ):
fp = open('./.objbrowse.c', 'a')
print >> fp, "int %s(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)" % fbrowse
print >> fp, "static int %s(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)" % fbrowse
print >> fp, "{"
print >> fp, " //TODO"
print >> fp, " return 0;"
@ -252,21 +242,16 @@ def cprintBrowseObj( fbrowse, name, mappingobj, dmobject ):
print >> fp, ""
fp.close()
def hprintBrowseObj( fbrowse ):
fp = open('./.objbrowse.h', 'a')
print >> fp, "int %s(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);" % fbrowse
fp.close()
def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, parentname, dmparam):
fp = open('./.getstevalue.c', 'a')
print >> fp, "int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)" % getvalue
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)" % getvalue
print >> fp, "{"
print >> fp, " //TODO"
print >> fp, " return 0;"
print >> fp, "}"
print >> fp, ""
if setvalue != "NULL":
print >> fp, "int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)" % setvalue
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)" % setvalue
print >> fp, "{"
print >> fp, " switch (action) {"
print >> fp, " case VALUECHECK:"
@ -280,16 +265,9 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par
print >> fp, ""
fp.close()
def hprintGetSetValue( getvalue, setvalue ):
fp = open('./.getstevalue.h', 'a')
print >> fp, "int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);" % getvalue
if setvalue != "NULL":
print >> fp, "int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);" % setvalue
fp.close()
def cprintOperate( get_operate ):
fp = open('./.operate.c', 'a')
print >> fp, "opr_ret_t %s(struct dmctx *dmctx, char *path, char *input)" % ("dynamic" + get_operate + "Operate")
print >> fp, "opr_ret_t %s(struct dmctx *dmctx, char *path, json_object *input)" % ("dynamic" + get_operate + "Operate")
print >> fp, "{"
print >> fp, " return SUCCESS;"
print >> fp, "}"
@ -301,11 +279,6 @@ def cprintheaderPARAMS( objname ):
print >> fp, "/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/"
fp.close()
def hprintOperate( get_operate ):
fp = open('./.operate.h', 'a')
print >> fp, "opr_ret_t %s(struct dmctx *dmctx, char *path, char *input);" % ("dynamic" + get_operate + "Operate")
fp.close()
def hprintheaderPARAMS( objname ):
fp = open('./.objparamarray.h', 'a')
print >> fp, "DMLEAF %s[];" % ("tdynamic" + getname(objname) + "Params")
@ -333,7 +306,6 @@ def printPARAMline( parentname, dmparam, value ):
instance = "FALSE"
cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, parentname, dmparam)
hprintGetSetValue(getvalue, setvalue)
fp = open('./.objparamarray.c', 'a')
print >> fp, "{\"%s\", %s, %s, %s, %s, NULL, NULL, %s}," % (dmparam, access, ptype, getvalue, setvalue, bbfdm)
@ -451,13 +423,6 @@ def generatecfiles( pdir ):
dmfpc.write(tmpd)
except:
pass
try:
tmpf = open("./.objparamarray.c", "r")
tmpd = tmpf.read()
tmpf.close()
dmfpc.write(tmpd)
except:
pass
try:
tmpf = open("./.objparamarray.h", "r")
tmpd = tmpf.read()
@ -478,14 +443,6 @@ def generatecfiles( pdir ):
dmfpc.write(tmpd)
except:
pass
try:
tmpf = open("./.objbrowse.h", "r")
tmpd = tmpf.read()
tmpf.close()
dmfph.write(tmpd)
print >> dmfph, ""
except:
pass
try:
exists = os.path.isfile("./.objadddel.c")
if exists:
@ -498,14 +455,6 @@ def generatecfiles( pdir ):
dmfpc.write(tmpd)
except:
pass
try:
tmpf = open("./.objadddel.h", "r")
tmpd = tmpf.read()
tmpf.close()
dmfph.write(tmpd)
print >> dmfph, ""
except:
pass
try:
exists = os.path.isfile("./.getstevalue.c")
if exists:
@ -518,13 +467,6 @@ def generatecfiles( pdir ):
dmfpc.write(tmpd)
except:
pass
try:
tmpf = open("./.getstevalue.h", "r")
tmpd = tmpf.read()
tmpf.close()
dmfph.write(tmpd)
except:
pass
try:
exists = os.path.isfile("./.operate.c")
if exists:
@ -538,10 +480,10 @@ def generatecfiles( pdir ):
except:
pass
try:
tmpf = open("./.operate.h", "r")
tmpf = open("./.objparamarray.c", "r")
tmpd = tmpf.read()
tmpf.close()
dmfph.write(tmpd)
dmfpc.write(tmpd)
except:
pass
hprintfootfile(dmfph)
@ -571,20 +513,15 @@ def generateRootDynamicarray( ):
commonname = getname(x)
printOperateRootDynamic(x, commonname, DictOperate[x])
cprintOperate(commonname)
hprintOperate(commonname)
printtailArrayRootDynamic()
def removetmpfiles( ):
removefile("./.objparamarray.c")
removefile("./.objparamarray.h")
removefile("./.objadddel.c")
removefile("./.objadddel.h")
removefile("./.objbrowse.c")
removefile("./.objbrowse.h")
removefile("./.getstevalue.c")
removefile("./.getstevalue.h")
removefile("./.operate.c")
removefile("./.operate.h")
removefile("./.objroot.c")
### main ###