dataslave.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "dataslave.h"
00024 #include "dataprotocol.h"
00025
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028
00029 #include <qtimer.h>
00030
00031 using namespace KIO;
00032
00033 #define KIO_DATA_POLL_INTERVAL 0
00034
00035
00036 #define DISPATCH_IMPL(type) \
00037 void DataSlave::dispatch_##type() { \
00038 if (_suspended) { \
00039 QueueStruct q(Queue_##type); \
00040 dispatchQueue.push_back(q); \
00041 if (!timer->isActive()) timer->start(KIO_DATA_POLL_INTERVAL); \
00042 } else \
00043 type(); \
00044 }
00045
00046
00047 #define DISPATCH_IMPL1(type, paramtype, paramname) \
00048 void DataSlave::dispatch_##type(paramtype paramname) { \
00049 if (_suspended) { \
00050 QueueStruct q(Queue_##type); \
00051 q.paramname = paramname; \
00052 dispatchQueue.push_back(q); \
00053 if (!timer->isActive()) timer->start(KIO_DATA_POLL_INTERVAL); \
00054 } else \
00055 type(paramname); \
00056 }
00057
00058
00059 DataSlave::DataSlave() :
00060 Slave(true, 0, "data", QString::null)
00061 {
00062 _suspended = false;
00063 timer = new QTimer(this);
00064 connect(timer, SIGNAL(timeout()), SLOT(dispatchNext()));
00065 }
00066
00067 DataSlave::~DataSlave() {
00068 }
00069
00070 void DataSlave::hold(const KURL &) {
00071
00072 }
00073
00074 void DataSlave::suspend() {
00075 _suspended = true;
00076
00077 timer->stop();
00078 }
00079
00080 void DataSlave::resume() {
00081 _suspended = false;
00082
00083
00084
00085
00086 timer->start(KIO_DATA_POLL_INTERVAL);
00087 }
00088
00089 void DataSlave::dispatchNext() {
00090 if (dispatchQueue.empty()) {
00091 timer->stop();
00092 return;
00093 }
00094
00095 const QueueStruct &q = dispatchQueue.front();
00096
00097 switch (q.type) {
00098 case Queue_mimeType: mimeType(q.s); break;
00099 case Queue_totalSize: totalSize(q.size); break;
00100 case Queue_sendMetaData: sendMetaData(); break;
00101 case Queue_data: data(q.ba); break;
00102 case Queue_finished: finished(); break;
00103 }
00104
00105 dispatchQueue.pop_front();
00106 }
00107
00108 void DataSlave::send(int cmd, const QByteArray &arr) {
00109 QDataStream stream(arr, IO_ReadOnly);
00110
00111 KURL url;
00112
00113 switch (cmd) {
00114 case CMD_GET: {
00115 stream >> url;
00116 get(url);
00117 break;
00118 }
00119 case CMD_MIMETYPE: {
00120 stream >> url;
00121 mimetype(url);
00122 break;
00123 }
00124
00125 case CMD_META_DATA:
00126 case CMD_SUBURL:
00127 break;
00128 default:
00129 error(ERR_UNSUPPORTED_ACTION,
00130 unsupportedActionErrorString(QString::fromLatin1("data"),cmd));
00131 }
00132 }
00133
00134 bool DataSlave::suspended() {
00135 return _suspended;
00136 }
00137
00138 void DataSlave::setHost(const QString &, int ,
00139 const QString &, const QString &) {
00140
00141 }
00142
00143 void DataSlave::setConfig(const MetaData &) {
00144
00145 #if 0
00146 QByteArray data;
00147 QDataStream stream( data, IO_WriteOnly );
00148 stream << config;
00149 slaveconn.send( CMD_CONFIG, data );
00150 #endif
00151 }
00152
00153 void DataSlave::setAllMetaData(const MetaData &md) {
00154 meta_data = md;
00155 }
00156
00157 void DataSlave::sendMetaData() {
00158 emit metaData(meta_data);
00159 }
00160
00161 void DataSlave::virtual_hook( int id, void* data ) {
00162 switch (id) {
00163 case VIRTUAL_SUSPEND: suspend(); return;
00164 case VIRTUAL_RESUME: resume(); return;
00165 case VIRTUAL_SEND: {
00166 SendParams *params = reinterpret_cast<SendParams *>(data);
00167 send(params->cmd, *params->arr);
00168 return;
00169 }
00170 case VIRTUAL_HOLD: {
00171 HoldParams *params = reinterpret_cast<HoldParams *>(data);
00172 hold(*params->url);
00173 return;
00174 }
00175 case VIRTUAL_SUSPENDED: {
00176 SuspendedParams *params = reinterpret_cast<SuspendedParams *>(data);
00177 params->retval = suspended();
00178 return;
00179 }
00180 case VIRTUAL_SET_HOST: {
00181 SetHostParams *params = reinterpret_cast<SetHostParams *>(data);
00182 setHost(*params->host,params->port,*params->user,*params->passwd);
00183 return;
00184 }
00185 case VIRTUAL_SET_CONFIG: {
00186 SetConfigParams *params = reinterpret_cast<SetConfigParams *>(data);
00187 setConfig(*params->config);
00188 return;
00189 }
00190 default:
00191 KIO::Slave::virtual_hook( id, data );
00192 }
00193 }
00194
00195 DISPATCH_IMPL1(mimeType, const QString &, s)
00196 DISPATCH_IMPL1(totalSize, KIO::filesize_t, size)
00197 DISPATCH_IMPL(sendMetaData)
00198 DISPATCH_IMPL1(data, const QByteArray &, ba)
00199 DISPATCH_IMPL(finished)
00200
00201 #undef DISPATCH_IMPL
00202 #undef DISPATCH_IMPL1
00203
00204 #include "dataslave.moc"
This file is part of the documentation for kio Library Version 3.3.2.