File tree Expand file tree Collapse file tree 3 files changed +22
-7
lines changed
Expand file tree Collapse file tree 3 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,6 @@ class RPCClient {
4444
4545 }
4646
47- protected:
4847 template <typename ... Args>
4948 bool send_rpc (const MsgPack::str_t method, Args&&... args) {
5049 int msg_id;
Original file line number Diff line number Diff line change 66
77struct DispatchEntry {
88 MsgPack::str_t name;
9+ MsgPack::str_t tag;
910 IFunctionWrapper* fn;
1011};
1112
1213template <size_t N>
1314class RpcFunctionDispatcher {
1415public:
1516 template <typename F>
16- bool bind (MsgPack::str_t name, F&& f) {
17+ bool bind (MsgPack::str_t name, F&& f, MsgPack:: str_t tag= " " ) {
1718 if (_count >= N) return false ;
1819
1920 if (isBound (name)) return false ;
2021
2122 using WrapperT = decltype (wrap (std::forward<F>(f)));
2223 WrapperT* instance = new WrapperT (wrap (std::forward<F>(f)));
23- _entries[_count++] = {name, instance};
24+ _entries[_count++] = {name, tag, instance};
2425 return true ;
2526 }
2627
@@ -33,6 +34,15 @@ class RpcFunctionDispatcher {
3334 return false ;
3435 }
3536
37+ bool hasTag (MsgPack::str_t name,MsgPack::str_t tag) const {
38+ for (size_t i = 0 ; i < _count; ++i) {
39+ if (_entries[i].name == name && _entries[i].tag == tag) {
40+ return true ;
41+ }
42+ }
43+ return false ;
44+ }
45+
3646 bool call (MsgPack::str_t name, MsgPack::Unpacker& unpacker, MsgPack::Packer& packer) {
3747 for (size_t i = 0 ; i < _count; ++i) {
3848 if (_entries[i].name == name) {
Original file line number Diff line number Diff line change @@ -23,8 +23,12 @@ class RPCServer {
2323 // }
2424
2525 template <typename F>
26- bool bind (const MsgPack::str_t & name, F&& func){
27- return dispatcher.bind (name, func);
26+ bool bind (const MsgPack::str_t & name, F&& func, MsgPack::str_t & tag){
27+ return dispatcher.bind (name, func, tag);
28+ }
29+
30+ bool hasTag (MsgPack::str_t name, MsgPack::str_t tag){
31+ return dispatcher.hasTag (name, tag);
2832 }
2933
3034 void run () {
@@ -34,15 +38,15 @@ class RPCServer {
3438 // delay(1);
3539 }
3640
37- protected:
3841 bool get_rpc () {
3942 decoder->decode ();
4043 if (_rpc_size > 0 ) return true ; // Already have a request
44+ // TODO USE A QUEUE
4145 _rpc_size = decoder->get_request (_rpc_buffer, RPC_BUFFER_SIZE);
4246 return _rpc_size > 0 ;
4347 }
4448
45- void process_request () {
49+ void process_request (MsgPack:: str_t tag= " " ) {
4650 if (_rpc_size == 0 ) return ;
4751
4852 MsgPack::Unpacker unpacker;
@@ -78,6 +82,8 @@ class RPCServer {
7882 return ; // Invalid request size/type
7983 }
8084
85+ if (!hasTag (method, tag)) return ;
86+
8187 _rpc_type = msg_type;
8288
8389 MsgPack::arr_size_t resp_size (RESPONSE_SIZE);
You can’t perform that action at this time.
0 commit comments