iFun Engine API  1.0.0-b3630
Great Technology for Great Games
 All Classes Files Functions Variables Typedefs Macros
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 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< string > GetTags () 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 string & LastReceivedMessageType () const =0
 
virtual const string & LastSentMessageType () 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 SetPingTimeout (size_t seconds)=0
 Sets ping timeout. More...
 
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 Ptr< SessionFind (const SessionId &session_id)
 
static SessionsSet FindWithTag (const string &key)
 Finds a session with the given key. More...
 

Member Function Documentation

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

These are thread-safe.

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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
virtual bool fun::Session::CloseTransport ( TransportProtocol  protocol)
pure virtual

protocol the transport protocol to close.

Returns
true if transport attached and closed.
static SessionsSet fun::Session::FindWithTag ( const string &  key)
static
Returns
a set of session pointers.
Parameters
keytag key string
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.
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.
virtual boost::mutex& fun::Session::GetContextMutex ( )
pure virtual

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

Returns
mutex instance.
virtual WallClock::Value fun::Session::GetExpirationTime ( ) const
pure virtual
Returns
WallClock::Value
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.
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.
virtual Ping fun::Session::GetPing ( ) const
pure virtual
Returns
round-trip time and sample count.
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.
virtual std::set<string> fun::Session::GetTags ( ) const
pure virtual
Returns
a set of tags
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.
virtual const SessionId& fun::Session::id ( ) const
pure virtual
Returns
Session id.
virtual bool fun::Session::IsOpened ( ) const
pure virtual

bool true if the session is opened. false otherwise.

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

true if any transport attached.

virtual bool fun::Session::IsTransportAttached ( TransportProtocol  protocol) const
pure virtual
Parameters
protocoltransport protocol that you want to know.
Returns
true if transport attached.
virtual const string& fun::Session::LastReceivedMessageType ( ) const
pure virtual
Returns
message type string that the engine received from the session.
virtual const string& fun::Session::LastSentMessageType ( ) const
pure virtual
Returns
message type string that the engine sent thru the session.
virtual void fun::Session::LockContext ( )
pure virtual

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

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.
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.
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.
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.
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.
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.
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.
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.

virtual void fun::Session::SetPingSamplingInterval ( size_t  seconds)
pure virtual
Parameters
secondssampling interval in second. if 0 stops sampling.
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.
virtual void fun::Session::Tag ( const string &  tag)
pure virtual
Parameters
tagtag key string
virtual void fun::Session::Untag ( const string &  tag)
pure virtual
Parameters
tagtag key string