1
0
forked from 0ad/0ad
0ad/source/network/Session.h
janwas b755ddefda remove all author/modified by tags.
make include guards consistent.

This was SVN commit r5040.
2007-05-07 16:33:24 +00:00

72 lines
1.5 KiB
C++

#ifndef INCLUDED_NETWORK_SESSION
#define INCLUDED_NETWORK_SESSION
#include "Network.h"
#include "SessionManager.h"
/*
CNetSession
DESCRIPTION:
The representation of a network session (on both the client and server
side)
*/
class CNetSession: public CMessageSocket
{
friend class CNetClient;
protected:
/*
The MessageHandler callback follows the contract of HandleMessage, see
the documentation for that function for more information.
*/
typedef bool (MessageHandler)(CNetMessage *, CNetSession *);
MessageHandler *m_pMessageHandler;
CStrW m_Name;
public:
inline CNetSession(MessageHandler *pMsgHandler=NULL):
m_pMessageHandler(pMsgHandler)
{
g_SessionManager.Register(this);
}
inline CNetSession(CSocketInternal *pInt, MessageHandler *pMsgHandler=NULL):
CMessageSocket(pInt),
m_pMessageHandler(pMsgHandler)
{
g_SessionManager.Register(this);
}
virtual ~CNetSession();
/*
Handle an incoming message.
THREADS:
When used with the session manager, this method will only be
called from the main thread.
ARGUMENTS:
pMsg The incoming message
pSocket The socket the message came from
RETURNS:
TRUE if the message was handled by this class or another protocol
that this class knows of. FALSE if the message was not handled.
*/
inline bool HandleMessage(CNetMessage *pMsg)
{
if (m_pMessageHandler)
return (m_pMessageHandler)(pMsg, this);
else
return false;
}
inline const CStrW& GetName()
{
return m_Name;
}
};
#endif //INCLUDED_NETWORK_SESSION