added 2 output_tests + some add to output_driver
This commit is contained in:
@@ -28,7 +28,7 @@ OutputRequestHandler::OutputRequestHandler(std::shared_ptr<output::OutputDriver>
|
||||
* address/{item_type}/[item_name]/[action]/[score]
|
||||
*
|
||||
* Where
|
||||
* {item_type} is either solenoids, lamps, sounds, displays
|
||||
* {item_type} is either solenoids, lamps, sounds, displays, or one of the two special events: activate and deactivate
|
||||
* [item_name] is the string name of an item (optional if you want to get the list of all available items)
|
||||
* [action] is the particular action for the item:
|
||||
* Solenoids: trigger
|
||||
@@ -43,15 +43,29 @@ void OutputRequestHandler::handleRequest(HTTPServerRequest &request,
|
||||
HTTPServerResponse &response)
|
||||
{
|
||||
auto path_segments = getPathSegments(URI(request.getURI()));
|
||||
// ToDo catch exception
|
||||
|
||||
// fill up vector
|
||||
for(int i = path_segments.size(); i < 4; i++)
|
||||
{
|
||||
path_segments.emplace_back("");
|
||||
}
|
||||
|
||||
std::string item_type = path_segments.at(0);
|
||||
std::string item_name = path_segments.at(1);
|
||||
std::string action = path_segments.at(2);
|
||||
std::string score = "";
|
||||
std::string score = path_segments.at(3);
|
||||
|
||||
if(item_type == "displays")
|
||||
if(item_type == "deactivate")
|
||||
{
|
||||
score = path_segments.at(3);
|
||||
this->output_driver->deactivate_displays();
|
||||
this->output_driver->deactivate_all_lamps();
|
||||
return;
|
||||
}
|
||||
|
||||
if(item_type == "activate")
|
||||
{
|
||||
this->output_driver->activate_displays();
|
||||
return;
|
||||
}
|
||||
|
||||
response.setContentType("text/json");
|
||||
@@ -105,7 +119,7 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseSolenoid(const st
|
||||
if(item_name == "")
|
||||
{
|
||||
Poco::JSON::Object response;
|
||||
response.set("solenoids", output_driver->get_solenoids());
|
||||
response.set("solenoids", this->output_driver->get_solenoids());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -135,7 +149,7 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseLamp(const std::s
|
||||
if(item_name == "")
|
||||
{
|
||||
Poco::JSON::Object response;
|
||||
response.set("lamps", output_driver->get_lamps());
|
||||
response.set("lamps", this->output_driver->get_lamps());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -169,7 +183,7 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseSound(const std::
|
||||
if(item_name == "")
|
||||
{
|
||||
Poco::JSON::Object response;
|
||||
response.set("sounds", output_driver->get_lamps());
|
||||
response.set("sounds", this->output_driver->get_lamps());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -199,9 +213,10 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseDisplay(const std
|
||||
if(item_name == "")
|
||||
{
|
||||
Poco::JSON::Object response;
|
||||
response.set("displays", output_driver->get_displays());
|
||||
response.set("displays", this->output_driver->get_displays());
|
||||
return response;
|
||||
}
|
||||
|
||||
uint8_t display_number = std::stoi(item_name);
|
||||
auto opt_display = this->output_driver->get_display(display_number);
|
||||
|
||||
@@ -240,7 +255,6 @@ std::vector<std::string> OutputRequestHandler::getPathSegments(Poco::URI uri)
|
||||
return path_segments;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user