Skip to content

Commit 21f9cf3

Browse files
committed
feat(jsonrpc):1.12.25, 将StrIdRpc与IntIdRpc合并为Rpc
1 parent 723b9e8 commit 21f9cf3

33 files changed

+500
-1384
lines changed

examples/jsonrpc/message/int_id/Makefile

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/jsonrpc/message/int_id/pong/Makefile

Lines changed: 0 additions & 36 deletions
This file was deleted.

examples/jsonrpc/message/str_id/ping/Makefile renamed to examples/jsonrpc/message/ping/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# of the source tree.
1919
#
2020

21-
PROJECT := examples/jsonrpc/message/str_id/ping
21+
PROJECT := examples/jsonrpc/message/ping
2222
EXE_NAME := ${PROJECT}
2323

2424
CPP_SRC_FILES := ping.cpp

examples/jsonrpc/message/int_id/ping/ping.cpp renamed to examples/jsonrpc/message/ping/ping.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* 如此周而复始,直至与pong端断开,或者接收到了SIGINT停止信号
2929
*/
3030

31+
#include <iostream>
3132
#include <tbox/base/log.h> //! 打印日志
3233
#include <tbox/base/log_output.h> //! 使能日志输出
3334
#include <tbox/base/scope_exit.hpp> //! 使用 SetScopeExitAction()
@@ -38,12 +39,24 @@
3839
#include <tbox/network/tcp_client.h> //! 导入TcpClient模块
3940
#include <tbox/util/json.h> //! 使用JSON操作的辅助函数 GetField()
4041
#include <tbox/jsonrpc/protos/raw_stream_proto.h> //! 导入 jsonrpc::RawStreamProto
41-
#include <tbox/jsonrpc/int_id_rpc.h> //! 导入 jsonrpc::IntIdRpc
42+
#include <tbox/jsonrpc/rpc.h> //! 导入 jsonrpc::Rpc
4243

4344
using namespace tbox;
4445

4546
int main(int argc, char **argv)
4647
{
48+
jsonrpc::Rpc::IdType id_type = jsonrpc::Rpc::IdType::kInt;
49+
if (argc >= 2) {
50+
std::string type_str(argv[1]);
51+
if (type_str == "str") {
52+
id_type = jsonrpc::Rpc::IdType::kString;
53+
} else if (type_str != "int") {
54+
std::cout << "id_type invalid!" << std::endl
55+
<< "Usage: " << argv[0] << " int|str" << std::endl;
56+
return 0;
57+
}
58+
}
59+
4760
LogOutput_Enable();
4861

4962
LogInfo("enter");
@@ -61,7 +74,7 @@ int main(int argc, char **argv)
6174

6275
network::TcpClient tcp_client(loop);
6376
jsonrpc::RawStreamProto proto;
64-
jsonrpc::IntIdRpc rpc(loop);
77+
jsonrpc::Rpc rpc(loop, id_type);
6578

6679
rpc.initialize(&proto, 3);
6780
std::string srv_addr = "/tmp/ping_pong.sock";

examples/jsonrpc/req_rsp/int_id/pong/Makefile renamed to examples/jsonrpc/message/pong/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# of the source tree.
1919
#
2020

21-
PROJECT := examples/jsonrpc/req_rsp/int_id/pong
21+
PROJECT := examples/jsonrpc/message/pong
2222
EXE_NAME := ${PROJECT}
2323

2424
CPP_SRC_FILES := pong.cpp

examples/jsonrpc/message/int_id/pong/pong.cpp renamed to examples/jsonrpc/message/pong/pong.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* 当收到ping请求后,将参数中的count提取出来作为结果直接回复。
2626
*/
2727

28+
#include <iostream>
2829
#include <tbox/base/log.h> //! 打印日志
2930
#include <tbox/base/log_output.h> //! LogOutput_Enable()
3031
#include <tbox/base/scope_exit.hpp> //! SetScopeExitAction()
@@ -35,12 +36,24 @@
3536
#include <tbox/event/signal_event.h> //! ctrl+c信号事件
3637
#include <tbox/network/tcp_server.h> //! TcpServer
3738
#include <tbox/jsonrpc/protos/raw_stream_proto.h> //! jsonrpc::RawStreamProto
38-
#include <tbox/jsonrpc/int_id_rpc.h> //! jsonrpc::IntIdRpc
39+
#include <tbox/jsonrpc/rpc.h> //! jsonrpc::Rpc
3940

4041
using namespace tbox;
4142

4243
int main(int argc, char **argv)
4344
{
45+
jsonrpc::Rpc::IdType id_type = jsonrpc::Rpc::IdType::kInt;
46+
if (argc >= 2) {
47+
std::string type_str(argv[1]);
48+
if (type_str == "str") {
49+
id_type = jsonrpc::Rpc::IdType::kString;
50+
} else if (type_str != "int") {
51+
std::cout << "id_type invalid!" << std::endl
52+
<< "Usage: " << argv[0] << " int|str" << std::endl;
53+
return 0;
54+
}
55+
}
56+
4457
LogOutput_Enable();
4558

4659
LogInfo("enter");
@@ -58,7 +71,7 @@ int main(int argc, char **argv)
5871

5972
network::TcpServer tcp_server(loop);
6073
jsonrpc::RawStreamProto proto;
61-
jsonrpc::IntIdRpc rpc(loop);
74+
jsonrpc::Rpc rpc(loop, id_type);
6275

6376
rpc.initialize(&proto, 3);
6477
std::string srv_addr = "/tmp/ping_pong.sock";

examples/jsonrpc/message/str_id/Makefile

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/jsonrpc/message/str_id/ping/ping.cpp

Lines changed: 0 additions & 134 deletions
This file was deleted.

examples/jsonrpc/message/str_id/pong/Makefile

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)