2019-04-10 20:28:10 +00:00
|
|
|
#include <LibCore/CNetworkJob.h>
|
|
|
|
#include <LibCore/CNetworkResponse.h>
|
2019-04-07 12:36:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2019-04-10 20:28:10 +00:00
|
|
|
CNetworkJob::CNetworkJob()
|
2019-04-07 12:36:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-10 20:28:10 +00:00
|
|
|
CNetworkJob::~CNetworkJob()
|
2019-04-07 12:36:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-21 16:37:47 +00:00
|
|
|
void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
|
2019-04-07 12:36:10 +00:00
|
|
|
{
|
|
|
|
m_response = move(response);
|
2019-08-04 20:10:54 +00:00
|
|
|
dbg() << *this << " job did_finish!";
|
2019-04-07 12:36:10 +00:00
|
|
|
ASSERT(on_finish);
|
|
|
|
on_finish(true);
|
2019-06-22 20:46:05 +00:00
|
|
|
delete_later();
|
2019-04-07 12:36:10 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 20:28:10 +00:00
|
|
|
void CNetworkJob::did_fail(Error error)
|
2019-04-07 12:36:10 +00:00
|
|
|
{
|
|
|
|
m_error = error;
|
2019-06-22 20:46:05 +00:00
|
|
|
dbgprintf("%s{%p} job did_fail! error: %u (%s)\n", class_name(), this, (unsigned)error, to_string(error));
|
2019-04-07 12:36:10 +00:00
|
|
|
ASSERT(on_finish);
|
|
|
|
on_finish(false);
|
2019-06-22 20:46:05 +00:00
|
|
|
delete_later();
|
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
default:
|
|
|
|
return "(Unknown error)";
|
|
|
|
}
|
2019-04-07 12:36:10 +00:00
|
|
|
}
|