• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KIO

dataslave.cpp
Go to the documentation of this file.
00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2003 Leo Savernik <l.savernik@aon.at>
00004  *  Derived from slave.cpp
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License version 2 as published by the Free Software Foundation.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Library General Public License
00016  *  along with this library; see the file COPYING.LIB.  If not, write to
00017  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  *  Boston, MA 02110-1301, USA.
00019  **/
00020 
00021 #include "dataslave.h"
00022 #include "dataprotocol.h"
00023 
00024 #include <config.h>
00025 
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028 
00029 #include <QtCore/QTimer>
00030 
00031 using namespace KIO;
00032 
00033 #define KIO_DATA_POLL_INTERVAL 0
00034 
00035 // don't forget to sync DISPATCH_DECL in dataslave.h
00036 #define DISPATCH_IMPL(type) \
00037     void DataSlave::dispatch_##type() { \
00038       if (_suspended) { \
00039         QueueStruct q(Queue_##type); \
00040         q.size = -1; \
00041         dispatchQueue.push_back(q); \
00042         if (!timer->isActive()) timer->start(KIO_DATA_POLL_INTERVAL); \
00043       } else \
00044         type(); \
00045     }
00046 
00047 // don't forget to sync DISPATCH_DECL1 in dataslave.h
00048 #define DISPATCH_IMPL1(type, paramtype, paramname) \
00049     void DataSlave::dispatch_##type(paramtype paramname) { \
00050       if (_suspended) { \
00051         QueueStruct q(Queue_##type); \
00052         q.paramname = paramname; \
00053         dispatchQueue.push_back(q); \
00054         if (!timer->isActive()) timer->start(KIO_DATA_POLL_INTERVAL); \
00055       } else \
00056         type(paramname); \
00057     }
00058 
00059 
00060 DataSlave::DataSlave() :
00061     Slave("data")
00062 {
00063   //kDebug() << this;
00064   _suspended = false;
00065   timer = new QTimer(this);
00066   connect(timer, SIGNAL(timeout()), SLOT(dispatchNext()));
00067 }
00068 
00069 DataSlave::~DataSlave() {
00070   //kDebug() << this;
00071 }
00072 
00073 void DataSlave::hold(const KUrl &/*url*/) {
00074   // ignored
00075 }
00076 
00077 void DataSlave::suspend() {
00078   _suspended = true;
00079   //kDebug() << this;
00080   timer->stop();
00081 }
00082 
00083 void DataSlave::resume() {
00084   _suspended = false;
00085   //kDebug() << this;
00086   // aarrrgh! This makes the once hyper fast and efficient data protocol
00087   // implementation slow as molasses. But it wouldn't work otherwise,
00088   // and I don't want to start messing around with threads
00089   timer->start(KIO_DATA_POLL_INTERVAL);
00090 }
00091 
00092 // finished is a special case. If we emit it right away, then
00093 // TransferJob::start can delete the job even before the end of the method
00094 void DataSlave::dispatch_finished() {
00095     QueueStruct q(Queue_finished);
00096     q.size = -1;
00097     dispatchQueue.push_back(q);
00098     if (!timer->isActive()) timer->start(KIO_DATA_POLL_INTERVAL);
00099 }
00100 
00101 void DataSlave::dispatchNext() {
00102   if (dispatchQueue.empty()) {
00103     timer->stop();
00104     return;
00105   }
00106 
00107   const QueueStruct &q = dispatchQueue.front();
00108   //kDebug() << this << "dispatching" << q.type << dispatchQueue.size() << "left";
00109   switch (q.type) {
00110     case Queue_mimeType:    mimeType(q.s); break;
00111     case Queue_totalSize:   totalSize(q.size); break;
00112     case Queue_sendMetaData:    sendMetaData(); break;
00113     case Queue_data:        data(q.ba); break;
00114     case Queue_finished:    finished(); break;
00115   }/*end switch*/
00116 
00117   dispatchQueue.pop_front();
00118 }
00119 
00120 void DataSlave::send(int cmd, const QByteArray &arr) {
00121   QDataStream stream(arr);
00122 
00123   KUrl url;
00124 
00125   switch (cmd) {
00126     case CMD_GET: {
00127       stream >> url;
00128       get(url);
00129       break;
00130     }
00131     case CMD_MIMETYPE: {
00132       stream >> url;
00133       mimetype(url);
00134       break;
00135     }
00136     // ignore these (must not emit error, otherwise SIGSEGV occurs)
00137     case CMD_META_DATA:
00138     case CMD_SUBURL:
00139       break;
00140     default:
00141       error(ERR_UNSUPPORTED_ACTION,
00142         unsupportedActionErrorString(QLatin1String("data"),cmd));
00143   }/*end switch*/
00144 }
00145 
00146 bool DataSlave::suspended() {
00147   return _suspended;
00148 }
00149 
00150 void DataSlave::setHost(const QString &/*host*/, quint16 /*port*/,
00151                      const QString &/*user*/, const QString &/*passwd*/) {
00152   // irrelevant -> will be ignored
00153 }
00154 
00155 void DataSlave::setConfig(const MetaData &/*config*/) {
00156   // FIXME: decide to handle this directly or not at all
00157 #if 0
00158     QByteArray data;
00159     QDataStream stream( data, QIODevice::WriteOnly );
00160     stream << config;
00161     slaveconn.send( CMD_CONFIG, data );
00162 #endif
00163 }
00164 
00165 void DataSlave::setAllMetaData(const MetaData &md) {
00166   meta_data = md;
00167 }
00168 
00169 void DataSlave::sendMetaData() {
00170   emit metaData(meta_data);
00171 }
00172 
00173 DISPATCH_IMPL1(mimeType, const QString &, s)
00174 DISPATCH_IMPL1(totalSize, KIO::filesize_t, size)
00175 DISPATCH_IMPL(sendMetaData)
00176 DISPATCH_IMPL1(data, const QByteArray &, ba)
00177 
00178 #undef DISPATCH_IMPL
00179 #undef DISPATCH_IMPL1
00180 
00181 #include "dataslave.moc"

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal