Mod aaa-12 增加对象管理配置管理接口

RCA:
SOL:
修改人:huangxin
检视人:huangxin
This commit is contained in:
huangxin 2019-10-10 16:36:08 +08:00
parent 24f01ce548
commit dc1a278ce7
17 changed files with 1664 additions and 569 deletions

View File

@ -1,19 +1,37 @@
cmake_minimum_required(VERSION 3.10)
project(drivers) #
set(PLAT_CFG_DIR "./Platform/user/configm/config-server")
#include(kernel_config.cmake) # add_definitions(xxx)
#add_definitions(-D__KERNEL__=1)
add_definitions(-D_GNU_SOURCE=1)
add_definitions(-D__USE_XOPEN=1)
add_definitions(-DOBJECT_DEMO=1)
aux_source_directory(./Product/user/object_manager DIR_SRCS)
aux_source_directory(./libs/src/lighttpd-1.4.51/src DIR_SRCS)
aux_source_directory(${PLAT_CFG_DIR} DIR_SRCS)
aux_source_directory(${PLAT_CFG_DIR}/object_manager DIR_SRCS)
aux_source_directory(${PLAT_CFG_DIR}/web_config DIR_SRCS)
set(MY_ANDROID_ROOT_DIR "./kernel/linux-4.14.83") # 便使
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -nostdinc") # C
add_executable(drivers ${DIR_SRCS}) # dummy targetexternal libraries
add_executable(drivers ${DIR_SRCS} Platform/user/configm/config-server/object_manager/object_manager.h Platform/user/configm/config-server/object_manager/object_manager.c) # dummy targetexternal libraries
# main.cClion
include_directories(
./Common
${PLAT_CFG_DIR}/include
./Platform/common/configm/include
./Platform/common
./Product/common
)
#include_directories(
# "${MY_ANDROID_ROOT_DIR}/kernel/include"
# "${MY_ANDROID_ROOT_DIR}/kernel/arch/arm/include"

View File

@ -12,6 +12,22 @@
/***********************操作类型定义结束 ********************/
/*************************** 模块定义 ************************/
typedef enum{
NETCONFIG_MODULE = 0x00000001, ///< NET CONFIG
USER_MANAGER_CONFIG_MODULE = 0x00000002, ///< USER MANAGER CONFIG
LOCALAUTH_CONFIG_MODULE = 0x00000003, ///< PORTAL SERVER CONFIG
LOG_CONFIG_MODULE = 0x00000004, ///<
VLAN_CONFIG_MODULE = 0x00000005, ///< vlan config
DHCP_CONFIG_MODULE = 0x00000007, ///< DHCP CONFIG
LTE_CONFIG_MODULE = 0x00000008, ///< 4G config
NAT_CONFIG_MODULE = 0x00000009, ///< nat config
STATIC_ROUTING_CONFIG_MODULE = 0x00000009, ///< static routing
OBJECT_MANAGER_CONFIG_MODULE = 0x0000000A, ///< Object manager config id
CONFIG_ID_MAX,
} CONFIG_ID_TYPE;
#if 0
/* NET CONFIG */
#define NETCONFIG_MODULE 0x00000001
@ -37,7 +53,7 @@
/*4G config*/
#define LTE_CONFIG_MODULE 0x00000007
#endif
/************************* 模块定义结束 **********************/
@ -80,6 +96,10 @@
#define GET_ALL_ROUTING_INFO (uint64)((uint64)STATIC_ROUTING_CONFIG_MODULE<<32|2)
#define LTE_CONFIG (uint64)((uint64)LTE_CONFIG_MODULE<<32|1)
#define OBJECT_CONFIG (uint64)((uint64)OBJECT_MANAGER_CONFIG_MODULE<<32|1)
#define OBJECT_GETALL_CONFIG (uint64)((uint64)OBJECT_MANAGER_CONFIG_MODULE<<32|2)
/************************ config id定义 end**********************/
#endif

View File

@ -28,7 +28,8 @@ VPATH = ../user/configm/config-server \
../user/configm/config-server/web_config \
../user/configm/config-server/dhcp_config \
../user/configm/config-server/user_manager_config \
../user/configm/config-server/log_config
../user/configm/config-server/log_config \
../user/configm/config-server/object_manager
# source code
@ -71,7 +72,10 @@ COMMON_SRCS = configserver.c \
dhcp_shared_network_config.c \
dhcp_subnet_config.c\
static_routing_config/static_routing_config.c \
LTE_config/LTE_config.c
LTE_config/LTE_config.c \
object_manager.c \
log.c \
hexdump.c
@ -84,7 +88,8 @@ COMMOM_CFLAGS = -I../user/configm/config-server/include \
-I../../Common -I../common/redismq -I../common/database \
-I../common/configm -I../common/rpc -I../common/rpc/hashtable \
-I../common/ulog -I../user/configm/config-server/netconfig/ \
-I../user/configm/config-server/netconfig/bridge/include
-I../user/configm/config-server/netconfig/bridge/include \
-I../common -I../../Producd/common
# gcc CFLAGS
PLAT_ARM64_CFLAGS := $(COMMOM_CFLAGS)
@ -98,7 +103,7 @@ COMMON_STD_LIB := -lpthread -lm -lcjson -levent -ljson-c -lhiredis -lodbc -lev -
PLAT_ARM64_LIBS := -lopenrpc-$(ARM64_OBJ_TARGET) -lnetlinku-$(ARM64_OBJ_TARGET) -lredismq-$(ARM64_OBJ_TARGET)
PLAT_ARM64_LIBS += -lulogapi-$(ARM64_OBJ_TARGET) -ldatabase-$(ARM64_OBJ_TARGET) $(COMMON_STD_LIB)
PLAT_LINUX_LIBS := -lopenrpc-$(LINUX_OBJ_TARGET) -lnetlinku-$(LINUX_OBJ_TARGET) -lredismq-$(LINUX_OBJ_TARGET)
PLAT_LINUX_LIBS := -lopenrpc-$(LINUX_OBJ_TARGET) -lnetlinku-$(LINUX_OBJ_TARGET) -lredismq-$(LINUX_OBJ_TARGET)
PLAT_LINUX_LIBS += -lulogapi-$(LINUX_OBJ_TARGET) -ldatabase-$(LINUX_OBJ_TARGET) $(COMMON_STD_LIB)

View File

@ -35,7 +35,7 @@ PLAT_LINUX_SRCS = $(COMMON_SRCS)
PLAT_ARM64_SRCS = $(COMMON_SRCS)
# gcc CFLAGS
PLAT_ARM64_CFLAGS := -I../user/configm/config-server/include -I../../Common -I../common/configm -I../common/rpc -I../common/rpc/hashtable
PLAT_ARM64_CFLAGS := -I../user/configm/config-server/include -I../../Common -I../common/configm -I../common -I../common/rpc -I../common/rpc/hashtable
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)

View File

@ -19,7 +19,7 @@ int cm_format_data(ret_code ret_code, cJSON *item_obj, char *output)
char *ret_char = NULL;
config_result_t tem_buff = {0};
config_result_t *config_ret = &tem_buff;
snprintf(config_ret->resultCode, RET_CODE_LEN - 1, "%d", ret_code);
config_ret->message = (char *)rpc_code_format(ret_code);
@ -32,7 +32,7 @@ int cm_format_data(ret_code ret_code, cJSON *item_obj, char *output)
s2j_json_set_basic_element(json_obj, config_ret, string, resultCode);
s2j_json_set_basic_element(json_obj, config_ret, string, message);
cJSON_AddItemToObject(json_obj, "data", item_obj);
ret_char = cJSON_PrintUnformatted(json_obj);
@ -80,7 +80,7 @@ void cm_return(rpc_conn *conn, ret_code err_code, char* err_message)
ret_char = cJSON_PrintUnformatted(json_obj);
rpc_return(conn, ret_char, strlen(ret_char)+1);
rpc_return(conn, ret_char, strlen(ret_char)+1);
rpc_free(ret_char);
cJSON_Delete(json_obj);
@ -106,40 +106,40 @@ config_service_t *cm_config_service_get(uint64 config_id)
ret_code cm_config_rec_pre(char **input, int *input_len, char **output, int *output_len)
{
/*if((access(CONFIG_RECOVERY_DONE, F_OK))!=-1)
{
/*if((access(CONFIG_RECOVERY_DONE, F_OK))!=-1)
{
return RET_ERR;
} */
*input = rpc_new(char, CM_BUFF_SIZE);
*output = rpc_new(char, CM_BUFF_SIZE);
} */
*input = rpc_new(char, CM_BUFF_SIZE);
*output = rpc_new(char, CM_BUFF_SIZE);
*input_len = CM_BUFF_SIZE;
*output_len = CM_BUFF_SIZE;
if(*input == NULL
if(*input == NULL
|| *output == NULL)
{
return RET_NOMEM;
}
memset(*input, 0, CM_BUFF_SIZE);
memset(*output, 0, CM_BUFF_SIZE);
rpc_log_info("==>config revocery start\n");
return RET_OK;
}
ret_code cm_config_rec_done(char *input, char *output)
{
int fd;
memset(input, 0, CM_BUFF_SIZE);
memset(output, 0, CM_BUFF_SIZE);
free(input);
free(input);
free(output);
fd = open(CONFIG_RECOVERY_DONE, O_CREAT, 0777);
if(fd <= 0)
{
@ -149,40 +149,40 @@ ret_code cm_config_rec_done(char *input, char *output)
{
close(fd);
}
rpc_log_info("==>config revocery done!\n");
return RET_OK;
}
ret_code cm_config_get_allconfig(uint source,
config_service_t *config_svr,
config_service_t *config_svr,
char *input, int *intput_len)
{
{
ret_code ret = RET_OK;
memset(input, 0, CM_BUFF_SIZE);
ret = config_svr->getall_callback(source, input, intput_len);
ASSERT_RET(ret);
return ret;
}
ret_code cm_config_config_rec(uint source,
config_service_t *config_svr,
config_service_t *config_svr,
char *input, int input_len,
char *output, int *output_len)
{
{
int config_type = CM_CONFIG_SET;
ret_code ret = RET_OK;
ret = config_svr->chk_callback(source, &config_type,
input, &input_len,
input, &input_len,
output, output_len);
if(ret == RET_OK)
{
config_svr->proc_callback(source, config_type,
config_svr->proc_callback(source, config_type,
input, input_len,
output, output_len);
}
@ -193,17 +193,17 @@ ret_code cm_config_get_allconfig(uint source,
void cm_config_module_init()
{
int len = sizeof(g_config_init) / sizeof(config_init_t);
config_init_t *config_svr;
config_init_t *config_svr;
int config_idx;
for(config_idx = 0; config_idx < len; config_idx++)
{
config_svr = &(g_config_init[config_idx]);
rpc_log_info("MODULE %d init\n", config_svr->config_mudlue);
if(config_svr->init_callback)
{
config_svr->init_callback();
config_svr->init_callback();
}
}
}
@ -212,11 +212,11 @@ void cm_config_module_init()
void cm_config_recovery()
{
int len = sizeof(g_config_service) / sizeof(config_service_t);
config_service_t *config_svr;
config_service_t *config_svr;
int input_len = 0;
int output_len = 0;
char *input = NULL;
char *output = NULL;
char *output = NULL;
ret_code ret = RET_OK;
int config_idx;
int recover_idx = 1,recover_phase;
@ -238,7 +238,7 @@ void cm_config_recovery()
{
break;
}
for(config_idx = 0; config_idx < len; config_idx++)
{
config_svr = &(g_config_service[config_idx]);
@ -247,26 +247,26 @@ void cm_config_recovery()
{
continue;
}
if(config_svr->chk_callback == NULL
if(config_svr->chk_callback == NULL
|| config_svr->proc_callback == NULL)
{
continue;
}
cm_config_get_allconfig(recover_phase, config_svr,
cm_config_get_allconfig(recover_phase, config_svr,
input, &input_len);
cm_config_config_rec(recover_phase, config_svr,
input, input_len,
cm_config_config_rec(recover_phase, config_svr,
input, input_len,
output, &output_len);
}
recover_idx++;
}
cm_config_rec_done(input, output);
return;
}
@ -284,27 +284,27 @@ ret_code cm_config_proc_pre(char **input, char **output, int *buff_len)
{
cm_get_buff = rpc_new(char, CM_BUFF_SIZE);
}
if(cm_get_buff == NULL || cm_set_buff == NULL)
{
return RET_NOMEM;
}
memset(cm_set_buff, 0, CM_BUFF_SIZE);
memset(cm_get_buff, 0, CM_BUFF_SIZE);
*input = cm_set_buff;
*output = cm_get_buff;
*buff_len = CM_BUFF_SIZE;
return RET_OK;
}
/* 配置处理入口函数,所有的配置,均在此函数中处理 */
void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
{
{
config_service_t *config_svr;
config_msg_t *config_msg;
char *cm_get_buff = NULL;
@ -325,21 +325,21 @@ void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
cm_return(conn, RET_NOMEM, "not enough memery");
return;
}
config_msg = (config_msg_t *)input;
config_len = input_len - sizeof(config_msg_t);
rpc_log_info("recv config from %d, config type is %d config id is 0x%llx ,len is %d\r\n",
config_msg->source, config_msg->config_type, config_msg->config_id,
config_len);
config_svr = cm_config_service_get(config_msg->config_id);
if(config_svr == NULL)
{
cm_return(conn, RET_NOCMID, "can not find config id");
return;
}
/*source check*/
if(!(config_svr->config_src & config_msg->source))
{
@ -352,17 +352,17 @@ void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
cm_return(conn, RET_NOMEM, "not enough memory");
return;
}
memcpy(cm_set_buff, config_msg->config_buff, config_len);
/*config check*/
if(config_svr->chk_callback)
{
ret = config_svr->chk_callback(config_msg->source,
&(config_msg->config_type),
cm_set_buff,
&config_len,
cm_get_buff,
cm_set_buff,
&config_len,
cm_get_buff,
&buff_len);
if(ret != RET_OK)
{
@ -370,28 +370,28 @@ void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
return;
}
}
/*config exec*/
switch(config_msg->config_type)
{
{
case CM_CONFIG_GET:
if(config_svr->get_callback)
{
ret = config_svr->get_callback(config_msg->source,
cm_set_buff,
config_len,
cm_get_buff,
ret = config_svr->get_callback(config_msg->source,
cm_set_buff,
config_len,
cm_get_buff,
&buff_len);
}
break;
case CM_CONFIG_GET_ALL:
if(config_svr->getall_callback)
{
ret = config_svr->getall_callback(config_msg->source,
cm_get_buff,
&buff_len);
{
ret = config_svr->getall_callback(config_msg->source,
cm_get_buff,
&buff_len);
}
break;
case CM_CONFIG_ADD:
@ -399,48 +399,48 @@ void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
case CM_CONFIG_SET:
if(config_svr->proc_callback)
{
ret = config_svr->proc_callback(config_msg->source,
ret = config_svr->proc_callback(config_msg->source,
config_msg->config_type,
cm_set_buff,
config_len,
cm_get_buff,
cm_set_buff,
config_len,
cm_get_buff,
&buff_len);
}
break;
default:
ret = RET_INPUTERR;
break;
}
if(buff_len > CM_BUFF_SIZE)
{
ret = RET_NOMEM;
}
if(ret != RET_OK)
{
cm_return(conn, ret, cm_get_buff);
return;
}
rpc_return(conn, cm_get_buff, buff_len);
return;
}
int main(int argc, char **argv)
int main(int argc, char **argv)
{
rpc_server *server;
signal(SIGPIPE,SIG_IGN);
if (server= rpc_server_create_ex("ConfigManger#0"))
if (server= rpc_server_create_ex("ConfigManger#0"))
{
rpc_log_info("start server\n");
}
else
}
else
{
rpc_log_error("start server error\n");
return EXIT_FAILURE;
@ -448,13 +448,13 @@ int main(int argc, char **argv)
/* 模块初始化 */
cm_config_module_init();
/* 配置恢复 */
cm_config_recovery();
/* 注册配置处理函数 */
rpc_server_regservice(server, "ConfigManger#0", "cm_config_process", cm_config_process);
for(;;)
{
rpc_sleep(1000);

View File

@ -17,6 +17,7 @@
#include "dhcp_lib.h"
#include "static_routing.h"
#include "LTE_config.h"
#include "../object_manager/object_manager.h"
#define RET_CODE_LEN 16
#define RET_MSG_LEN 128
@ -42,18 +43,22 @@
{ \
LTE_CONFIG_MODULE, \
LTE_config_init \
} \
}, \
{ \
OBJECT_MANAGER_CONFIG_MODULE, \
object_config_init \
} \
}
/*
/*
1ID
2,
WEB
WEB
3
4
5
6
7
5
6
7
8
*/
#define CONFIG_SERVICE_ARRAY \
@ -309,29 +314,47 @@
LTE_config_proc, \
NULL, \
LTE_config_get_all \
}\
}, \
{ \
OBJECT_CONFIG, \
CONFIG_FROM_WEB, \
FALSE, \
object_config_chk, \
object_config_proc, \
NULL, \
NULL, \
}, \
{ \
OBJECT_GETALL_CONFIG, \
CONFIG_FROM_WEB, \
FALSE, \
object_config_chk, \
NULL, \
object_config_get, \
object_config_get_all, \
} \
}
typedef ret_code (*cm_config_init)();
typedef ret_code (*cm_config_chk)(uint source, uint *config_type,
pointer input, int *input_len,
pointer input, int *input_len,
pointer output, int *output_len);
typedef ret_code (*cm_config_proc)(uint source, uint config_type,
pointer input, int input_len,
pointer input, int input_len,
pointer output, int *output_len);
typedef ret_code (*cm_config_get)(uint source,
typedef ret_code (*cm_config_get)(uint source,
pointer input, int input_len,
pointer output, int *output_len);
typedef ret_code (*cm_config_get_all)(uint source,
typedef ret_code (*cm_config_get_all)(uint source,
pointer output, int *output_len);
/* 配置注册 */
struct _config_init {
uint config_mudlue;
uint config_mudlue;
cm_config_init init_callback;
};
typedef struct _config_init config_init_t;

View File

@ -0,0 +1,326 @@
#ifndef __KERNEL__
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <uthash/utstring.h>
#include "log.h"
static const char hex_asc[] = "0123456789abcdef";
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
char* IHW_bin2hex(char *p, const unsigned char *cp, int count)
{
while (count) {
unsigned char c = *cp++;
/* put lowercase hex digits */
*p++ = 0x20 | hex_asc[c >> 4];
*p++ = 0x20 | hex_asc[c & 0xf];
count--;
}
return p;
}
/**
* hex_to_bin - convert a hex digit to its real value
* @ch: ascii character represents hex digit
*
* hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
* input.
*/
int hex_to_bin(char ch)
{
if((ch >= '0') && (ch <= '9'))
{
return ch - '0';
}
ch = tolower(ch);
if((ch >= 'a') && (ch <= 'f'))
{
return ch - 'a' + 10;
}
return -1;
}
/**
* hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
* @buf: data blob to dump
* @len: number of bytes in the @buf
* @rowsize: number of bytes to print per line; must be 16 or 32
* @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
* @linebuf: where to put the converted data
* @linebuflen: total size of @linebuf, including space for terminating NUL
* @ascii: include ASCII after the hex output
*
* hex_dump_to_buffer() works on one "line" of output at a time, i.e.,
* 16 or 32 bytes of input data converted to hex + ASCII output.
*
* Given a buffer of u8 data, hex_dump_to_buffer() converts the input data
* to a hex + ASCII dump at the supplied memory location.
* The converted output is always NUL-terminated.
*
* E.g.:
* hex_dump_to_buffer(frame->data, frame->len, 16, 1,
* linebuf, sizeof(linebuf), true);
*
* example output buffer:
* 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
*/
void hex_dump_to_buffer(const void* buf, int len, int rowsize,
int groupsize, char* linebuf, size_t linebuflen,
int ascii)
{
const unsigned char* ptr = (const unsigned char *)buf;
unsigned char ch;
int j, lx = 0;
int ascii_column;
if(rowsize != 16 && rowsize != 32)
{
rowsize = 16;
}
if(!len)
{
goto nil;
}
if(len > rowsize) /* limit to one line at a time */
{
len = rowsize;
}
if((len % groupsize) != 0) /* no mixed size output */
{
groupsize = 1;
}
switch(groupsize)
{
case 8:
{
const unsigned long long* ptr8 = (const unsigned long long *)buf;
int ngroups = len / groupsize;
for(j = 0; j < ngroups; j++)
lx += snprintf(linebuf + lx, linebuflen - lx,
"%s%16.16llx", j ? " " : "",
(unsigned long long) * (ptr8 + j));
ascii_column = 17 * ngroups + 2;
break;
}
case 4:
{
const unsigned int* ptr4 = (const unsigned int *)buf;
int ngroups = len / groupsize;
for(j = 0; j < ngroups; j++)
lx += snprintf(linebuf + lx, linebuflen - lx,
"%s%8.8x", j ? " " : "", *(ptr4 + j));
ascii_column = 9 * ngroups + 2;
break;
}
case 2:
{
const unsigned short* ptr2 = (const unsigned short *)buf;
int ngroups = len / groupsize;
for(j = 0; j < ngroups; j++)
lx += snprintf(linebuf + lx, linebuflen - lx,
"%s%4.4x", j ? " " : "", *(ptr2 + j));
ascii_column = 5 * ngroups + 2;
break;
}
default:
for(j = 0; (j < len) && (lx + 3) <= linebuflen; j++)
{
ch = ptr[j];
linebuf[lx++] = hex_asc_hi(ch);
linebuf[lx++] = hex_asc_lo(ch);
linebuf[lx++] = ' ';
}
if(j)
{
lx--;
}
ascii_column = 3 * rowsize + 2;
break;
}
if(!ascii)
{
goto nil;
}
while(lx < (linebuflen - 1) && lx < (ascii_column - 1))
{
linebuf[lx++] = ' ';
}
for(j = 0; (j < len) && (lx + 2) < linebuflen; j++)
{
ch = ptr[j];
linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
}
nil:
linebuf[lx++] = '\0';
}
/**
* print_hex_dump - print a text hex dump to syslog for a binary blob of data
* @level: kernel log level (e.g. KERN_DEBUG)
* @prefix_str: string to prefix each line with;
* caller supplies trailing spaces for alignment if desired
* @prefix_type: controls whether prefix of an offset, address, or none
* is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
* @rowsize: number of bytes to print per line; must be 16 or 32
* @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
* @buf: data blob to dump
* @len: number of bytes in the @buf
* @ascii: include ASCII after the hex output
*
* Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump
* to the kernel log at the specified kernel log level, with an optional
* leading prefix.
*
* print_hex_dump() works on one "line" of output at a time, i.e.,
* 16 or 32 bytes of input data converted to hex + ASCII output.
* print_hex_dump() iterates over the entire input @buf, breaking it into
* "line size" chunks to format and print.
*
* E.g.:
* print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS,
* 16, 1, frame->data, frame->len, true);
*
* Example output using %DUMP_PREFIX_OFFSET and 1-byte mode:
* 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
* Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode:
* ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~.
*/
void print_hex_dump(const char* prefix_str, int prefix_type,
int rowsize, int groupsize,
const void* buf, int len, int ascii)
{
const unsigned char* ptr = (const unsigned char *)buf;
int i, remaining = len;
unsigned char linebuf[32 * 3 + 2 + 32 + 1];
if(rowsize != 16 && rowsize != 32)
{
rowsize = 16;
}
for(i = 0; i < len; i += rowsize)
{
int linelen = MIN(remaining, rowsize);
remaining -= rowsize;
hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
(char *)linebuf, sizeof(linebuf), ascii);
switch(prefix_type)
{
case DUMP_PREFIX_ADDRESS:
print("%s%p: %s\n",
prefix_str, ptr + i, linebuf);
break;
case DUMP_PREFIX_OFFSET:
print("%s%.8x: %s\n", prefix_str, i, linebuf);
break;
default:
print("%s%.8x: %s\n", prefix_str, i, linebuf);
break;
}
}
print("%s", "\n");
}
/**
* print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
* @prefix_str: string to prefix each line with;
* caller supplies trailing spaces for alignment if desired
* @prefix_type: controls whether prefix of an offset, address, or none
* is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
* @buf: data blob to dump
* @len: number of bytes in the @buf
*
* Calls print_hex_dump(), with log level of KERN_DEBUG,
* rowsize of 16, groupsize of 1, and ASCII output included.
*/
void print_hex_dump_bytes(const char* prefix_str, int prefix_type,
const void* buf, int len)
{
print_hex_dump(prefix_str, prefix_type, 16, 1,
buf, len, 1);
}
const char* format_hex_buf(const char* prefix_str, int prefix_type,
int rowsize, int groupsize,
const void* buf, int len, int ascii)
{
UT_string* pLogStr = NULL;
const char* pFormatStr;
const unsigned char* ptr = (const unsigned char *)buf;
int i, remaining = len;
unsigned char linebuf[32 * 3 + 2 + 32 + 1];
if(rowsize != 16 && rowsize != 32)
{
rowsize = 16;
}
utstring_new(pLogStr);
for(i = 0; i < len; i += rowsize)
{
int linelen = MIN(remaining, rowsize);
remaining -= rowsize;
hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
(char *)linebuf, sizeof(linebuf), ascii);
switch(prefix_type)
{
case DUMP_PREFIX_ADDRESS:
utstring_printf(pLogStr, "%s%p: %s\n",
prefix_str, ptr + i, linebuf);
break;
case DUMP_PREFIX_OFFSET:
utstring_printf(pLogStr, "%s%.8x: %s\n",
prefix_str, i, linebuf);
break;
default:
utstring_printf(pLogStr, "%s%.8x: %s\n",
prefix_str, i, linebuf);
break;
}
}
pFormatStr = strdup(utstring_body(pLogStr));
utstring_free(pLogStr);
return pFormatStr;
}
#endif

View File

@ -0,0 +1,441 @@
/** @file log.c
@brief
@version 1.0.0
*/
#include <sys/time.h>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include <uthash/utlist.h>
#include <uthash/utstring.h>
#include "log.h"
#include "../../../../Product/common/common.h"
#define SHOW_CONSOLE_RED ("\033[31;48m\033[1m%s\033[0m%c")
#define SHOW_CONSOLE_YELLOW ("\033[33;48m\033[1m%s\033[0m%c")
#define SHOW_CONSOLE_GREEN ("\033[32;48m\033[1m%s\033[0m%c")
#define SHOW_CONSOLE_BLUE ("\033[34;48m\033[1m%s\033[0m%c")
#define LOG_FILE_BASEDIR (".")
#define MAX_LOG_FILE_SIZE (1024 * 1024)
#define MAX_PATH (256)
typedef struct LOG_ITEM
{
LOG_LEVEL level;
int isPrinted;
int isAddTags;
struct timeval timestamp;
char *pLogContent;
struct LOG_ITEM *next, *prev;
}*PLOG_ITEM;
typedef struct
{
pid_t pid;
char exeName[MAX_PATH];
char logFilePath[MAX_PATH];
FILE *pLogFile;
} LOG_PROCESS_INFO, *PLOG_PROCESS_INFO;
static int g_bEnableLog = TRUE; // 是否启用 Log 功能
static int g_bEnLogToFile = TRUE;
static char g_strLogTag[32]; // Log 标志
static unsigned int g_LogRdPos = 0;
static pthread_t g_logThreadId;
static LOG_PROCESS_INFO g_LogProcessInfo;
static pthread_mutex_t g_logLock;
static PLOG_ITEM g_pLogItemList = NULL;
static int g_iMinLevel = LOG_Fatal | LOG_Error | LOG_Warn | LOG_Debug | LOG_Info | LOG_Step;
/**
* @brief Log
* @param level
* @return
*/
const char* LogLevelToStr(LOG_LEVEL level)
{
switch(level)
{
case LOG_Test:
return "T";
case LOG_Info:
return "I";
case LOG_Call:
return "C";
case LOG_Debug:
return "D";
case LOG_Warn:
return "W";
case LOG_Error:
return "E";
case LOG_Fatal:
return "F";
case LOG_Step:
return "S";
case LOG_Devp:
return "V";
case LOG_Unknown:
return "U";
case LOG_All:
return "A";
default:
return "?";
}
}
static void __logColorOutput(const char* pColFmt, UT_string* pLog)
{
if(pLog == NULL)
{
return;
}
if(pColFmt == NULL)
{
print("%s", utstring_body(pLog));
}
else
{
if(utstring_find(pLog, -1, "\n", 1) == utstring_len(pLog) - 1)
{
char* pLogArray = utstring_body(pLog);
pLogArray[utstring_len(pLog) - 1] = 0;
print(pColFmt, pLogArray, '\n');
strcat(pLogArray, "\n");
}
else
{
print(pColFmt, utstring_body(pLog), '\0');
}
}
}
static void* __logOutputThread(void *p)
{
(void)p;
while(TRUE)
{
int isWriteLog = FALSE;
PLOG_ITEM pItem = NULL, pTmp = NULL;
pthread_mutex_lock(&g_logLock);
LL_FOREACH_SAFE(g_pLogItemList, pItem, pTmp)
{
UT_string *pLogStr;
struct tm lTime;
int logFileSize = 0;
if(++g_LogRdPos % 100 == 0)
{
GET_FILE_SIZE(g_LogProcessInfo.logFilePath, logFileSize);
}
localtime_r(&(pItem->timestamp.tv_sec), &lTime);
utstring_new(pLogStr);
if(pItem->isAddTags)
{
utstring_printf(pLogStr, "[%04d-%02d-%02d %02d:%02d:%02d.%03ld] [%s] %s",
lTime.tm_year + 1900, lTime.tm_mon + 1, lTime.tm_mday,
lTime.tm_hour, lTime.tm_min, lTime.tm_sec, pItem->timestamp.tv_usec / 1000,
LogLevelToStr(pItem->level), pItem->pLogContent);
}
else
{
utstring_printf(pLogStr, "%s", pItem->pLogContent);
}
if(pItem->isPrinted == FALSE)
{
if(pItem->level & LOG_Error
|| pItem->level & LOG_Fatal)
{
__logColorOutput(SHOW_CONSOLE_RED, pLogStr);
}
else if(pItem->level & LOG_Warn
|| pItem->level & LOG_Unknown)
{
__logColorOutput(SHOW_CONSOLE_YELLOW, pLogStr);
}
else if(pItem->level & LOG_Test
|| pItem->level & LOG_Call)
{
__logColorOutput(SHOW_CONSOLE_BLUE, pLogStr);
}
else if(pItem->level & LOG_Devp)
{
__logColorOutput(SHOW_CONSOLE_GREEN, pLogStr);
}
else
{
print("%s", utstring_body(pLogStr));
}
pItem->isPrinted = TRUE;
}
if(g_LogProcessInfo.pLogFile != NULL && g_bEnLogToFile)
{
if(logFileSize >= MAX_LOG_FILE_SIZE)
{
fflush(g_LogProcessInfo.pLogFile);
fclose(g_LogProcessInfo.pLogFile);
g_LogProcessInfo.pLogFile = fopen(g_LogProcessInfo.logFilePath, "w+");
}
if(g_LogProcessInfo.pLogFile)
{
fwrite(utstring_body(pLogStr), 1, utstring_len(pLogStr), g_LogProcessInfo.pLogFile);
}
isWriteLog = TRUE;
}
LL_DELETE(g_pLogItemList, pItem);
utstring_free(pLogStr);
free(pItem->pLogContent);
free(pItem);
if(g_LogRdPos % 100 == 0)
{
break;
}
}
pthread_mutex_unlock(&g_logLock);
usleep(1000);
if(g_LogProcessInfo.pLogFile != NULL && isWriteLog)
{
fflush(g_LogProcessInfo.pLogFile);
}
}
}
/**
* @brief
* @param level
* @param iEnable 1 0
*/
void IHW_EnableLogLevel(LOG_LEVEL level, int iEnable)
{
if(iEnable > 0)
{
g_iMinLevel |= level;
}
else
{
g_iMinLevel &= ~(level);
}
}
/**
* @brief
* @param pLogTag
* @param pPath
* @param bEnable /
*/
void IHW_InitLOG(const char* pLogTag, const char* pPath, int bEnable)
{
char strPath[MAX_PATH * 2];
(void)pPath;
pthread_mutex_init(&g_logLock, 0);
g_LogRdPos = 0;
memset(g_strLogTag, 0, 32);
memset(&g_LogProcessInfo, 0, sizeof(LOG_PROCESS_INFO));
if(pLogTag == NULL)
{
strcpy(g_strLogTag, "");
}
else
{
strncpy(g_strLogTag, pLogTag, 31);
}
memset(strPath, 0, MAX_PATH * 2);
g_LogProcessInfo.pid = getpid();
if(readlink("/proc/self/exe", strPath, MAX_PATH) == -1)
{
strcpy(g_LogProcessInfo.exeName, pLogTag);
}
else
{
char *pExeName = strrchr(strPath, '/');
if(pExeName == NULL)
{
strncpy(g_LogProcessInfo.exeName, strPath, MAX_PATH - 1);
}
else
{
strncpy(g_LogProcessInfo.exeName, pExeName + 1, MAX_PATH - 1);
}
}
memset(g_LogProcessInfo.logFilePath, 0, MAX_PATH);
sprintf(g_LogProcessInfo.logFilePath, "%s/%s_%d.log", LOG_FILE_BASEDIR, g_LogProcessInfo.exeName, g_LogProcessInfo.pid);
memset(strPath, 0, MAX_PATH);
//sprintf(strPath, "rm -f %s/%s_*.log > /dev/zero", LOG_FILE_BASEDIR, g_LogProcessInfo.exeName);
//ret = system(strPath);
//g_LogProcessInfo.pLogFile = fopen(g_LogProcessInfo.logFilePath, "w+");
g_bEnableLog = bEnable;
IHW_RunLogService();
}
void IHW_RunLogService(void)
{
pthread_create(&g_logThreadId, NULL, __logOutputThread, NULL);
}
static void __logTo(LOG_LEVEL level, int isAddTag, char* pMsg, int isPrint)
{
PLOG_ITEM pLogItem;
pLogItem = (PLOG_ITEM)malloc(sizeof(struct LOG_ITEM));
if(pLogItem == NULL)
{
return;
}
pLogItem->pLogContent = strdup(pMsg);
pLogItem->isPrinted = isPrint ? FALSE : TRUE;
pLogItem->level = level;
pLogItem->isAddTags = isAddTag ? TRUE : FALSE;
gettimeofday(&(pLogItem->timestamp), NULL);
pthread_mutex_lock(&g_logLock);
LL_APPEND(g_pLogItemList, pLogItem);
pthread_mutex_unlock(&g_logLock);
}
void IHW_LogStrWithoutPrint(int level, char* pMsg)
{
__logTo(level, TRUE, pMsg, FALSE);
}
void IHW_LogRawString(int level, char* pMsg)
{
__logTo(level, TRUE, pMsg, TRUE);
}
/**
* @brief
* @param cFlag
* @param pMsg
*/
void IHW_LOG_UNTAG(LOG_LEVEL level, const char* pMsg, ...)
{
va_list arg_ptr;
UT_string *pLogContent;
if(!g_bEnableLog)
{
return;
}
// 检查调试等级
if(!(g_iMinLevel & level))
{
return;
}
utstring_new(pLogContent);
va_start(arg_ptr, pMsg);
utstring_printf_va(pLogContent, pMsg, arg_ptr);
va_end(arg_ptr);
__logTo(level, FALSE, utstring_body(pLogContent), TRUE);
utstring_free(pLogContent);
}
/**
* @brief
* @param cFlag
* @param pMsg
*/
void IHW_LOG(LOG_LEVEL level, const char* pMsg, ...)
{
UT_string* pLogContent = NULL;
va_list arg_ptr;
if(!g_bEnableLog)
{
fprintf(stdout, "skip2\n");
return;
}
// 检查调试等级
if(!(g_iMinLevel & level))
{
fprintf(stdout, "skip1\n");
return;
}
utstring_new(pLogContent);
va_start(arg_ptr, pMsg);
utstring_printf_va(pLogContent, pMsg, arg_ptr);
va_end(arg_ptr);
__logTo(level, TRUE, utstring_body(pLogContent), TRUE);
utstring_free(pLogContent);
}
const char* LogLeveToString(LOG_LEVEL lv)
{
switch(lv)
{
case LOG_Fatal: return "LOG_Fatal";
case LOG_Error: return "LOG_Error";
case LOG_Warn: return "LOG_Warn";
case LOG_Debug: return "LOG_Debug";
case LOG_Info: return "LOG_Info";
case LOG_Test: return "LOG_Test";
case LOG_Call: return "LOG_Call";
case LOG_Devp: return "LOG_Devp";
case LOG_Step: return "LOG_Step";
case LOG_Unknown: return "LOG_Unknown";
case LOG_All: return "LOG_All";
case LOG_Close: return "LOG_Close";
}
return "Unknown";
}

View File

@ -0,0 +1,208 @@
/** @file log.h
@brief
@details
@version 1.0.0
*/
#ifndef LOG_H_
#define LOG_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __KERNEL__
#include <string.h>
#include <time.h>
#else
#include <linux/string.h>
#endif
#ifndef TRUE
#define TRUE (1)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef MAX
/** @def MAX
@brief
*/
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
/** @def MIN
@brief
*/
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#define TIMEZONE_EAST_8H (8 * 3600)
#ifndef __KERNEL__
#define DUMP_PREFIX_ADDRESS (1)
#define DUMP_PREFIX_OFFSET (2)
#endif
#define print(format, ...) fprintf(stdout, format, __VA_ARGS__)
typedef enum
{
CMD_LOG_ENABLE = 0,
CMD_LOG_FILE = 1,
CMD_LOG_MAIL = 2,
CMD_LOG_LEVEL = 3,
CMD_LOG_NETWORK = 4,
CMD_LOG_SERVER = 5
} LOG_CFG_CMD;
/** @enum _LOG_LEVEL_
* LOG等级枚举变量
*/
typedef enum
{
LOG_Fatal = (1 << 0),
LOG_Error = (1 << 1),
LOG_Warn = (1 << 2),
LOG_Debug = (1 << 3),
LOG_Info = (1 << 4),
LOG_Test = (1 << 5),
LOG_Call = (1 << 6),
LOG_Devp = (1 << 7),
LOG_Step = (1 << 8),
LOG_Unknown = (1 << 9),
LOG_All = (0xFFFFFFFF),
LOG_Close = 0x0,
} LOG_LEVEL;
/** @var typedef _LOG_LEVEL_ LOG_LEVEL
* @brief
*/
#ifdef DISABLE_LOG
#define LOG_BUF(level, buf, len)
#define LOG_EX(level, format, args...)
#define LOG_EX2(level, format, args...)
#define LOG_TAG_EX(tag, level, format, args...)
#define DEBUG_CODE_LINE()
#define DEBUG_FUNCTION_BEGIN()
#define DEBUG_FUNCTION_END()
#else
#define LOG_BUF(level, buf, len) do { \
const char* pFmtBuf = format_hex_buf("", DUMP_PREFIX_ADDRESS, 16, 1, buf, len, 1); \
IHW_LOG(level, "[%s] - %s(%04d): %s[0-%d]:\n%s", basename_v2(__FILE__), __FUNCTION__, __LINE__, \
#buf, len, pFmtBuf); \
free((void*)pFmtBuf); \
} while(0);
/*! \def LOG_EX
\brief
*/
#define LOG_EX(level, format, args...) (IHW_LOG(level, "[%s] - %s(%04d):" format , basename_v2(__FILE__), __FUNCTION__, __LINE__, ##args))
/*! \def LOG_TAG_EX
\brief
*/
#define LOG_TAG_EX(tag, level, format, args...) (IHW_LOG(level, "{%s} [%s] %s(%04d):" format , tag, basename_v2(__FILE__), __FUNCTION__, __LINE__, ##args))
#define LOG_EX2(level, format, args...) (IHW_LOG_UNTAG(level, format , ##args))
/*! @def APP_BUILD_INFO
@brief
*/
#define APP_BUILD_INFO(appname, appver) (IHW_LOG(LOG_Info, "%s Ver:%s (Build: %s %s GCC Ver:%s) With %d(bits) OS\n", \
appname, appver, __DATE__, __TIME__, __VERSION__, sizeof(int*) * 8))
/*! @def DEBUG_CODE_LINE
@brief
*/
#define DEBUG_CODE_LINE() (LOG_EX(LOG_Info, "\n"))
/*! @def DEBUG_FUNCTION_BEGIN
@brief
*/
#define DEBUG_FUNCTION_BEGIN() (LOG_EX(LOG_Call, "+++++\n"))
/*! @def DEBUG_FUNCTION_END
@brief
*/
#define DEBUG_FUNCTION_END() (LOG_EX(LOG_Call, "-----\n"))
/**
* @brief
* @param level
* @param pMsg
*/
void IHW_LOG(LOG_LEVEL level, const char* pMsg, ...);
void IHW_LOG_UNTAG(LOG_LEVEL level, const char* pMsg, ...);
void IHW_LogStrWithoutPrint(int level, char* pMsg);
void IHW_LogRawString(int level, char* pMsg);
/**
* @brief
* @param level
* @param iEnable 1 0
*/
void IHW_EnableLogLevel(LOG_LEVEL level, int iEnable);
/**
* @brief
* @param pLogTag
* @param pPath
* @param bEnable /
*/
void IHW_InitLOG(const char* pLogTag, const char* pPath, int bEnable);
void IHW_RunLogService(void);
/**
* @brief
* @param pPath -
* @return int 1, 0;
*/
int IHW_IsFileExist(const char* pPath);
char* IHW_bin2hex(char *p, const unsigned char *cp, int count);
/* Return the last part of a pathname */
static inline const char* basename_v2(const char* path)
{
const char* tail = strrchr(path, '/');
return tail ? tail + 1 : path;
}
static inline int dirname_v2(const char* path, char* dir)
{
const char* tail = strrchr(path, '/');
if(tail)
{
memcpy(dir, path, tail - path);
dir[tail - path] = 0;
}
else
{
strcpy(dir, "./");
}
return 0;
}
#endif
const char* LogLeveToString(LOG_LEVEL lv);
const char* format_hex_buf(const char* prefix_str, int prefix_type,
int rowsize, int groupsize,
const void* buf, int len, int ascii);
#ifndef __KERNEL__
void print_hex_dump_bytes(const char* prefix_str, int prefix_type,
const void* buf, int len);
#endif
#ifdef __cplusplus
}
#endif
#endif //LOG_H_

View File

@ -0,0 +1,43 @@
//
// Created by xajhu on 2019/10/10 0010.
//
#include "object_manager.h"
#include "configm.h"
#include "log.h"
ret_code object_config_init()
{
IHW_InitLOG("obj", NULL, TRUE);
return RET_OK;
}
ret_code object_config_chk(uint source, uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len)
{
return RET_OK;
}
ret_code object_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len)
{
LOG_EX(LOG_Debug, "[%016X]:type = %u, %s\n", source, config_type, (const char*)input);
return RET_OK;
}
ret_code object_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len)
{
LOG_EX(LOG_Debug, "[%016X]: %s\n", source, (const char*)input);
return RET_OK;
}
ret_code object_config_get_all(uint source,
pointer output, int *output_len)
{
LOG_EX(LOG_Debug, "[%016X]: \n", source);
return RET_OK;
}

View File

@ -0,0 +1,22 @@
//
// Created by xajhu on 2019/10/10 0010.
//
#ifndef DRIVERS_OBJECT_MANAGER_H
#define DRIVERS_OBJECT_MANAGER_H
#include "rpc/rpc_common.h"
ret_code object_config_init();
ret_code object_config_chk(uint source, uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len);
ret_code object_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len);
ret_code object_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len);
ret_code object_config_get_all(uint source,
pointer output, int *output_len);
#endif //DRIVERS_OBJECT_MANAGER_H

View File

@ -35,13 +35,16 @@ PLAT_LINUX_SRCS := $(subst $(SRC_DIR)/, , $(wildcard $(SRC_DIR)/*.c))
PLAT_ARM64_SRCS := $(PLAT_LINUX_SRCS)
# gcc CFLAGS
COMMON_CFLAGS := -I../../Common
COMMON_CFLAGS := -I../../Common -I../../Platform/common -I../../Product/common -DOBJECT_DEMO=1
PLAT_LINUX_CFLAGS += $(COMMON_CFLAGS)
PLAT_ARM64_CFLAGS += $(COMMON_CFLAGS) -D_GNU_SOURCE -D__USE_XOPEN
PLAT_ARM64_LDFLAGS := -L ../../Platform/build/debug
PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS)
COMMON_LIBS := -lcjson -lpthread -lpcre
PLAT_LINUX_LIBS := $(COMMON_LIBS)
PLAT_ARM64_LIBS := $(COMMON_LIBS)
PLAT_ARM64_LIBS := -lopenrpc-$(ARM64_OBJ_TARGET) -lconfigmapi-$(ARM64_OBJ_TARGET) $(COMMON_LIBS)
PLAT_LINUX_LIBS := -lopenrpc-$(LINUX_OBJ_TARGET) -lconfigmapi-$(LINUX_OBJ_TARGET) $(COMMON_LIBS)
# this line must be at below of thus, because of...
include ../../Common/common.Makefile

View File

@ -28,7 +28,7 @@
} \
} while (0)
#if 1
#if OBJECT_DEMO
#define RET_OK 0
#define RET_ERR 1
#define RET_UNKNOWN 2

View File

@ -1,5 +1,3 @@
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <cjson/cJSON.h>
@ -865,8 +863,7 @@ static int __obj_search_decode(const char *pJsonS, void **pStruct)
{
cJSON *pRoot, *pVal;
PIFACE_SEARCH_OBJ pData;
int arraySize;
int i;
*pStruct = malloc(sizeof(IFACE_SEARCH_OBJ));
if(*pStruct == NULL) {
@ -908,55 +905,55 @@ static int __obj_search_decode(const char *pJsonS, void **pStruct)
return RET_OK;
}
static int __obj_search_encode(const char *pJsonS, void **pStruct)
static const char *__obj_search_encode(void *pData)
{
cJSON *pRoot, *pVal;
PIFACE_SEARCH_LIST pData;
*pStruct = malloc(sizeof(IFACE_SEARCH_LIST));
const char *pJsonS;
PIFC_RET_MSG p = (PIFC_RET_MSG)pData;
cJSON *pRoot = cJSON_CreateObject();
if(*pStruct == NULL) {
return -RET_NOMEM;
if(!p) {
return NULL;
}
pData = (PIFACE_SEARCH_LIST) * pStruct;
pRoot = cJSON_Parse(pJsonS);
cJSON_AddNumberToObject(pRoot, "retCode", p->ret_code);
if(!pRoot) {
return -RET_SYSERR;
if(p->mesg) {
cJSON_AddStringToObject(pRoot, "mesg", p->mesg);
}
memset(pData, 0, sizeof(IFACE_SEARCH_LIST));
pVal = cJSON_GetObjectItem(pRoot, "type");
if(p->n_items > 0) {
cJSON *pArray = cJSON_AddArrayToObject(pRoot, "data");
if(cJSON_IsNumber(pVal)) {
pData->type = pVal->valueint;
}
pVal = cJSON_GetObjectItem(pRoot, "start");
if(cJSON_IsNumber(pVal)) {
pData->start = pVal->valueint;
}
pVal = cJSON_GetObjectItem(pRoot, "end");
if(cJSON_IsNumber(pVal)) {
pData->end = pVal->valueint;
}
pVal = cJSON_GetObjectItem(pRoot, "session");
if(cJSON_IsString(pVal)) {
strncpy(pData->session, pVal->valuestring, MAX_SESSION - 1);
if(pArray) {
int i;
for(i = 0; i < p->n_items; i++) {
cJSON *pItem = cJSON_CreateObject();
if(!pItem) {
continue;
}
cJSON_AddStringToObject(pItem, "name", p->data[i].name);
cJSON_AddNumberToObject(pItem, "retCode", p->data[i].ret_code);
if(p->data[i].mesg) {
cJSON_AddStringToObject(pItem, "mesg", p->data[i].mesg);
}
cJSON_AddItemToArray(pArray, pItem);
}
}
}
pJsonS = cJSON_Print(pRoot);
cJSON_Delete(pRoot);
return RET_OK;
return pJsonS;
}
static JSON_ENGINE g_jSonEngine[] = {
{JE_INTERFACE, __interface_encode, __interface_decode, NULL},
{OBJ_CMD_ADD, __obj_add_encode, __obj_add_decode, NULL},
{JE_OBJ_ADD, __obj_add_encode, __obj_add_decode, NULL},
{JE_OBJ_DEL, __obj_del_encode, __obj_del_decode, NULL},
{JE_OBJ_MOD, __obj_mod_encode, __obj_mod_decode, NULL},
{JE_OBJ_QUERYLIST, __obj_query_list_encode, __obj_query_list_decode, NULL},

View File

@ -82,7 +82,7 @@ typedef struct {
typedef struct {
char name[MAX_NAME_LEN];
char *mesg;
char* desc[MAX_DESC];
char desc[MAX_DESC];
int prio;
int ret_code;
POBJECT_K pObjK;

View File

@ -6,17 +6,14 @@
#include <fcntl.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include <uthash/utlist.h>
#include <uthash/utstring.h>
#include <uthash/utringbuffer.h>
#include "log.h"
#include "../../common/common.h"
@ -28,9 +25,7 @@
#define LOG_FILE_BASEDIR (".")
#define MAX_LOG_ITEM (1000)
#define MAX_LOG_FILE_SIZE (1024 * 1024)
#define LOG_PRE_SIZE (512)
#define MAX_PATH (256)
typedef struct LOG_ITEM
@ -107,8 +102,6 @@ const char* LogLevelToStr(LOG_LEVEL level)
default:
return "?";
}
return "U";
}
static void __logColorOutput(const char* pColFmt, UT_string* pLog)
@ -142,6 +135,7 @@ static void __logColorOutput(const char* pColFmt, UT_string* pLog)
static void* __logOutputThread(void *p)
{
(void)p;
while(TRUE)
{
int isWriteLog = FALSE;
@ -243,9 +237,6 @@ static void* __logOutputThread(void *p)
fflush(g_LogProcessInfo.pLogFile);
}
}
pthread_detach(pthread_self());
return (NULL);
}
/**
@ -274,6 +265,7 @@ void IHW_EnableLogLevel(LOG_LEVEL level, int iEnable)
void IHW_InitLOG(const char* pLogTag, const char* pPath, int bEnable)
{
char strPath[MAX_PATH * 2];
(void)pPath;
pthread_mutex_init(&g_logLock, 0);

File diff suppressed because it is too large Load Diff