Handle job notification.
This commit is contained in:
parent
1ecee56eb6
commit
4c06d8b080
5 changed files with 37 additions and 2 deletions
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
|
class Job;
|
||||||
|
|
||||||
|
|
||||||
class IClientListener
|
class IClientListener
|
||||||
|
@ -33,7 +34,9 @@ class IClientListener
|
||||||
public:
|
public:
|
||||||
virtual ~IClientListener() {}
|
virtual ~IClientListener() {}
|
||||||
|
|
||||||
|
virtual void onJobReceived(Client *client, const Job &job) = 0;
|
||||||
virtual void onLoginCredentialsRequired(Client *client) = 0;
|
virtual void onLoginCredentialsRequired(Client *client) = 0;
|
||||||
|
virtual void onLoginSuccess(Client *client) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "Console.h"
|
#include "Console.h"
|
||||||
#include "interfaces/IClientListener.h"
|
#include "interfaces/IClientListener.h"
|
||||||
#include "net/Client.h"
|
#include "net/Client.h"
|
||||||
#include "net/Job.h"
|
|
||||||
#include "net/Url.h"
|
#include "net/Url.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,8 +159,9 @@ bool Client::parseJob(const json_t *params, int *code)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_NOTICE("PARSE JOB %d %lld %lld", job.size(), job.target(), job.diff());
|
m_job = job;
|
||||||
|
|
||||||
|
LOG_DEBUG("[%s:%u] job: \"%s\", diff: %lld", m_host, m_port, job.id(), job.diff());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +257,20 @@ void Client::parse(char *line, size_t len)
|
||||||
|
|
||||||
void Client::parseNotification(const char *method, const json_t *params)
|
void Client::parseNotification(const char *method, const json_t *params)
|
||||||
{
|
{
|
||||||
|
if (!method) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(method, "job") == 0) {
|
||||||
|
int code = -1;
|
||||||
|
if (parseJob(params, &code)) {
|
||||||
|
m_listener->onJobReceived(this, m_job);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_WARN("[%s:%u] unsupported method: \"%s\"", m_host, m_port, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,6 +297,8 @@ void Client::parseResponse(int64_t id, const json_t *result, const json_t *error
|
||||||
return close();
|
return close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_listener->onLoginSuccess(this);
|
||||||
|
m_listener->onJobReceived(this, m_job);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "net/Job.h"
|
||||||
|
|
||||||
|
|
||||||
class Url;
|
class Url;
|
||||||
class IClientListener;
|
class IClientListener;
|
||||||
|
|
||||||
|
@ -81,6 +84,7 @@ private:
|
||||||
IClientListener *m_listener;
|
IClientListener *m_listener;
|
||||||
int64_t m_retries;
|
int64_t m_retries;
|
||||||
int64_t m_sequence;
|
int64_t m_sequence;
|
||||||
|
Job m_job;
|
||||||
size_t m_recvBufPos;
|
size_t m_recvBufPos;
|
||||||
SocketState m_state;
|
SocketState m_state;
|
||||||
struct addrinfo m_hints;
|
struct addrinfo m_hints;
|
||||||
|
|
|
@ -59,7 +59,18 @@ void Network::connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Network::onJobReceived(Client *client, const Job &job)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Network::onLoginCredentialsRequired(Client *client)
|
void Network::onLoginCredentialsRequired(Client *client)
|
||||||
{
|
{
|
||||||
client->login(m_options->user(), m_options->pass(), m_agent);
|
client->login(m_options->user(), m_options->pass(), m_agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Network::onLoginSuccess(Client *client)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -42,7 +42,9 @@ public:
|
||||||
static char *userAgent();
|
static char *userAgent();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void onJobReceived(Client *client, const Job &job) override;
|
||||||
void onLoginCredentialsRequired(Client *client) override;
|
void onLoginCredentialsRequired(Client *client) override;
|
||||||
|
void onLoginSuccess(Client *client) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *m_agent;
|
char *m_agent;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue