/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SIRC_COMMTHREAD_H
#define SIRC_COMMTHREAD_H
#include <string>
#include <iostream>
#include <util/message.h>
#include <util/looper.h>
#include <util/string.h>
#include <util/messenger.h>
#include "bgnet.h"
//----------------------------------------------------------------------------------
class CommThread:public os::Looper
{
protected:
enum state_t { S_START, S_STOP };
public:
CommThread( const os::Messenger &cTarget );
virtual void HandleMessage( os::Message *pcMessage );
void SendReceiveLoop( void );
void Send( const os::String cSend );
bool IsConnected( void );
private:
bool SendReceiveLoop( state_t eState );
bool PingPong( const os::String cData );
void SendMessage( const os::String& cName );
os::Messenger m_cTarget;
state_t m_eState;
int sockfd;
Bgnet bgnet;
///////////////////////////////////////////////////////////////////////////
////////////////////////////// STATE FUNCTIONS ////////////////////////////
///////////////////////////////////////////////////////////////////////////
public:
void SetState( state_t eState ) { m_eState = eState; }
state_t GetState( void ) { return m_eState; }
void SetHost( os::String zHost ) { m_zHost = zHost; }
os::String GetHost( void ) { return m_zHost; }
void SetPort( os::String zPort ) { m_zPort = zPort; }
os::String GetPort( void ) { return m_zPort; }
void SetUsername( os::String zUsername ) { m_zUsername = zUsername; }
os::String GetUsername( void ) { return m_zUsername; }
void SetPassword( os::String zPassword ) { m_zPassword = zPassword; }
os::String GetPassword( void ) { return m_zPassword; }
void SetRealname( os::String zRealname ) { m_zRealname = zRealname; }
os::String GetRealname( void ) { return m_zRealname; }
void SetNickname( os::String zNickname ) { m_zNickname = zNickname; }
os::String GetNickname( void ) { return m_zNickname; }
void SetChannel( os::String zChannel ) { m_zChannel = zChannel; }
os::String GetChannel( void ) { return m_zChannel; }
private:
os::String m_zHost;
os::String m_zPort;
os::String m_zUsername;
os::String m_zPassword;
os::String m_zRealname;
os::String m_zNickname;
os::String m_zChannel;
};
#endif