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
16class 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
24namespace 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 */
35class DataWorker : public KIO::Worker
36{
37 Q_OBJECT
38public:
39 DataWorker();
40
41 ~DataWorker() 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 // pure virtual methods that are defined by the actual protocol
52 virtual void get(const QUrl &url) = 0;
53 virtual void mimetype(const QUrl &url) = 0;
54
55protected:
56 /**
57 * Sets metadata
58 * @internal
59 */
60 void setAllMetaData(const MetaData &);
61 /**
62 * Sends metadata set with setAllMetaData
63 * @internal
64 */
65 void sendMetaData();
66
67 // queuing methods
68 /** identifiers of functions to be queued */
69 enum QueueType {
70 Queue_mimeType = 1,
71 Queue_totalSize,
72 Queue_sendMetaData,
73 Queue_data,
74 Queue_finished,
75 };
76 /** structure for queuing. It is very primitive, it doesn't
77 * even try to conserve memory.
78 */
79 struct QueueStruct {
80 QueueType type;
81 QString s;
82 KIO::filesize_t size;
83 QByteArray ba;
84
85 QueueStruct()
86 {
87 }
88 QueueStruct(QueueType type)
89 : type(type)
90 {
91 }
92 };
93 typedef QList<QueueStruct> DispatchQueue;
94 DispatchQueue dispatchQueue;
95
96 DISPATCH_DECL1(mimeType, const QString &, s)
97 DISPATCH_DECL1(totalSize, KIO::filesize_t, size)
98 DISPATCH_DECL(sendMetaData)
99 DISPATCH_DECL1(data, const QByteArray &, ba)
100 DISPATCH_DECL(finished)
101
102protected Q_SLOTS:
103 /** dispatches next queued method. Does nothing if there are no
104 * queued methods.
105 */
106 void dispatchNext();
107
108private:
109 MetaData meta_data;
110 bool _suspended;
111 QTimer *timer;
112};
113
114}
115
116#undef DISPATCH_DECL
117#undef DISPATCH_DECL1
118
119#endif
120

source code of kio/src/core/dataworker_p.h