home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kio / slave.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  7.2 KB  |  270 lines

  1. // -*- c++ -*-
  2. /*
  3.  *  This file is part of the KDE libraries
  4.  *  Copyright (c) 2000 Waldo Bastian <bastian@kde.org>
  5.  *                2000 Stephan Kulow <coolo@kde.org>
  6.  *
  7.  *  This library is free software; you can redistribute it and/or
  8.  *  modify it under the terms of the GNU Library General Public
  9.  *  License version 2 as published by the Free Software Foundation.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public License
  17.  *  along with this library; see the file COPYING.LIB.  If not, write to
  18.  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.  *  Boston, MA 02110-1301, USA.
  20.  **/
  21.  
  22. #ifndef KIO_SLAVE_H
  23. #define KIO_SLAVE_H
  24.  
  25. #include <time.h>
  26. #include <unistd.h>
  27.  
  28. #include <qobject.h>
  29.  
  30. #include <kurl.h>
  31.  
  32. #include "kio/slaveinterface.h"
  33. #include "kio/connection.h"
  34.  
  35. class KServerSocket;
  36. class KSocket;
  37.  
  38. namespace KIO {
  39.  
  40.     /** Attention developers: If you change the implementation of KIO::Slave,
  41.     * do *not* use connection() or slaveconn but the respective KIO::Slave
  42.     * accessor methods. Otherwise classes derived from Slave might break. (LS)
  43.     */
  44.     class KIO_EXPORT Slave : public KIO::SlaveInterface
  45.     {
  46.     Q_OBJECT
  47.  
  48.     protected:
  49.     /**
  50.      * Use this constructor if you derive your own class from Slave
  51.      * @p derived must be true in any case
  52.      * @internal
  53.      * @since 3.2
  54.      */
  55.     Slave(bool derived, KServerSocket *unixdomain, const QString &protocol,
  56.         const QString &socketname);    // TODO(BIC): Remove in KDE 4
  57.  
  58.     public:
  59.     Slave(KServerSocket *unixdomain,
  60.           const QString &protocol, const QString &socketname);
  61.  
  62.         virtual ~Slave();
  63.  
  64.     void setPID(pid_t);
  65.  
  66.         int slave_pid() { return m_pid; }
  67.  
  68.     /**
  69.      * Force termination
  70.      */
  71.     void kill();
  72.  
  73.         /**
  74.          * @return true if the slave survived the last mission.
  75.          */
  76.         bool isAlive() { return !dead; }
  77.  
  78.         /**
  79.          * Set host for url
  80.          * @param host to connect to.
  81.          * @param port to connect to.
  82.          * @param user to login as
  83.          * @param passwd to login with
  84.          */
  85.         void setHost( const QString &host, int port,
  86.                       const QString &user, const QString &passwd); // TODO(BIC): make virtual
  87.  
  88.         /**
  89.          * Clear host info.
  90.          */
  91.         void resetHost();
  92.  
  93.         /**
  94.          * Configure slave
  95.          */
  96.         void setConfig(const MetaData &config);    // TODO(BIC): make virtual
  97.  
  98.         /**
  99.      * The protocol this slave handles.
  100.      *
  101.          * @return name of protocol handled by this slave, as seen by the user
  102.          */
  103.         QString protocol() { return m_protocol; }
  104.  
  105.         void setProtocol(const QString & protocol);
  106.         /**
  107.      * The actual protocol used to handle the request.
  108.      *
  109.      * This method will return a different protocol than
  110.      * the one obtained by using protocol() if a
  111.      * proxy-server is used for the given protocol.  This
  112.      * usually means that this method will return "http"
  113.      * when the actuall request was to retrieve a resource
  114.      * from an "ftp" server by going through a proxy server.
  115.      *
  116.          * @return the actual protocol (io-slave) that handled the request
  117.          */
  118.         QString slaveProtocol() { return m_slaveProtocol; }
  119.  
  120.         /**
  121.          * @return Host this slave is (was?) connected to
  122.          */
  123.         QString host() { return m_host; }
  124.  
  125.         /**
  126.          * @return port this slave is (was?) connected to
  127.          */
  128.         int port() { return m_port; }
  129.  
  130.         /**
  131.          * @return User this slave is (was?) logged in as
  132.          */
  133.         QString user() { return m_user; }
  134.  
  135.         /**
  136.          * @return Passwd used to log in
  137.          */
  138.         QString passwd() { return m_passwd; }
  139.  
  140.     /**
  141.      * Creates a new slave.
  142.      *
  143.      * @param protocol protocol the slave is for.
  144.      * @param url URL the slave should operate on.
  145.      * @param error is the error code on failure and undefined else.
  146.      * @param error_text is the error text on failure and undefined else.
  147.      *
  148.      * @return 0 on failure, or a pointer to a slave otherwise.
  149.      * @todo What are legal @p protocol values?
  150.      */
  151.     static Slave* createSlave( const QString &protocol, const KURL& url, int& error, QString& error_text );
  152.  
  153.         static Slave* holdSlave( const QString &protocol, const KURL& url );
  154.  
  155.     // == communication with connected kioslave ==
  156.     // whenever possible prefer these methods over the respective
  157.     // methods in connection()
  158.     /**
  159.      * Suspends the operation of the attached kioslave.
  160.      */
  161.         void suspend();        // TODO(BIC): make virtual
  162.     /**
  163.      * Resumes the operation of the attached kioslave.
  164.      */
  165.         void resume();        // TODO(BIC): make virtual
  166.     /**
  167.      * Tells wether the kioslave is suspended.
  168.      * @return true if the kioslave is suspended.
  169.      * @since 3.2
  170.      */
  171.         bool suspended();    // TODO(BIC): make virtual
  172.     /**
  173.      * Sends the given command to the kioslave.
  174.      * @param cmd command id
  175.      * @param data byte array containing data
  176.      * @since 3.2
  177.      */
  178.         void send(int cmd, const QByteArray &data = QByteArray());// TODO(BIC): make virtual
  179.     // == end communication with connected kioslave ==
  180.  
  181.     /**
  182.      * Puts the kioslave associated with @p url at halt.
  183.      */
  184.     void hold(const KURL &url);    // TODO(BIC): make virtual
  185.  
  186.     /**
  187.      * @return The time this slave has been idle.
  188.      */
  189.     time_t idleTime();
  190.  
  191.     /**
  192.      * Marks this slave as idle.
  193.      */
  194.     void setIdle();
  195.  
  196.         /*
  197.          * @returns Whether the slave is connected
  198.          * (Connection oriented slaves only)
  199.          */
  200.         bool isConnected() { return contacted; }
  201.         void setConnected(bool c) { contacted = c; }
  202.  
  203.     /** @deprecated This method is obsolete, use the accessor methods
  204.       * within KIO::Slave instead. Old code directly accessing connection()
  205.       * will not be able to access special protocols.
  206.       */
  207.         KDE_DEPRECATED Connection *connection() { return &slaveconn; }    // TODO(BIC): remove before KDE 4
  208.  
  209.         void ref() { m_refCount++; }
  210.         void deref() { m_refCount--; if (!m_refCount) delete this; }
  211.  
  212.     public slots:
  213.         void accept(KSocket *socket);
  214.     void gotInput();
  215.     void timeout();
  216.     signals:
  217.         void slaveDied(KIO::Slave *slave);
  218.  
  219.     protected:
  220.         void unlinkSocket();
  221.  
  222.     private:
  223.         QString m_protocol;
  224.         QString m_slaveProtocol;
  225.         QString m_host;
  226.         int m_port;
  227.         QString m_user;
  228.         QString m_passwd;
  229.     KServerSocket *serv;
  230.     QString m_socket;
  231.     pid_t m_pid;
  232.     bool contacted;
  233.     bool dead;
  234.     time_t contact_started;
  235.     time_t idle_since;
  236.     KIO::Connection slaveconn;
  237.     int m_refCount;
  238.     protected:
  239.     virtual void virtual_hook( int id, void* data );
  240.     // grant SlaveInterface all IDs < 0x200
  241.     enum { VIRTUAL_SUSPEND = 0x200, VIRTUAL_RESUME, VIRTUAL_SEND,
  242.         VIRTUAL_HOLD, VIRTUAL_SUSPENDED,
  243.         VIRTUAL_SET_HOST, VIRTUAL_SET_CONFIG };
  244.     struct SendParams {
  245.       int cmd;
  246.       const QByteArray *arr;
  247.     };
  248.     struct HoldParams {
  249.       const KURL *url;
  250.     };
  251.     struct SuspendedParams {
  252.       bool retval;
  253.     };
  254.     struct SetHostParams {
  255.       const QString *host;
  256.       int port;
  257.       const QString *user;
  258.       const QString *passwd;
  259.     };
  260.     struct SetConfigParams {
  261.       const MetaData *config;
  262.     };
  263.     private:
  264.     class SlavePrivate* d;
  265.     };
  266.  
  267. }
  268.  
  269. #endif
  270.