Commit d6953a69 authored by legoc's avatar legoc

Corrected bug of Break command box that was not inserted

parent 8d33536e
......@@ -199,6 +199,33 @@ ConditionCommandBox* CommandZoneResponder::getConditionCommandBox(unsigned long
return dynamic_cast<ConditionCommandBox*>(getCommandBox(commandBoxID));
}
bool checkBreakCommandBox(BreakCommandBox* commandBox, common::BooleanResponse & responseMessage, std::string & response) {
if (commandBox) {
responseMessage.set_error(common::Error::COMMAND_BOX_FORBIDDEN);
// Serialize the response.
responseMessage.SerializeToString(&response);
return true;
}
return false;
}
bool checkAddBreakCommandBox(int32 boxType, common::Int32Response & responseMessage, std::string & response) {
// check for Break command
if ((ControlCommandBox::BoxType)boxType == ControlCommandBox::BREAK) {
responseMessage.set_error(common::Error::COMMAND_BOX_FORBIDDEN);
// Serialize the response.
responseMessage.SerializeToString(&response);
return true;
}
return false;
}
void CommandZoneResponder::processToggleBackground(const std::string & message, std::string & response) {
commandzone::CommandBoxRequest messageRequest;
......@@ -1465,21 +1492,15 @@ void CommandZoneResponder::processAddNewControlCommandBoxAtEnd(const std::string
messageRequest.ParseFromString(message);
common::Int32Response responseMessage;
// check for Break command
if ((ControlCommandBox::BoxType)messageRequest.boxtype() == ControlCommandBox::BREAK) {
responseMessage.set_error(common::Error::COMMAND_BOX_FORBIDDEN);
// Serialize the response.
responseMessage.SerializeToString(&response);
return;
}
commandzone::Container::Type type = messageRequest.type();
try {
if (type == commandzone::Container::IfThenCommmandBox || type == commandzone::Container::IfElseCommmandBox) {
if (checkAddBreakCommandBox(messageRequest.boxtype(), responseMessage, response)) {
return;
}
IfCommandBox* ifCommandBox = getIfCommandBox(messageRequest.containerid());
if (ifCommandBox == 0) {
......@@ -1517,8 +1538,12 @@ void CommandZoneResponder::processAddNewControlCommandBoxAtEnd(const std::string
}
else if (type == commandzone::Container::CommandZone) {
if (checkAddBreakCommandBox(messageRequest.boxtype(), responseMessage, response)) {
return;
}
try {
CommandBox* commandBox = CommandBoxFactory::getInstance()->createGenericCommandBox((GenericCommandBox::BoxType)messageRequest.boxtype());
CommandBox* commandBox = CommandBoxFactory::getInstance()->createControlCommandBox((ControlCommandBox::BoxType)messageRequest.boxtype());
responseMessage.set_value(CommandZone::getInstance(messageRequest.containerid())->addCommandBoxAtEnd(commandBox));
} catch (CommandZone::CommandZoneNotFound& e) {
......@@ -1540,21 +1565,15 @@ void CommandZoneResponder::processAddNewControlCommandBox(const std::string & me
messageRequest.ParseFromString(message);
common::Int32Response responseMessage;
// check for Break command
if ((ControlCommandBox::BoxType)messageRequest.boxtype() == ControlCommandBox::BREAK) {
responseMessage.set_error(common::Error::COMMAND_BOX_FORBIDDEN);
// Serialize the response.
responseMessage.SerializeToString(&response);
return;
}
commandzone::Container::Type type = messageRequest.type();
try {
if (type == commandzone::Container::IfThenCommmandBox || type == commandzone::Container::IfElseCommmandBox) {
if (checkAddBreakCommandBox(messageRequest.boxtype(), responseMessage, response)) {
return;
}
IfCommandBox* ifCommandBox = getIfCommandBox(messageRequest.containerid());
if (ifCommandBox == 0) {
......@@ -1580,6 +1599,10 @@ void CommandZoneResponder::processAddNewControlCommandBox(const std::string & me
}
else if (type == commandzone::Container::CommandZone) {
if (checkAddBreakCommandBox(messageRequest.boxtype(), responseMessage, response)) {
return;
}
try {
CommandBox* commandBox = CommandBoxFactory::getInstance()->createControlCommandBox((ControlCommandBox::BoxType)messageRequest.boxtype());
responseMessage.set_value(CommandZone::getInstance(messageRequest.containerid())->addCommandBox(commandBox, messageRequest.commandboxidtomove(), messageRequest.above()));
......@@ -1603,20 +1626,16 @@ void CommandZoneResponder::processMoveCommandBox(const std::string & message, st
messageRequest.ParseFromString(message);
common::BooleanResponse responseMessage;
if (getBreakCommandBox(messageRequest.commandboxidtomove())) {
responseMessage.set_error(common::Error::COMMAND_BOX_FORBIDDEN);
// Serialize the response.
responseMessage.SerializeToString(&response);
return;
}
commandzone::Container::Type type = messageRequest.type();
try {
if (type == commandzone::Container::IfThenCommmandBox || type == commandzone::Container::IfElseCommmandBox) {
// Do not authorize to move a break command box here.
if (checkBreakCommandBox(getBreakCommandBox(messageRequest.commandboxidtomove()), responseMessage, response)) {
return;
}
IfCommandBox* ifCommandBox = getIfCommandBox(messageRequest.containerid());
if (ifCommandBox == 0) {
......@@ -1642,6 +1661,11 @@ void CommandZoneResponder::processMoveCommandBox(const std::string & message, st
}
else if (type == commandzone::Container::CommandZone) {
// Do not authorize to move a break command box here.
if (checkBreakCommandBox(getBreakCommandBox(messageRequest.commandboxidtomove()), responseMessage, response)) {
return;
}
try {
CommandZone::getInstance(messageRequest.containerid())->moveCommandBox(messageRequest.commandboxidtomove(), messageRequest.commandboxidtoshift(), messageRequest.above());
responseMessage.set_value(true);
......@@ -1665,20 +1689,16 @@ void CommandZoneResponder::processMoveCommandBoxToEnd(const std::string & messag
messageRequest.ParseFromString(message);
common::BooleanResponse responseMessage;
if (getBreakCommandBox(messageRequest.commandboxidtomove())) {
responseMessage.set_error(common::Error::COMMAND_BOX_FORBIDDEN);
// Serialize the response.
responseMessage.SerializeToString(&response);
return;
}
commandzone::Container::Type type = messageRequest.type();
try {
if (type == commandzone::Container::IfThenCommmandBox || type == commandzone::Container::IfElseCommmandBox) {
// Do not authorize to move a break command box here.
if (checkBreakCommandBox(getBreakCommandBox(messageRequest.commandboxidtomove()), responseMessage, response)) {
return;
}
IfCommandBox* ifCommandBox = getIfCommandBox(messageRequest.containerid());
if (ifCommandBox == 0) {
......@@ -1704,6 +1724,11 @@ void CommandZoneResponder::processMoveCommandBoxToEnd(const std::string & messag
}
else if (type == commandzone::Container::CommandZone) {
// Do not authorize to move a break command box here.
if (checkBreakCommandBox(getBreakCommandBox(messageRequest.commandboxidtomove()), responseMessage, response)) {
return;
}
try {
CommandZone::getInstance(messageRequest.containerid())->moveCommandBoxToEnd(messageRequest.commandboxidtomove());
responseMessage.set_value(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment