connectionbase.h
/*
Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef CONNECTIONBASE_H__
#define CONNECTIONBASE_H__
#include "gloox.h"
#include "connectiondatahandler.h"
#include <string>
namespace gloox
{
class GLOOX_API ConnectionBase
{
public:
ConnectionBase( ConnectionDataHandler* cdh )
: m_handler( cdh ), m_state( StateDisconnected ), m_port( -1 )
{}
virtual ~ConnectionBase() { cleanup(); }
virtual ConnectionError connect() = 0;
virtual ConnectionError recv( int timeout = -1 ) = 0;
virtual bool send( const std::string& data ) = 0;
virtual ConnectionError receive() = 0;
virtual void disconnect() = 0;
virtual void cleanup() {}
ConnectionState state() const { return m_state; }
void registerConnectionDataHandler( ConnectionDataHandler* cdh ) { m_handler = cdh; }
void setServer( const std::string &server, int port = -1 ) { m_server = server; m_port = port; }
const std::string& server() const { return m_server; }
int port() const { return m_port; }
virtual int localPort() const { return -1; }
virtual const std::string localInterface() const { return EmptyString; }
virtual void getStatistics( long int &totalIn, long int &totalOut ) = 0;
virtual ConnectionBase* newInstance() const = 0;
protected:
ConnectionDataHandler* m_handler;
ConnectionState m_state;
std::string m_server;
int m_port;
};
}
#endif // CONNECTIONBASE_H__
gloox::ConnectionBase::localInterface
virtual const std::string localInterface() const
Definition connectionbase.h:133
gloox::ConnectionBase::cleanup
virtual void cleanup()
Definition connectionbase.h:89
gloox::ConnectionBase::m_state
ConnectionState m_state
Definition connectionbase.h:155
gloox::ConnectionBase::port
int port() const
Definition connectionbase.h:121
gloox::ConnectionBase::server
const std::string & server() const
Definition connectionbase.h:115
gloox::ConnectionBase::localPort
virtual int localPort() const
Definition connectionbase.h:127
gloox::ConnectionBase::state
ConnectionState state() const
Definition connectionbase.h:95
gloox::ConnectionBase::m_port
int m_port
Definition connectionbase.h:161
gloox::ConnectionBase::newInstance
virtual ConnectionBase * newInstance() const =0
gloox::ConnectionBase::recv
virtual ConnectionError recv(int timeout=-1)=0
gloox::ConnectionBase::send
virtual bool send(const std::string &data)=0
gloox::ConnectionBase::m_handler
ConnectionDataHandler * m_handler
Definition connectionbase.h:152
gloox::ConnectionBase::connect
virtual ConnectionError connect()=0
gloox::ConnectionBase::m_server
std::string m_server
Definition connectionbase.h:158
gloox::ConnectionBase::ConnectionBase
ConnectionBase(ConnectionDataHandler *cdh)
Definition connectionbase.h:42
gloox::ConnectionBase::receive
virtual ConnectionError receive()=0
gloox::ConnectionBase::getStatistics
virtual void getStatistics(long int &totalIn, long int &totalOut)=0
gloox::ConnectionBase::disconnect
virtual void disconnect()=0
gloox::ConnectionBase::setServer
void setServer(const std::string &server, int port=-1)
Definition connectionbase.h:109
gloox::ConnectionBase::~ConnectionBase
virtual ~ConnectionBase()
Definition connectionbase.h:49
gloox::ConnectionBase::registerConnectionDataHandler
void registerConnectionDataHandler(ConnectionDataHandler *cdh)
Definition connectionbase.h:102
gloox::ConnectionDataHandler
This is an abstract base class to receive events from a ConnectionBase-derived object.
Definition connectiondatahandler.h:36
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::ConnectionError
ConnectionError
Definition gloox.h:684
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124
gloox::ConnectionState
ConnectionState
Definition gloox.h:641
gloox::StateDisconnected
@ StateDisconnected
Definition gloox.h:642