iFun Engine API  1.0.0-b3630
Great Technology for Great Games
 All Classes Files Functions Variables Typedefs Macros
dedicated_server_rpc.h
Go to the documentation of this file.
1 // Copyright (C) 2017 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
10 #ifndef INCLUDE_FUNAPI_DISTRIBUTION_DEDICATED_SERVER_RPC_H_
11 #define INCLUDE_FUNAPI_DISTRIBUTION_DEDICATED_SERVER_RPC_H_
12 
13 #include <boost/asio.hpp>
14 #include <boost/function.hpp>
15 #include <boost/noncopyable.hpp>
16 #include <funapi/distribution/fun_dedicated_server_rpc_message.pb.h>
17 #include <funapi/types.h>
18 
19 #include <map>
20 
21 
22 namespace fun {
23 
24 class DedicatedServerRpc : private boost::noncopyable {
25  public:
26  typedef Uuid PeerId;
27  typedef Uuid Xid;
28  typedef boost::asio::ip::tcp::endpoint PeerEndpoint;
29  typedef std::map<PeerId, PeerEndpoint> PeerMap;
30  typedef string Tag;
31 
33  typedef boost::function<void(const PeerId &/*peer*/)> ConnectHandler;
34 
36  typedef boost::function<void(const PeerId &/*peer*/)> DisconnectHandler;
37 
39  typedef boost::function<
40  void(const PeerId &/*peer*/, const Xid &/*xid*/,
41  const Ptr<const FunDedicatedServerRpcMessage> &/*reply*/)> Callback;
42 
43  static const Xid kNullXid;
44  static const PeerId kNullPeerId;
45 
49  static bool HasTag(const PeerId &peer, const Tag &tag);
50 
54  static Tag GetPeerTag(const PeerId &peer);
55 
59  static size_t GetPeers(PeerMap *ret);
60 
65  static size_t GetPeersWithTag(PeerMap *ret, const Tag &tag);
66 
70  static bool IsPeerConnected(const PeerId &peer);
71 
73  static void RegisterConnectHandler(const ConnectHandler &h);
74 
76  static void RegisterDisconnectHandler(const DisconnectHandler &h);
77 
82  static void Call(const PeerId &peer,
83  const Ptr<FunDedicatedServerRpcMessage> &msg,
84  const Callback &callback) ASSERT_NO_ROLLBACK;
85 
89  static void CallRandomly(const Ptr<FunDedicatedServerRpcMessage> &msg,
90  const Callback &callback) ASSERT_NO_ROLLBACK;
91 };
92 
93 } // namespace fun
94 
95 #endif // INCLUDE_FUNAPI_DISTRIBUTION_DEDICATED_SERVER_RPC_H_
static void RegisterDisconnectHandler(const DisconnectHandler &h)
Registers a handler for notifying a peer disconnection.
static void Call(const PeerId &peer, const Ptr< FunDedicatedServerRpcMessage > &msg, const Callback &callback) ASSERT_NO_ROLLBACK
Sends a RPC requst to the given Dedicated Server RPC peer.
Definition: dedicated_server_rpc.h:24
boost::function< void(const PeerId &)> ConnectHandler
Functor to be invoked when a peer connected.
Definition: dedicated_server_rpc.h:33
static void CallRandomly(const Ptr< FunDedicatedServerRpcMessage > &msg, const Callback &callback) ASSERT_NO_ROLLBACK
Sends a RPC requst to the Deidcated Server RPC peer randomly.
static Tag GetPeerTag(const PeerId &peer)
Gets a tag of the peer.
static bool HasTag(const PeerId &peer, const Tag &tag)
Checks if the RPC peer has the tag.
boost::function< void(const PeerId &)> DisconnectHandler
Functor to be invoked when a peer disconnected.
Definition: dedicated_server_rpc.h:36
static size_t GetPeers(PeerMap *ret)
Returns information on Dedicated Server RPC peers.
static void RegisterConnectHandler(const ConnectHandler &h)
Registers a handler for notifying a new peer connection.
static size_t GetPeersWithTag(PeerMap *ret, const Tag &tag)
Returns a list of RPC peers with the given tag.
boost::function< void(const PeerId &, const Xid &, const Ptr< const FunDedicatedServerRpcMessage > &)> Callback
Functor to be invoked when a client receives back a reply.
Definition: dedicated_server_rpc.h:41
static bool IsPeerConnected(const PeerId &peer)
Checks if the peer is connected.