9 #ifndef INCLUDE_FUNAPI_DISTRIBUTION_RPC_H_ 10 #define INCLUDE_FUNAPI_DISTRIBUTION_RPC_H_ 12 #include <boost/asio.hpp> 13 #include <boost/enable_shared_from_this.hpp> 14 #include <boost/function.hpp> 15 #include <boost/noncopyable.hpp> 16 #include <funapi/distribution/fun_rpc_message.pb.h> 27 class FUNAPI_DLL_VISIBILITY
Rpc :
public boost::enable_shared_from_this<Rpc>,
28 private boost::noncopyable {
32 typedef Uuid SerializationTag;
33 typedef boost::asio::ip::tcp::endpoint PeerEndpoint;
34 typedef std::map<PeerId, PeerEndpoint> PeerMap;
36 typedef std::set<Tag> Tags;
48 typedef boost::function<
49 void(
const PeerId & ,
const Xid & ,
50 const Ptr<const FunRpcMessage> & ,
53 typedef boost::function<
54 void(
const PeerId & ,
const Xid & ,
55 const Ptr<const FunRpcMessage> & )> VoidReplyHandler;
58 typedef boost::function<
59 void(
const PeerId & ,
const Xid & ,
62 static const Xid kNullXid;
63 static const PeerId kNullPeerId;
64 static const SerializationTag kDefaultSerializationTag;
68 static void AddTag(
const Tag &tag);
72 static void AddTags(
const Tags &tags);
76 static void RemoveTag(
const Tag &tag);
80 static void RemoveTags(
const Tags &tags);
85 static bool HasTag(
const Tag &tag);
88 static Json GetStatus();
92 static void SetStatus(
const Json &status);
96 static PeerId GetSelfId();
100 static PeerEndpoint GetSelfEndpoint();
106 static size_t GetPeers(PeerMap *ret,
bool include_self =
false);
113 static size_t GetPeersWithTag(PeerMap *ret,
const Tag &tag,
114 bool include_self =
false);
120 static size_t GetPeerTags(Tags *ret,
const PeerId &peer);
128 static std::string GetPeerExternalHostname(
const PeerId &peer);
135 static boost::asio::ip::address GetPeerExternalIp(
const PeerId &peer);
142 static HardwareInfo::ProtocolPortMap GetPeerExternalPorts(
const PeerId &peer);
146 static bool IsExternalPeer(
const PeerId &peer);
150 static Json GetPeerStatus(
const PeerId &peer);
155 static bool IsPeerConnected(
const PeerId &peer);
158 static void RegisterConnectHandler(
const ConnectHandler &h);
161 static void RegisterDisconnectHandler(
const DisconnectHandler &h);
167 static void RegisterHandler(
const string &type,
const Handler &h);
176 const Ptr<FunRpcMessage> &msg,
177 const Callback &callback,
178 const SerializationTag &tag = kDefaultSerializationTag)
185 static void RegisterVoidReplyHandler(
const string &type,
186 const VoidReplyHandler &h);
194 const Ptr<FunRpcMessage> &msg,
195 const SerializationTag &tag = kDefaultSerializationTag)
201 #endif // INCLUDE_FUNAPI_DISTRIBUTION_RPC_H_
boost::function< void(const Ptr< FunRpcMessage > &)> ReadyBack ASSERT_NO_ROLLBACK
Functor to signal that a RPC server finished processing.
Definition: rpc.h:39
boost::function< void(const PeerId &)> DisconnectHandler
Functor to be invoked when a server disconnected.
Definition: rpc.h:45
boost::function< void(const PeerId &, const Xid &, const Ptr< const FunRpcMessage > &, const ReadyBack &)> Handler
Functor to be invoked when a RPC server receives RPC messages.
Definition: rpc.h:51
boost::uuids::uuid Uuid
UUID type used throughout Funapi.
Definition: types.h:56
boost::function< void(const PeerId &, const Xid &, const Ptr< const FunRpcMessage > &)> Callback
Functor to be invoked when a RPC client receives back a reply.
Definition: rpc.h:60
Funapi RPC interface.
Definition: rpc.h:27
boost::function< void(const PeerId &)> ConnectHandler
Functor to be invoked when a new server connected.
Definition: rpc.h:42