Mod aaa-12 增加对象管理配置管理接口
RCA: SOL: 修改人:huangxin 检视人:huangxin
This commit is contained in:
parent
24f01ce548
commit
dc1a278ce7
|
@ -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 target,没有这个的话external 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 target,没有这个的话external libraries就是空的,
|
||||
# 弄一个main.c糊弄糊弄Clion
|
||||
|
||||
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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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,6 +43,10 @@
|
|||
{ \
|
||||
LTE_CONFIG_MODULE, \
|
||||
LTE_config_init \
|
||||
}, \
|
||||
{ \
|
||||
OBJECT_MANAGER_CONFIG_MODULE, \
|
||||
object_config_init \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@ -309,7 +314,25 @@
|
|||
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)();
|
||||
|
|
|
@ -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
|
|
@ -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";
|
||||
}
|
|
@ -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_
|
||||
|
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#if 1
|
||||
#if OBJECT_DEMO
|
||||
#define RET_OK 0
|
||||
#define RET_ERR 1
|
||||
#define RET_UNKNOWN 2
|
||||
|
|
|
@ -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;
|
||||
if(pArray) {
|
||||
int i;
|
||||
|
||||
for(i = 0; i < p->n_items; i++) {
|
||||
cJSON *pItem = cJSON_CreateObject();
|
||||
|
||||
if(!pItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pVal = cJSON_GetObjectItem(pRoot, "start");
|
||||
cJSON_AddStringToObject(pItem, "name", p->data[i].name);
|
||||
cJSON_AddNumberToObject(pItem, "retCode", p->data[i].ret_code);
|
||||
|
||||
if(cJSON_IsNumber(pVal)) {
|
||||
pData->start = pVal->valueint;
|
||||
if(p->data[i].mesg) {
|
||||
cJSON_AddStringToObject(pItem, "mesg", p->data[i].mesg);
|
||||
}
|
||||
|
||||
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);
|
||||
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},
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
Loading…
Reference in New Issue