2019-04-07 14:36:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibCore/CObject.h>
|
2019-04-07 14:36:10 +02:00
|
|
|
|
2019-04-10 22:28:10 +02:00
|
|
|
class CNetworkResponse;
|
2019-04-07 14:36:10 +02:00
|
|
|
|
2019-04-10 22:28:10 +02:00
|
|
|
class CNetworkJob : public CObject {
|
2019-07-25 19:49:28 +02:00
|
|
|
C_OBJECT(CNetworkJob)
|
2019-04-07 14:36:10 +02:00
|
|
|
public:
|
2019-06-07 17:13:23 +02:00
|
|
|
enum class Error {
|
2019-04-07 14:36:10 +02:00
|
|
|
None,
|
|
|
|
ConnectionFailed,
|
|
|
|
TransmissionFailed,
|
2019-04-07 19:35:07 +02:00
|
|
|
ProtocolFailed,
|
2019-04-07 14:36:10 +02:00
|
|
|
};
|
2019-04-10 22:28:10 +02:00
|
|
|
virtual ~CNetworkJob() override;
|
2019-04-07 14:36:10 +02:00
|
|
|
|
|
|
|
Function<void(bool success)> on_finish;
|
|
|
|
|
|
|
|
bool has_error() const { return m_error != Error::None; }
|
|
|
|
Error error() const { return m_error; }
|
2019-04-10 22:28:10 +02:00
|
|
|
CNetworkResponse* response() { return m_response.ptr(); }
|
|
|
|
const CNetworkResponse* response() const { return m_response.ptr(); }
|
2019-04-07 14:36:10 +02:00
|
|
|
|
|
|
|
virtual void start() = 0;
|
|
|
|
|
|
|
|
protected:
|
2019-04-10 22:28:10 +02:00
|
|
|
CNetworkJob();
|
2019-06-21 18:37:47 +02:00
|
|
|
void did_finish(NonnullRefPtr<CNetworkResponse>&&);
|
2019-04-07 14:36:10 +02:00
|
|
|
void did_fail(Error);
|
|
|
|
|
|
|
|
private:
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<CNetworkResponse> m_response;
|
2019-04-07 14:36:10 +02:00
|
|
|
Error m_error { Error::None };
|
|
|
|
};
|
2019-06-22 22:46:05 +02:00
|
|
|
|
|
|
|
const char* to_string(CNetworkJob::Error);
|