diff --git a/server/src/ctx/master.hpp b/server/src/ctx/master.hpp index 91e4805..59612df 100644 --- a/server/src/ctx/master.hpp +++ b/server/src/ctx/master.hpp @@ -3,7 +3,19 @@ namespace sosc { namespace ctx { +class MasterClientContext { +public: +private: + +}; + +class MasterIntraContext { +public: + +private: + +}; }} #endif diff --git a/server/src/hosts/master.hpp b/server/src/hosts/master.hpp index 9eca8bc..2408cf0 100644 --- a/server/src/hosts/master.hpp +++ b/server/src/hosts/master.hpp @@ -10,6 +10,8 @@ #include "../db/database.hpp" +#include "../ctx/master.hpp" + #include namespace sosc { @@ -24,10 +26,14 @@ private: cgc::Cipher cipher; }; -class MasterClientPool : public Pool { +class MasterClientPool : public Pool { protected: void SetupQueries(Queries* queries) override; - bool ProcessClient(MasterClient& client, const Queries* queries) override { + bool ProcessClient( + MasterClient& client, + ctx::MasterClientContext* context, + const Queries* queries) override + { // TODO implement return true; } @@ -79,10 +85,14 @@ private: const Pool::Queries* queries; }; -class MasterIntraPool : public Pool { +class MasterIntraPool : public Pool { protected: void SetupQueries(Queries* queries) override; - bool ProcessClient(MasterIntra& client, const Queries* queries) override { + bool ProcessClient + (MasterIntra& client, + ctx::MasterIntraContext* context, + const Queries* queries) override + { return client.Process(queries); } }; diff --git a/server/src/hosts/slave.hpp b/server/src/hosts/slave.hpp index 9246161..ae1be3f 100644 --- a/server/src/hosts/slave.hpp +++ b/server/src/hosts/slave.hpp @@ -3,6 +3,7 @@ #include "../sock/scapesock.hpp" #include "../sock/pool.hpp" +#include "../ctx/slave.hpp" namespace sosc { /** SLAVE -> CLIENT **/ @@ -14,9 +15,13 @@ private: ScapeConnection sock; }; -class SlaveClientPool : public Pool { +class SlaveClientPool : public Pool { protected: - bool ProcessClient(SlaveClient& client, const Queries* queries) override { + bool ProcessClient + (SlaveClient& client, + ctx::SlaveContext* context, + const Queries* queries) override + { // TODO implement return true; } diff --git a/server/src/sock/pool.hpp b/server/src/sock/pool.hpp index ab1f78b..0953b6c 100644 --- a/server/src/sock/pool.hpp +++ b/server/src/sock/pool.hpp @@ -27,7 +27,7 @@ typedef struct { int tolerance = -1; } poolinfo_t; -template +template class Pool { public: Pool(); @@ -46,14 +46,15 @@ public: typedef std::vector Queries; protected: virtual void SetupQueries(Queries* queries) {}; - virtual bool ProcessClient(T& client, const Queries* queries) = 0; + virtual bool ProcessClient + (T& client, U* context, const Queries* queries) = 0; private: bool IsStackFull(int stackCount) const; bool CanAddStack() const; class Stack { public: - explicit Stack(Pool* pool); + explicit Stack(Pool* pool); Stack(const Stack&) = delete; void Start(); @@ -70,7 +71,7 @@ private: Queries queries; std::thread* thread; - Pool* pool; + Pool* pool; bool is_open; bool is_running; @@ -81,25 +82,26 @@ private: poolinfo_t info; bool is_open; + U context; Queries queries; std::vector stacks; friend class Stack; }; -template -Pool::Pool() { +template +Pool::Pool() { this->info = poolinfo_t(); } -template -void Pool::Configure(const poolinfo_t& info) { +template +void Pool::Configure(const poolinfo_t& info) { this->info = info; this->is_open = false; } -template -void Pool::Start() { +template +void Pool::Start() { if(this->is_open) return; @@ -113,8 +115,8 @@ void Pool::Start() { this->is_open = true; } -template -bool Pool::IsStackFull(int stackCount) const { +template +bool Pool::IsStackFull(int stackCount) const { const poolinfo_t *info = &this->info; return info->max_size != -1 && stackCount < @@ -124,14 +126,14 @@ bool Pool::IsStackFull(int stackCount) const { && stackCount < info->max_size; } -template -bool Pool::CanAddStack() const { +template +bool Pool::CanAddStack() const { return this->info.max_count == -1 || this->stacks.size() < this->info.max_count; } -template -bool Pool::AddClient(T client) { +template +bool Pool::AddClient(T client) { if(!this->is_open) return false; @@ -160,8 +162,8 @@ bool Pool::AddClient(T client) { return true; } -template -int Pool::ClientCount() { +template +int Pool::ClientCount() { if(!this->is_open) return 0; @@ -171,8 +173,8 @@ int Pool::ClientCount() { return count; } -template -void Pool::Stop() { +template +void Pool::Stop() { if(!this->is_open) return; @@ -190,15 +192,15 @@ void Pool::Stop() { this->is_open = false; } -template -Pool::Stack::Stack(Pool* pool) { +template +Pool::Stack::Stack(Pool* pool) { this->pool = pool; this->is_open = false; this->is_running = false; } -template -void Pool::Stack::Start() { +template +void Pool::Stack::Start() { if(this->is_open || this->is_running) return; @@ -212,8 +214,8 @@ void Pool::Stack::Start() { }); } -template -void Pool::Stack::AddClient(T client) { +template +void Pool::Stack::AddClient(T client) { if(!this->is_open || !this->is_running) return; @@ -222,8 +224,8 @@ void Pool::Stack::AddClient(T client) { this->clients_mtx.unlock(); } -template -int Pool::Stack::ClientCount() { +template +int Pool::Stack::ClientCount() { if(!this->is_open || !this->is_running) return 0; @@ -234,8 +236,8 @@ int Pool::Stack::ClientCount() { return count; } -template -void Pool::Stack::StackThread() { +template +void Pool::Stack::StackThread() { while(this->is_running) { for(auto client = this->clients.begin(); @@ -246,15 +248,18 @@ void Pool::Stack::StackThread() { break; this->clients_mtx.lock(); - if(!this->pool->ProcessClient(*client, &this->queries)) + if(!this->pool->ProcessClient + (*client, &this->pool->context, &this->queries)) + { this->clients.erase(client); + } this->clients_mtx.unlock(); } } } -template -void Pool::Stack::Stop() { +template +void Pool::Stack::Stop() { if(!this->is_open || !this->is_running) return; diff --git a/server/src/sock/scapesock.hpp b/server/src/sock/scapesock.hpp index 488f3e1..f25d499 100644 --- a/server/src/sock/scapesock.hpp +++ b/server/src/sock/scapesock.hpp @@ -10,8 +10,8 @@ #include "tcpsock.hpp" #define SOSC_SHAKE_ERR (-1) -#define SOSC_SHAKE_CONT 0 -#define SOSC_SHAKE_DONE 1 +#define SOSC_SHAKE_CONT 0 +#define SOSC_SHAKE_DONE 1 namespace sosc { class ScapeConnection {