From 251e3a28c1dc4ad1fdcf7a77630d4e0e2321c825 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Thu, 26 Aug 2021 23:29:55 -0700 Subject: [PATCH] Requests: Reorder some requests --- src/requesthandler/RequestHandler.cpp | 6 +- src/requesthandler/RequestHandler.h | 6 +- src/requesthandler/RequestHandler_Inputs.cpp | 138 +++++++++---------- src/requesthandler/RequestHandler_Scenes.cpp | 38 ++--- 4 files changed, 94 insertions(+), 94 deletions(-) diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index a5491a79..a9a64960 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -38,13 +38,15 @@ const std::map RequestHandler::_handlerMap {"SetCurrentProgramScene", &RequestHandler::SetCurrentProgramScene}, {"GetCurrentPreviewScene", &RequestHandler::GetCurrentPreviewScene}, {"SetCurrentPreviewScene", &RequestHandler::SetCurrentPreviewScene}, - {"SetSceneName", &RequestHandler::SetSceneName}, {"CreateScene", &RequestHandler::CreateScene}, {"RemoveScene", &RequestHandler::RemoveScene}, + {"SetSceneName", &RequestHandler::SetSceneName}, // Inputs {"GetInputList", &RequestHandler::GetInputList}, {"GetInputKindList", &RequestHandler::GetInputKindList}, + {"CreateInput", &RequestHandler::CreateInput}, + {"SetInputName", &RequestHandler::SetInputName}, {"GetInputDefaultSettings", &RequestHandler::GetInputDefaultSettings}, {"GetInputSettings", &RequestHandler::GetInputSettings}, {"SetInputSettings", &RequestHandler::SetInputSettings}, @@ -53,8 +55,6 @@ const std::map RequestHandler::_handlerMap {"ToggleInputMute", &RequestHandler::ToggleInputMute}, {"GetInputVolume", &RequestHandler::GetInputVolume}, {"SetInputVolume", &RequestHandler::SetInputVolume}, - {"SetInputName", &RequestHandler::SetInputName}, - {"CreateInput", &RequestHandler::CreateInput}, // Stream {"GetStreamStatus", &RequestHandler::GetStreamStatus}, diff --git a/src/requesthandler/RequestHandler.h b/src/requesthandler/RequestHandler.h index 6bf25761..fede22d5 100644 --- a/src/requesthandler/RequestHandler.h +++ b/src/requesthandler/RequestHandler.h @@ -53,13 +53,15 @@ class RequestHandler { RequestResult SetCurrentProgramScene(const Request&); RequestResult GetCurrentPreviewScene(const Request&); RequestResult SetCurrentPreviewScene(const Request&); - RequestResult SetSceneName(const Request&); RequestResult CreateScene(const Request&); RequestResult RemoveScene(const Request&); + RequestResult SetSceneName(const Request&); // Inputs RequestResult GetInputList(const Request&); RequestResult GetInputKindList(const Request&); + RequestResult CreateInput(const Request&); + RequestResult SetInputName(const Request&); RequestResult GetInputDefaultSettings(const Request&); RequestResult GetInputSettings(const Request&); RequestResult SetInputSettings(const Request&); @@ -68,8 +70,6 @@ class RequestHandler { RequestResult ToggleInputMute(const Request&); RequestResult GetInputVolume(const Request&); RequestResult SetInputVolume(const Request&); - RequestResult SetInputName(const Request&); - RequestResult CreateInput(const Request&); // Stream RequestResult GetStreamStatus(const Request&); diff --git a/src/requesthandler/RequestHandler_Inputs.cpp b/src/requesthandler/RequestHandler_Inputs.cpp index a08101f6..dc8eac05 100644 --- a/src/requesthandler/RequestHandler_Inputs.cpp +++ b/src/requesthandler/RequestHandler_Inputs.cpp @@ -37,6 +37,75 @@ RequestResult RequestHandler::GetInputKindList(const Request& request) return RequestResult::Success(responseData); } +RequestResult RequestHandler::CreateInput(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSourceAutoRelease sceneSource = request.ValidateScene("sceneName", statusCode, comment); + if (!(request.ValidateString("inputName", statusCode, comment) && + request.ValidateString("inputKind", statusCode, comment) && + sceneSource)) + return RequestResult::Error(statusCode, comment); + + std::string inputName = request.RequestData["inputName"]; + OBSSourceAutoRelease existingInput = obs_get_source_by_name(inputName.c_str()); + if (existingInput) + return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that input name."); + + std::string inputKind = request.RequestData["inputKind"]; + + auto kinds = Utils::Obs::ListHelper::GetInputKindList(); + if (std::find(kinds.begin(), kinds.end(), inputKind) == kinds.end()) + return RequestResult::Error(RequestStatus::InvalidInputKind, "Your specified input kind is not supported by OBS. Check that your specified kind is properly versioned and that any necessary plugins are loaded."); + + OBSDataAutoRelease inputSettings = nullptr; + if (request.RequestData.contains("inputSettings") && !request.RequestData["inputSettings"].is_null()) { + if (!request.ValidateObject("inputSettings", statusCode, comment, true)) + return RequestResult::Error(statusCode, comment); + + inputSettings = Utils::Json::JsonToObsData(request.RequestData["inputSettings"]); + } + + OBSScene scene = obs_scene_from_source(sceneSource); + + bool sceneItemEnabled = true; + if (request.RequestData.contains("sceneItemEnabled") && !request.RequestData["sceneItemEnabled"].is_null()) { + if (!request.ValidateBoolean("sceneItemEnabled", statusCode, comment)) + return RequestResult::Error(statusCode, comment); + + sceneItemEnabled = request.RequestData["sceneItemEnabled"]; + } + + // Create the input and add it as a scene item to the destination scene + obs_sceneitem_t *sceneItem = Utils::Obs::ActionHelper::CreateInput(inputName, inputKind, inputSettings, scene, sceneItemEnabled); + + if (!sceneItem) + return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Creation of the input or scene item failed."); + + json responseData; + responseData["sceneItemId"] = obs_sceneitem_get_id(sceneItem); + return RequestResult::Success(responseData); +} + +RequestResult RequestHandler::SetInputName(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment); + if (!(input && request.ValidateString("newInputName", statusCode, comment))) + return RequestResult::Error(statusCode, comment); + + std::string newInputName = request.RequestData["newInputName"]; + + OBSSourceAutoRelease existingSource = obs_get_source_by_name(newInputName.c_str()); + if (existingSource) + return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new input name."); + + obs_source_set_name(input, newInputName.c_str()); + + return RequestResult::Success(); +} + RequestResult RequestHandler::GetInputDefaultSettings(const Request& request) { RequestStatus::RequestStatus statusCode; @@ -199,72 +268,3 @@ RequestResult RequestHandler::SetInputVolume(const Request& request) return RequestResult::Success(); } - -RequestResult RequestHandler::SetInputName(const Request& request) -{ - RequestStatus::RequestStatus statusCode; - std::string comment; - OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment); - if (!(input && request.ValidateString("newInputName", statusCode, comment))) - return RequestResult::Error(statusCode, comment); - - std::string newInputName = request.RequestData["newInputName"]; - - OBSSourceAutoRelease existingSource = obs_get_source_by_name(newInputName.c_str()); - if (existingSource) - return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new input name."); - - obs_source_set_name(input, newInputName.c_str()); - - return RequestResult::Success(); -} - -RequestResult RequestHandler::CreateInput(const Request& request) -{ - RequestStatus::RequestStatus statusCode; - std::string comment; - OBSSourceAutoRelease sceneSource = request.ValidateScene("sceneName", statusCode, comment); - if (!(request.ValidateString("inputName", statusCode, comment) && - request.ValidateString("inputKind", statusCode, comment) && - sceneSource)) - return RequestResult::Error(statusCode, comment); - - std::string inputName = request.RequestData["inputName"]; - OBSSourceAutoRelease existingInput = obs_get_source_by_name(inputName.c_str()); - if (existingInput) - return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that input name."); - - std::string inputKind = request.RequestData["inputKind"]; - - auto kinds = Utils::Obs::ListHelper::GetInputKindList(); - if (std::find(kinds.begin(), kinds.end(), inputKind) == kinds.end()) - return RequestResult::Error(RequestStatus::InvalidInputKind, "Your specified input kind is not supported by OBS. Check that your specified kind is properly versioned and that any necessary plugins are loaded."); - - OBSDataAutoRelease inputSettings = nullptr; - if (request.RequestData.contains("inputSettings") && !request.RequestData["inputSettings"].is_null()) { - if (!request.ValidateObject("inputSettings", statusCode, comment, true)) - return RequestResult::Error(statusCode, comment); - - inputSettings = Utils::Json::JsonToObsData(request.RequestData["inputSettings"]); - } - - OBSScene scene = obs_scene_from_source(sceneSource); - - bool sceneItemEnabled = true; - if (request.RequestData.contains("sceneItemEnabled") && !request.RequestData["sceneItemEnabled"].is_null()) { - if (!request.ValidateBoolean("sceneItemEnabled", statusCode, comment)) - return RequestResult::Error(statusCode, comment); - - sceneItemEnabled = request.RequestData["sceneItemEnabled"]; - } - - // Create the input and add it as a scene item to the destination scene - obs_sceneitem_t *sceneItem = Utils::Obs::ActionHelper::CreateInput(inputName, inputKind, inputSettings, scene, sceneItemEnabled); - - if (!sceneItem) - return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Creation of the input or scene item failed."); - - json responseData; - responseData["sceneItemId"] = obs_sceneitem_get_id(sceneItem); - return RequestResult::Success(responseData); -} diff --git a/src/requesthandler/RequestHandler_Scenes.cpp b/src/requesthandler/RequestHandler_Scenes.cpp index ca8ffd2e..ed1aa81b 100644 --- a/src/requesthandler/RequestHandler_Scenes.cpp +++ b/src/requesthandler/RequestHandler_Scenes.cpp @@ -68,25 +68,6 @@ RequestResult RequestHandler::SetCurrentPreviewScene(const Request& request) return RequestResult::Success(); } -RequestResult RequestHandler::SetSceneName(const Request& request) -{ - RequestStatus::RequestStatus statusCode; - std::string comment; - OBSSourceAutoRelease scene = request.ValidateScene("sceneName", statusCode, comment); - if (!(scene && request.ValidateString("newSceneName", statusCode, comment))) - return RequestResult::Error(statusCode, comment); - - std::string newSceneName = request.RequestData["newSceneName"]; - - OBSSourceAutoRelease existingSource = obs_get_source_by_name(newSceneName.c_str()); - if (existingSource) - return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new scene name."); - - obs_source_set_name(scene, newSceneName.c_str()); - - return RequestResult::Success(); -} - RequestResult RequestHandler::CreateScene(const Request& request) { RequestStatus::RequestStatus statusCode; @@ -118,3 +99,22 @@ RequestResult RequestHandler::RemoveScene(const Request& request) return RequestResult::Success(); } + +RequestResult RequestHandler::SetSceneName(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSourceAutoRelease scene = request.ValidateScene("sceneName", statusCode, comment); + if (!(scene && request.ValidateString("newSceneName", statusCode, comment))) + return RequestResult::Error(statusCode, comment); + + std::string newSceneName = request.RequestData["newSceneName"]; + + OBSSourceAutoRelease existingSource = obs_get_source_by_name(newSceneName.c_str()); + if (existingSource) + return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new scene name."); + + obs_source_set_name(scene, newSceneName.c_str()); + + return RequestResult::Success(); +}