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

KIO

  • 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
31using 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
60DataSlave::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
69DataSlave::~DataSlave() {
70 //kDebug() << this;
71}
72
73void DataSlave::hold(const KUrl &/*url*/) {
74 // ignored
75}
76
77void DataSlave::suspend() {
78 _suspended = true;
79 //kDebug() << this;
80 timer->stop();
81}
82
83void 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
94void 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
101void 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
120void 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
147bool DataSlave::suspended() {
148 return _suspended;
149}
150
151void DataSlave::setHost(const QString &/*host*/, quint16 /*port*/,
152 const QString &/*user*/, const QString &/*passwd*/) {
153 // irrelevant -> will be ignored
154}
155
156void 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
166void DataSlave::setAllMetaData(const MetaData &md) {
167 meta_data = md;
168}
169
170void DataSlave::sendMetaData() {
171 emit metaData(meta_data);
172}
173
174DISPATCH_IMPL1(mimeType, const QString &, s)
175DISPATCH_IMPL1(totalSize, KIO::filesize_t, size)
176DISPATCH_IMPL(sendMetaData)
177DISPATCH_IMPL1(data, const QByteArray &, ba)
178
179#undef DISPATCH_IMPL
180#undef DISPATCH_IMPL1
181
182#include "dataslave.moc"
KIO::DataSlave::get
virtual void get(const KUrl &url)=0
KIO::DataSlave::dispatchNext
void dispatchNext()
dispatches next queued method.
Definition: dataslave.cpp:101
KIO::DataSlave::setConfig
virtual void setConfig(const MetaData &config)
Configure slave.
Definition: dataslave.cpp:156
KIO::DataSlave::~DataSlave
virtual ~DataSlave()
Definition: dataslave.cpp:69
KIO::DataSlave::Queue_totalSize
@ Queue_totalSize
Definition: dataslave.h:85
KIO::DataSlave::Queue_mimeType
@ Queue_mimeType
Definition: dataslave.h:85
KIO::DataSlave::Queue_finished
@ Queue_finished
Definition: dataslave.h:86
KIO::DataSlave::Queue_sendMetaData
@ Queue_sendMetaData
Definition: dataslave.h:86
KIO::DataSlave::Queue_data
@ Queue_data
Definition: dataslave.h:86
KIO::DataSlave::DataSlave
DataSlave()
Definition: dataslave.cpp:60
KIO::DataSlave::suspended
virtual bool suspended()
Tells whether the kioslave is suspended.
Definition: dataslave.cpp:147
KIO::DataSlave::setAllMetaData
void setAllMetaData(const MetaData &)
Sets metadata.
Definition: dataslave.cpp:166
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::DataSlave::send
virtual void send(int cmd, const QByteArray &arr=QByteArray())
Sends the given command to the kioslave.
Definition: dataslave.cpp:120
KIO::DataSlave::suspend
virtual void suspend()
Suspends the operation of the attached kioslave.
Definition: dataslave.cpp:77
KIO::DataSlave::resume
virtual void resume()
Resumes the operation of the attached kioslave.
Definition: dataslave.cpp:83
KIO::DataSlave::mimetype
virtual void mimetype(const KUrl &url)=0
KIO::DataSlave::sendMetaData
void sendMetaData()
Sends metadata set with setAllMetaData.
Definition: dataslave.cpp:170
KIO::DataSlave::dispatchQueue
DispatchQueue dispatchQueue
Definition: dataslave.h:100
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::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:397
KIO::SlaveInterface::totalSize
void totalSize(KIO::filesize_t)
KIO::SlaveInterface::finished
void finished()
KIO::SlaveInterface::metaData
void metaData(const KIO::MetaData &)
KIO::SlaveInterface::data
void data(const QByteArray &)
KIO::SlaveInterface::mimeType
void mimeType(const QString &)
KIO::SlaveInterface::error
void error(int, const QString &)
KIO::Slave
Definition: slave.h:49
KIO::Slave::timeout
void timeout()
Definition: slave.cpp:123
KUrl
dataprotocol.h
KIO_DATA_POLL_INTERVAL
#define KIO_DATA_POLL_INTERVAL
Definition: dataslave.cpp:33
DISPATCH_IMPL1
#define DISPATCH_IMPL1(type, paramtype, paramname)
Definition: dataslave.cpp:48
DISPATCH_IMPL
#define DISPATCH_IMPL(type)
Definition: dataslave.cpp:36
dataslave.h
kdebug.h
klocale.h
config
KSharedConfigPtr config()
KIO
A namespace for KIO globals.
Definition: kbookmarkmenu.h:55
KIO::CMD_SUBURL
@ CMD_SUBURL
Definition: global.h:174
KIO::CMD_CONFIG
@ CMD_CONFIG
Definition: global.h:177
KIO::CMD_REPARSECONFIGURATION
@ CMD_REPARSECONFIGURATION
Definition: global.h:171
KIO::CMD_META_DATA
@ CMD_META_DATA
Definition: global.h:172
KIO::CMD_GET
@ CMD_GET
Definition: global.h:159
KIO::CMD_MIMETYPE
@ CMD_MIMETYPE
Definition: global.h:162
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::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:57
KIO::ERR_UNSUPPORTED_ACTION
@ ERR_UNSUPPORTED_ACTION
Definition: global.h:202
KIO::DataSlave::QueueStruct
structure for queuing.
Definition: dataslave.h:90
KIO::DataSlave::QueueStruct::ba
QByteArray ba
Definition: dataslave.h:94
KIO::DataSlave::QueueStruct::size
KIO::filesize_t size
Definition: dataslave.h:93
KIO::DataSlave::QueueStruct::s
QString s
Definition: dataslave.h:92
KIO::DataSlave::QueueStruct::type
QueueType type
Definition: dataslave.h:91
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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