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-10-15 17:14:11 +00:00
|
|
|
//#define CNETWORKJOB_DEBUG
|
|
|
|
|
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-10-15 17:14:11 +00:00
|
|
|
#ifdef CNETWORKJOB_DEBUG
|
2019-08-04 20:10:54 +00:00
|
|
|
dbg() << *this << " job did_finish!";
|
2019-10-15 17:14:11 +00:00
|
|
|
#endif
|
2019-04-07 12:36:10 +00:00
|
|
|
ASSERT(on_finish);
|
|
|
|
on_finish(true);
|
2019-09-21 15:32:26 +00:00
|
|
|
shutdown();
|
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-10-15 17:14:11 +00:00
|
|
|
#ifdef CNETWORKJOB_DEBUG
|
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-10-15 17:14:11 +00:00
|
|
|
#endif
|
2019-04-07 12:36:10 +00:00
|
|
|
ASSERT(on_finish);
|
|
|
|
on_finish(false);
|
2019-09-21 15:32:26 +00:00
|
|
|
shutdown();
|
2019-06-22 20:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
2019-09-21 15:32:26 +00:00
|
|
|
case CNetworkJob::Error::Cancelled:
|
|
|
|
return "Cancelled";
|
2019-06-22 20:46:05 +00:00
|
|
|
default:
|
|
|
|
return "(Unknown error)";
|
|
|
|
}
|
2019-04-07 12:36:10 +00:00
|
|
|
}
|