mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-01-28 01:47:18 +01:00
Add support for data model schema
This commit is contained in:
parent
ccc15bd9e1
commit
c4701f0968
3 changed files with 73 additions and 3 deletions
|
|
@ -20,7 +20,8 @@ static void usage(char *prog)
|
|||
fprintf(stderr, "options:\n");
|
||||
fprintf(stderr, " -m <ms name> micro-service name\n");
|
||||
fprintf(stderr, " -l <loglevel> log verbosity value as per standard syslog\n");
|
||||
fprintf(stderr, " -h Displays this help\n");
|
||||
fprintf(stderr, " -d Display the schema data model supported by micro-service\n");
|
||||
fprintf(stderr, " -h Display this help\n");
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
|
|
@ -29,11 +30,11 @@ int main(int argc, char **argv)
|
|||
struct bbfdm_context bbfdm_ctx = {0};
|
||||
char proc_name[64] = {0};
|
||||
int log_level = LOG_ERR;
|
||||
int err = 0, ch;
|
||||
int err = 0, ch, dm_type = 0;
|
||||
|
||||
memset(&bbfdm_ctx, 0, sizeof(struct bbfdm_context));
|
||||
|
||||
while ((ch = getopt(argc, argv, "hl:m:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "hdl:m:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'm':
|
||||
bbfdm_ubus_set_service_name(&bbfdm_ctx, optarg);
|
||||
|
|
@ -45,6 +46,9 @@ int main(int argc, char **argv)
|
|||
log_level = 7;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
dm_type++;
|
||||
break;
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
exit(0);
|
||||
|
|
@ -58,6 +62,11 @@ int main(int argc, char **argv)
|
|||
exit(-1);
|
||||
}
|
||||
|
||||
if (dm_type > 0) {
|
||||
int res = bbfdm_print_data_model_schema(&bbfdm_ctx, dm_type);
|
||||
exit(res);
|
||||
}
|
||||
|
||||
bbfdm_ubus_set_log_level(log_level);
|
||||
|
||||
openlog(bbfdm_ctx.config.service_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
||||
|
|
|
|||
|
|
@ -716,6 +716,65 @@ static int load_micro_service_data_model(struct bbfdm_context *daemon_ctx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int bbfdm_print_data_model_schema(struct bbfdm_context *bbfdm_ctx, const enum bbfdm_type_enum type)
|
||||
{
|
||||
struct dmctx bbf_ctx = {
|
||||
.in_param = ROOT_NODE,
|
||||
.nextlevel = false,
|
||||
.iscommand = true,
|
||||
.isevent = true,
|
||||
.isinfo = true,
|
||||
.dm_type = type
|
||||
};
|
||||
int err = 0;
|
||||
|
||||
err = load_micro_service_config(&bbfdm_ctx->config);
|
||||
if (err) {
|
||||
fprintf(stderr, "Failed to load micro-service config\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
err = load_micro_service_data_model(bbfdm_ctx);
|
||||
if (err) {
|
||||
fprintf(stderr, "Failed to load micro-service data model\n");
|
||||
bbfdm_ctx_cleanup(bbfdm_ctx);
|
||||
return err;
|
||||
}
|
||||
|
||||
bbf_init(&bbf_ctx);
|
||||
|
||||
err = bbf_entry_method(&bbf_ctx, BBF_SCHEMA);
|
||||
if (!err) {
|
||||
struct blob_attr *cur = NULL;
|
||||
size_t rem = 0;
|
||||
|
||||
blobmsg_for_each_attr(cur, bbf_ctx.bb.head, rem) {
|
||||
struct blob_attr *tb[3] = {0};
|
||||
const struct blobmsg_policy p[3] = {
|
||||
{ "path", BLOBMSG_TYPE_STRING },
|
||||
{ "data", BLOBMSG_TYPE_STRING },
|
||||
{ "type", BLOBMSG_TYPE_STRING }
|
||||
};
|
||||
|
||||
blobmsg_parse(p, 3, tb, blobmsg_data(cur), blobmsg_len(cur));
|
||||
|
||||
char *name = (tb[0]) ? blobmsg_get_string(tb[0]) : "";
|
||||
char *data = (tb[1]) ? blobmsg_get_string(tb[1]) : "";
|
||||
char *type = (tb[2]) ? blobmsg_get_string(tb[2]) : "";
|
||||
|
||||
printf("%s %s %s\n", name, type, strlen(data) ? data : "0");
|
||||
}
|
||||
} else {
|
||||
printf("ERROR: %d retrieving %s\n", err, ROOT_NODE);
|
||||
err = -1;
|
||||
}
|
||||
|
||||
bbf_cleanup(&bbf_ctx);
|
||||
|
||||
bbfdm_ctx_cleanup(bbfdm_ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx)
|
||||
{
|
||||
int err = 0;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ typedef struct bbfdm_data {
|
|||
int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx);
|
||||
int bbfdm_ubus_regiter_free(struct bbfdm_context *bbfdm_ctx);
|
||||
|
||||
int bbfdm_print_data_model_schema(struct bbfdm_context *bbfdm_ctx, const enum bbfdm_type_enum type);
|
||||
|
||||
void bbfdm_ubus_set_service_name(struct bbfdm_context *bbfdm_ctx, const char *srv_name);
|
||||
void bbfdm_ubus_set_log_level(int log_level);
|
||||
void bbfdm_ubus_load_data_model(DM_MAP_OBJ *DynamicObj);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue