OpenMortal Apocalypse mirror
Sourceforge mirror
SourceForge.net Logo
      News | Info | Characters | Arenas | Screenshots | Forums | Download  
Developer: Making of | Character-HOWTO | AI Design | Submit a Character
Documentation: Main Page | Modules | Class Hierarchy | Class List | File List

OnlineChatBEImpl.h

Go to the documentation of this file.
00001 //
00002 // C++ Interface: COnlineChatBEImpl
00003 //
00004 // Description: 
00005 //
00006 //
00007 // Author: upi <upi@feel>, (C) 2004
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 #ifndef CONLINECHATBEIMPL_H
00013 #define CONLINECHATBEIMPL_H
00014 
00015 
00016 #include "OnlineChatBE.h"
00017 #include "SDL_net.h"
00018 #include "SDL_thread.h"
00019 #include <list>
00020 
00026 class COnlineChatBEImpl: public IOnlineChatBE
00027 {
00028 public:
00029     COnlineChatBEImpl();
00030 
00031     ~COnlineChatBEImpl();
00032 
00033 
00034 public:
00035     // Connection
00036     
00037     virtual void                connect( std::string a_sNick );
00038     virtual void                disconnect();
00039     virtual ConnectionStateEnum getConnectionState() const;
00040     
00041     // Getting/setting my connection parameters
00042     
00043     virtual std::string         getMyNick() const;
00044     virtual void                setMyNick( std::string a_sNick );
00045     virtual ClientModeEnum      getMyClientMode() const;
00046     virtual void                setMyClientMode( ClientModeEnum a_enClientMode );
00047     virtual const UserInfo&     getMyUserInfo() const;              
00048     
00049     // User control
00050     
00051     virtual int                 getUserCount() const;
00052     virtual const UserInfo&     getUserInfo( int a_iUserNumber ) const;
00053     virtual ClientModeEnum      getClientMode() const;
00054     virtual void                setClientMode( ClientModeEnum a_enNewMode );
00055     
00056     // Event sinks
00057     
00058     virtual void                addEventSink( IOnlineEventSink* a_poSink );
00059     virtual void                removeEventSink( IOnlineEventSink* a_poSink );
00060     virtual void                removeAllEventSinks();
00061 
00062 protected:
00063     void                        notifyEvent( const IOnlineChatBE::SChatEvent& a_roEvent );
00064     void                        notifyConnectionState( IOnlineChatBE::ConnectionStateEnum a_enOldState, 
00065                                                        IOnlineChatBE::ConnectionStateEnum a_enNewState,
00066                                                        const std::string& a_rsMessage );
00067     void                        notifyConnectionState( const std::string& a_rsMessage );
00068                                                        
00069     void                        threadFunction();
00070     void                        internalConnect();
00071     void                        internalDisconnect();
00072     void                        internalProcessMessage();
00073     void                        sendNick();
00074     void                        sendRawData( char a_cPrefix, const char* a_pcMessage );
00075 
00076 protected:
00077     // typedef
00078     typedef std::list<IOnlineEventSink*> EventSinkList;
00079     typedef std::list<UserInfo*> UserInfoList;
00080     
00081     // Internal state
00082     ConnectionStateEnum         m_enConnectionState;        // The current state of the connection to the server
00083     ConnectionStateEnum         m_enNotifiedState;          // The last notified connection state
00084     ClientModeEnum              m_enClientMode;             // The current state of the client (e.g. "away")
00085     std::string                 m_sMyNick;                  // The last received nick from the server
00086     EventSinkList               m_apoSinks;                 // Receivers of events
00087     UserInfoList                m_apoUsers;                 // User list from the server
00088     
00089     // Connection to the server
00090     TCPsocket                   m_poSocket;                 // The TCP/IP network socket.
00091     SDLNet_SocketSet            m_poSocketSet;              // SDLNet construct for watching the socket.
00092     char                        m_acIncomingBuffer[4096];   
00093     int                         m_iIncomingBufferSize;      
00094     
00095     SDL_mutex*                  m_poLock;
00096 };
00097 
00098 #endif