iFun Engine API  1.0.0-b6053
Great Technology for Great Games
dedicated_server_rpc.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 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 FUNAPI_DLL_VISIBILITY 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_
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
Definition: json.h:18
boost::uuids::uuid Uuid
UUID type used throughout Funapi.
Definition: types.h:56
boost::function< void(const PeerId &)> DisconnectHandler
Functor to be invoked when a peer disconnected.
Definition: dedicated_server_rpc.h:36
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