slave.h
00001 // -*- c++ -*- 00002 /* 00003 * This file is part of the KDE libraries 00004 * Copyright (c) 2000 Waldo Bastian <bastian@kde.org> 00005 * 2000 Stephan Kulow <coolo@kde.org> 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Library General Public 00009 * License version 2 as published by the Free Software Foundation. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 **/ 00021 00022 #ifndef TDEIO_SLAVE_H 00023 #define TDEIO_SLAVE_H 00024 00025 #include <time.h> 00026 #include <unistd.h> 00027 00028 #include <tqobject.h> 00029 00030 #include <kurl.h> 00031 00032 #include "tdeio/slaveinterface.h" 00033 #include "tdeio/connection.h" 00034 00035 class TDEServerSocket; 00036 class TDESocket; 00037 00038 namespace TDEIO { 00039 00044 class TDEIO_EXPORT Slave : public TDEIO::SlaveInterface 00045 { 00046 Q_OBJECT 00047 00048 00049 protected: 00056 Slave(bool derived, TDEServerSocket *unixdomain, const TQString &protocol, 00057 const TQString &socketname); // TODO(BIC): Remove in KDE 4 00058 00059 public: 00060 Slave(TDEServerSocket *unixdomain, 00061 const TQString &protocol, const TQString &socketname); 00062 00063 virtual ~Slave(); 00064 00065 void setPID(pid_t); 00066 00067 int slave_pid() { return m_pid; } 00068 00072 void kill(); 00073 00077 bool isAlive() { return !dead; } 00078 00086 void setHost( const TQString &host, int port, 00087 const TQString &user, const TQString &passwd); // TODO(BIC): make virtual 00088 00092 void resetHost(); 00093 00097 void setConfig(const MetaData &config); // TODO(BIC): make virtual 00098 00104 TQString protocol() { return m_protocol; } 00105 00106 void setProtocol(const TQString & protocol); 00119 TQString slaveProtocol() { return m_slaveProtocol; } 00120 00124 TQString host() { return m_host; } 00125 00129 int port() { return m_port; } 00130 00134 TQString user() { return m_user; } 00135 00139 TQString passwd() { return m_passwd; } 00140 00152 static Slave* createSlave( const TQString &protocol, const KURL& url, int& error, TQString& error_text ); 00153 00154 static Slave* holdSlave( const TQString &protocol, const KURL& url ); 00155 00156 // == communication with connected tdeioslave == 00157 // whenever possible prefer these methods over the respective 00158 // methods in connection() 00162 void suspend(); // TODO(BIC): make virtual 00166 void resume(); // TODO(BIC): make virtual 00172 bool suspended(); // TODO(BIC): make virtual 00179 void send(int cmd, const TQByteArray &data = TQByteArray());// TODO(BIC): make virtual 00180 // == end communication with connected tdeioslave == 00181 00185 void hold(const KURL &url); // TODO(BIC): make virtual 00186 00190 time_t idleTime(); 00191 00195 void setIdle(); 00196 00197 /* 00198 * @returns Whether the slave is connected 00199 * (Connection oriented slaves only) 00200 */ 00201 bool isConnected() { return contacted; } 00202 void setConnected(bool c) { contacted = c; } 00203 00208 KDE_DEPRECATED Connection *connection() { return &slaveconn; } // TODO(BIC): remove before KDE 4 00209 00210 void ref() { m_refCount++; } 00211 void deref() { m_refCount--; if (!m_refCount) delete this; } 00212 00213 public slots: 00214 void accept(TDESocket *socket); 00215 void gotInput(); 00216 void timeout(); 00217 signals: 00218 void slaveDied(TDEIO::Slave *slave); 00219 00220 protected: 00221 void unlinkSocket(); 00222 00223 private: 00224 TQString m_protocol; 00225 TQString m_slaveProtocol; 00226 TQString m_host; 00227 int m_port; 00228 TQString m_user; 00229 TQString m_passwd; 00230 TDEServerSocket *serv; 00231 TQString m_socket; 00232 pid_t m_pid; 00233 bool contacted; 00234 bool dead; 00235 time_t contact_started; 00236 time_t idle_since; 00237 TDEIO::Connection slaveconn; 00238 int m_refCount; 00239 protected: 00240 virtual void virtual_hook( int id, void* data ); 00241 // grant SlaveInterface all IDs < 0x200 00242 enum { VIRTUAL_SUSPEND = 0x200, VIRTUAL_RESUME, VIRTUAL_SEND, 00243 VIRTUAL_HOLD, VIRTUAL_SUSPENDED, 00244 VIRTUAL_SET_HOST, VIRTUAL_SET_CONFIG }; 00245 struct SendParams { 00246 int cmd; 00247 const TQByteArray *arr; 00248 }; 00249 struct HoldParams { 00250 const KURL *url; 00251 }; 00252 struct SuspendedParams { 00253 bool retval; 00254 }; 00255 struct SetHostParams { 00256 const TQString *host; 00257 int port; 00258 const TQString *user; 00259 const TQString *passwd; 00260 }; 00261 struct SetConfigParams { 00262 const MetaData *config; 00263 }; 00264 private: 00265 class SlavePrivate* d; 00266 }; 00267 00268 } 00269 00270 #endif