bet you thought i'd forget to commit huh

This commit is contained in:
malloc 2018-11-06 16:59:19 -06:00
parent fff2db63b6
commit b2f32e6cdf
4 changed files with 136 additions and 91 deletions

2
src/common/utils/ini.cpp Normal file
View file

@ -0,0 +1,2 @@
#include "ini.hpp"

37
src/common/utils/ini.hpp Normal file
View file

@ -0,0 +1,37 @@
#ifndef SOSC_UTIL_INI_H
#define SOSC_UTIL_INI_H
#include <vector>
#include <map>
namespace sosc {
namespace ini {
class File {
public:
struct Rule {
Rule() = delete;
Rule(
const std::string& name,
bool required,
bool allow_multiple,
const std::vector<std::string>& required_fields
) : name(name),
required(required),
allow_multiple(allow_multiple),
required_fields(required_fields) {};
std::string name;
bool required;
bool allow_multiple;
std::vector<std::string> required_fields;
};
class Section {
};
private:
std::map<std::string, Section>
};
}}
#endif

View file

@ -30,7 +30,7 @@ public:
int ColumnCount(); int ColumnCount();
private: private:
ResultSet(Query* query); explicit ResultSet(Query* query);
Query* query; Query* query;
friend class Query; friend class Query;

View file

@ -8,52 +8,54 @@
#include "hosts/master.hpp" #include "hosts/master.hpp"
#include "hosts/slave.hpp" #include "hosts/slave.hpp"
static struct _slave_ctx { template<class T, class U>
sosc::ScapeServer server; struct _server_ctx {
sosc::SlaveClientPool pool; std::thread thread;
T server;
U pool;
}; };
typedef _server_ctx<sosc::IntraServer, sosc::MasterIntraPool>
master_intra_ctx;
typedef _server_ctx<sosc::ScapeServer, sosc::MasterClientPool>
master_client_ctx;
typedef _server_ctx<sosc::ScapeServer, sosc::SlaveClientPool>
slave_ctx;
static struct { static struct {
struct { master_intra_ctx* master_intra = nullptr;
sosc::IntraServer server; master_client_ctx* master_client = nullptr;
sosc::MasterIntraPool pool; slave_ctx* slaves = nullptr;
} master_intra; int slave_count = 0;
struct {
sosc::ScapeServer server;
sosc::MasterIntraPool pool;
} master_client;
_slave_ctx* slaves;
bool running;
} _ctx; } _ctx;
bool master_intra(uint16_t port, const sosc::poolinfo_t& info); bool master_intra_start(uint16_t port, const sosc::poolinfo_t& info);
bool master_client(uint16_t port, const sosc::poolinfo_t& info); bool master_client_start(uint16_t port, const sosc::poolinfo_t& info);
bool slave(uint16_t port, const sosc::poolinfo_t& info); bool slave_start(uint16_t port, const sosc::poolinfo_t& info, slave_ctx* ctx);
void master_intra_stop();
void master_client_stop();
void slave_stop(slave_ctx* ctx);
int main(int argc, char **argv) { int main(int argc, char **argv) {
using namespace sosc; using namespace sosc;
if(argc < 2) if(argc < 2)
return -1; return -1;
_ctx.running = true;
std::vector<std::thread*> threads;
if(argv[1][0] == 'm') { if(argv[1][0] == 'm') {
if(!db::init_databases(nullptr)) if(!db::init_databases(nullptr))
return -1; return -1;
threads.push_back(new std::thread([&] { _ctx.master_intra = new master_intra_ctx;
master_client(8008, poolinfo_t()); master_intra_start(1234, poolinfo_t());
})); _ctx.master_client = new master_client_ctx;
threads.push_back(new std::thread([&] { master_client_start(8008, poolinfo_t());
master_intra(1234, poolinfo_t());
}));
} else { } else {
threads.push_back(new std::thread([&] { _ctx.slave_count = 1;
slave(1234, poolinfo_t()); _ctx.slaves = new slave_ctx[_ctx.slave_count];
}));
for(int i = 0; i < _ctx.slave_count; ++i)
slave_start(1234, poolinfo_t(), _ctx.slaves + i);
} }
std::cout << "Server threads started. Type STOP to cancel." << std::endl; std::cout << "Server threads started. Type STOP to cancel." << std::endl;
@ -67,89 +69,93 @@ int main(int argc, char **argv) {
break; break;
} }
_ctx.running = false; master_client_stop();
for(const auto& thread : threads) { master_intra_stop();
thread->join(); for(int i = 0; i < _ctx.slave_count; ++i)
delete thread; slave_stop(_ctx.slaves + i);
}
return 0; return 0;
} }
bool master_intra(uint16_t port, const sosc::poolinfo_t& info) { bool master_intra_start(uint16_t port, const sosc::poolinfo_t& info) {
using namespace sosc; if(!_ctx.master_intra->server.Listen(port))
IntraServer server;
IntraClient client;
if(!server.Listen(port))
return false; return false;
MasterIntraPool pool; _ctx.master_intra->pool.Configure(info);
pool.Configure(info); _ctx.master_intra->pool.Start();
pool.Start();
auto listenThread = std::thread([&] { _ctx.master_intra->thread = std::thread([&] {
while (server.Accept(&client)) sosc::IntraClient client;
pool.AddClient(new MasterIntra(client)); while (_ctx.master_intra->server.Accept(&client))
_ctx.master_intra->pool.AddClient(new sosc::MasterIntra(client));
}); });
while(_ctx.running);
server.Close();
listenThread.join();
pool.Stop();
return true; return true;
} }
bool master_client(uint16_t port, const sosc::poolinfo_t& info) { bool master_client_start(uint16_t port, const sosc::poolinfo_t& info) {
using namespace sosc; if(!_ctx.master_client->server.Listen(port, true))
ScapeServer server;
ScapeConnection client;
if(!server.Listen(port, true))
return false; return false;
MasterClientPool pool; _ctx.master_client->pool.Configure(info);
pool.Configure(info); _ctx.master_client->pool.Start();
pool.Start();
auto listenThread = std::thread([&] { _ctx.master_client->thread = std::thread([&] {
while(server.Accept(&client)) sosc::ScapeConnection client;
pool.AddClient(new MasterClient(client)); while(_ctx.master_client->server.Accept(&client))
_ctx.master_client->pool.AddClient(new sosc::MasterClient(client));
}); });
while(_ctx.running);
server.Close();
listenThread.join();
pool.Stop();
return true; return true;
} }
bool slave(uint16_t port, const sosc::poolinfo_t& info) { bool slave_start(uint16_t port, const sosc::poolinfo_t& info, slave_ctx* ctx) {
using namespace sosc; if(!ctx->server.Listen(port))
ScapeServer server;
ScapeConnection client;
if(!server.Listen(port))
return false; return false;
SlaveClientPool pool; ctx->pool.Configure(info);
pool.Configure(info); ctx->pool.Start();
pool.Start();
auto listenThread = std::thread([&] { ctx->thread = std::thread([&] {
while (server.Accept(&client)) sosc::ScapeConnection client;
pool.AddClient(new SlaveClient(client)); while (ctx->server.Accept(&client))
ctx->pool.AddClient(new sosc::SlaveClient(client));
}); });
while(_ctx.running);
server.Close();
listenThread.join();
pool.Stop();
return true; return true;
} }
void master_intra_stop() {
if(_ctx.master_intra == nullptr)
return;
_ctx.master_intra->server.Close();
_ctx.master_intra->thread.join();
_ctx.master_intra->pool.Stop();
delete _ctx.master_intra;
_ctx.master_intra = nullptr;
}
void master_client_stop() {
if(_ctx.master_client == nullptr)
return;
_ctx.master_client->server.Close();
_ctx.master_client->thread.join();
_ctx.master_client->pool.Stop();
delete _ctx.master_client;
_ctx.master_client = nullptr;
}
void slave_stop(slave_ctx* ctx) {
if(ctx == nullptr)
return;
ctx->server.Close();
ctx->thread.join();
ctx->pool.Stop();
delete ctx;
}