Connection.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2005-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 
00023 #ifndef PROTOCOLS__TRANSPORTS__CONNECTION_H
00024 #define PROTOCOLS__TRANSPORTS__CONNECTION_H
00025 
00026 #include "NodeAddress.h"
00027 
00028 namespace Protocols {
00029 namespace Transports {
00030 
00031 class ConnectionPrivate;
00032 
00034 
00036 class Connection : public QIODevice
00037 {
00038     Q_OBJECT
00039 
00040 public:
00041     enum State
00042     {
00043         DisconnectedState,
00044         ResolvingHostNameState,
00045         ConnectingState,
00046         ConnectedState,
00047         TimeoutState,
00048         DisconnectingState
00049     };
00050 
00051                         Connection();
00052     virtual             ~Connection();
00053 
00054     void                connectToNode (NodeAddress);
00055     void                disconnectFromNode();
00056 
00057     State               state() const;
00058     NodeAddress         remoteNodeAddress() const;
00059 
00060     bool                isSequential() const;
00061 
00062 protected:
00063     void                setState (State);
00064     void                setRemoteNodeAddress (const NodeAddress &);
00065 
00066     virtual void        doConnectToNode (const NodeAddress &) = 0;
00067     virtual void        doDisconnectFromNode() = 0;
00068 
00069     virtual qint64      readData (char * data, qint64 maxSize) = 0;
00070     virtual qint64      writeData (const char * data, qint64 maxSize) = 0;
00071 
00072 signals:
00073     void                connectionFailed();
00074     void                connectionEstablished();
00075     //void              QIODevice::readyRead();
00076     //void              QIODevice::bytesWritten (qint64);
00077     void                connectionClosed();
00078 
00079 private:
00080                         Connection (const Connection &);
00081     Connection &        operator= (const Connection &);
00082 
00083 private slots:
00084     void                lookupFinished (QHostInfo);
00085 
00086 private:
00087     auto_ptr <ConnectionPrivate> p;
00088 };
00089 
00090 } // namespace Transports
00091 } // namespace Protocols
00092 
00093 #endif // PROTOCOLS__TRANSPORTS__CONNECTION_H