121 lines
3.1 KiB
C
121 lines
3.1 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "rpc_thread.h"
|
|
#include "rpc.h"
|
|
#include "configmapi.h"
|
|
|
|
|
|
rpc_client *g_config_client = NULL;
|
|
|
|
/*rpc_client *config_client_get()
|
|
{
|
|
if(config_client == NULL)
|
|
{
|
|
config_client = rpc_client_connect_ex("ConfigManger#0");
|
|
if(config_client == NULL)
|
|
{
|
|
rpc_log_error("connect ConfigManger#0 error\n");
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
return config_client;
|
|
}
|
|
|
|
void config_client_destroy()
|
|
{
|
|
if(config_client)
|
|
{
|
|
rpc_client_destroy(config_client);
|
|
config_client = NULL;
|
|
}
|
|
|
|
return;
|
|
}*/
|
|
|
|
|
|
ret_code config_construct_msg(uint config_type, uint64 config_id,
|
|
char* config_data, int config_len,
|
|
config_msg_t **config_msg, int *msg_len)
|
|
{
|
|
config_msg_t *pconfig_msg;
|
|
|
|
if(config_data == NULL)
|
|
{
|
|
return RET_NULLP;
|
|
}
|
|
|
|
*msg_len = sizeof(config_msg_t) + config_len;
|
|
pconfig_msg= (config_msg_t *) malloc(*msg_len);
|
|
if(pconfig_msg == NULL)
|
|
{
|
|
return RET_NOMEM;
|
|
}
|
|
|
|
pconfig_msg->source = CONFIG_FROM_WEB;
|
|
pconfig_msg->config_type = config_type;
|
|
pconfig_msg->config_id = config_id;
|
|
|
|
memcpy(pconfig_msg->config_buff, config_data, config_len);
|
|
*config_msg = pconfig_msg;
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
ret_code config_destroy_msg(config_msg_t *config_msg, int msg_len)
|
|
{
|
|
if(config_msg)
|
|
{
|
|
memset(config_msg, 0, msg_len);
|
|
free(config_msg);
|
|
}
|
|
}
|
|
|
|
ret_code web_config_exec_sync(uint config_type, uint64 config_id,
|
|
char* config_data, int config_len,
|
|
char**output, int *output_len)
|
|
{
|
|
//rpc_client * client = config_client_get();
|
|
ret_code code = RET_OK ;
|
|
config_msg_t *config_msg;
|
|
int msg_len = 0;
|
|
|
|
code = config_construct_msg(config_type, config_id, config_data,
|
|
config_len, &config_msg, &msg_len);
|
|
ASSERT_RET(code);
|
|
|
|
code = rpc_client_recall(&g_config_client, "ConfigManger#0", "ConfigManger#0",
|
|
"cm_config_process", config_msg, msg_len,
|
|
(pointer)output, output_len);
|
|
ASSERT_RET_NO(code);
|
|
|
|
config_destroy_msg(config_msg, msg_len);
|
|
|
|
return code;
|
|
}
|
|
|
|
ret_code web_config_exec_async(uint config_type, uint64 config_id,
|
|
char* config_data, int config_len,
|
|
rpc_callback callback, pointer data)
|
|
{
|
|
//rpc_client * client = config_client_get();
|
|
config_msg_t *config_msg;
|
|
int msg_len = 0;
|
|
ret_code ret = RET_OK ;
|
|
|
|
ret = config_construct_msg(config_type, config_id, config_data,
|
|
config_len, &config_msg, &msg_len);
|
|
ASSERT_RET(ret);
|
|
|
|
ret = rpc_client_recall_async(&g_config_client, "ConfigManger#0", "ConfigManger#0",
|
|
"cm_config_process", config_msg, msg_len, callback, data);
|
|
ASSERT_RET_NO(ret);
|
|
|
|
config_destroy_msg(config_msg, msg_len);
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
|