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

KIO

  • sources
  • kde-4.14
  • kdelibs
  • kio
  • kio
dataslave.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2003 Leo Savernik <l.savernik@aon.at>
4  * Derived from slave.cpp
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License version 2 as published by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  **/
20 
21 #include "dataslave.h"
22 #include "dataprotocol.h"
23 
24 #include <config.h>
25 
26 #include <klocale.h>
27 #include <kdebug.h>
28 
29 #include <QtCore/QTimer>
30 
31 using namespace KIO;
32 
33 #define KIO_DATA_POLL_INTERVAL 0
34 
35 // don't forget to sync DISPATCH_DECL in dataslave.h
36 #define DISPATCH_IMPL(type) \
37  void DataSlave::dispatch_##type() { \
38  if (_suspended) { \
39  QueueStruct q(Queue_##type); \
40  q.size = -1; \
41  dispatchQueue.push_back(q); \
42  if (!timer->isActive()) timer->start(KIO_DATA_POLL_INTERVAL); \
43  } else \
44  type(); \
45  }
46 
47 // don't forget to sync DISPATCH_DECL1 in dataslave.h
48 #define DISPATCH_IMPL1(type, paramtype, paramname) \
49  void DataSlave::dispatch_##type(paramtype paramname) { \
50  if (_suspended) { \
51  QueueStruct q(Queue_##type); \
52  q.paramname = paramname; \
53  dispatchQueue.push_back(q); \
54  if (!timer->isActive()) timer->start(KIO_DATA_POLL_INTERVAL); \
55  } else \
56  type(paramname); \
57  }
58 
59 
60 DataSlave::DataSlave() :
61  Slave("data")
62 {
63  //kDebug() << this;
64  _suspended = false;
65  timer = new QTimer(this);
66  connect(timer, SIGNAL(timeout()), SLOT(dispatchNext()));
67 }
68 
69 DataSlave::~DataSlave() {
70  //kDebug() << this;
71 }
72 
73 void DataSlave::hold(const KUrl &/*url*/) {
74  // ignored
75 }
76 
77 void DataSlave::suspend() {
78  _suspended = true;
79  //kDebug() << this;
80  timer->stop();
81 }
82 
83 void DataSlave::resume() {
84  _suspended = false;
85  //kDebug() << this;
86  // aarrrgh! This makes the once hyper fast and efficient data protocol
87  // implementation slow as molasses. But it wouldn't work otherwise,
88  // and I don't want to start messing around with threads
89  timer->start(KIO_DATA_POLL_INTERVAL);
90 }
91 
92 // finished is a special case. If we emit it right away, then
93 // TransferJob::start can delete the job even before the end of the method
94 void DataSlave::dispatch_finished() {
95  QueueStruct q(Queue_finished);
96  q.size = -1;
97  dispatchQueue.push_back(q);
98  if (!timer->isActive()) timer->start(KIO_DATA_POLL_INTERVAL);
99 }
100 
101 void DataSlave::dispatchNext() {
102  if (dispatchQueue.empty()) {
103  timer->stop();
104  return;
105  }
106 
107  const QueueStruct &q = dispatchQueue.front();
108  //kDebug() << this << "dispatching" << q.type << dispatchQueue.size() << "left";
109  switch (q.type) {
110  case Queue_mimeType: mimeType(q.s); break;
111  case Queue_totalSize: totalSize(q.size); break;
112  case Queue_sendMetaData: sendMetaData(); break;
113  case Queue_data: data(q.ba); break;
114  case Queue_finished: finished(); break;
115  }/*end switch*/
116 
117  dispatchQueue.pop_front();
118 }
119 
120 void DataSlave::send(int cmd, const QByteArray &arr) {
121  QDataStream stream(arr);
122 
123  KUrl url;
124 
125  switch (cmd) {
126  case CMD_GET: {
127  stream >> url;
128  get(url);
129  break;
130  }
131  case CMD_MIMETYPE: {
132  stream >> url;
133  mimetype(url);
134  break;
135  }
136  // ignore these (must not emit error, otherwise SIGSEGV occurs)
137  case CMD_REPARSECONFIGURATION:
138  case CMD_META_DATA:
139  case CMD_SUBURL:
140  break;
141  default:
142  error(ERR_UNSUPPORTED_ACTION,
143  unsupportedActionErrorString(QLatin1String("data"),cmd));
144  }/*end switch*/
145 }
146 
147 bool DataSlave::suspended() {
148  return _suspended;
149 }
150 
151 void DataSlave::setHost(const QString &/*host*/, quint16 /*port*/,
152  const QString &/*user*/, const QString &/*passwd*/) {
153  // irrelevant -> will be ignored
154 }
155 
156 void DataSlave::setConfig(const MetaData &/*config*/) {
157  // FIXME: decide to handle this directly or not at all
158 #if 0
159  QByteArray data;
160  QDataStream stream( data, QIODevice::WriteOnly );
161  stream << config;
162  slaveconn.send( CMD_CONFIG, data );
163 #endif
164 }
165 
166 void DataSlave::setAllMetaData(const MetaData &md) {
167  meta_data = md;
168 }
169 
170 void DataSlave::sendMetaData() {
171  emit metaData(meta_data);
172 }
173 
174 DISPATCH_IMPL1(mimeType, const QString &, s)
175 DISPATCH_IMPL1(totalSize, KIO::filesize_t, size)
176 DISPATCH_IMPL(sendMetaData)
177 DISPATCH_IMPL1(data, const QByteArray &, ba)
178 
179 #undef DISPATCH_IMPL
180 #undef DISPATCH_IMPL1
181 
182 #include "dataslave.moc"
KIO::DataSlave::sendMetaData
void sendMetaData()
Sends metadata set with setAllMetaData.
Definition: dataslave.cpp:170
KIO::DataSlave::dispatchQueue
DispatchQueue dispatchQueue
Definition: dataslave.h:100
KIO::unsupportedActionErrorString
QString unsupportedActionErrorString(const QString &protocol, int cmd)
Returns an appropriate error message if the given command cmd is an unsupported action (ERR_UNSUPPORT...
Definition: global.cpp:376
KIO::DataSlave::QueueStruct
structure for queuing.
Definition: dataslave.h:90
KIO::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:57
KIO::SlaveInterface::data
void data(const QByteArray &)
kdebug.h
KIO::DataSlave::setConfig
virtual void setConfig(const MetaData &config)
Configure slave.
Definition: dataslave.cpp:156
KIO::CMD_CONFIG
Definition: global.h:177
QList::push_back
void push_back(const T &value)
QByteArray
QDataStream
KIO::DataSlave::suspended
virtual bool suspended()
Tells whether the kioslave is suspended.
Definition: dataslave.cpp:147
KIO::DataSlave::send
virtual void send(int cmd, const QByteArray &arr=QByteArray())
Sends the given command to the kioslave.
Definition: dataslave.cpp:120
KIO::CMD_SUBURL
Definition: global.h:174
DISPATCH_IMPL
#define DISPATCH_IMPL(type)
Definition: dataslave.cpp:36
KIO::SlaveInterface::totalSize
void totalSize(KIO::filesize_t)
KIO::CMD_MIMETYPE
Definition: global.h:162
KIO::DataSlave::QueueStruct::ba
QByteArray ba
Definition: dataslave.h:94
KIO::DataSlave::QueueStruct::type
QueueType type
Definition: dataslave.h:91
DISPATCH_IMPL1
#define DISPATCH_IMPL1(type, paramtype, paramname)
Definition: dataslave.cpp:48
klocale.h
KIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:396
KIO::DataSlave::mimetype
virtual void mimetype(const KUrl &url)=0
KUrl
KIO::Slave
Definition: slave.h:48
KIO::DataSlave::DataSlave
DataSlave()
Definition: dataslave.cpp:60
KIO::CMD_META_DATA
Definition: global.h:172
config
KSharedConfigPtr config()
KIO::DataSlave::setAllMetaData
void setAllMetaData(const MetaData &)
Sets metadata.
Definition: dataslave.cpp:166
KIO::SlaveInterface::finished
void finished()
dataprotocol.h
QList::empty
bool empty() const
QList::pop_front
void pop_front()
QTimer
KIO::DataSlave::hold
virtual void hold(const KUrl &url)
Puts the kioslave associated with url at halt, and return it to klauncher, in order to let another ap...
Definition: dataslave.cpp:73
KIO_DATA_POLL_INTERVAL
#define KIO_DATA_POLL_INTERVAL
Definition: dataslave.cpp:33
KIO::DataSlave::Queue_sendMetaData
Definition: dataslave.h:86
KIO::DataSlave::resume
virtual void resume()
Resumes the operation of the attached kioslave.
Definition: dataslave.cpp:83
QList::front
T & front()
QString
KIO::Slave::timeout
void timeout()
Definition: slave.cpp:123
KIO::DataSlave::Queue_finished
Definition: dataslave.h:86
QTimer::stop
void stop()
KIO::SlaveInterface::mimeType
void mimeType(const QString &)
KIO::DataSlave::QueueStruct::s
QString s
Definition: dataslave.h:92
KIO::DataSlave::Queue_data
Definition: dataslave.h:86
dataslave.h
KIO::DataSlave::Queue_totalSize
Definition: dataslave.h:85
QLatin1String
KIO::DataSlave::suspend
virtual void suspend()
Suspends the operation of the attached kioslave.
Definition: dataslave.cpp:77
KIO::SlaveInterface::error
void error(int, const QString &)
KIO::ERR_UNSUPPORTED_ACTION
Definition: global.h:202
KIO::DataSlave::Queue_mimeType
Definition: dataslave.h:85
KIO::SlaveInterface::metaData
void metaData(const KIO::MetaData &)
QTimer::start
void start(int msec)
KIO::DataSlave::~DataSlave
virtual ~DataSlave()
Definition: dataslave.cpp:69
QTimer::isActive
bool isActive() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KIO::DataSlave::dispatchNext
void dispatchNext()
dispatches next queued method.
Definition: dataslave.cpp:101
KIO::DataSlave::setHost
virtual void setHost(const QString &host, quint16 port, const QString &user, const QString &passwd)
Set host for url.
Definition: dataslave.cpp:151
KIO::DataSlave::QueueStruct::size
KIO::filesize_t size
Definition: dataslave.h:93
KIO::CMD_REPARSECONFIGURATION
Definition: global.h:171
KIO::CMD_GET
Definition: global.h:159
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

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 API Reference

Skip menu "kdelibs API Reference"
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal