1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef SESSION_BROWSER_H
18 #define SESSION_BROWSER_H
20 #include "nel/misc/thread.h"
21 #include "nel/misc/singleton.h"
22 #include "nel/misc/mutex.h"
23 #include "game_share/ring_session_manager_itf.h"
25 /** Interface class to implement in order to be called back
26 * when events arrive on the session brownser.
28 //class ISessionBrowserEvent
32 // /// The list of session is available
33 // virtual void onSessionListReady(const std::vector<RSMGR::TSessionDesc> &sessions) =0;
37 class CCallbackClientAdaptor
;
39 /** Session browser requester.
40 * NB : all request are served asynchronously.
41 * You must derive this class and implement the
42 * virtuals to receive return messages.
44 class CSessionBrowser
: public RSMGR::CSessionBrowserServerWebClientItf
,
45 public NLMISC::IRunnable
47 friend class CCallbackClientAdaptor
;
49 // the comm thread object
50 NLMISC::IThread
*_CommThread
;
51 // the thread termination flag
54 // the server address for connection
55 NLNET::CInetAddress _ServerAddr
;
57 // a flag to signal a failure in connection attempt
60 // The auth information
61 NLNET::CLoginCookie _LoginCookie
;
63 // received message counter
64 uint32 _NBReceivedMessage
;
66 // A list of last received message name, in order of arrival
67 std::list
<std::string
> _LastReceivedMessageNames
;
69 // a flag set when we are waiting for a message. This bypass the
70 // disconnection timeout
71 bool _WaitingForMessage
;
75 CCallbackClientAdaptor
*getCallbackAdaptor();
78 /// clear all message queued in the send queue
79 void clearSendQueue();
81 // the comm thread entry point
84 // called before each message is dispatched
85 void on_preDispatchMessage(NLNET::CMessage
&msgin
, NLNET::TSockId from
, NLNET::CCallbackNetBase
&netbase
);
93 virtual ~CSessionBrowser();
96 void setAuthInfo(const NLNET::CLoginCookie
&cookie
);
98 /** Send a message (Used to implement direct message to Dss
100 void send(const NLNET::CMessage
& msg
);
102 /** 'connect' the interface to the server, in fact, only store the
103 * connection information, the connection is made only when the
104 * client effectively send message.
106 virtual void connectItf(NLNET::CInetAddress address
);
108 // call update each frame
112 // the connection attempt to the server has failed
113 virtual void on_connectionFailed() =0;
115 // The connection has been closed.
116 // virtual void on_connectionClosed() =0;
118 /** Wait until the client receive a message OR a disconnection is signaled
119 * Return true if the specified message is received, false in case of
120 * disconnection or if another message is received.
122 bool waitOneMessage(const std::string
&msgName
);
131 #endif //SESSION_BROWSER_H