MOD aaa-12 配置管理模块增加模块初始化钩子

SOL  配置管理模块增加模块初始化钩子
修改人:zhangliang
检视人:zhangliang
This commit is contained in:
zhanglianghy 2019-08-02 15:33:53 +08:00
parent 0c75e14a95
commit ee27856922
4 changed files with 53 additions and 3 deletions

View File

@ -72,10 +72,22 @@ extern "C" {
#define s2j_struct_get_basic_element(to_struct, from_json, type, element) \ #define s2j_struct_get_basic_element(to_struct, from_json, type, element) \
S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, element) S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, element)
#define s2j_struct_get_string_element(to_struct, from_json, type, element, n) \
S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, type, element, n)
/* Get array type element for structure object */ /* Get array type element for structure object */
#define s2j_struct_get_array_element(to_struct, from_json, type, element) \ #define s2j_struct_get_array_element(to_struct, from_json, type, element) \
S2J_STRUCT_GET_ARRAY_ELEMENT(to_struct, from_json, type, element) S2J_STRUCT_GET_ARRAY_ELEMENT(to_struct, from_json, type, element)
/* Get array type element for structure object */
#define s2j_struct_get_array_element_n(to_struct, from_json, type, element, NUM) \
S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, element)
/* Get array type element for structure object */
#define s2j_struct_get_array_string_n(to_struct, from_json, type, element, NUM, BUFFLEN) \
S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, type, element, NUM, BUFFLEN)
/* Get child structure type element for structure object */ /* Get child structure type element for structure object */
#define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \ #define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \
S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element) S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element)

View File

@ -52,8 +52,9 @@ typedef struct {
#define S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, _element, n) \ #define S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, _element, n) \
json_temp = cJSON_GetObjectItem(from_json, #_element); \ json_temp = cJSON_GetObjectItem(from_json, #_element); \
if (json_temp && json_temp->valuestring && n > 1)\ if (json_temp && json_temp->valuestring && n > 1){\
strncpy((to_struct)->_element, json_temp->valuestring, n-1); strncpy((to_struct)->_element, json_temp->valuestring, n - 1);\
to_struct->_element[n - 1] = '\0';}
#define S2J_STRUCT_GET_double_ELEMENT(to_struct, from_json, _element) \ #define S2J_STRUCT_GET_double_ELEMENT(to_struct, from_json, _element) \
json_temp = cJSON_GetObjectItem(from_json, #_element); \ json_temp = cJSON_GetObjectItem(from_json, #_element); \
@ -65,6 +66,9 @@ typedef struct {
#define S2J_STRUCT_ARRAY_GET_string_ELEMENT(to_struct, from_json, _element, index) \ #define S2J_STRUCT_ARRAY_GET_string_ELEMENT(to_struct, from_json, _element, index) \
strcpy((to_struct)->_element[index], from_json->valuestring); strcpy((to_struct)->_element[index], from_json->valuestring);
#define S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, from_json, _element, index, maxlen) \
strncpy((to_struct)->_element + maxlen * index, from_json->valuestring, maxlen - 1);
#define S2J_STRUCT_ARRAY_GET_double_ELEMENT(to_struct, from_json, _element, index) \ #define S2J_STRUCT_ARRAY_GET_double_ELEMENT(to_struct, from_json, _element, index) \
(to_struct)->_element[index] = from_json->valuedouble; (to_struct)->_element[index] = from_json->valuedouble;
@ -145,6 +149,38 @@ typedef struct {
} \ } \
} }
#define S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, _element, NUM) \
{ \
cJSON *array, *array_element; \
size_t index = 0, size = 0; \
array = cJSON_GetObjectItem(from_json, #_element); \
if (array) { \
size = cJSON_GetArraySize(array); \
while (index < size && index < NUM) { \
array_element = cJSON_GetArrayItem(array, index); \
if (array_element) S2J_STRUCT_ARRAY_GET_ELEMENT(to_struct, array_element, type, _element, index++); \
} \
} \
}
#define S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, type, _element, NUM, LEN) \
{ \
cJSON *array, *array_element; \
size_t index = 0, size = 0; \
array = cJSON_GetObjectItem(from_json, #_element); \
if (array) { \
size = cJSON_GetArraySize(array); \
NUM = size;\
(to_struct)->_element = (char *)malloc(size * LEN);\
memset((to_struct)->_element, 0, size * LEN);\
while (index < size) { \
array_element = cJSON_GetArrayItem(array, index); \
if (array_element) S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, array_element, type, _element, index++, LEN); \
} \
} \
}
#define S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, _element) \ #define S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, _element) \
type *child_struct = &((to_struct)->_element); \ type *child_struct = &((to_struct)->_element); \
cJSON *child_json = cJSON_GetObjectItem(from_json, #_element); cJSON *child_json = cJSON_GetObjectItem(from_json, #_element);

View File

@ -169,7 +169,7 @@ typedef struct _config_init config_init_t;
/* 配置注册 */ /* 配置注册 */
struct _config_service { struct _config_service {
uint32 config_id; /* 配置ID全局唯一用于寻找对应的配置业务*/ uint64 config_id; /* 配置ID全局唯一用于寻找对应的配置业务*/
uint config_src; /* 配置源检查,全局唯一,用于寻找对应的配置业务,从低位到高位第一位表示web后续配置扩展 */ uint config_src; /* 配置源检查,全局唯一,用于寻找对应的配置业务,从低位到高位第一位表示web后续配置扩展 */
boolean recovery; /* 配置恢复处理函数如果为FALSE则不进行配置恢复 */ boolean recovery; /* 配置恢复处理函数如果为FALSE则不进行配置恢复 */
boolean multi_inst; /* 是否是多实例 */ boolean multi_inst; /* 是否是多实例 */

View File

@ -1,6 +1,8 @@
#ifndef PARSEFILE_H_ #ifndef PARSEFILE_H_
#define PARSEFILE_H_ #define PARSEFILE_H_
#include "rpc_common.h"
#define IFCONFIG_PATH "/etc/network/interfaces" #define IFCONFIG_PATH "/etc/network/interfaces"
#define IF_BUFF_LEN 128 #define IF_BUFF_LEN 128