/* $Id: serverconnection.hpp,v 1.6.4.1 2006/03/26 08:24:22 chfreund Exp $ */ #ifndef _SERVERCONNECTION_HPP_ #define _SERVERCONNECTION_HPP_ #include #include "serverentry.hpp" #include "tcpconnection.hpp" struct Message; struct EchoMessage; class Client; //! Base class for connections to a server that are kept on client side class ServerConnection { private: //! The entry describing the server ServerEntry serverEntry; protected: //! The client Client* m_client; //! The client ID Uint8 m_clientID; //! Flag for using compression on outgoing messages bool m_compress; //! Flag if the connection is valid bool m_valid; //! Progress listener TCPProgressListener* m_listener; public: //! Constructor ServerConnection() : m_client( 0 ), m_compress( false ), m_valid( true ), m_listener( 0 ) { } //! Destructor virtual ~ServerConnection() { } //! Get the type of the connection (DIRECT, REMOTE) virtual ServerEntry::Type getType() const = 0; //! \name Checking, starting and finishing the connection //@{ //! Check if connection to a certain server is possible virtual bool checkConnection( ServerEntry* server ) = 0; //! Initiate the communication virtual bool openConnection() = 0; //! Close the connection virtual void closeConnection() = 0; //@} //! Sets the client void setClient( Client* client ) { m_client = client; } //! \return The ID identifying this client Uint8 getClientID() { return m_clientID; } void setCompression( bool value ) { m_compress = value; } void setProgressListener( TCPProgressListener* listener ) { m_listener = listener; } bool isValid() const { return m_valid; } //! \name Sending and receiving messages //@{ //! Send a message to the server //! \param message The message to be sent virtual void sendMessage( Message* message ) = 0; //! Get the echo message for a certain frame //! \param frame The frame number virtual EchoMessage* getEchoMessage( Uint32 frame ) = 0; //! Get (and remove from the message queue) the next message from the server virtual Message* popMessage() = 0; //! Get the next message without removing it from the queue virtual Message* peekMessage() = 0; //@} }; #endif // _SERVERCONNECTION_HPP_