From e20b717d17dd9d0bbbbc80bc51c9764d2563b942 Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Thu, 3 Sep 2020 22:34:15 +0100 Subject: [PATCH] bbf: update dynamic library generator --- dynamic_parameters/library/example/Makefile | 14 +- dynamic_parameters/library/example/example.c | 213 +++++++++--------- dynamic_parameters/library/example/example.h | 6 - .../library/generate_library.py | 101 ++------- 4 files changed, 128 insertions(+), 206 deletions(-) diff --git a/dynamic_parameters/library/example/Makefile b/dynamic_parameters/library/example/Makefile index e61c1eec..e4c46815 100644 --- a/dynamic_parameters/library/example/Makefile +++ b/dynamic_parameters/library/example/Makefile @@ -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) diff --git a/dynamic_parameters/library/example/example.c b/dynamic_parameters/library/example/example.c index 67a3de6b..c40061d4 100644 --- a/dynamic_parameters/library/example/example.c +++ b/dynamic_parameters/library/example/example.c @@ -8,13 +8,11 @@ * Author: Amin Ben Ramdhane */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "example.h" /* ********** RootDynamicObj ********** */ @@ -26,11 +24,107 @@ LIB_MAP_OBJ tRootDynamicObj[] = { /* ********** RootDynamicOperate ********** */ LIB_MAP_OPERATE tRootDynamicOperate[] = { -/* pathname, operation */ -{"Device.BBKSpeedTest", dynamicDeviceOperate}, +/* pathname, operation, type */ +{"Device.BBKSpeedTest", dynamicDeviceOperate, "async"}, {0} }; +/************************************************************* + * GET & SET PARAM +/*************************************************************/ +static int execute_bbk_speedtest() +{ + json_object *res; + char *latency, *download, *upload = NULL; + + dmubus_call("bbk", "start", UBUS_ARGS{}, 0, &res); + if (res) { + dmuci_set_varstate_value("cwmp", "@bbkspeedtest[0]", "DiagnosticState", "Complete"); + latency = dmjson_get_value(res, 1, "latency"); + if (latency != NULL && strlen(latency) > 0) + dmuci_set_varstate_value("cwmp", "@bbkspeedtest[0]", "Latency", latency); + download = dmjson_get_value(res, 1, "download"); + if (download != NULL && strlen(latency) > 0) + dmuci_set_varstate_value("cwmp", "@bbkspeedtest[0]", "Download", download); + upload=dmjson_get_value(res, 1, "upload"); + if (upload != NULL && strlen(upload) > 0) + dmuci_set_varstate_value("cwmp", "@bbkspeedtest[0]", "Upload", upload); + } + return 0; +} + +static inline char *bbk_speedtest_get(char *option, char *def) +{ + char *tmp; + dmuci_get_varstate_string("cwmp", "@bbkspeedtest[0]", option, &tmp); + return tmp[0] == '\0' ? dmstrdup(def) : tmp; +} + +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; +} + +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; + + switch (action) { + case VALUECHECK: + break; + case VALUESET: + 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(); + } + break; + } + return 0; +} + +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; +} + +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; +} + +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; +} + +/************************************************************* + * OPERATE +/*************************************************************/ +opr_ret_t dynamicDeviceOperate(struct dmctx *dmctx, char *path, json_object *input) +{ + json_object *ubus_res = NULL; + + dmubus_call("bbk", "start", UBUS_ARGS{}, 0, &ubus_res); + + char *param_latency = (char *) dmjson_get_value(ubus_res, 1, "latency"); + char *param_download = (char *) dmjson_get_value(ubus_res, 1, "download"); + char *param_upload = (char *) dmjson_get_value(ubus_res, 1, "upload"); + + add_list_paramameter(dmctx, dmstrdup("Latency"), param_latency, "string", NULL, 0); + add_list_paramameter(dmctx, dmstrdup("Download"), param_download, "string", NULL, 0); + add_list_paramameter(dmctx, dmstrdup("Upload"), param_upload, "string", NULL, 0); + + return SUCCESS; +} + /* *** Device.IP.Diagnostics. *** */ DMOBJ tdynamicIPDiagnosticsObj[] = { /* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -48,104 +142,3 @@ DMLEAF tdynamicIPDiagnosticsX_IOPSYS_EU_BBKSpeedTestParams[] = { {0} }; -/************************************************************* - * GET & SET PARAM -/*************************************************************/ -static int execute_bbk_speedtest() -{ - json_object *res; - char *latency, *download, *upload = NULL; - - dmubus_call("bbk", "start", UBUS_ARGS{}, 0, &res); - if (res) { - dmuci_set_varstate_value("cwmp", "@bbkspeedtest[0]", "DiagnosticState", "Complete"); - latency=dmjson_get_value(res, 1, "latency"); - if(latency!=NULL && strlen(latency)>0) - dmuci_set_varstate_value("cwmp", "@bbkspeedtest[0]", "Latency", latency); - download=dmjson_get_value(res, 1, "download"); - if(download!=NULL && strlen(latency)>0) - dmuci_set_varstate_value("cwmp", "@bbkspeedtest[0]", "Download", download); - upload=dmjson_get_value(res, 1, "upload"); - if(upload!=NULL && strlen(upload)>0) - dmuci_set_varstate_value("cwmp", "@bbkspeedtest[0]", "Upload", upload); - } - return 0; -} - -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; -} - - -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) -{ - char *tmp; - struct uci_section *curr_section = NULL; - - switch (action) { - case VALUECHECK: - break; - case VALUESET: - 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(); - } - break; - } - return 0; -} - -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) -{ - *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) -{ - *value = bbk_speedtest_get("Upload", "0"); - return 0; -} - -/************************************************************* - * OPERATE -/*************************************************************/ -opr_ret_t dynamicDeviceOperate(struct dmctx *dmctx, char *path, char *input) -{ - json_object *ubus_res = NULL; - - dmubus_call("bbk", "start", UBUS_ARGS{}, 0, &ubus_res); - - char *param_latency = (char *) dmjson_get_value(ubus_res, 1, "latency"); - char *param_download = (char *) dmjson_get_value(ubus_res, 1, "download"); - char *param_upload = (char *) dmjson_get_value(ubus_res, 1, "upload"); - - add_list_paramameter(dmctx, dmstrdup("Latency"), param_latency, "string", NULL, 0); - add_list_paramameter(dmctx, dmstrdup("Download"), param_download, "string", NULL, 0); - add_list_paramameter(dmctx, dmstrdup("Upload"), param_upload, "string", NULL, 0); - - return SUCCESS; -} diff --git a/dynamic_parameters/library/example/example.h b/dynamic_parameters/library/example/example.h index 74c13480..db534bc3 100644 --- a/dynamic_parameters/library/example/example.h +++ b/dynamic_parameters/library/example/example.h @@ -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 diff --git a/dynamic_parameters/library/generate_library.py b/dynamic_parameters/library/generate_library.py index d7fddb30..1a53f43f 100755 --- a/dynamic_parameters/library/generate_library.py +++ b/dynamic_parameters/library/generate_library.py @@ -158,13 +158,11 @@ def cprinttopfile ( fp ): print >> fp, " * Author: Amin Ben Ramdhane " print >> fp, " */" print >> fp, "" - print >> fp, "#include " - print >> fp, "#include " - print >> fp, "#include " - print >> fp, "#include " - print >> fp, "#include " - print >> fp, "#include " - print >> fp, "#include " + print >> fp, "#include " + print >> fp, "#include " + print >> fp, "#include " + print >> fp, "#include " + print >> fp, "#include " 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 ###