KIO
connection_p.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2007 Thiago Macieira <thiago@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef KIO_CONNECTION_P_H 00021 #define KIO_CONNECTION_P_H 00022 00023 #include <QObject> 00024 #include <klocalsocket.h> 00025 00026 class KUrl; 00027 00028 namespace KIO { 00029 struct Task { 00030 int cmd; 00031 QByteArray data; 00032 }; 00033 00034 class AbstractConnectionBackend: public QObject 00035 { 00036 Q_OBJECT 00037 public: 00038 QString address; 00039 QString errorString; 00040 enum { Idle, Listening, Connected } state; 00041 00042 explicit AbstractConnectionBackend(QObject *parent = 0); 00043 ~AbstractConnectionBackend(); 00044 00045 virtual void setSuspended(bool enable) = 0; 00046 virtual bool connectToRemote(const KUrl &url) = 0; 00047 virtual bool listenForRemote() = 0; 00048 virtual bool waitForIncomingTask(int ms) = 0; 00049 virtual bool sendCommand(const Task &task) = 0; 00050 virtual AbstractConnectionBackend *nextPendingConnection() = 0; 00051 00052 Q_SIGNALS: 00053 void disconnected(); 00054 void commandReceived(const Task &task); 00055 void newConnection(); 00056 }; 00057 00058 class SocketConnectionBackend: public AbstractConnectionBackend 00059 { 00060 Q_OBJECT 00061 public: 00062 enum Mode { LocalSocketMode, TcpSocketMode }; 00063 00064 private: 00065 enum { HeaderSize = 10, StandardBufferSize = 32*1024 }; 00066 00067 QTcpSocket *socket; 00068 union { 00069 KLocalSocketServer *localServer; 00070 QTcpServer *tcpServer; 00071 }; 00072 long len; 00073 int cmd; 00074 int port; 00075 bool signalEmitted; 00076 quint8 mode; 00077 00078 public: 00079 explicit SocketConnectionBackend(Mode m, QObject *parent = 0); 00080 ~SocketConnectionBackend(); 00081 00082 void setSuspended(bool enable); 00083 bool connectToRemote(const KUrl &url); 00084 bool listenForRemote(); 00085 bool waitForIncomingTask(int ms); 00086 bool sendCommand(const Task &task); 00087 AbstractConnectionBackend *nextPendingConnection(); 00088 public slots: 00089 void socketReadyRead(); 00090 void socketDisconnected(); 00091 }; 00092 } 00093 00094 #endif
KDE 4.6 API Reference