From 190232ddeafb0433af672fd07c425fddcb133b82 Mon Sep 17 00:00:00 2001 From: zhanglianghy <zhanglianghy@cmhi.chinamobile.com> Date: Fri, 30 Aug 2019 15:40:07 +0800 Subject: [PATCH] =?UTF-8?q?MOD=20aaa-12=20=E5=B0=81=E8=A3=85rpc=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=8F=90=E4=BE=9B=E4=BA=8C?= =?UTF-8?q?=E6=AC=A1=E5=8F=91=E9=80=81=E6=8E=A5=E5=8F=A3=20SOL=20=20=20?= =?UTF-8?q?=E5=B0=81=E8=A3=85rpc=E8=B0=83=E7=94=A8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E4=BE=9B=E4=BA=8C=E6=AC=A1=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangl?= =?UTF-8?q?iang=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Platform/common/rpc/rpc_client.h | 9 +++ .../user/configm/config-api/configclient.c | 48 +++--------- Platform/user/rpc/rpc_client.c | 73 ++++++++++++++++++- 3 files changed, 92 insertions(+), 38 deletions(-) diff --git a/Platform/common/rpc/rpc_client.h b/Platform/common/rpc/rpc_client.h index 50ad39de7..b01f35bb8 100755 --- a/Platform/common/rpc/rpc_client.h +++ b/Platform/common/rpc/rpc_client.h @@ -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_ */ diff --git a/Platform/user/configm/config-api/configclient.c b/Platform/user/configm/config-api/configclient.c index 6b6e910e0..ae58e4172 100644 --- a/Platform/user/configm/config-api/configclient.c +++ b/Platform/user/configm/config-api/configclient.c @@ -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; diff --git a/Platform/user/rpc/rpc_client.c b/Platform/user/rpc/rpc_client.c index 4eb652b21..39644bfd3 100755 --- a/Platform/user/rpc/rpc_client.c +++ b/Platform/user/rpc/rpc_client.c @@ -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; +} \ No newline at end of file