8 #ifndef NTCORE_RPCSERVER_H_ 9 #define NTCORE_RPCSERVER_H_ 13 #include <llvm/DenseMap.h> 14 #include <support/mutex.h> 16 #include "CallbackManager.h" 18 #include "IRpcServer.h" 25 typedef std::pair<unsigned int, unsigned int> RpcIdPair;
30 IRpcServer::SendResponseFunc send_response_)
31 :
RpcAnswer{entry_, call_, name_, params_, conn_},
32 send_response{send_response_} {}
34 IRpcServer::SendResponseFunc send_response;
41 :
public CallbackThread<RpcServerThread, RpcAnswer, RpcListenerData,
45 : m_inst(inst), m_logger(logger) {}
48 return !data.
name.empty() && data.send_response;
52 unsigned int local_id =
Handle{data->
entry}.GetIndex();
53 unsigned int call_uid =
Handle{data->
call}.GetIndex();
54 RpcIdPair lookup_uid{local_id, call_uid};
55 m_response_map.insert(std::make_pair(lookup_uid, data->send_response));
58 void DoCallback(std::function<
void(
const RpcAnswer&
call)> callback,
60 DEBUG4(
"rpc calling " << data.
name);
61 unsigned int local_id =
Handle{data.
entry}.GetIndex();
62 unsigned int call_uid =
Handle{data.
call}.GetIndex();
63 RpcIdPair lookup_uid{local_id, call_uid};
66 std::lock_guard<wpi::mutex> lock(m_mutex);
67 auto i = m_response_map.find(lookup_uid);
68 if (i != m_response_map.end()) {
71 m_response_map.erase(i);
85 friend class RpcServerTest;
89 RpcServer(int inst, wpi::Logger& logger);
93 unsigned int Add(std::function<void(const RpcAnswer& answer)> callback);
94 unsigned int AddPolled(unsigned int poller_uid);
95 void RemoveRpc(unsigned int rpc_uid) override;
97 void ProcessRpc(unsigned int local_id, unsigned int call_uid, StringRef name,
98 StringRef params, const ConnectionInfo& conn,
99 SendResponseFunc send_response,
100 unsigned int rpc_uid) override;
103 llvm::StringRef result);
112 #endif // NTCORE_RPCSERVER_H_ NetworkTables Connection Information.
Definition: ntcore_cpp.h:61
Definition: DenseMap.h:585
Definition: CallbackManager.h:54
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:124
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:132
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:135
Definition: RpcServer.h:40
void PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result)
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.cpp:563
Definition: IEntryNotifier.h:16
Definition: CallbackManager.h:168
Definition: RpcServer.h:27
std::string name
Entry name.
Definition: ntcore_cpp.h:138
Definition: IRpcServer.h:18
Definition: RpcServer.h:83
Definition: CallbackManager.h:30
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42