iFun Engine API  1.0.0-b6053
Great Technology for Great Games
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
fun::Rpc Class Reference

Funapi RPC interface.

#include <rpc.h>

Inheritance diagram for fun::Rpc:

Public Types

typedef boost::function< void(const Ptr< FunRpcMessage > &)> ReadyBack ASSERT_NO_ROLLBACK
 Functor to signal that a RPC server finished processing.
 
typedef boost::function< void(const PeerId &, const Xid &, const Ptr< const FunRpcMessage > &)> Callback
 Functor to be invoked when a RPC client receives back a reply.
 
typedef boost::function< void(const PeerId &)> ConnectHandler
 Functor to be invoked when a new server connected.
 
typedef boost::function< void(const PeerId &)> DisconnectHandler
 Functor to be invoked when a server disconnected.
 
typedef 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.
 
typedef boost::asio::ip::tcp::endpoint PeerEndpoint
 
typedef Uuid PeerId
 
typedef std::map< PeerId, PeerEndpoint > PeerMap
 
typedef Uuid SerializationTag
 
typedef string Tag
 
typedef std::set< Tag > Tags
 
typedef boost::function< void(const PeerId &, const Xid &, const Ptr< const FunRpcMessage > &)> VoidReplyHandler
 
typedef Uuid Xid
 

Static Public Member Functions

static void AddTag (const Tag &tag)
 Tags a local RPC server. More...
 
static void AddTags (const Tags &tags)
 Tags a local RPC server. More...
 
static void Call (const PeerId &peer, const Ptr< FunRpcMessage > &msg, const Callback &callback, const SerializationTag &tag=kDefaultSerializationTag) ASSERT_NO_ROLLBACK
 Sends a RPC requst to the given RPC server. More...
 
static void Call (const PeerId &peer, const Ptr< FunRpcMessage > &msg, const SerializationTag &tag=kDefaultSerializationTag) ASSERT_NO_ROLLBACK
 Sends a RPC requst to the given RPC server. More...
 
static std::string GetPeerExternalHostname (const PeerId &peer)
 Returns a hostname of the peer. More...
 
static boost::asio::ip::address GetPeerExternalIp (const PeerId &peer)
 Returns a public IP of the peer. More...
 
static HardwareInfo::ProtocolPortMap GetPeerExternalPorts (const PeerId &peer)
 Returns a public ports of the peer. More...
 
static size_t GetPeers (PeerMap *ret, bool include_self=false)
 Returns information on other RPC peers. More...
 
static Json GetPeerStatus (const PeerId &peer)
 Returns a status of the peer. More...
 
static size_t GetPeersWithTag (PeerMap *ret, const Tag &tag, bool include_self=false)
 Returns a list of RPC peers with the given tag. More...
 
static size_t GetPeerTags (Tags *ret, const PeerId &peer)
 Returns a set of tags associated with the given peer. More...
 
static PeerEndpoint GetSelfEndpoint ()
 Returns an endpoint information to which RPC listens. More...
 
static PeerId GetSelfId ()
 Returns an identifier to distinguish from RPC servers. More...
 
static Json GetStatus ()
 Gets the server status.
 
static bool HasTag (const Tag &tag)
 Checks if a local RPC server has the tag. More...
 
static bool IsExternalPeer (const PeerId &peer)
 Checks if the peer is from external. More...
 
static bool IsPeerConnected (const PeerId &peer)
 Checks if the peer is connected. More...
 
static void RegisterConnectHandler (const ConnectHandler &h)
 Registers a handler for notifying a new server connection.
 
static void RegisterDisconnectHandler (const DisconnectHandler &h)
 Registers a handler for notifying a server disconnection.
 
static void RegisterHandler (const string &type, const Handler &h)
 Registers a handler for a particular RPC message type. More...
 
static void RegisterVoidReplyHandler (const string &type, const VoidReplyHandler &h)
 Registers a handler for a particular RPC message type. More...
 
static void RemoveTag (const Tag &tag)
 Untags a local RPC server. More...
 
static void RemoveTags (const Tags &tags)
 Untags a local RPC server. More...
 
static void SetStatus (const Json &status)
 Sets the server status and broadcasts using RPC. More...
 

Static Public Attributes

static const SerializationTag kDefaultSerializationTag
 
static const PeerId kNullPeerId
 
static const Xid kNullXid
 

Member Function Documentation

◆ AddTag()

static void fun::Rpc::AddTag ( const Tag &  tag)
static

(e.g., lobby, room, ...)

Parameters
tagstring to tag the server.

◆ AddTags()

static void fun::Rpc::AddTags ( const Tags &  tags)
static

(e.g., lobby, room, ...)

Parameters
tagsa set of strings to tag the server.

◆ Call() [1/2]

static void fun::Rpc::Call ( const PeerId &  peer,
const Ptr< FunRpcMessage > &  msg,
const Callback callback,
const SerializationTag &  tag = kDefaultSerializationTag 
)
static
Parameters
peerPeerId that identifies the target RPC server.
msgFunRpcMessage protobuf instance to send.
callbackCallback instance to be invoked once a reply arrives.
tagSerializationTag tag for serializing messages.

◆ Call() [2/2]

static void fun::Rpc::Call ( const PeerId &  peer,
const Ptr< FunRpcMessage > &  msg,
const SerializationTag &  tag = kDefaultSerializationTag 
)
static
Parameters
peerPeerId that identifies the target RPC server.
msgFunRpcMessage protobuf instance to send.
tagSerializationTag tag for serializing messages.

◆ GetPeerExternalHostname()

static std::string fun::Rpc::GetPeerExternalHostname ( const PeerId &  peer)
static

Exteranl hostname is resolved by HardwareInfo's external_ip_resolver in MANIFEST.json. If not specified, it would be the same as GetPeerExternalIp().

Returns
hostname
Parameters
peerpeer id in question.

◆ GetPeerExternalIp()

static boost::asio::ip::address fun::Rpc::GetPeerExternalIp ( const PeerId &  peer)
static

Exteranl IP is resolved by HardwareInfo's external_ip_resolver field in MANIFEST.json.

Returns
public IP address.
Parameters
peerpeer id in question.

◆ GetPeerExternalPorts()

static HardwareInfo::ProtocolPortMap fun::Rpc::GetPeerExternalPorts ( const PeerId &  peer)
static

External ports is resolved by HardwareInfo's external_ip_resolver field in MANIFEST.json, and specifically by 'nat:ip:porto=port:proto=prot'.

Returns
public ports. If not behind NAT, should be empty.
Parameters
peerpeer id in question.

◆ GetPeers()

static size_t fun::Rpc::GetPeers ( PeerMap *  ret,
bool  include_self = false 
)
static
Returns
the number of peers.
Parameters
retret a pointer to PeerMap instance.
include_selfinclude a local rpc server.

◆ GetPeerStatus()

static Json fun::Rpc::GetPeerStatus ( const PeerId &  peer)
static
Parameters
peerpeer id in question.

◆ GetPeersWithTag()

static size_t fun::Rpc::GetPeersWithTag ( PeerMap *  ret,
const Tag &  tag,
bool  include_self = false 
)
static
Returns
the number of peers.
Parameters
retret a pointer to PeerMap instance.
tagstring to identify rpc peers.
include_selfinclude a local rpc server.

◆ GetPeerTags()

static size_t fun::Rpc::GetPeerTags ( Tags *  ret,
const PeerId &  peer 
)
static
Returns
the number of tags.
Parameters
reta pointer to an STL set of string.
peerpeer id in question.

◆ GetSelfEndpoint()

static PeerEndpoint fun::Rpc::GetSelfEndpoint ( )
static
Returns
PeerEndpoint instance

◆ GetSelfId()

static PeerId fun::Rpc::GetSelfId ( )
static
Returns
PeerId instance

◆ HasTag()

static bool fun::Rpc::HasTag ( const Tag &  tag)
static
Returns
true if a local RPC server has the tag.
Parameters
tagstring to check.

◆ IsExternalPeer()

static bool fun::Rpc::IsExternalPeer ( const PeerId &  peer)
static
Returns
true if the peer is from external.

◆ IsPeerConnected()

static bool fun::Rpc::IsPeerConnected ( const PeerId &  peer)
static
Returns
true if the peer is connected.
Parameters
peerpeer id in question.

◆ RegisterHandler()

static void fun::Rpc::RegisterHandler ( const string type,
const Handler h 
)
static

The type must match the sender field in FunRpcMessage protobuf.

Parameters
typestring to identify a message type.
hHandler to be invoked when msg of the given type arrives.

◆ RegisterVoidReplyHandler()

static void fun::Rpc::RegisterVoidReplyHandler ( const string type,
const VoidReplyHandler &  h 
)
static

The type must match the sender field in FunRpcMessage protobuf.

Parameters
typestring to identify a message type.
hHandler to be invoked when msg of the given type arrives.

◆ RemoveTag()

static void fun::Rpc::RemoveTag ( const Tag &  tag)
static

(e.g., lobby, room, ...)

Parameters
tagstring to remove.

◆ RemoveTags()

static void fun::Rpc::RemoveTags ( const Tags &  tags)
static

(e.g., lobby, room, ...)

Parameters
tagsa set of tag strings to remove.

◆ SetStatus()

static void fun::Rpc::SetStatus ( const Json status)
static
Parameters
statusthe server status.