iFun Engine API  1.0.0-b6053
Great Technology for Great Games
Public Types | Public Member Functions | Static Public Member Functions | List of all members
fun::Session Class Referenceabstract
Inheritance diagram for fun::Session:

Public Types

typedef std::pair< MonotonicClock::Duration, size_t > Ping
 
typedef boost::unordered_set< Ptr< Session > > SessionsSet
 

Public Member Functions

virtual void AddToContext (const string &key, const string &value)=0
 Shortcuts to access the context. More...
 
virtual void AddToContext (const string &key, const int64_t &value)=0
 
virtual void Close ()=0
 Closes the session explicitly.
 
virtual void CloseTransport ()=0
 Closes all the attached transport.
 
virtual bool CloseTransport (TransportProtocol protocol)=0
 Closes the specified transport if attached. More...
 
 DECLARE_CLASS_PTR (Session)
 
virtual bool DeleteFromContext (const string &key)=0
 
virtual const JsonGetContext () const =0
 Returns the associated context. More...
 
virtual JsonGetContext ()=0
 Returns the associated context. More...
 
virtual boost::mutex & GetContextMutex ()=0
 Returns mutex of the session for per-session synchronization. More...
 
virtual WallClock::Value GetExpirationTime () const =0
 Returns a time when the session gets expired. More...
 
virtual bool GetFromContext (const string &key, string *ret) const =0
 
virtual bool GetFromContext (const string &key, int64_t *ret) const =0
 
virtual bool GetLastReceiveTime (const string &message_type, WallClock::Value *receive_time) const =0
 Gets the last time received specified message. More...
 
virtual bool GetLastSendTime (const string &message_type, WallClock::Value *send_time) const =0
 Gets the last time sent a specified message. More...
 
virtual Ping GetPing () const =0
 Gets round-trip time to the client associated with the session. More...
 
virtual Ping GetPing (TransportProtocol protocol) const =0
 
virtual size_t GetPingSamplingInterval () const =0
 Returns ping sampling interval. More...
 
virtual size_t GetPingSamplingInterval (TransportProtocol protocol) const =0
 
virtual size_t GetPingTimeout () const =0
 Returns ping timeout. More...
 
virtual size_t GetPingTimeout (TransportProtocol protocol) const =0
 
virtual bool GetRemoteEndPoint (TransportProtocol protocol, string *ip, uint16_t *port=NULL) const =0
 Gets a remote end point with the given protocol. More...
 
virtual std::set< stringGetTags () const =0
 Returns tags associated with the session. More...
 
virtual bool HasTag (const string &tag) const =0
 Checks if the session has the tag key. More...
 
virtual const SessionId & id () const =0
 
virtual bool IsOpened () const =0
 Checks if the session is opened. More...
 
virtual bool IsRestored () const =0
 Checks if the session is restored session or not. More...
 
virtual bool IsTransportAttached () const =0
 Checks if there is any transport attached to this session. More...
 
virtual bool IsTransportAttached (TransportProtocol protocol) const =0
 Checks if there is the specified transport attached to this session. More...
 
virtual const stringLastReceivedMessageType () const =0
 
virtual const stringLastSentMessageType () const =0
 
virtual void LockContext ()=0
 Locks/Unlocks mutex of the session. More...
 
virtual operator boost::mutex & () const =0
 
virtual void SendBackMessage (const Json &message, Encryption encryption=kDefaultEncryption, TransportProtocol protocol=kDefaultProtocol)=0ASSERT_NO_ROLLBACK
 Send out given message in JSON with the last-seen message type. More...
 
virtual void SendBackMessage (const Ptr< FunMessage > &message, Encryption encryption=kDefaultEncryption, TransportProtocol protocol=kDefaultProtocol)=0ASSERT_NO_ROLLBACK
 Sends out given message in Protobuf with the last-seen message type. More...
 
virtual void SendMessage (const string &message_type, Encryption encryption=kDefaultEncryption, TransportProtocol protocol=kDefaultProtocol)=0ASSERT_NO_ROLLBACK
 Sends out given message. More...
 
virtual void SendMessage (const string &message_type, const Json &message, Encryption encryption=kDefaultEncryption, TransportProtocol protocol=kDefaultProtocol)=0ASSERT_NO_ROLLBACK
 Sends out given message in Json type. More...
 
virtual void SendMessage (const string &message_type, const Ptr< FunMessage > &message, Encryption encryption=kDefaultEncryption, TransportProtocol protocol=kDefaultProtocol)=0ASSERT_NO_ROLLBACK
 Sends out given message in Protobuf type. More...
 
virtual void SendMessage (int32_t message_type, const Ptr< FunMessage > &message, Encryption encryption=kDefaultEncryption, TransportProtocol protocol=kDefaultProtocol)=0ASSERT_NO_ROLLBACK
 Sends out given message in Protobuf type. More...
 
virtual void SendMessage (const ProtobufExtensionIdentifier &message_type, const Ptr< FunMessage > &message, Encryption encryption=kDefaultEncryption, TransportProtocol protocol=kDefaultProtocol)=0ASSERT_NO_ROLLBACK
 Sends out given message in Protobuf type. More...
 
virtual void SetContext (const Json &ctxt)=0
 Associate the session with the given user-prvided context. More...
 
virtual void SetPingSamplingInterval (size_t seconds)=0
 Sets ping sampling interval. More...
 
virtual void SetPingSamplingInterval (size_t seconds, TransportProtocol protocol)=0
 
virtual void SetPingTimeout (size_t seconds)=0
 Sets ping timeout. More...
 
virtual void SetPingTimeout (size_t seconds, TransportProtocol protocol)=0
 
virtual void Tag (const string &tag)=0
 Tags the session. More...
 
virtual void UnlockContext ()=0
 
virtual void Untag (const string &tag)=0
 Untags the session. More...
 

Static Public Member Functions

static void BroadcastGlobally (const string &message_type, const Json &message, const Rpc::Tag &server_tag, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a Json message to all the sessions of the given RPC servers. More...
 
static void BroadcastGlobally (const string &message_type, const Ptr< FunMessage > &message, const Rpc::Tag &server_tag, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a protobuf message to all the sessions of the given RPC servers. More...
 
static void BroadcastGlobally (int32_t message_type, const Ptr< FunMessage > &message, const Rpc::Tag &server_tag, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a protobuf message to all the sessions of the given RPC servers. More...
 
static void BroadcastGlobally (const ProtobufExtensionIdentifier &message_type, const Ptr< FunMessage > &message, const Rpc::Tag &server_tag, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a protobuf message to all the sessions of the given RPC servers. More...
 
static void BroadcastGlobally (const string &message_type, const Json &message, const Rpc::PeerMap &servers, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a Json message to all the sessions of the given RPC servers. More...
 
static void BroadcastGlobally (const string &message_type, const Ptr< FunMessage > &message, const Rpc::PeerMap &servers, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a protobuf message to all the sessions of the given RPC servers. More...
 
static void BroadcastGlobally (int32_t message_type, const Ptr< FunMessage > &message, const Rpc::PeerMap &servers, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a protobuf message to all the sessions of the given RPC servers. More...
 
static void BroadcastGlobally (const ProtobufExtensionIdentifier &message_type, const Ptr< FunMessage > &message, const Rpc::PeerMap &servers, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a protobuf message to all the sessions of the given RPC servers. More...
 
static void BroadcastLocally (const string &message_type, const Json &message, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a Json message to all the local sessions. More...
 
static void BroadcastLocally (const string &message_type, const Ptr< FunMessage > &message, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a protobuf message to all the local sessions. More...
 
static void BroadcastLocally (int32_t message_type, const Ptr< FunMessage > &message, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a protobuf message to all the local sessions. More...
 
static void BroadcastLocally (const ProtobufExtensionIdentifier &message_type, const Ptr< FunMessage > &message, Encryption encryption, TransportProtocol protocol) ASSERT_NO_ROLLBACK
 Broadcasts a protobuf message to all the local sessions. More...
 
static size_t CountWithTag (const string &key)
 Returns the number of sessions with the given key. More...
 
static Ptr< SessionFind (const SessionId &session_id)
 
static SessionsSet FindWithTag (const string &key)
 Finds a session with the given key. More...
 

Member Function Documentation

◆ AddToContext()

virtual void fun::Session::AddToContext ( const string key,
const string value 
)
pure virtual

These are thread-safe.

◆ BroadcastGlobally() [1/8]

static void fun::Session::BroadcastGlobally ( const string message_type,
const Json message,
const Rpc::Tag &  server_tag,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
server_tagRpc::Tag that identify the targets RPC servers.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastGlobally() [2/8]

static void fun::Session::BroadcastGlobally ( const string message_type,
const Ptr< FunMessage > &  message,
const Rpc::Tag &  server_tag,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
server_tagRpc::Tag that identify the targets RPC servers.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastGlobally() [3/8]

static void fun::Session::BroadcastGlobally ( int32_t  message_type,
const Ptr< FunMessage > &  message,
const Rpc::Tag &  server_tag,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
server_tagRpc::Tag that identify the targets RPC servers.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastGlobally() [4/8]

static void fun::Session::BroadcastGlobally ( const ProtobufExtensionIdentifier message_type,
const Ptr< FunMessage > &  message,
const Rpc::Tag &  server_tag,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
server_tagRpc::Tag that identify the targets RPC servers.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastGlobally() [5/8]

static void fun::Session::BroadcastGlobally ( const string message_type,
const Json message,
const Rpc::PeerMap &  servers,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
serversRpc::PeerMap that identify the targets RPC servers.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastGlobally() [6/8]

static void fun::Session::BroadcastGlobally ( const string message_type,
const Ptr< FunMessage > &  message,
const Rpc::PeerMap &  servers,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
serversRpc::PeerMap that identify the targets RPC servers.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastGlobally() [7/8]

static void fun::Session::BroadcastGlobally ( int32_t  message_type,
const Ptr< FunMessage > &  message,
const Rpc::PeerMap &  servers,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
serversRpc::PeerMap that identify the targets RPC servers.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastGlobally() [8/8]

static void fun::Session::BroadcastGlobally ( const ProtobufExtensionIdentifier message_type,
const Ptr< FunMessage > &  message,
const Rpc::PeerMap &  servers,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
serversRpc::PeerMap that identify the targets RPC servers.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastLocally() [1/4]

static void fun::Session::BroadcastLocally ( const string message_type,
const Json message,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastLocally() [2/4]

static void fun::Session::BroadcastLocally ( const string message_type,
const Ptr< FunMessage > &  message,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastLocally() [3/4]

static void fun::Session::BroadcastLocally ( int32_t  message_type,
const Ptr< FunMessage > &  message,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ BroadcastLocally() [4/4]

static void fun::Session::BroadcastLocally ( const ProtobufExtensionIdentifier message_type,
const Ptr< FunMessage > &  message,
Encryption  encryption,
TransportProtocol  protocol 
)
static
Parameters
message_typemessage type.
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol supports kTcp, kUdp types only.

◆ CloseTransport()

virtual bool fun::Session::CloseTransport ( TransportProtocol  protocol)
pure virtual

protocol the transport protocol to close.

Returns
true if transport attached and closed.

◆ CountWithTag()

static size_t fun::Session::CountWithTag ( const string key)
static
Returns
the number of sessions
Parameters
keytag key string

◆ FindWithTag()

static SessionsSet fun::Session::FindWithTag ( const string key)
static
Returns
a set of session pointers.
Parameters
keytag key string

◆ GetContext() [1/2]

virtual const Json& fun::Session::GetContext ( ) const
pure virtual

This is not thread-safe. Use event tag or context mutex for multi-thread synchronization.

Returns
const JSON instance.

◆ GetContext() [2/2]

virtual Json& fun::Session::GetContext ( )
pure virtual

This is not thread-safe. Use event tag or context mutex for multi-thread synchronization.

Returns
Json instance.

◆ GetContextMutex()

virtual boost::mutex& fun::Session::GetContextMutex ( )
pure virtual

Example: boost::mutex::scoped_lock lock(*session); session->GetContext()["example"] = 1234;

Returns
mutex instance.

◆ GetExpirationTime()

virtual WallClock::Value fun::Session::GetExpirationTime ( ) const
pure virtual
Returns
WallClock::Value

◆ GetLastReceiveTime()

virtual bool fun::Session::GetLastReceiveTime ( const string message_type,
WallClock::Value *  receive_time 
) const
pure virtual
Parameters
message_typemessage type.
receive_timereceive time.
Returns
false if never once received. true otherwise.

◆ GetLastSendTime()

virtual bool fun::Session::GetLastSendTime ( const string message_type,
WallClock::Value *  send_time 
) const
pure virtual
Parameters
message_typemessage type.
receive_timesend time.
Returns
false if never once sent. true otherwise.

◆ GetPing()

virtual Ping fun::Session::GetPing ( ) const
pure virtual
Returns
round-trip time and sample count.

◆ GetPingSamplingInterval()

virtual size_t fun::Session::GetPingSamplingInterval ( ) const
pure virtual
Returns
ping sampling interval in seconds.

◆ GetPingTimeout()

virtual size_t fun::Session::GetPingTimeout ( ) const
pure virtual
Returns
ping timeout in seconds.

◆ GetRemoteEndPoint()

virtual bool fun::Session::GetRemoteEndPoint ( TransportProtocol  protocol,
string ip,
uint16_t *  port = NULL 
) const
pure virtual
Parameters
protocoltransport protocol that you want to know.
ipip of remote.
portport of remote.
Returns
true if the given protocol has attached. false otherwise.

◆ GetTags()

virtual std::set<string> fun::Session::GetTags ( ) const
pure virtual
Returns
a set of tags

◆ HasTag()

virtual bool fun::Session::HasTag ( const string tag) const
pure virtual
Returns
bool true if the session has the tag. false otherwise.
Parameters
tagtag key string.

◆ id()

virtual const SessionId& fun::Session::id ( ) const
pure virtual
Returns
Session id.

◆ IsOpened()

virtual bool fun::Session::IsOpened ( ) const
pure virtual

bool true if the session is opened. false otherwise.

◆ IsRestored()

virtual bool fun::Session::IsRestored ( ) const
pure virtual
Returns
true if the session is restored. false otherwise.

◆ IsTransportAttached() [1/2]

virtual bool fun::Session::IsTransportAttached ( ) const
pure virtual

true if any transport attached.

◆ IsTransportAttached() [2/2]

virtual bool fun::Session::IsTransportAttached ( TransportProtocol  protocol) const
pure virtual
Parameters
protocoltransport protocol that you want to know.
Returns
true if transport attached.

◆ LastReceivedMessageType()

virtual const string& fun::Session::LastReceivedMessageType ( ) const
pure virtual
Returns
message type string that the engine received from the session.

◆ LastSentMessageType()

virtual const string& fun::Session::LastSentMessageType ( ) const
pure virtual
Returns
message type string that the engine sent thru the session.

◆ LockContext()

virtual void fun::Session::LockContext ( )
pure virtual

Example: session->LockContext(); session->GetContext()["example"] = 1234; session->UnlockContext();

◆ SendBackMessage() [1/2]

virtual void fun::Session::SendBackMessage ( const Json message,
Encryption  encryption = kDefaultEncryption,
TransportProtocol  protocol = kDefaultProtocol 
)
pure virtual
Parameters
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol.

◆ SendBackMessage() [2/2]

virtual void fun::Session::SendBackMessage ( const Ptr< FunMessage > &  message,
Encryption  encryption = kDefaultEncryption,
TransportProtocol  protocol = kDefaultProtocol 
)
pure virtual
Parameters
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol.

◆ SendMessage() [1/5]

virtual void fun::Session::SendMessage ( const string message_type,
Encryption  encryption = kDefaultEncryption,
TransportProtocol  protocol = kDefaultProtocol 
)
pure virtual
Parameters
message_typemessage type.
encryptionencryption method.
protocoltransport protocol.

◆ SendMessage() [2/5]

virtual void fun::Session::SendMessage ( const string message_type,
const Json message,
Encryption  encryption = kDefaultEncryption,
TransportProtocol  protocol = kDefaultProtocol 
)
pure virtual
Parameters
message_typemessage type.
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol.

◆ SendMessage() [3/5]

virtual void fun::Session::SendMessage ( const string message_type,
const Ptr< FunMessage > &  message,
Encryption  encryption = kDefaultEncryption,
TransportProtocol  protocol = kDefaultProtocol 
)
pure virtual
Parameters
message_typemessage type.
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol.

◆ SendMessage() [4/5]

virtual void fun::Session::SendMessage ( int32_t  message_type,
const Ptr< FunMessage > &  message,
Encryption  encryption = kDefaultEncryption,
TransportProtocol  protocol = kDefaultProtocol 
)
pure virtual
Parameters
message_typemessage type.
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol.

◆ SendMessage() [5/5]

virtual void fun::Session::SendMessage ( const ProtobufExtensionIdentifier message_type,
const Ptr< FunMessage > &  message,
Encryption  encryption = kDefaultEncryption,
TransportProtocol  protocol = kDefaultProtocol 
)
pure virtual
Parameters
message_typemessage type which is google::protobuf::internal::ExtensionIdentifier type.
messageTarget message to be sent.
encryptionencryption method.
protocoltransport protocol.

◆ SetContext()

virtual void fun::Session::SetContext ( const Json ctxt)
pure virtual

Context is a user-provided JSON instance and meaningful only within a single server node. This is not thread-safe. Use event tag or context mutex for multi-thread synchronization.

◆ SetPingSamplingInterval()

virtual void fun::Session::SetPingSamplingInterval ( size_t  seconds)
pure virtual
Parameters
secondssampling interval in second. if 0 stops sampling.

◆ SetPingTimeout()

virtual void fun::Session::SetPingTimeout ( size_t  seconds)
pure virtual

if ping response did not arrive until specified wait time, close the transport.

Parameters
secondstimeout in second. 0 for off.

◆ Tag()

virtual void fun::Session::Tag ( const string tag)
pure virtual
Parameters
tagtag key string

◆ Untag()

virtual void fun::Session::Untag ( const string tag)
pure virtual
Parameters
tagtag key string