RequestHandler: Simplify request statuses

This commit is contained in:
tt2468 2021-09-01 10:30:40 -07:00
parent 26bef074ac
commit fb0656c31e
11 changed files with 129 additions and 241 deletions

View File

@ -186,11 +186,11 @@ enum RequestStatus {
Success = 100, Success = 100,
// The `requestType` key is missing from the request data // The `requestType` field is missing from the request data
MissingRequestType = 203, MissingRequestType = 203,
// The request type is invalid (does not exist) // The request type is invalid or does not exist
UnknownRequestType = 204, UnknownRequestType = 204,
// Generic error code (comment is expected to be provided) // Generic error code (comment required)
GenericError = 205, GenericError = 205,
// A required request parameter is missing // A required request parameter is missing
@ -198,10 +198,10 @@ enum RequestStatus {
// The request does not have a valid requestData object. // The request does not have a valid requestData object.
MissingRequestData = 301, MissingRequestData = 301,
// Generic invalid request parameter message // Generic invalid request parameter message (comment required)
InvalidRequestParameter = 400, InvalidRequestParameter = 400,
// A request parameter has the wrong data type // A request parameter has the wrong data type
InvalidRequestParameterDataType = 401, InvalidRequestParameterType = 401,
// A request parameter (float or int) is out of valid range // A request parameter (float or int) is out of valid range
RequestParameterOutOfRange = 402, RequestParameterOutOfRange = 402,
// A request parameter (string or array) is empty and cannot be // A request parameter (string or array) is empty and cannot be
@ -213,102 +213,36 @@ enum RequestStatus {
OutputRunning = 500, OutputRunning = 500,
// An output is not running and should be // An output is not running and should be
OutputNotRunning = 501, OutputNotRunning = 501,
// Stream is running and cannot be // An output is paused and should not be
StreamRunning = 502, OutputPaused = 502,
// Stream is not running and should be // An output is disabled and should not be
StreamNotRunning = 503, OutputDisabled = 503,
// Record is running and cannot be
RecordRunning = 504,
// Record is not running and should be
RecordNotRunning = 505,
// Record is paused and cannot be
RecordPaused = 506,
// Replay buffer is running and cannot be
ReplayBufferRunning = 507,
// Replay buffer is not running and should be
ReplayBufferNotRunning = 508,
// Replay buffer is disabled and cannot be
ReplayBufferDisabled = 509,
// Studio mode is active and cannot be // Studio mode is active and cannot be
StudioModeActive = 510, StudioModeActive = 504,
// Studio mode is not active and should be // Studio mode is not active and should be
StudioModeNotActive = 511, StudioModeNotActive = 505,
// Virtualcam is running and cannot be
VirtualcamRunning = 512,
// Virtualcam is not running and should be
VirtualcamNotRunning = 513,
// The specified source (obs_source_t) was of the invalid type (Eg. input instead of scene) // The resource was not found
InvalidSourceType = 600, ResourceNotFound = 600,
// The specified source (obs_source_t) was not found (generic for input, filter, transition, scene) // The resource already exists
SourceNotFound = 601, ResourceAlreadyExists = 601,
// The specified source (obs_source_t) already exists. Applicable to inputs, filters, transitions, scenes // The type of resource found is invalid
SourceAlreadyExists = 602, InvalidResourceType = 602,
// The specified input (obs_source_t-OBS_SOURCE_TYPE_FILTER) was not found // There are not enough instances of the resource in order to perform the request
InputNotFound = 603, NotEnoughResources = 603,
// The state of the resource is invalid. For example, if the resource is blocked from being accessed
InvalidResourceState = 604,
// The specified input (obs_source_t-OBS_SOURCE_TYPE_INPUT) had the wrong kind // The specified input (obs_source_t-OBS_SOURCE_TYPE_INPUT) had the wrong kind
InvalidInputKind = 604, InvalidInputKind = 605,
// The specified filter (obs_source_t-OBS_SOURCE_TYPE_FILTER) was not found
FilterNotFound = 605,
// The specified transition (obs_source_t-OBS_SOURCE_TYPE_TRANSITION) was not found
TransitionNotFound = 606,
// The specified transition (obs_source_t-OBS_SOURCE_TYPE_TRANSITION) does not support setting its position (transition is of fixed type)
TransitionDurationFixed = 607,
// The specified scene (obs_source_t-OBS_SOURCE_TYPE_SCENE), (obs_scene_t) was not found
SceneNotFound = 608,
// The specified scene item (obs_sceneitem_t) was not found
SceneItemNotFound = 609,
// The specified scene collection was not found
SceneCollectionNotFound = 610,
// The specified profile was not found
ProfileNotFound = 611,
// The specified output (obs_output_t) was not found
OutputNotFound = 612,
// The specified encoder (obs_encoder_t) was not found
EncoderNotFound = 613,
// The specified service (obs_service_t) was not found
ServiceNotFound = 614,
// The specified hotkey was not found
HotkeyNotFound = 615,
// The specified directory was not found
DirectoryNotFound = 616,
// The specified config item (config_t) was not found. Could be section or parameter name
ConfigParameterNotFound = 617,
// The specified property (obs_properties_t) was not found
PropertyNotFound = 618,
// The specififed key (OBS_KEY_*) was not found
KeyNotFound = 619,
// The specified data realm (OBS_WEBSOCKET_DATA_REALM_*) was not found
DataRealmNotFound = 620,
// The scene collection already exists
SceneCollectionAlreadyExists = 621,
// There are not enough scene collections to perform the action
NotEnoughSceneCollections = 622,
// The profile already exists
ProfileAlreadyExists = 623,
// There are not enough profiles to perform the action
NotEnoughProfiles = 624,
// There are not enough scenes to perform the action
NotEnoughScenes = 625,
// Processing the request failed unexpectedly // Creating the resource failed
RequestProcessingFailed = 700, ResourceCreationFailed = 700,
// Starting the Output failed // Performing an action on the resource failed
OutputStartFailed = 701, ResourceActionFailed = 701,
// Duplicating the scene item failed // Processing the request failed unexpectedly (comment required)
SceneItemDuplicationFailed = 702, RequestProcessingFailed = 702,
// Rendering the screenshot failed
ScreenshotRenderFailed = 703,
// Encoding the screenshot failed
ScreenshotEncodeFailed = 704,
// Saving the screenshot failed
ScreenshotSaveFailed = 705,
// Creating the directory failed
DirectoryCreationFailed = 706,
// The combination of request parameters cannot be used to perform an action // The combination of request parameters cannot be used to perform an action
CannotAct = 707, CannotAct = 703,
// Creation of a new stream service failed
StreamServiceCreationFailed = 708,
}; };
``` ```

View File

@ -59,6 +59,8 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
{"ToggleInputMute", &RequestHandler::ToggleInputMute}, {"ToggleInputMute", &RequestHandler::ToggleInputMute},
{"GetInputVolume", &RequestHandler::GetInputVolume}, {"GetInputVolume", &RequestHandler::GetInputVolume},
{"SetInputVolume", &RequestHandler::SetInputVolume}, {"SetInputVolume", &RequestHandler::SetInputVolume},
{"GetInputAudioSyncOffset", &RequestHandler::GetInputAudioSyncOffset},
{"SetInputAudioSyncOffset", &RequestHandler::SetInputAudioSyncOffset},
{"GetInputAudioMonitorType", &RequestHandler::GetInputAudioMonitorType}, {"GetInputAudioMonitorType", &RequestHandler::GetInputAudioMonitorType},
{"SetInputAudioMonitorType", &RequestHandler::SetInputAudioMonitorType}, {"SetInputAudioMonitorType", &RequestHandler::SetInputAudioMonitorType},
{"GetInputPropertiesListPropertyItems", &RequestHandler::GetInputPropertiesListPropertyItems}, {"GetInputPropertiesListPropertyItems", &RequestHandler::GetInputPropertiesListPropertyItems},
@ -74,7 +76,7 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
RequestResult RequestHandler::ProcessRequest(const Request& request) RequestResult RequestHandler::ProcessRequest(const Request& request)
{ {
if (!request.RequestData.is_null() && !request.RequestData.is_object()) if (!request.RequestData.is_null() && !request.RequestData.is_object())
return RequestResult::Error(RequestStatus::InvalidRequestParameterDataType, "Your request data is not an object."); return RequestResult::Error(RequestStatus::InvalidRequestParameterType, "Your request data is not an object.");
if (request.RequestType.empty()) if (request.RequestType.empty())
return RequestResult::Error(RequestStatus::MissingRequestType, "Your request is missing a `requestType`"); return RequestResult::Error(RequestStatus::MissingRequestType, "Your request is missing a `requestType`");

View File

@ -74,6 +74,8 @@ class RequestHandler {
RequestResult ToggleInputMute(const Request&); RequestResult ToggleInputMute(const Request&);
RequestResult GetInputVolume(const Request&); RequestResult GetInputVolume(const Request&);
RequestResult SetInputVolume(const Request&); RequestResult SetInputVolume(const Request&);
RequestResult GetInputAudioSyncOffset(const Request&);
RequestResult SetInputAudioSyncOffset(const Request&);
RequestResult GetInputAudioMonitorType(const Request&); RequestResult GetInputAudioMonitorType(const Request&);
RequestResult SetInputAudioMonitorType(const Request&); RequestResult SetInputAudioMonitorType(const Request&);
RequestResult GetInputPropertiesListPropertyItems(const Request&); RequestResult GetInputPropertiesListPropertyItems(const Request&);

View File

@ -20,7 +20,7 @@ RequestResult RequestHandler::GetPersistentData(const Request& request)
else if (realm == "OBS_WEBSOCKET_DATA_REALM_PROFILE") else if (realm == "OBS_WEBSOCKET_DATA_REALM_PROFILE")
persistentDataPath += "/obsWebSocketPersistentData.json"; persistentDataPath += "/obsWebSocketPersistentData.json";
else else
return RequestResult::Error(RequestStatus::DataRealmNotFound, "You have specified an invalid persistent data realm."); return RequestResult::Error(RequestStatus::ResourceNotFound, "You have specified an invalid persistent data realm.");
json responseData; json responseData;
json persistentData; json persistentData;
@ -49,7 +49,7 @@ RequestResult RequestHandler::SetPersistentData(const Request& request)
else if (realm == "OBS_WEBSOCKET_DATA_REALM_PROFILE") else if (realm == "OBS_WEBSOCKET_DATA_REALM_PROFILE")
persistentDataPath += "/obsWebSocketPersistentData.json"; persistentDataPath += "/obsWebSocketPersistentData.json";
else else
return RequestResult::Error(RequestStatus::DataRealmNotFound, "You have specified an invalid persistent data realm."); return RequestResult::Error(RequestStatus::ResourceNotFound, "You have specified an invalid persistent data realm.");
json persistentData = json::object(); json persistentData = json::object();
Utils::Json::GetJsonFileContent(persistentDataPath, persistentData); Utils::Json::GetJsonFileContent(persistentDataPath, persistentData);
@ -79,7 +79,7 @@ RequestResult RequestHandler::SetCurrentSceneCollection(const Request& request)
auto sceneCollections = Utils::Obs::ListHelper::GetSceneCollectionList(); auto sceneCollections = Utils::Obs::ListHelper::GetSceneCollectionList();
if (std::find(sceneCollections.begin(), sceneCollections.end(), sceneCollectionName) == sceneCollections.end()) if (std::find(sceneCollections.begin(), sceneCollections.end(), sceneCollectionName) == sceneCollections.end())
return RequestResult::Error(RequestStatus::SceneCollectionNotFound); return RequestResult::Error(RequestStatus::ResourceNotFound);
std::string currentSceneCollectionName = Utils::Obs::StringHelper::GetCurrentSceneCollection(); std::string currentSceneCollectionName = Utils::Obs::StringHelper::GetCurrentSceneCollection();
// Avoid queueing tasks if nothing will change // Avoid queueing tasks if nothing will change
@ -103,7 +103,7 @@ RequestResult RequestHandler::CreateSceneCollection(const Request& request)
auto sceneCollections = Utils::Obs::ListHelper::GetSceneCollectionList(); auto sceneCollections = Utils::Obs::ListHelper::GetSceneCollectionList();
if (std::find(sceneCollections.begin(), sceneCollections.end(), sceneCollectionName) != sceneCollections.end()) if (std::find(sceneCollections.begin(), sceneCollections.end(), sceneCollectionName) != sceneCollections.end())
return RequestResult::Error(RequestStatus::SceneCollectionAlreadyExists); return RequestResult::Error(RequestStatus::ResourceAlreadyExists);
QMainWindow* mainWindow = reinterpret_cast<QMainWindow*>(obs_frontend_get_main_window()); QMainWindow* mainWindow = reinterpret_cast<QMainWindow*>(obs_frontend_get_main_window());
bool success = false; bool success = false;
@ -133,7 +133,7 @@ RequestResult RequestHandler::SetCurrentProfile(const Request& request)
auto profiles = Utils::Obs::ListHelper::GetProfileList(); auto profiles = Utils::Obs::ListHelper::GetProfileList();
if (std::find(profiles.begin(), profiles.end(), profileName) == profiles.end()) if (std::find(profiles.begin(), profiles.end(), profileName) == profiles.end())
return RequestResult::Error(RequestStatus::ProfileNotFound); return RequestResult::Error(RequestStatus::ResourceNotFound);
std::string currentProfileName = Utils::Obs::StringHelper::GetCurrentProfile(); std::string currentProfileName = Utils::Obs::StringHelper::GetCurrentProfile();
// Avoid queueing tasks if nothing will change // Avoid queueing tasks if nothing will change
@ -157,7 +157,7 @@ RequestResult RequestHandler::CreateProfile(const Request& request)
auto profiles = Utils::Obs::ListHelper::GetProfileList(); auto profiles = Utils::Obs::ListHelper::GetProfileList();
if (std::find(profiles.begin(), profiles.end(), profileName) != profiles.end()) if (std::find(profiles.begin(), profiles.end(), profileName) != profiles.end())
return RequestResult::Error(RequestStatus::ProfileAlreadyExists); return RequestResult::Error(RequestStatus::ResourceAlreadyExists);
QMainWindow* mainWindow = reinterpret_cast<QMainWindow*>(obs_frontend_get_main_window()); QMainWindow* mainWindow = reinterpret_cast<QMainWindow*>(obs_frontend_get_main_window());
QMetaObject::invokeMethod(mainWindow, "NewProfile", Qt::BlockingQueuedConnection, Q_ARG(QString, QString::fromStdString(profileName))); QMetaObject::invokeMethod(mainWindow, "NewProfile", Qt::BlockingQueuedConnection, Q_ARG(QString, QString::fromStdString(profileName)));
@ -176,10 +176,10 @@ RequestResult RequestHandler::RemoveProfile(const Request& request)
auto profiles = Utils::Obs::ListHelper::GetProfileList(); auto profiles = Utils::Obs::ListHelper::GetProfileList();
if (std::find(profiles.begin(), profiles.end(), profileName) == profiles.end()) if (std::find(profiles.begin(), profiles.end(), profileName) == profiles.end())
return RequestResult::Error(RequestStatus::ProfileNotFound); return RequestResult::Error(RequestStatus::ResourceNotFound);
if (profiles.size() < 2) if (profiles.size() < 2)
return RequestResult::Error(RequestStatus::NotEnoughProfiles); return RequestResult::Error(RequestStatus::NotEnoughResources);
QMainWindow* mainWindow = reinterpret_cast<QMainWindow*>(obs_frontend_get_main_window()); QMainWindow* mainWindow = reinterpret_cast<QMainWindow*>(obs_frontend_get_main_window());
QMetaObject::invokeMethod(mainWindow, "DeleteProfile", Qt::BlockingQueuedConnection, Q_ARG(QString, QString::fromStdString(profileName))); QMetaObject::invokeMethod(mainWindow, "DeleteProfile", Qt::BlockingQueuedConnection, Q_ARG(QString, QString::fromStdString(profileName)));
@ -233,12 +233,12 @@ RequestResult RequestHandler::SetProfileParameter(const Request& request)
// Using check helpers here would just make the logic more complicated // Using check helpers here would just make the logic more complicated
if (!request.RequestData.contains("parameterValue") || request.RequestData["parameterValue"].is_null()) { if (!request.RequestData.contains("parameterValue") || request.RequestData["parameterValue"].is_null()) {
if (!config_remove_value(profile, parameterCategory.c_str(), parameterName.c_str())) if (!config_remove_value(profile, parameterCategory.c_str(), parameterName.c_str()))
return RequestResult::Error(RequestStatus::ConfigParameterNotFound); return RequestResult::Error(RequestStatus::ResourceNotFound, "There are no existing instances of that profile parameter.");
} else if (request.RequestData["parameterValue"].is_string()) { } else if (request.RequestData["parameterValue"].is_string()) {
std::string parameterValue = request.RequestData["parameterValue"]; std::string parameterValue = request.RequestData["parameterValue"];
config_set_string(profile, parameterCategory.c_str(), parameterName.c_str(), parameterValue.c_str()); config_set_string(profile, parameterCategory.c_str(), parameterName.c_str(), parameterValue.c_str());
} else { } else {
return RequestResult::Error(RequestStatus::InvalidRequestParameterDataType, "The parameter `parameterValue` must be a string."); return RequestResult::Error(RequestStatus::InvalidRequestParameterType, "The parameter `parameterValue` must be a string.");
} }
return RequestResult::Success(); return RequestResult::Success();
@ -322,7 +322,7 @@ RequestResult RequestHandler::GetStreamServiceSettings(const Request& request)
RequestResult RequestHandler::SetStreamServiceSettings(const Request& request) RequestResult RequestHandler::SetStreamServiceSettings(const Request& request)
{ {
if (obs_frontend_streaming_active()) if (obs_frontend_streaming_active())
return RequestResult::Error(RequestStatus::StreamRunning); return RequestResult::Error(RequestStatus::OutputRunning, "You cannot change stream service settings while streaming.");
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
@ -350,7 +350,7 @@ RequestResult RequestHandler::SetStreamServiceSettings(const Request& request)
OBSService newStreamService = obs_service_create(requestedStreamServiceType.c_str(), "obs_websocket_custom_service", requestedStreamServiceSettings, NULL); OBSService newStreamService = obs_service_create(requestedStreamServiceType.c_str(), "obs_websocket_custom_service", requestedStreamServiceSettings, NULL);
// TODO: Check service type here, instead of relying on service creation to fail. // TODO: Check service type here, instead of relying on service creation to fail.
if (!newStreamService) if (!newStreamService)
return RequestResult::Error(RequestStatus::StreamServiceCreationFailed, "Creating the stream service with the requested streamServiceType failed. It may be an invalid type."); return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Creating the stream service with the requested streamServiceType failed. It may be an invalid type.");
obs_frontend_set_streaming_service(newStreamService); obs_frontend_set_streaming_service(newStreamService);
} }

View File

@ -66,7 +66,7 @@ RequestResult RequestHandler::TriggerHotkeyByName(const Request& request)
obs_hotkey_t *hotkey = Utils::Obs::SearchHelper::GetHotkeyByName(request.RequestData["hotkeyName"]); obs_hotkey_t *hotkey = Utils::Obs::SearchHelper::GetHotkeyByName(request.RequestData["hotkeyName"]);
if (!hotkey) if (!hotkey)
return RequestResult::Error(RequestStatus::HotkeyNotFound); return RequestResult::Error(RequestStatus::ResourceNotFound, "No hotkeys were found by that name.");
obs_hotkey_trigger_routed_callback(obs_hotkey_get_id(hotkey), true); obs_hotkey_trigger_routed_callback(obs_hotkey_get_id(hotkey), true);

View File

@ -50,7 +50,7 @@ RequestResult RequestHandler::CreateInput(const Request& request)
std::string inputName = request.RequestData["inputName"]; std::string inputName = request.RequestData["inputName"];
OBSSourceAutoRelease existingInput = obs_get_source_by_name(inputName.c_str()); OBSSourceAutoRelease existingInput = obs_get_source_by_name(inputName.c_str());
if (existingInput) if (existingInput)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that input name."); return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A source already exists by that input name.");
std::string inputKind = request.RequestData["inputKind"]; std::string inputKind = request.RequestData["inputKind"];
@ -99,7 +99,7 @@ RequestResult RequestHandler::SetInputName(const Request& request)
OBSSourceAutoRelease existingSource = obs_get_source_by_name(newInputName.c_str()); OBSSourceAutoRelease existingSource = obs_get_source_by_name(newInputName.c_str());
if (existingSource) if (existingSource)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new input name."); return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A source already exists by that new input name.");
obs_source_set_name(input, newInputName.c_str()); obs_source_set_name(input, newInputName.c_str());
@ -269,6 +269,35 @@ RequestResult RequestHandler::SetInputVolume(const Request& request)
return RequestResult::Success(); return RequestResult::Success();
} }
RequestResult RequestHandler::GetInputAudioSyncOffset(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment);
if (!input)
return RequestResult::Error(statusCode, comment);
json responseData;
// Offset is stored in nanoseconds in OBS.
responseData["inputAudioSyncOffset"] = obs_source_get_sync_offset(input) / 1000000;
return RequestResult::Success(responseData);
}
RequestResult RequestHandler::SetInputAudioSyncOffset(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment);
if (!(input && request.ValidateNumber("inputAudioSyncOffset", statusCode, comment, -950, 20000)))
return RequestResult::Error(statusCode, comment);
int64_t syncOffset = request.RequestData["inputAudioSyncOffset"];
obs_source_set_sync_offset(input, syncOffset * 1000000);
return RequestResult::Success();
}
RequestResult RequestHandler::GetInputAudioMonitorType(const Request& request) RequestResult RequestHandler::GetInputAudioMonitorType(const Request& request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;

View File

@ -79,7 +79,7 @@ RequestResult RequestHandler::CreateScene(const Request& request)
OBSSourceAutoRelease scene = obs_get_source_by_name(sceneName.c_str()); OBSSourceAutoRelease scene = obs_get_source_by_name(sceneName.c_str());
if (scene) if (scene)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that scene name."); return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A source already exists by that scene name.");
obs_scene_t *createdScene = obs_scene_create(sceneName.c_str()); obs_scene_t *createdScene = obs_scene_create(sceneName.c_str());
obs_scene_release(createdScene); obs_scene_release(createdScene);
@ -112,7 +112,7 @@ RequestResult RequestHandler::SetSceneName(const Request& request)
OBSSourceAutoRelease existingSource = obs_get_source_by_name(newSceneName.c_str()); OBSSourceAutoRelease existingSource = obs_get_source_by_name(newSceneName.c_str());
if (existingSource) if (existingSource)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new scene name."); return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A source already exists by that new scene name.");
obs_source_set_name(scene, newSceneName.c_str()); obs_source_set_name(scene, newSceneName.c_str());

View File

@ -102,10 +102,10 @@ RequestResult RequestHandler::GetSourceActive(const Request& request)
OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str()); OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str());
if (!source) if (!source)
return RequestResult::Error(RequestStatus::SourceNotFound); return RequestResult::Error(RequestStatus::ResourceNotFound);
if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT && obs_source_get_type(source) != OBS_SOURCE_TYPE_SCENE) if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT && obs_source_get_type(source) != OBS_SOURCE_TYPE_SCENE)
return RequestResult::Error(RequestStatus::InvalidSourceType, "The specified source is not an input or a scene."); return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not an input or a scene.");
json responseData; json responseData;
responseData["videoActive"] = obs_source_active(source); responseData["videoActive"] = obs_source_active(source);
@ -124,10 +124,10 @@ RequestResult RequestHandler::GetSourceScreenshot(const Request& request)
OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str()); OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str());
if (!source) if (!source)
return RequestResult::Error(RequestStatus::SourceNotFound); return RequestResult::Error(RequestStatus::ResourceNotFound);
if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT && obs_source_get_type(source) != OBS_SOURCE_TYPE_SCENE) if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT && obs_source_get_type(source) != OBS_SOURCE_TYPE_SCENE)
return RequestResult::Error(RequestStatus::InvalidSourceType, "The specified source is not an input or a scene."); return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not an input or a scene.");
std::string imageFormat = request.RequestData["imageFormat"]; std::string imageFormat = request.RequestData["imageFormat"];
@ -163,14 +163,14 @@ RequestResult RequestHandler::GetSourceScreenshot(const Request& request)
QImage renderedImage = TakeSourceScreenshot(source, success, requestedWidth, requestedHeight); QImage renderedImage = TakeSourceScreenshot(source, success, requestedWidth, requestedHeight);
if (!success) if (!success)
return RequestResult::Error(RequestStatus::ScreenshotRenderFailed); return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Failed to render screenshot.");
QByteArray encodedImgBytes; QByteArray encodedImgBytes;
QBuffer buffer(&encodedImgBytes); QBuffer buffer(&encodedImgBytes);
buffer.open(QBuffer::WriteOnly); buffer.open(QBuffer::WriteOnly);
if (!renderedImage.save(&buffer, imageFormat.c_str(), compressionQuality)) if (!renderedImage.save(&buffer, imageFormat.c_str(), compressionQuality))
return RequestResult::Error(RequestStatus::ScreenshotEncodeFailed); return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Failed to encode screenshot.");
buffer.close(); buffer.close();
@ -192,10 +192,10 @@ RequestResult RequestHandler::SaveSourceScreenshot(const Request& request)
OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str()); OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str());
if (!source) if (!source)
return RequestResult::Error(RequestStatus::SourceNotFound); return RequestResult::Error(RequestStatus::ResourceNotFound, "No source was found by that name.");
if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT && obs_source_get_type(source) != OBS_SOURCE_TYPE_SCENE) if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT && obs_source_get_type(source) != OBS_SOURCE_TYPE_SCENE)
return RequestResult::Error(RequestStatus::InvalidSourceType, "The specified source is not an input or a scene."); return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not an input or a scene.");
std::string imageFormat = request.RequestData["imageFormat"]; std::string imageFormat = request.RequestData["imageFormat"];
@ -231,18 +231,18 @@ RequestResult RequestHandler::SaveSourceScreenshot(const Request& request)
QImage renderedImage = TakeSourceScreenshot(source, success, requestedWidth, requestedHeight); QImage renderedImage = TakeSourceScreenshot(source, success, requestedWidth, requestedHeight);
if (!success) if (!success)
return RequestResult::Error(RequestStatus::ScreenshotRenderFailed); return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Failed to render screenshot.");
std::string imageFilePath = request.RequestData["imageFilePath"]; std::string imageFilePath = request.RequestData["imageFilePath"];
QFileInfo filePathInfo(QString::fromStdString(imageFilePath)); QFileInfo filePathInfo(QString::fromStdString(imageFilePath));
if (!filePathInfo.absoluteDir().exists()) if (!filePathInfo.absoluteDir().exists())
return RequestResult::Error(RequestStatus::DirectoryNotFound, "The directory for your file path does not exist."); return RequestResult::Error(RequestStatus::ResourceNotFound, "The directory for your file path does not exist.");
QString absoluteFilePath = filePathInfo.absoluteFilePath(); QString absoluteFilePath = filePathInfo.absoluteFilePath();
if (!renderedImage.save(absoluteFilePath, imageFormat.c_str(), compressionQuality)) if (!renderedImage.save(absoluteFilePath, imageFormat.c_str(), compressionQuality))
return RequestResult::Error(RequestStatus::ScreenshotSaveFailed); return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Failed to save screenshot.");
return RequestResult::Success(); return RequestResult::Success();
} }

View File

@ -34,7 +34,7 @@ RequestResult RequestHandler::ToggleStream(const Request& request)
RequestResult RequestHandler::StartStream(const Request& request) RequestResult RequestHandler::StartStream(const Request& request)
{ {
if (obs_frontend_streaming_active()) if (obs_frontend_streaming_active())
return RequestResult::Error(RequestStatus::StreamRunning); return RequestResult::Error(RequestStatus::OutputRunning);
// TODO: Call signal directly to perform blocking wait // TODO: Call signal directly to perform blocking wait
obs_frontend_streaming_start(); obs_frontend_streaming_start();
@ -45,7 +45,7 @@ RequestResult RequestHandler::StartStream(const Request& request)
RequestResult RequestHandler::StopStream(const Request& request) RequestResult RequestHandler::StopStream(const Request& request)
{ {
if (!obs_frontend_streaming_active()) if (!obs_frontend_streaming_active())
return RequestResult::Error(RequestStatus::StreamNotRunning); return RequestResult::Error(RequestStatus::OutputNotRunning);
// TODO: Call signal directly to perform blocking wait // TODO: Call signal directly to perform blocking wait
obs_frontend_streaming_stop(); obs_frontend_streaming_stop();

View File

@ -42,7 +42,7 @@ const bool Request::ValidateNumber(const std::string keyName, RequestStatus::Req
return false; return false;
if (!RequestData[keyName].is_number()) { if (!RequestData[keyName].is_number()) {
statusCode = RequestStatus::InvalidRequestParameterDataType; statusCode = RequestStatus::InvalidRequestParameterType;
comment = std::string("The parameter `") + keyName + "` must be a number."; comment = std::string("The parameter `") + keyName + "` must be a number.";
return false; return false;
} }
@ -68,7 +68,7 @@ const bool Request::ValidateString(const std::string keyName, RequestStatus::Req
return false; return false;
if (!RequestData[keyName].is_string()) { if (!RequestData[keyName].is_string()) {
statusCode = RequestStatus::InvalidRequestParameterDataType; statusCode = RequestStatus::InvalidRequestParameterType;
comment = std::string("The parameter `") + keyName + "` must be a string."; comment = std::string("The parameter `") + keyName + "` must be a string.";
return false; return false;
} }
@ -88,7 +88,7 @@ const bool Request::ValidateBoolean(const std::string keyName, RequestStatus::Re
return false; return false;
if (!RequestData[keyName].is_boolean()) { if (!RequestData[keyName].is_boolean()) {
statusCode = RequestStatus::InvalidRequestParameterDataType; statusCode = RequestStatus::InvalidRequestParameterType;
comment = std::string("The parameter `") + keyName + "` must be boolean."; comment = std::string("The parameter `") + keyName + "` must be boolean.";
return false; return false;
} }
@ -102,7 +102,7 @@ const bool Request::ValidateObject(const std::string keyName, RequestStatus::Req
return false; return false;
if (!RequestData[keyName].is_object()) { if (!RequestData[keyName].is_object()) {
statusCode = RequestStatus::InvalidRequestParameterDataType; statusCode = RequestStatus::InvalidRequestParameterType;
comment = std::string("The parameter `") + keyName + "` must be an object."; comment = std::string("The parameter `") + keyName + "` must be an object.";
return false; return false;
} }
@ -122,7 +122,7 @@ const bool Request::ValidateArray(const std::string keyName, RequestStatus::Requ
return false; return false;
if (!RequestData[keyName].is_array()) { if (!RequestData[keyName].is_array()) {
statusCode = RequestStatus::InvalidRequestParameterDataType; statusCode = RequestStatus::InvalidRequestParameterType;
comment = std::string("The parameter `") + keyName + "` must be an array."; comment = std::string("The parameter `") + keyName + "` must be an array.";
return false; return false;
} }
@ -145,14 +145,14 @@ obs_source_t *Request::ValidateScene(const std::string keyName, RequestStatus::R
obs_source_t *ret = obs_get_source_by_name(sceneName.c_str()); obs_source_t *ret = obs_get_source_by_name(sceneName.c_str());
if (!ret) { if (!ret) {
statusCode = RequestStatus::SceneNotFound; statusCode = RequestStatus::ResourceNotFound;
comment = std::string("No scene was found by the name of `") + sceneName + "`."; comment = std::string("No scene was found by the name of `") + sceneName + "`.";
return nullptr; return nullptr;
} }
if (obs_source_get_type(ret) != OBS_SOURCE_TYPE_SCENE) { if (obs_source_get_type(ret) != OBS_SOURCE_TYPE_SCENE) {
obs_source_release(ret); obs_source_release(ret);
statusCode = RequestStatus::InvalidSourceType; statusCode = RequestStatus::InvalidResourceType;
comment = "The specified source is not a scene."; comment = "The specified source is not a scene.";
return nullptr; return nullptr;
} }
@ -160,7 +160,7 @@ obs_source_t *Request::ValidateScene(const std::string keyName, RequestStatus::R
OBSScene scene = obs_scene_from_source(ret); OBSScene scene = obs_scene_from_source(ret);
if (obs_scene_is_group(scene)) { if (obs_scene_is_group(scene)) {
obs_source_release(ret); obs_source_release(ret);
statusCode = RequestStatus::InvalidSourceType; statusCode = RequestStatus::InvalidResourceType;
comment = "The specified source is not a scene."; comment = "The specified source is not a scene.";
return nullptr; return nullptr;
} }
@ -177,14 +177,14 @@ obs_source_t *Request::ValidateInput(const std::string keyName, RequestStatus::R
obs_source_t *ret = obs_get_source_by_name(inputName.c_str()); obs_source_t *ret = obs_get_source_by_name(inputName.c_str());
if (!ret) { if (!ret) {
statusCode = RequestStatus::InputNotFound; statusCode = RequestStatus::ResourceNotFound;
comment = std::string("No input was found by the name of `") + inputName + "`."; comment = std::string("No input was found by the name of `") + inputName + "`.";
return nullptr; return nullptr;
} }
if (obs_source_get_type(ret) != OBS_SOURCE_TYPE_INPUT) { if (obs_source_get_type(ret) != OBS_SOURCE_TYPE_INPUT) {
obs_source_release(ret); obs_source_release(ret);
statusCode = RequestStatus::InvalidSourceType; statusCode = RequestStatus::InvalidResourceType;
comment = "The specified source is not an input."; comment = "The specified source is not an input.";
return nullptr; return nullptr;
} }

View File

@ -11,9 +11,9 @@ namespace RequestStatus {
// The `requestType` field is missing from the request data // The `requestType` field is missing from the request data
MissingRequestType = 203, MissingRequestType = 203,
// The request type is invalid (does not exist) // The request type is invalid or does not exist
UnknownRequestType = 204, UnknownRequestType = 204,
// Generic error code (comment is expected to be provided) // Generic error code (comment required)
GenericError = 205, GenericError = 205,
// A required request parameter is missing // A required request parameter is missing
@ -21,129 +21,50 @@ namespace RequestStatus {
// The request does not have a valid requestData object. // The request does not have a valid requestData object.
MissingRequestData = 301, MissingRequestData = 301,
// Generic invalid request parameter message // Generic invalid request parameter message (comment required)
InvalidRequestParameter = 400, InvalidRequestParameter = 400,
// A request parameter has the wrong data type // A request parameter has the wrong data type
InvalidRequestParameterDataType = 401, InvalidRequestParameterType = 401,
// A request parameter (float or int) is out of valid range // A request parameter (float or int) is out of valid range
RequestParameterOutOfRange = 402, RequestParameterOutOfRange = 402,
// A request parameter (string or array) is empty and cannot be // A request parameter (string or array) is empty and cannot be
RequestParameterEmpty = 403, RequestParameterEmpty = 403,
// There are too many request parameters (eg. a request takes two optionals, where only one is allowed at a time) // There are too many request parameters (eg. a request takes two optionals, where only one is allowed at a time)
TooManyRequestParameters = 404, TooManyRequestParameters = 404,
InvalidRequestParameterType = 405,
// An output is running and cannot be in order to perform the request (generic) // An output is running and cannot be in order to perform the request (generic)
OutputRunning = 500, OutputRunning = 500,
// An output is not running and should be // An output is not running and should be
OutputNotRunning = 501, OutputNotRunning = 501,
// Stream is running and cannot be // An output is paused and should not be
StreamRunning = 502, OutputPaused = 502,
// Stream is not running and should be // An output is disabled and should not be
StreamNotRunning = 503, OutputDisabled = 503,
// Record is running and cannot be
RecordRunning = 504,
// Record is not running and should be
RecordNotRunning = 505,
// Record is paused and cannot be
RecordPaused = 506,
// Replay buffer is running and cannot be
ReplayBufferRunning = 507,
// Replay buffer is not running and should be
ReplayBufferNotRunning = 508,
// Replay buffer is disabled and cannot be
ReplayBufferDisabled = 509,
// Studio mode is active and cannot be // Studio mode is active and cannot be
StudioModeActive = 510, StudioModeActive = 504,
// Studio mode is not active and should be // Studio mode is not active and should be
StudioModeNotActive = 511, StudioModeNotActive = 505,
// Virtualcam is running and cannot be
VirtualcamRunning = 512,
// Virtualcam is not running and should be
VirtualcamNotRunning = 513,
OutputPaused = 514,
OutputDisabled = 515,
// The specified source (obs_source_t) was of the invalid type (Eg. input instead of scene)
InvalidSourceType = 600,
// The specified source (obs_source_t) was not found (generic for input, filter, transition, scene)
SourceNotFound = 601,
// The specified source (obs_source_t) already exists. Applicable to inputs, filters, transitions, scenes
SourceAlreadyExists = 602,
// The specified input (obs_source_t-OBS_SOURCE_TYPE_FILTER) was not found
InputNotFound = 603,
// The specified input (obs_source_t-OBS_SOURCE_TYPE_INPUT) had the wrong kind
InvalidInputKind = 604,
// The specified filter (obs_source_t-OBS_SOURCE_TYPE_FILTER) was not found
FilterNotFound = 605,
// The specified transition (obs_source_t-OBS_SOURCE_TYPE_TRANSITION) was not found
TransitionNotFound = 606,
// The specified transition (obs_source_t-OBS_SOURCE_TYPE_TRANSITION) does not support setting its position (transition is of fixed type)
TransitionDurationFixed = 607,
// The specified scene (obs_source_t-OBS_SOURCE_TYPE_SCENE), (obs_scene_t) was not found
SceneNotFound = 608,
// The specified scene item (obs_sceneitem_t) was not found
SceneItemNotFound = 609,
// The specified scene collection was not found
SceneCollectionNotFound = 610,
// The specified profile was not found
ProfileNotFound = 611,
// The specified output (obs_output_t) was not found
OutputNotFound = 612,
// The specified encoder (obs_encoder_t) was not found
EncoderNotFound = 613,
// The specified service (obs_service_t) was not found
ServiceNotFound = 614,
// The specified hotkey was not found
HotkeyNotFound = 615,
// The specified directory was not found
DirectoryNotFound = 616,
// The specified config item (config_t) was not found. Could be section or parameter name
ConfigParameterNotFound = 617,
// The specified property (obs_properties_t) was not found
PropertyNotFound = 618,
// The specififed key (OBS_KEY_*) was not found
KeyNotFound = 619,
// The specified data realm (OBS_WEBSOCKET_DATA_REALM_*) was not found
DataRealmNotFound = 620,
// The scene collection already exists
SceneCollectionAlreadyExists = 621,
// There are not enough scene collections to perform the action
NotEnoughSceneCollections = 622,
// The profile already exists
ProfileAlreadyExists = 623,
// There are not enough profiles to perform the action
NotEnoughProfiles = 624,
// There are not enough scenes to perform the action
NotEnoughScenes = 625,
// The resource was not found // The resource was not found
ResourceNotFound = 626, ResourceNotFound = 600,
// The resource already exists
ResourceAlreadyExists = 601,
// The type of resource found is invalid // The type of resource found is invalid
InvalidResourceType = 627, InvalidResourceType = 602,
// There are not enough instances of the resource in order to perform the request
NotEnoughResources = 603,
// The state of the resource is invalid. For example, if the resource is blocked from being accessed // The state of the resource is invalid. For example, if the resource is blocked from being accessed
InvalidResourceState = 628, InvalidResourceState = 604,
NotEnoughResources = 629, // The specified input (obs_source_t-OBS_SOURCE_TYPE_INPUT) had the wrong kind
ResourceAlreadyExists = 630, InvalidInputKind = 605,
// Processing the request failed unexpectedly // Creating the resource failed
RequestProcessingFailed = 700, ResourceCreationFailed = 700,
// Starting the Output failed // Performing an action on the resource failed
OutputStartFailed = 701, ResourceActionFailed = 701,
// Duplicating the scene item failed // Processing the request failed unexpectedly (comment required)
SceneItemDuplicationFailed = 702, RequestProcessingFailed = 702,
// Rendering the screenshot failed
ScreenshotRenderFailed = 703,
// Encoding the screenshot failed
ScreenshotEncodeFailed = 704,
// Saving the screenshot failed
ScreenshotSaveFailed = 705,
// Creating the directory failed
DirectoryCreationFailed = 706,
// The combination of request parameters cannot be used to perform an action // The combination of request parameters cannot be used to perform an action
CannotAct = 707, CannotAct = 703,
// Creation of a new stream service failed
StreamServiceCreationFailed = 708,
ResourceCreationFailed = 709,
ResourceActionFailed = 710,
}; };
}; };