• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
dataslave.cpp
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 <config.h>
22 
23 #include "dataslave.h"
24 #include "dataprotocol.h"
25 
26 #include <tdelocale.h>
27 #include <kdebug.h>
28 
29 #include <tqtimer.h>
30 
31 using namespace TDEIO;
32 
33 #define TDEIO_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  dispatchQueue.push_back(q); \
41  if (!timer->isActive()) timer->start(TDEIO_DATA_POLL_INTERVAL); \
42  } else \
43  type(); \
44  }
45 
46 // don't forget to sync DISPATCH_DECL1 in dataslave.h
47 #define DISPATCH_IMPL1(type, paramtype, paramname) \
48  void DataSlave::dispatch_##type(paramtype paramname) { \
49  if (_suspended) { \
50  QueueStruct q(Queue_##type); \
51  q.paramname = paramname; \
52  dispatchQueue.push_back(q); \
53  if (!timer->isActive()) timer->start(TDEIO_DATA_POLL_INTERVAL); \
54  } else \
55  type(paramname); \
56  }
57 
58 
59 DataSlave::DataSlave() :
60  Slave(true, 0, "data", TQString::null)
61 {
62  //kdDebug() << this << k_funcinfo << endl;
63  _suspended = false;
64  timer = new TQTimer(this);
65  connect(timer, TQ_SIGNAL(timeout()), TQ_SLOT(dispatchNext()));
66 }
67 
68 DataSlave::~DataSlave() {
69  //kdDebug() << this << k_funcinfo << endl;
70 }
71 
72 void DataSlave::hold(const KURL &/*url*/) {
73  // ignored
74 }
75 
76 void DataSlave::suspend() {
77  _suspended = true;
78  //kdDebug() << this << k_funcinfo << endl;
79  timer->stop();
80 }
81 
82 void DataSlave::resume() {
83  _suspended = false;
84  //kdDebug() << this << k_funcinfo << endl;
85  // aarrrgh! This makes the once hyper fast and efficient data protocol
86  // implementation slow as molasses. But it wouldn't work otherwise,
87  // and I don't want to start messing around with threads
88  timer->start(TDEIO_DATA_POLL_INTERVAL);
89 }
90 
91 // finished is a special case. If we emit it right away, then
92 // TransferJob::start can delete the job even before the end of the method
93 void DataSlave::dispatch_finished() {
94  QueueStruct q(Queue_finished);
95  dispatchQueue.push_back(q);
96  if (!timer->isActive()) timer->start(TDEIO_DATA_POLL_INTERVAL);
97 }
98 
99 void DataSlave::dispatchNext() {
100  if (dispatchQueue.empty()) {
101  timer->stop();
102  return;
103  }
104 
105  const QueueStruct &q = dispatchQueue.front();
106  //kdDebug() << this << k_funcinfo << "dispatching " << q.type << " " << dispatchQueue.size() << " left" << endl;
107  switch (q.type) {
108  case Queue_mimeType: mimeType(q.s); break;
109  case Queue_totalSize: totalSize(q.size); break;
110  case Queue_sendMetaData: sendMetaData(); break;
111  case Queue_data: data(q.ba); break;
112  case Queue_finished: finished(); break;
113  }/*end switch*/
114 
115  dispatchQueue.pop_front();
116 }
117 
118 void DataSlave::send(int cmd, const TQByteArray &arr) {
119  TQDataStream stream(arr, IO_ReadOnly);
120 
121  KURL url;
122 
123  switch (cmd) {
124  case CMD_GET: {
125  stream >> url;
126  get(url);
127  break;
128  }
129  case CMD_MIMETYPE: {
130  stream >> url;
131  mimetype(url);
132  break;
133  }
134  // ignore these (must not emit error, otherwise SIGSEGV occurs)
135  case CMD_META_DATA:
136  case CMD_SUBURL:
137  break;
138  default:
139  error(ERR_UNSUPPORTED_ACTION,
140  unsupportedActionErrorString(TQString::fromLatin1("data"),cmd));
141  }/*end switch*/
142 }
143 
144 bool DataSlave::suspended() {
145  return _suspended;
146 }
147 
148 void DataSlave::setHost(const TQString &/*host*/, int /*port*/,
149  const TQString &/*user*/, const TQString &/*passwd*/) {
150  // irrelevant -> will be ignored
151 }
152 
153 void DataSlave::setConfig(const MetaData &/*config*/) {
154  // FIXME: decide to handle this directly or not at all
155 #if 0
156  TQByteArray data;
157  TQDataStream stream( data, IO_WriteOnly );
158  stream << config;
159  slaveconn.send( CMD_CONFIG, data );
160 #endif
161 }
162 
163 void DataSlave::setAllMetaData(const MetaData &md) {
164  meta_data = md;
165 }
166 
167 void DataSlave::sendMetaData() {
168  emit metaData(meta_data);
169 }
170 
171 void DataSlave::virtual_hook( int id, void* data ) {
172  switch (id) {
173  case VIRTUAL_SUSPEND: suspend(); return;
174  case VIRTUAL_RESUME: resume(); return;
175  case VIRTUAL_SEND: {
176  SendParams *params = reinterpret_cast<SendParams *>(data);
177  send(params->cmd, *params->arr);
178  return;
179  }
180  case VIRTUAL_HOLD: {
181  HoldParams *params = reinterpret_cast<HoldParams *>(data);
182  hold(*params->url);
183  return;
184  }
185  case VIRTUAL_SUSPENDED: {
186  SuspendedParams *params = reinterpret_cast<SuspendedParams *>(data);
187  params->retval = suspended();
188  return;
189  }
190  case VIRTUAL_SET_HOST: {
191  SetHostParams *params = reinterpret_cast<SetHostParams *>(data);
192  setHost(*params->host,params->port,*params->user,*params->passwd);
193  return;
194  }
195  case VIRTUAL_SET_CONFIG: {
196  SetConfigParams *params = reinterpret_cast<SetConfigParams *>(data);
197  setConfig(*params->config);
198  return;
199  }
200  default:
201  TDEIO::Slave::virtual_hook( id, data );
202  }
203 }
204 
205 DISPATCH_IMPL1(mimeType, const TQString &, s)
206 DISPATCH_IMPL1(totalSize, TDEIO::filesize_t, size)
207 DISPATCH_IMPL(sendMetaData)
208 DISPATCH_IMPL1(data, const TQByteArray &, ba)
209 
210 #undef DISPATCH_IMPL
211 #undef DISPATCH_IMPL1
212 
213 #include "dataslave.moc"
TDEIO::DataSlave::dispatchNext
void dispatchNext()
dispatches next queued method.
Definition: dataslave.cpp:99
TDEIO::DataSlave::setAllMetaData
void setAllMetaData(const MetaData &)
Sets metadata.
Definition: dataslave.cpp:163
TDEIO::DataSlave::sendMetaData
void sendMetaData()
Sends metadata set with setAllMetaData.
Definition: dataslave.cpp:167
TDEIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:516
TDEIO::Slave
Attention developers: If you change the implementation of TDEIO::Slave, do not use connection() or sl...
Definition: slave.h:44
TDEIO
A namespace for TDEIO globals.
Definition: authinfo.h:29
TDEIO::unsupportedActionErrorString
TDEIO_EXPORT TQString unsupportedActionErrorString(const TQString &protocol, int cmd)
Returns an appropriate error message if the given command cmd is an unsupported action (ERR_UNSUPPORT...
Definition: global.cpp:439
TDEIO::filesize_t
TQ_ULLONG filesize_t
64-bit file size
Definition: global.h:39
TDEIO::DataSlave::QueueStruct
structure for queueing.
Definition: dataslave.h:89

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.1
This website is maintained by Timothy Pearson.