diff --git a/src/interfaces/IClientListener.h b/src/interfaces/IClientListener.h index 26ff10aa..8a2a439f 100644 --- a/src/interfaces/IClientListener.h +++ b/src/interfaces/IClientListener.h @@ -26,6 +26,7 @@ class Client; +class Job; class IClientListener @@ -33,7 +34,9 @@ class IClientListener public: virtual ~IClientListener() {} + virtual void onJobReceived(Client *client, const Job &job) = 0; virtual void onLoginCredentialsRequired(Client *client) = 0; + virtual void onLoginSuccess(Client *client) = 0; }; diff --git a/src/net/Client.cpp b/src/net/Client.cpp index ee2c6873..296acf64 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -25,7 +25,6 @@ #include "Console.h" #include "interfaces/IClientListener.h" #include "net/Client.h" -#include "net/Job.h" #include "net/Url.h" @@ -160,8 +159,9 @@ bool Client::parseJob(const json_t *params, int *code) 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; } @@ -257,7 +257,20 @@ void Client::parse(char *line, size_t len) 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(); } + m_listener->onLoginSuccess(this); + m_listener->onJobReceived(this, m_job); return; } diff --git a/src/net/Client.h b/src/net/Client.h index 2eecb044..309078de 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -29,6 +29,9 @@ #include +#include "net/Job.h" + + class Url; class IClientListener; @@ -81,6 +84,7 @@ private: IClientListener *m_listener; int64_t m_retries; int64_t m_sequence; + Job m_job; size_t m_recvBufPos; SocketState m_state; struct addrinfo m_hints; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 91b62621..f87c41d5 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -59,7 +59,18 @@ void Network::connect() } +void Network::onJobReceived(Client *client, const Job &job) +{ + +} + + void Network::onLoginCredentialsRequired(Client *client) { client->login(m_options->user(), m_options->pass(), m_agent); } + + +void Network::onLoginSuccess(Client *client) +{ +} diff --git a/src/net/Network.h b/src/net/Network.h index 5ee7c295..87e31909 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -42,7 +42,9 @@ public: static char *userAgent(); protected: + void onJobReceived(Client *client, const Job &job) override; void onLoginCredentialsRequired(Client *client) override; + void onLoginSuccess(Client *client) override; private: char *m_agent;