just one scööp

This commit is contained in:
malloc 2018-11-12 16:33:04 -06:00
parent 045db422a0
commit f0ae8feb26
3 changed files with 53 additions and 12 deletions

View file

@ -132,6 +132,10 @@ std::runtime_error File::LoadError
)); ));
} }
bool File::HasSection(std::string name) const {
return this->section_lists.count(name) > 0;
}
const File::SectionList& const File::SectionList&
File::operator[] (std::string name) const File::operator[] (std::string name) const
{ {
@ -150,9 +154,7 @@ int File::SectionList::SectionCount() const {
return this->sections.size(); return this->sections.size();
} }
const File::Proxy& const File::Proxy File::SectionList::operator[] (std::string key) const{
File::SectionList::operator[] (std::string key) const
{
return this->sections[0][key]; return this->sections[0][key];
} }
@ -170,7 +172,7 @@ bool File::SectionList::Section::HasKey(std::string name) const {
return this->values.count(name) == 1; return this->values.count(name) == 1;
} }
const File::Proxy& const File::Proxy
File::SectionList::Section::operator[] (std::string key) const File::SectionList::Section::operator[] (std::string key) const
{ {
str::tolower(&key); str::tolower(&key);

View file

@ -88,7 +88,7 @@ public:
class Section { class Section {
public: public:
bool HasKey(std::string name) const; bool HasKey(std::string name) const;
const Proxy& operator[] (std::string key) const; const Proxy operator[] (std::string key) const;
private: private:
std::map<std::string, std::string> values; std::map<std::string, std::string> values;
friend class File; friend class File;
@ -97,7 +97,7 @@ public:
bool HasKey(std::string name) const; bool HasKey(std::string name) const;
int SectionCount() const; int SectionCount() const;
const Proxy& operator[] (std::string key) const; const Proxy operator[] (std::string key) const;
const Section& operator[] (int index) const; const Section& operator[] (int index) const;
private: private:
std::vector<Section> sections; std::vector<Section> sections;

View file

@ -25,6 +25,8 @@ typedef _server_ctx<sosc::ScapeServer, sosc::SlaveClientPool>
slave_ctx; slave_ctx;
static struct { static struct {
sosc::poolinfo_t default_info;
master_intra_ctx* master_intra = nullptr; master_intra_ctx* master_intra = nullptr;
master_client_ctx* master_client = nullptr; master_client_ctx* master_client = nullptr;
slave_ctx* slaves = nullptr; slave_ctx* slaves = nullptr;
@ -39,6 +41,28 @@ void master_intra_stop();
void master_client_stop(); void master_client_stop();
void slave_stop(slave_ctx* ctx); void slave_stop(slave_ctx* ctx);
void configure_poolinfo(sosc::poolinfo_t* info,
const sosc::ini::File::SectionList::Section& section)
{
*info = sosc::poolinfo_t(_ctx.default_info);
if(section.HasKey("inital count"))
info->initial_count = (int)section["initial count"];
if(section.HasKey("inital size"))
info->initial_size = (int)section["initial size"];
if(section.HasKey("size growth"))
info->size_growth = (int)section["size growth"];
if(section.HasKey("max size"))
info->max_size = (int)section["max size"];
if(section.HasKey("max count"))
info->max_count = (int)section["max count"];
if(section.HasKey("max total"))
info->max_total = (int)section["max total"];
if(section.HasKey("tolerance"))
info->tolerance = (int)section["tolerance"];
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
using namespace sosc; using namespace sosc;
if(argc < 2) if(argc < 2)
@ -62,9 +86,11 @@ int main(int argc, char **argv) {
ini::Field("max total", ini::Field::INT32), ini::Field("max total", ini::Field::INT32),
ini::Field("tolerance", ini::Field::INT32), ini::Field("tolerance", ini::Field::INT32),
}), }),
ini::Rule("master", true, false, { ini::Rule("master to client", false, false, {
ini::Field("client port", ini::Field::UINT32), ini::Field("port", ini::Field::UINT32),
ini::Field("intra port", ini::Field::UINT32), }),
ini::Rule("master to slave", false, false, {
ini::Field("port", ini::Field::UINT32),
}), }),
ini::Rule("slave", false, true, { ini::Rule("slave", false, true, {
ini::Field("port", ini::Field::UINT32), ini::Field("port", ini::Field::UINT32),
@ -76,19 +102,31 @@ int main(int argc, char **argv) {
return -1; return -1;
} }
poolinfo_t info = poolinfo_t(); poolinfo_t info;
info.initial_count = configure_poolinfo(&_ctx.default_info, (*config)["defaults"][0]);
if((*config)["master"]["run master"]) { if((*config)["master"]["run master"]) {
if(!db::init_databases(nullptr)) if(!config->HasSection("master to client") ||
!config->HasSection("master to slave"))
{
std::cout << "'MASTER TO CLIENT' and 'MASTER TO SLAVE' sections "
<< "must exist if 'RUN MASTER' is true." << std::endl;
return -1; return -1;
}
if(!db::init_databases(nullptr)) {
std::cout << "Could not initialized master database.";
return -1;
}
configure_poolinfo(&info, (*config)["master to slave"][0]);
_ctx.master_intra = new master_intra_ctx; _ctx.master_intra = new master_intra_ctx;
master_intra_start( master_intra_start(
(uint16_t)(*config)["master"]["intra port"], (uint16_t)(*config)["master"]["intra port"],
poolinfo_t() poolinfo_t()
); );
configure_poolinfo(&info, (*config)["master to client"][0]);
_ctx.master_client = new master_client_ctx; _ctx.master_client = new master_client_ctx;
master_client_start( master_client_start(
(uint16_t)(*config)["master"]["client port"], (uint16_t)(*config)["master"]["client port"],
@ -101,6 +139,7 @@ int main(int argc, char **argv) {
_ctx.slaves = new slave_ctx[_ctx.slave_count]; _ctx.slaves = new slave_ctx[_ctx.slave_count];
for(int i = 0; i < _ctx.slave_count; ++i) { for(int i = 0; i < _ctx.slave_count; ++i) {
configure_poolinfo(&info, (*config)["slave"][i]);
slave_start( slave_start(
(uint16_t)(*config)["slave"][i]["port"], (uint16_t)(*config)["slave"][i]["port"],
poolinfo_t(), poolinfo_t(),