mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Requests: Add Compare
Non-functional, will have to finish impl later
This commit is contained in:
parent
f0b207d021
commit
3687086ce0
@ -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},
|
||||
|
@ -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&);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ RequestResult::RequestResult(RequestStatus::RequestStatus statusCode, json respo
|
||||
StatusCode(statusCode),
|
||||
ResponseData(responseData),
|
||||
Comment(comment),
|
||||
SleepFrames(0)
|
||||
SleepFrames(0),
|
||||
NewRequestIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -12,4 +12,5 @@ struct RequestResult
|
||||
json ResponseData;
|
||||
std::string Comment;
|
||||
size_t SleepFrames;
|
||||
size_t NewRequestIndex;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user