67 lines
1.4 KiB
C
67 lines
1.4 KiB
C
|
#include <stdio.h>
|
||
|
|
||
|
#include "cmd_console.h"
|
||
|
#include "ulog_api.h"
|
||
|
#include "s2j/s2j.h"
|
||
|
|
||
|
#define LOGGING_MODULE_NAME "logging"
|
||
|
|
||
|
typedef int (*cmd_cb)(cJSON *, int, char **);
|
||
|
|
||
|
typedef struct _log_cmd {
|
||
|
char cmd[20];
|
||
|
cmd_cb cb;
|
||
|
} log_cmd_t;
|
||
|
|
||
|
ulog_t *g_log;
|
||
|
log_cmd_t log_cmd[] = {
|
||
|
{"console", conf_console}
|
||
|
};
|
||
|
|
||
|
cmd_cb get_cb_by_cmd(const char *cmd)
|
||
|
{
|
||
|
for (int i = 0; i < (sizeof(log_cmd) / sizeof(log_cmd_t)); i++) {
|
||
|
if (strcmp(cmd, log_cmd[i].cmd) == 0) {
|
||
|
return log_cmd[i].cb;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char **argv)
|
||
|
{
|
||
|
if (argc < 2) {
|
||
|
fprintf(stdout, "Parameter too few");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
g_log = ulog_init(LOGGING_MODULE_NAME, 1);
|
||
|
if (g_log == NULL) {
|
||
|
fprintf(stderr, "Initiating ulog is failure");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
cmd_cb func = get_cb_by_cmd(argv[1]);
|
||
|
if (func == NULL) {
|
||
|
ULOG_WARNING(g_log, "Not find logging cmd:%s", argv[1]);
|
||
|
goto END;
|
||
|
}
|
||
|
|
||
|
s2j_create_json_obj(json_obj);
|
||
|
if(json_obj == NULL)
|
||
|
{
|
||
|
ULOG_ERR(g_log, "Creating json object is failure");
|
||
|
goto END;
|
||
|
}
|
||
|
|
||
|
func(json_obj, argc, argv);
|
||
|
|
||
|
END:
|
||
|
if(json_obj != NULL) {
|
||
|
cJSON_Delete(json_obj);
|
||
|
}
|
||
|
ulog_close(g_log);
|
||
|
return 0;
|
||
|
}
|