| 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 worker_p.h |
| 6 | |
| 7 | SPDX-License-Identifier: LGPL-2.0-only |
| 8 | */ |
| 9 | |
| 10 | #ifndef KIO_DATAWORKER_P_H |
| 11 | #define KIO_DATAWORKER_P_H |
| 12 | |
| 13 | #include "global.h" |
| 14 | #include "worker_p.h" |
| 15 | |
| 16 | class QTimer; |
| 17 | |
| 18 | // don't forget to sync DISPATCH_IMPL in dataworker.cpp |
| 19 | #define DISPATCH_DECL(type) void dispatch_##type(); |
| 20 | |
| 21 | // don't forget to sync DISPATCH_IMPL1 in dataworker.cpp |
| 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 | */ |
| 34 | class DataWorker : public KIO::Worker |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | public: |
| 38 | DataWorker(); |
| 39 | |
| 40 | ~DataWorker() override; |
| 41 | |
| 42 | void setHost(const QString &host, quint16 port, const QString &user, const QString &passwd) override; |
| 43 | void setConfig(const MetaData &config) override; |
| 44 | |
| 45 | void suspend() override; |
| 46 | void resume() override; |
| 47 | bool suspended() override; |
| 48 | void send(int cmd, const QByteArray &arr = QByteArray()) override; |
| 49 | |
| 50 | // pure virtual methods that are defined by the actual protocol |
| 51 | virtual void get(const QUrl &url) = 0; |
| 52 | virtual void mimetype(const QUrl &url) = 0; |
| 53 | |
| 54 | protected: |
| 55 | /*! |
| 56 | * Sets metadata |
| 57 | * \internal |
| 58 | */ |
| 59 | void setAllMetaData(const MetaData &); |
| 60 | /*! |
| 61 | * Sends metadata set with setAllMetaData |
| 62 | * \internal |
| 63 | */ |
| 64 | void sendMetaData(); |
| 65 | |
| 66 | // queuing methods |
| 67 | /*! identifiers of functions to be queued */ |
| 68 | enum QueueType { |
| 69 | Queue_mimeType = 1, |
| 70 | Queue_totalSize, |
| 71 | Queue_sendMetaData, |
| 72 | Queue_data, |
| 73 | Queue_finished, |
| 74 | }; |
| 75 | /*! structure for queuing. It is very primitive, it doesn't |
| 76 | * even try to conserve memory. |
| 77 | */ |
| 78 | struct QueueStruct { |
| 79 | QueueType type; |
| 80 | QString s; |
| 81 | KIO::filesize_t size; |
| 82 | QByteArray ba; |
| 83 | |
| 84 | QueueStruct() |
| 85 | { |
| 86 | } |
| 87 | QueueStruct(QueueType type) |
| 88 | : type(type) |
| 89 | { |
| 90 | } |
| 91 | }; |
| 92 | typedef QList<QueueStruct> DispatchQueue; |
| 93 | DispatchQueue dispatchQueue; |
| 94 | |
| 95 | DISPATCH_DECL1(mimeType, const QString &, s) |
| 96 | DISPATCH_DECL1(totalSize, KIO::filesize_t, size) |
| 97 | DISPATCH_DECL(sendMetaData) |
| 98 | DISPATCH_DECL1(data, const QByteArray &, ba) |
| 99 | DISPATCH_DECL(finished) |
| 100 | |
| 101 | protected Q_SLOTS: |
| 102 | /*! dispatches next queued method. Does nothing if there are no |
| 103 | * queued methods. |
| 104 | */ |
| 105 | void dispatchNext(); |
| 106 | |
| 107 | private: |
| 108 | MetaData meta_data; |
| 109 | bool _suspended; |
| 110 | QTimer *timer; |
| 111 | }; |
| 112 | |
| 113 | } |
| 114 | |
| 115 | #undef DISPATCH_DECL |
| 116 | #undef DISPATCH_DECL1 |
| 117 | |
| 118 | #endif |
| 119 | |