bool LabBot::DummyCrate::handleRequest(LabBot::Request &req, LabBot::Response &resp) { std::string reqtype = req.m_json["reqtype"].asString(); if (reqtype == "getData") { return getData(req, resp); } else if (reqtype == "prepareForShot") { return prepareForShot(req, resp); } else if (reqtype == "getDataSync") { Json::Value root; root["status"] = "success"; std::vector<Request> reqs; std::vector<Response> resps; for (auto dev: m_devs) { Json::Value reqRoot; reqRoot["reqtype"] = "getDummyData"; reqRoot["subsystem"] = dev; Request lreq(JsonBson(reqRoot).str(), this); reqs.push_back(lreq); } localMultiRequest(reqs, resps); int i = 0; for (auto lresp: resps) { root["data"][i] = (Json::Value)(JsonBson(lresp.m_string)); i++; } resp = root; return true; } return false; }
bool ArchiveModule::handleUpdate(Request &req, Response &resp) { Json::Value root; m_backend->updateUnique(req.m_json["collection"].asString(), JsonBson(req.m_json["search"]), JsonBson(req.m_json["update"]), false); root["status"] = "success"; resp = root; return true; }
bool LabBot::DummyCrate::getData(LabBot::Request &req, LabBot::Response &resp) { Json::Value root; int i = 0; for (auto dev: m_devs) { Response lresp; Json::Value reqRoot; reqRoot["reqtype"] = "getDummyData"; reqRoot["subsystem"] = dev; Request lreq(JsonBson(reqRoot).str(), this); localRequest(lreq, lresp); root["data"][i] = (Json::Value)(JsonBson(lresp.m_string)); i++; } root["status"] = "success"; resp = root; return true; }
bool ArchiveModule::loadConfig(Json::Value &config) { std::cout << m_backend << " Loading database config: " << JsonBson(config).str() << std::endl; m_backend->setDbCredentials(config["uri"].asString(), config["database"].asString(), config["user"].asString(), config["pass"].asString() ); return true; }
bool ArchiveModule::handleFindUnique(Request &req, Response &resp) { Json::Value root; JsonBson result; m_backend->findUnique(req.m_json["collection"].asString(), JsonBson(req.m_json["request"]), result); root["data"] = result; root["status"] = "success"; resp = root; return true; }
bool ArchiveModule::handleGetDatastoresList(Request &req, Response &resp) { Json::Value root; JsonBson result; m_backend->findUnique("dbinfo", JsonBson(std::string( "{\"dbInfoSection\":\"datastoresList\"}")), result); root["data"] = result; root["status"] = "success"; resp = root; return true; }
void Kernel::loadConfig(const std::string &confPath) { std::ostringstream contents; std::ifstream file(confPath); if (!file.is_open()) { throw std::runtime_error("Failed to load config"); } contents << file.rdbuf(); std::string confStr = contents.str(); m_configuration = JsonBson(confStr); m_archive->loadConfig(m_configuration["database"]); m_scheduler->loadConfig(m_configuration["scripts"]); std::cout << "Starting Flugegeheimen on " << m_configuration["server"]["port"].asString() << std::endl; }
LabBot::Module::State LabBot::DummyCrate::getState() { Json::Value root; root["status"] = "success"; std::vector<Request> reqs; std::vector<Response> resps; for (auto dev: m_devs) { Json::Value reqRoot; reqRoot["reqtype"] = "getDeviceInfo"; reqRoot["subsystem"] = dev; Request lreq(JsonBson(reqRoot).str(), this); reqs.push_back(lreq); } localMultiRequest(reqs, resps); for (auto lresp: resps) { if (lresp.m_json["status"] != "success") { throw std::runtime_error("Some devices are not responding"); } } return LabBot::Module::ST_ONLINE; }