MOD aaa-12 封装rpc调用接口,提供二次发送接口
SOL 封装rpc调用接口,提供二次发送接口 修改人:zhangliang 检视人:zhangliang
This commit is contained in:
parent
7e5868858e
commit
190232ddea
|
@ -33,6 +33,10 @@ ret_code rpc_client_call(rpc_client* client, char* service_name,
|
|||
char* method_name, pointer input, int input_len, pointer* output,
|
||||
int* output_len);
|
||||
|
||||
ret_code rpc_client_recall(rpc_client**pclient, char* service_name,
|
||||
char* method_name, pointer input, int input_len,
|
||||
pointer* output, int* output_len);
|
||||
|
||||
void rpc_client_call_async_thread(rpc_client* client, char* service_name,
|
||||
char* method_name, pointer input, int input_len,
|
||||
rpc_callback callback, pointer data);
|
||||
|
@ -41,5 +45,10 @@ ret_code rpc_client_call_async(rpc_client* client, char* service_name,
|
|||
char* method_name, pointer input, int input_len,
|
||||
rpc_callback callback, pointer data);
|
||||
|
||||
ret_code rpc_client_recall_async(rpc_client**pclient, char* service_name,
|
||||
char* method_name, pointer input, int input_len,
|
||||
rpc_callback callback, pointer data);
|
||||
|
||||
|
||||
|
||||
#endif /* RPC_CLIENT_H_ */
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
#include "configmapi.h"
|
||||
|
||||
|
||||
rpc_client *config_client = NULL;
|
||||
rpc_client *g_config_client = NULL;
|
||||
|
||||
rpc_client *config_client_get()
|
||||
/*rpc_client *config_client_get()
|
||||
{
|
||||
if(config_client == NULL)
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ void config_client_destroy()
|
|||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
ret_code config_construct_msg(uint config_type, uint64 config_id,
|
||||
|
@ -75,35 +75,18 @@ 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();
|
||||
//rpc_client * client = config_client_get();
|
||||
ret_code code = RET_OK ;
|
||||
config_msg_t *config_msg;
|
||||
int msg_len = 0;
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
code = config_construct_msg(config_type, config_id, config_data,
|
||||
config_len, &config_msg, &msg_len);
|
||||
ASSERT_RET(code);
|
||||
|
||||
code = rpc_client_call(client, "ConfigManger#0", "cm_config_process",
|
||||
config_msg, msg_len, (pointer)output, output_len);
|
||||
code = rpc_client_recall(&g_config_client, "ConfigManger#0", "cm_config_process",
|
||||
config_msg, msg_len, (pointer)output, output_len);
|
||||
ASSERT_RET_NO(code);
|
||||
|
||||
if(code == RET_SENDERR || code == RET_TIMEOUT)
|
||||
{
|
||||
config_client_destroy();
|
||||
client = config_client_get();
|
||||
if(client)
|
||||
{
|
||||
code = rpc_client_call(client, "ConfigManger#0", "cm_config_process",
|
||||
config_msg, msg_len, (pointer)output, output_len);
|
||||
ASSERT_RET_NO(code);
|
||||
}
|
||||
}
|
||||
|
||||
config_destroy_msg(config_msg, msg_len);
|
||||
|
||||
|
@ -114,28 +97,19 @@ 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();
|
||||
//rpc_client * client = config_client_get();
|
||||
config_msg_t *config_msg;
|
||||
int msg_len = 0;
|
||||
|
||||
ret_code ret = RET_OK ;
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
ret = config_construct_msg(config_type, config_id, config_data,
|
||||
config_len, &config_msg, &msg_len);
|
||||
ASSERT_RET(ret);
|
||||
|
||||
ret = rpc_client_call_async(client, "ConfigManger#0", "cm_config_process",
|
||||
config_msg, msg_len, callback, data);
|
||||
if(ret == RET_SENDERR || ret == RET_TIMEOUT)
|
||||
{
|
||||
config_client_destroy();
|
||||
}
|
||||
|
||||
ret = rpc_client_recall_async(&g_config_client, "ConfigManger#0", "cm_config_process",
|
||||
config_msg, msg_len, callback, data);
|
||||
ASSERT_RET_NO(ret);
|
||||
|
||||
config_destroy_msg(config_msg, msg_len);
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -139,7 +139,6 @@ static void cb_call_ex(ret_code code, pointer output,
|
|||
write(POINTER_TO_INT(rsp->data), &n, sizeof(n));
|
||||
}
|
||||
|
||||
|
||||
ret_code rpc_client_call(rpc_client* client, char* service_name,
|
||||
char* method_name, pointer input, int input_len, pointer* output,
|
||||
int* output_len) {
|
||||
|
@ -190,6 +189,42 @@ ret_code rpc_client_call(rpc_client* client, char* service_name,
|
|||
}
|
||||
}
|
||||
|
||||
ret_code rpc_client_recall(rpc_client**pclient, char* service_name,
|
||||
char* method_name, pointer input, int input_len,
|
||||
pointer* output, int* output_len)
|
||||
{
|
||||
ret_code code = RET_OK ;
|
||||
rpc_client *client = *pclient;
|
||||
|
||||
if(client)
|
||||
{
|
||||
code = rpc_client_call(client, service_name, method_name,
|
||||
input, input_len, output, output_len);
|
||||
if(code == RET_SENDERR || code == RET_TIMEOUT)
|
||||
{
|
||||
ASSERT_RET_NO(code);
|
||||
rpc_client_destroy(client);
|
||||
client = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
client = rpc_client_connect_ex(service_name);
|
||||
if(client)
|
||||
{
|
||||
*pclient = client;
|
||||
code = rpc_client_call(client, service_name, method_name,
|
||||
input, input_len, output, output_len);
|
||||
}
|
||||
|
||||
ASSERT_PTR(client, RET_NULLP);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void rpc_client_call_async_thread(rpc_client* client, char* service_name,
|
||||
char* method_name, pointer input, int input_len,
|
||||
rpc_callback callback, pointer data) {
|
||||
|
@ -267,3 +302,39 @@ ret_code rpc_client_call_async(rpc_client* client, char* service_name,
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code rpc_client_recall_async(rpc_client**pclient, char* service_name,
|
||||
char* method_name, pointer input, int input_len,
|
||||
rpc_callback callback, pointer data)
|
||||
{
|
||||
ret_code code = RET_OK ;
|
||||
rpc_client *client = *pclient;
|
||||
|
||||
if(client)
|
||||
{
|
||||
code = rpc_client_call_async(client, service_name, method_name,
|
||||
input, input_len, callback, data);
|
||||
if(code == RET_SENDERR || code == RET_TIMEOUT)
|
||||
{
|
||||
ASSERT_RET_NO(code);
|
||||
rpc_client_destroy(client);
|
||||
client = NULL;
|
||||
*pclient = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
client = rpc_client_connect_ex(service_name);
|
||||
if(client)
|
||||
{
|
||||
*pclient = client;
|
||||
code = rpc_client_call_async(client, service_name, method_name,
|
||||
input, input_len, callback, data);
|
||||
}
|
||||
|
||||
ASSERT_PTR(client, RET_NULLP);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
Loading…
Reference in New Issue