2004-08-16 17:19:17 +02:00
|
|
|
#ifndef _Network_SessionManager_H
|
|
|
|
#define _Network_SessionManager_H
|
|
|
|
|
|
|
|
#include <ThreadUtil.h>
|
|
|
|
|
|
|
|
class CNetSession;
|
|
|
|
|
|
|
|
/*
|
|
|
|
NAME: CSessionManager
|
|
|
|
|
|
|
|
The central nexus of network message handling. Contains the entry point
|
2005-02-21 18:13:31 +01:00
|
|
|
called from the main thread.
|
|
|
|
CNetSession's are registered and when the Poll method finds that the session
|
|
|
|
has a pending message, the session object's HandleMessage method is called
|
|
|
|
to handle it. Any unhandled messages (HandleMessage returns false) are
|
|
|
|
logged to the system log.
|
2004-08-16 17:19:17 +02:00
|
|
|
*/
|
|
|
|
class CSessionManager: public Singleton<CSessionManager>
|
|
|
|
{
|
|
|
|
typedef std::map <CNetSession *, CNetSession *> SessionMap;
|
2005-02-21 18:13:31 +01:00
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
SessionMap m_Sessions;
|
2005-02-21 18:13:31 +01:00
|
|
|
SessionMap m_AddQueue;
|
|
|
|
SessionMap m_RemoveQueue;
|
2004-08-16 17:19:17 +02:00
|
|
|
CMutex m_Mutex;
|
2005-02-21 18:13:31 +01:00
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
/*
|
|
|
|
Poll all registered sessions and pass all messages to their
|
|
|
|
message handlers.
|
|
|
|
|
|
|
|
THREADS: Call from Main Thread only
|
|
|
|
*/
|
|
|
|
void Poll();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Register a network session with the session manager. Future calls to
|
|
|
|
Poll() will poll this session's socket and pass any messages to
|
|
|
|
its message handler function.
|
|
|
|
|
|
|
|
THREADS: Safe from all threads
|
|
|
|
*/
|
|
|
|
void Register(CNetSession *pSession);
|
|
|
|
|
|
|
|
/*
|
2005-02-21 18:13:31 +01:00
|
|
|
Delete the protocol context associated with the specified socket.
|
2004-08-16 17:19:17 +02:00
|
|
|
|
|
|
|
THREADS: Safe from all threads
|
|
|
|
*/
|
2005-02-21 18:13:31 +01:00
|
|
|
void Deregister(CNetSession *pSession);
|
2004-08-16 17:19:17 +02:00
|
|
|
};
|
|
|
|
#define g_SessionManager (CSessionManager::GetSingleton())
|
|
|
|
|
|
|
|
#endif
|