summaryrefslogtreecommitdiff
path: root/Libraries/LibCore/CNetworkJob.cpp
blob: f668fac9a3c143ff1991829beb3c53fad7b78e10 (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
#include <LibCore/CNetworkJob.h>
#include <LibCore/CNetworkResponse.h>
#include <stdio.h>

//#define CNETWORKJOB_DEBUG

CNetworkJob::CNetworkJob()
{
}

CNetworkJob::~CNetworkJob()
{
}

void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
{
    m_response = move(response);
#ifdef CNETWORKJOB_DEBUG
    dbg() << *this << " job did_finish!";
#endif
    ASSERT(on_finish);
    on_finish(true);
    shutdown();
}

void CNetworkJob::did_fail(Error error)
{
    m_error = error;
#ifdef CNETWORKJOB_DEBUG
    dbgprintf("%s{%p} job did_fail! error: %u (%s)\n", class_name(), this, (unsigned)error, to_string(error));
#endif
    ASSERT(on_finish);
    on_finish(false);
    shutdown();
}

const char* to_string(CNetworkJob::Error error)
{
    switch (error) {
    case CNetworkJob::Error::ProtocolFailed:
        return "ProtocolFailed";
    case CNetworkJob::Error::ConnectionFailed:
        return "ConnectionFailed";
    case CNetworkJob::Error::TransmissionFailed:
        return "TransmissionFailed";
    case CNetworkJob::Error::Cancelled:
        return "Cancelled";
    default:
        return "(Unknown error)";
    }
}