Requests: Add Compare

Non-functional, will have to finish impl later
This commit is contained in:
tt2468 2021-10-04 17:29:17 -07:00
parent f0b207d021
commit 3687086ce0
5 changed files with 34 additions and 1 deletions

View File

@ -12,6 +12,7 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
{"GetStudioModeEnabled", &RequestHandler::GetStudioModeEnabled},
{"SetStudioModeEnabled", &RequestHandler::SetStudioModeEnabled},
{"Sleep", &RequestHandler::Sleep},
{"Compare", &RequestHandler::Compare},
// Config
{"GetPersistentData", &RequestHandler::GetPersistentData},

View File

@ -33,6 +33,7 @@ class RequestHandler {
RequestResult GetStudioModeEnabled(const Request&);
RequestResult SetStudioModeEnabled(const Request&);
RequestResult Sleep(const Request&);
RequestResult Compare(const Request&);
// Config
RequestResult GetPersistentData(const Request&);

View File

@ -165,3 +165,32 @@ RequestResult RequestHandler::Sleep(const Request& request)
return RequestResult::Error(RequestStatus::UnsupportedRequestBatchExecutionType);
}
}
RequestResult RequestHandler::Compare(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
if (!(request.ValidateBasic("compareValueOne", statusCode, comment) && request.ValidateBasic("compareValueTwo", statusCode, comment) && request.ValidateNumber("newRequestIndex", statusCode, comment, 0)))
return RequestResult::Error(statusCode, comment);
if (!(request.RequestBatchExecutionType == OBS_WEBSOCKET_REQUEST_BATCH_EXECUTION_TYPE_SERIAL_REALTIME || request.RequestBatchExecutionType == OBS_WEBSOCKET_REQUEST_BATCH_EXECUTION_TYPE_SERIAL_FRAME))
return RequestResult::Error(RequestStatus::UnsupportedRequestBatchExecutionType);
bool invert = false;
if (request.Contains("compareInvert")) {
if (!request.ValidateOptionalBoolean("compareInvert", statusCode, comment))
return RequestResult::Error(statusCode, comment);
invert = request.RequestData["compareInvert"];
}
bool result = (request.RequestData["compareValueOne"] == request.RequestData["compareValueTwo"]);
if (invert)
result = !result;
json responseData;
responseData["compareResult"] = result;
RequestResult ret = RequestResult::Success(responseData);
if (result)
ret.NewRequestIndex = request.RequestData["newRequestIndex"];
return ret;
}

View File

@ -4,7 +4,8 @@ RequestResult::RequestResult(RequestStatus::RequestStatus statusCode, json respo
StatusCode(statusCode),
ResponseData(responseData),
Comment(comment),
SleepFrames(0)
SleepFrames(0),
NewRequestIndex(0)
{
}

View File

@ -12,4 +12,5 @@ struct RequestResult
json ResponseData;
std::string Comment;
size_t SleepFrames;
size_t NewRequestIndex;
};