summaryrefslogtreecommitdiffstats
path: root/api/logic/net/ByteArraySink.h
blob: 20e6764c04b4769ca22d31761078e5519ea7d2f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include "Sink.h"

namespace Net {
/*
 * Sink object for downloads that uses an external QByteArray it doesn't own as a target.
 */
class ByteArraySink : public Sink
{
public:
    ByteArraySink(QByteArray *output)
        :m_output(output)
    {
        // nil
    };

    virtual ~ByteArraySink()
    {
        // nil
    }

public:
    JobStatus init(QNetworkRequest & request) override
    {
        m_output->clear();
        if(initAllValidators(request))
            return Job_InProgress;
        return Job_Failed;
    };

    JobStatus write(QByteArray & data) override
    {
        m_output->append(data);
        if(writeAllValidators(data))
            return Job_InProgress;
        return Job_Failed;
    }

    JobStatus abort() override
    {
        m_output->clear();
        failAllValidators();
        return Job_Failed;
    }

    JobStatus finalize(QNetworkReply &reply) override
    {
        if(finalizeAllValidators(reply))
            return Job_Finished;
        return Job_Failed;
    }

    bool hasLocalData() override
    {
        return false;
    }

private:
    QByteArray * m_output;
};
}