1 // -*- c++ -*- 2 /* 3 This file is part of the KDE libraries 4 SPDX-FileCopyrightText: 2003 Leo Savernik <l.savernik@aon.at> 5 Derived from slave.h 6 7 SPDX-License-Identifier: LGPL-2.0-only 8 */ 9 10 #ifndef KIO_DATASLAVE_P_H 11 #define KIO_DATASLAVE_P_H 12 13 #include "global.h" 14 #include "slave.h" 15 16 class QTimer; 17 18 // don't forget to sync DISPATCH_IMPL in dataslave_p.h 19 #define DISPATCH_DECL(type) void dispatch_##type(); 20 21 // don't forget to sync DISPATCH_IMPL1 in dataslave_p.h 22 #define DISPATCH_DECL1(type, paramtype, param) void dispatch_##type(paramtype param); 23 24 namespace KIO 25 { 26 /** 27 * This class provides a high performance implementation for the data 28 * url scheme (rfc2397). 29 * 30 * @internal 31 * Do not use this class in external applications. It is an implementation 32 * detail of KIO and subject to change without notice. 33 * @author Leo Savernik 34 */ 35 class DataSlave : public KIO::Slave 36 { 37 Q_OBJECT 38 public: 39 DataSlave(); 40 41 ~DataSlave() override; 42 43 virtual void setHost(const QString &host, quint16 port, const QString &user, const QString &passwd) override; 44 void setConfig(const MetaData &config) override; 45 46 void suspend() override; 47 void resume() override; 48 bool suspended() override; 49 void send(int cmd, const QByteArray &arr = QByteArray()) override; 50 51 void hold(const QUrl &url) override; 52 53 // pure virtual methods that are defined by the actual protocol 54 virtual void get(const QUrl &url) = 0; 55 virtual void mimetype(const QUrl &url) = 0; 56 57 protected: 58 /** 59 * Sets metadata 60 * @internal 61 */ 62 void setAllMetaData(const MetaData &); 63 /** 64 * Sends metadata set with setAllMetaData 65 * @internal 66 */ 67 void sendMetaData(); 68 69 // queuing methods 70 /** identifiers of functions to be queued */ 71 enum QueueType { 72 Queue_mimeType = 1, 73 Queue_totalSize, 74 Queue_sendMetaData, 75 Queue_data, 76 Queue_finished, 77 }; 78 /** structure for queuing. It is very primitive, it doesn't 79 * even try to conserve memory. 80 */ 81 struct QueueStruct { 82 QueueType type; 83 QString s; 84 KIO::filesize_t size; 85 QByteArray ba; 86 QueueStructQueueStruct87 QueueStruct() 88 { 89 } QueueStructQueueStruct90 QueueStruct(QueueType type) 91 : type(type) 92 { 93 } 94 }; 95 typedef QList<QueueStruct> DispatchQueue; 96 DispatchQueue dispatchQueue; 97 98 DISPATCH_DECL1(mimeType, const QString &, s) 99 DISPATCH_DECL1(totalSize, KIO::filesize_t, size) 100 DISPATCH_DECL(sendMetaData) 101 DISPATCH_DECL1(data, const QByteArray &, ba) 102 DISPATCH_DECL(finished) 103 104 protected Q_SLOTS: 105 /** dispatches next queued method. Does nothing if there are no 106 * queued methods. 107 */ 108 void dispatchNext(); 109 110 private: 111 MetaData meta_data; 112 bool _suspended; 113 QTimer *timer; 114 }; 115 116 } 117 118 #undef DISPATCH_DECL 119 #undef DISPATCH_DECL1 120 121 #endif 122