base: Apply latest clang-format changes from upstream

Minus, some customizations, of course
This commit is contained in:
tt2468 2024-04-22 23:44:04 -07:00
parent 74719ce502
commit 5fc39ef054
19 changed files with 229 additions and 85 deletions

View File

@ -1,6 +1,6 @@
# please use clang-format version 8 or later # please use clang-format version 16 or later
Standard: Cpp11 Standard: c++17
AccessModifierOffset: -8 AccessModifierOffset: -8
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false AlignConsecutiveAssignments: false
@ -8,14 +8,14 @@ AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left AlignEscapedNewlines: Left
AlignOperands: true AlignOperands: true
AlignTrailingComments: true AlignTrailingComments: true
#AllowAllArgumentsOnNextLine: false # requires clang-format 9 AllowAllArgumentsOnNextLine: false
#AllowAllConstructorInitializersOnNextLine: false # requires clang-format 9 AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false
#AllowShortLambdasOnASingleLine: Inline # requires clang-format 9 AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None AlwaysBreakAfterReturnType: None
@ -57,6 +57,7 @@ ForEachMacros:
- 'json_object_foreach' - 'json_object_foreach'
- 'json_object_foreach_safe' - 'json_object_foreach_safe'
- 'json_array_foreach' - 'json_array_foreach'
- 'HASH_ITER'
IncludeBlocks: Preserve IncludeBlocks: Preserve
IndentCaseLabels: false IndentCaseLabels: false
IndentPPDirectives: None IndentPPDirectives: None
@ -65,7 +66,7 @@ IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1 MaxEmptyLinesToKeep: 1
NamespaceIndentation: All NamespaceIndentation: All
#ObjCBinPackProtocolList: Auto # requires clang-format 7 ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 8 ObjCBlockIndentWidth: 8
ObjCSpaceAfterProperty: true ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true ObjCSpaceBeforeProtocolList: true
@ -83,13 +84,13 @@ ReflowComments: false
SortIncludes: false SortIncludes: false
SortUsingDeclarations: false SortUsingDeclarations: false
SpaceAfterCStyleCast: false SpaceAfterCStyleCast: false
#SpaceAfterLogicalNot: false # requires clang-format 9 SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true SpaceBeforeAssignmentOperators: true
#SpaceBeforeCtorInitializerColon: true # requires clang-format 7 SpaceBeforeCtorInitializerColon: true
#SpaceBeforeInheritanceColon: true # requires clang-format 7 SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements SpaceBeforeParens: ControlStatements
#SpaceBeforeRangeBasedForLoopColon: true # requires clang-format 7 SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1 SpacesBeforeTrailingComments: 1
SpacesInAngles: false SpacesInAngles: false
@ -97,11 +98,111 @@ SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false SpacesInContainerLiterals: false
SpacesInParentheses: false SpacesInParentheses: false
SpacesInSquareBrackets: false SpacesInSquareBrackets: false
#StatementMacros: # requires clang-format 8 StatementMacros:
# - 'Q_OBJECT' - 'Q_OBJECT'
TabWidth: 8 TabWidth: 8
#TypenameMacros: # requires clang-format 9 TypenameMacros:
# - 'DARRAY' - 'DARRAY'
UseTab: ForContinuationAndIndentation UseTab: ForContinuationAndIndentation
--- ---
Language: ObjC Language: ObjC
AccessModifierOffset: 2
AlignArrayOfStructures: Right
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: false
AcrossComments: true
AllowShortBlocksOnASingleLine: Never
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AttributeMacros: ['__unused', '__autoreleasing', '_Nonnull', '__bridge']
BitFieldColonSpacing: Both
#BreakBeforeBraces: Webkit
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: true
BreakAfterAttributes: Never
BreakArrays: false
BreakBeforeConceptDeclarations: Allowed
BreakBeforeInlineASMColon: OnlyMultiline
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterComma
ColumnLimit: 120
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: false
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: true
InsertBraces: false
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCBreakBeforeNestedBlockParam: false
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PPIndentWidth: -1
PackConstructorInitializers: NextLine
QualifierAlignment: Leave
ReferenceAlignment: Right
RemoveSemicolon: false
RequiresClausePosition: WithPreceding
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 1
SortIncludes: false
#SortUsingDeclarations: LexicographicNumeric
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInConditionalStatement: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
Standard: c++17
TabWidth: 4
UseTab: Never

View File

@ -195,12 +195,14 @@ bool MigratePersistentData()
if (!std::filesystem::exists(moduleConfigDirectory, ec)) if (!std::filesystem::exists(moduleConfigDirectory, ec))
std::filesystem::create_directories(moduleConfigDirectory, ec); std::filesystem::create_directories(moduleConfigDirectory, ec);
if (ec) { if (ec) {
blog(LOG_ERROR, "[MigratePersistentData] Failed to create directory `%s`: %s", moduleConfigDirectory.c_str(), ec.message().c_str()); blog(LOG_ERROR, "[MigratePersistentData] Failed to create directory `%s`: %s", moduleConfigDirectory.c_str(),
ec.message().c_str());
return false; return false;
} }
// Move any existing persistent data to module config directory, then delete old file // Move any existing persistent data to module config directory, then delete old file
std::string oldPersistentDataPath = Utils::Obs::StringHelper::GetCurrentProfilePath() + "/../../../obsWebSocketPersistentData.json"; std::string oldPersistentDataPath =
Utils::Obs::StringHelper::GetCurrentProfilePath() + "/../../../obsWebSocketPersistentData.json";
if (std::filesystem::exists(oldPersistentDataPath, ec)) { if (std::filesystem::exists(oldPersistentDataPath, ec)) {
std::string persistentDataPath = Utils::Obs::StringHelper::GetModuleConfigPath("persistent_data.json"); std::string persistentDataPath = Utils::Obs::StringHelper::GetModuleConfigPath("persistent_data.json");
std::filesystem::copy_file(oldPersistentDataPath, persistentDataPath, ec); std::filesystem::copy_file(oldPersistentDataPath, persistentDataPath, ec);

View File

@ -80,7 +80,8 @@ void EventHandler::ProcessSubscriptionChange(bool type, uint64_t eventSubscripti
if ((eventSubscriptions & EventSubscription::InputVolumeMeters) != 0) { if ((eventSubscriptions & EventSubscription::InputVolumeMeters) != 0) {
if (_inputVolumeMetersRef.fetch_add(1) == 0) { if (_inputVolumeMetersRef.fetch_add(1) == 0) {
if (_inputVolumeMetersHandler) if (_inputVolumeMetersHandler)
blog(LOG_WARNING, "[EventHandler::ProcessSubscription] Input volume meter handler already exists!"); blog(LOG_WARNING,
"[EventHandler::ProcessSubscription] Input volume meter handler already exists!");
else else
_inputVolumeMetersHandler = std::make_unique<Utils::Obs::VolumeMeter::Handler>( _inputVolumeMetersHandler = std::make_unique<Utils::Obs::VolumeMeter::Handler>(
std::bind(&EventHandler::HandleInputVolumeMeters, this, std::placeholders::_1)); std::bind(&EventHandler::HandleInputVolumeMeters, this, std::placeholders::_1));

View File

@ -36,16 +36,10 @@ public:
typedef std::function<void(uint64_t, std::string, json, uint8_t)> typedef std::function<void(uint64_t, std::string, json, uint8_t)>
BroadcastCallback; // uint64_t requiredIntent, std::string eventType, json eventData, uint8_t rpcVersion BroadcastCallback; // uint64_t requiredIntent, std::string eventType, json eventData, uint8_t rpcVersion
inline void SetBroadcastCallback(BroadcastCallback cb) inline void SetBroadcastCallback(BroadcastCallback cb) { _broadcastCallback = cb; }
{
_broadcastCallback = cb;
}
typedef std::function<void(bool)> ObsReadyCallback; // bool ready typedef std::function<void(bool)> ObsReadyCallback; // bool ready
inline void SetObsReadyCallback(ObsReadyCallback cb) inline void SetObsReadyCallback(ObsReadyCallback cb) { _obsReadyCallback = cb; }
{
_obsReadyCallback = cb;
}
void ProcessSubscriptionChange(bool type, uint64_t eventSubscriptions); void ProcessSubscriptionChange(bool type, uint64_t eventSubscriptions);
@ -130,7 +124,7 @@ private:
calldata_t *data); // Direct callback calldata_t *data); // Direct callback
static void HandleInputAudioMonitorTypeChanged(void *param, static void HandleInputAudioMonitorTypeChanged(void *param,
calldata_t *data); // Direct callback calldata_t *data); // Direct callback
void HandleInputVolumeMeters(std::vector<json> inputs); // AudioMeter::Handler callback void HandleInputVolumeMeters(std::vector<json> inputs); // AudioMeter::Handler callback
// Transitions // Transitions
void HandleCurrentSceneTransitionChanged(); void HandleCurrentSceneTransitionChanged();
@ -152,7 +146,7 @@ private:
void HandleSourceFilterCreated(obs_source_t *source, obs_source_t *filter); void HandleSourceFilterCreated(obs_source_t *source, obs_source_t *filter);
void HandleSourceFilterRemoved(obs_source_t *source, obs_source_t *filter); void HandleSourceFilterRemoved(obs_source_t *source, obs_source_t *filter);
static void HandleSourceFilterNameChanged(void *param, static void HandleSourceFilterNameChanged(void *param,
calldata_t *data); // Direct callback calldata_t *data); // Direct callback
void HandleSourceFilterSettingsChanged(obs_source_t *source); void HandleSourceFilterSettingsChanged(obs_source_t *source);
static void HandleSourceFilterEnableStateChanged(void *param, calldata_t *data); // Direct callback static void HandleSourceFilterEnableStateChanged(void *param, calldata_t *data); // Direct callback

View File

@ -177,10 +177,10 @@ void SettingsDialog::SaveFormData()
} }
} }
bool needsRestart = bool needsRestart = (conf->ServerEnabled != ui->enableWebSocketServerCheckBox->isChecked()) ||
(conf->ServerEnabled != ui->enableWebSocketServerCheckBox->isChecked()) || (conf->ServerPort != ui->serverPortSpinBox->value()) ||
(conf->ServerPort != ui->serverPortSpinBox->value()) || (ui->enableAuthenticationCheckBox->isChecked() &&
(ui->enableAuthenticationCheckBox->isChecked() && conf->ServerPassword != ui->serverPasswordLineEdit->text().toStdString()); conf->ServerPassword != ui->serverPasswordLineEdit->text().toStdString());
conf->ServerEnabled = ui->enableWebSocketServerCheckBox->isChecked(); conf->ServerEnabled = ui->enableWebSocketServerCheckBox->isChecked();
conf->AlertsEnabled = ui->enableSystemTrayAlertsCheckBox->isChecked(); conf->AlertsEnabled = ui->enableSystemTrayAlertsCheckBox->isChecked();

View File

@ -82,9 +82,12 @@ bool obs_module_load(void)
_webSocketServer = std::make_shared<WebSocketServer>(); _webSocketServer = std::make_shared<WebSocketServer>();
// Attach event handlers between WebSocket server and event handler // Attach event handlers between WebSocket server and event handler
_eventHandler->SetBroadcastCallback(std::bind(&WebSocketServer::BroadcastEvent, _webSocketServer.get(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _eventHandler->SetBroadcastCallback(std::bind(&WebSocketServer::BroadcastEvent, _webSocketServer.get(),
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4));
_eventHandler->SetObsReadyCallback(std::bind(&WebSocketServer::SetObsReady, _webSocketServer.get(), std::placeholders::_1)); _eventHandler->SetObsReadyCallback(std::bind(&WebSocketServer::SetObsReady, _webSocketServer.get(), std::placeholders::_1));
_webSocketServer->SetClientSubscriptionCallback(std::bind(&EventHandler::ProcessSubscriptionChange, _eventHandler.get(), std::placeholders::_1, std::placeholders::_2)); _webSocketServer->SetClientSubscriptionCallback(std::bind(&EventHandler::ProcessSubscriptionChange, _eventHandler.get(),
std::placeholders::_1, std::placeholders::_2));
// Initialize the settings dialog // Initialize the settings dialog
obs_frontend_push_ui_translation(obs_module_get_string); obs_frontend_push_ui_translation(obs_module_get_string);

View File

@ -37,7 +37,9 @@ struct SerialFrameBatch {
std::condition_variable condition; std::condition_variable condition;
SerialFrameBatch(RequestHandler &requestHandler, json &variables, bool haltOnFailure) SerialFrameBatch(RequestHandler &requestHandler, json &variables, bool haltOnFailure)
: requestHandler(requestHandler), variables(variables), haltOnFailure(haltOnFailure) : requestHandler(requestHandler),
variables(variables),
haltOnFailure(haltOnFailure)
{ {
} }
}; };

View File

@ -106,8 +106,7 @@ RequestResult RequestHandler::GetSceneItemId(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneAutoRelease scene = OBSSceneAutoRelease scene = request.ValidateScene2(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
request.ValidateScene2(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!(scene && request.ValidateString("sourceName", statusCode, comment))) // TODO: Source UUID support if (!(scene && request.ValidateString("sourceName", statusCode, comment))) // TODO: Source UUID support
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -280,7 +279,8 @@ RequestResult RequestHandler::DuplicateSceneItem(const Request &request)
// Get destination scene // Get destination scene
obs_scene_t *destinationScene; obs_scene_t *destinationScene;
if (request.Contains("destinationSceneName")) { if (request.Contains("destinationSceneName")) {
OBSSourceAutoRelease destinationSceneSource = request.ValidateSource("destinationSceneName", "destinationSceneUuid", statusCode, comment); OBSSourceAutoRelease destinationSceneSource =
request.ValidateSource("destinationSceneName", "destinationSceneUuid", statusCode, comment);
if (!destinationSceneSource) if (!destinationSceneSource)
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -288,7 +288,8 @@ RequestResult RequestHandler::DuplicateSceneItem(const Request &request)
if (obs_source_get_type(destinationSceneSource) != OBS_SOURCE_TYPE_SCENE) if (obs_source_get_type(destinationSceneSource) != OBS_SOURCE_TYPE_SCENE)
return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not a scene."); return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not a scene.");
if (obs_source_is_group(destinationSceneSource)) if (obs_source_is_group(destinationSceneSource))
return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not a scene. (Is group)"); return RequestResult::Error(RequestStatus::InvalidResourceType,
"The specified source is not a scene. (Is group)");
destinationScene = obs_scene_get_ref(obs_scene_from_source(destinationSceneSource)); destinationScene = obs_scene_get_ref(obs_scene_from_source(destinationSceneSource));
} else { } else {
@ -346,7 +347,8 @@ RequestResult RequestHandler::GetSceneItemTransform(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!sceneItem) if (!sceneItem)
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -375,7 +377,8 @@ RequestResult RequestHandler::SetSceneItemTransform(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!(sceneItem && request.ValidateObject("sceneItemTransform", statusCode, comment))) if (!(sceneItem && request.ValidateObject("sceneItemTransform", statusCode, comment)))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -533,7 +536,8 @@ RequestResult RequestHandler::GetSceneItemEnabled(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!sceneItem) if (!sceneItem)
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -564,7 +568,8 @@ RequestResult RequestHandler::SetSceneItemEnabled(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!(sceneItem && request.ValidateBoolean("sceneItemEnabled", statusCode, comment))) if (!(sceneItem && request.ValidateBoolean("sceneItemEnabled", statusCode, comment)))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -597,7 +602,8 @@ RequestResult RequestHandler::GetSceneItemLocked(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!sceneItem) if (!sceneItem)
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -628,7 +634,8 @@ RequestResult RequestHandler::SetSceneItemLocked(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!(sceneItem && request.ValidateBoolean("sceneItemLocked", statusCode, comment))) if (!(sceneItem && request.ValidateBoolean("sceneItemLocked", statusCode, comment)))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -663,7 +670,8 @@ RequestResult RequestHandler::GetSceneItemIndex(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!sceneItem) if (!sceneItem)
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -694,7 +702,8 @@ RequestResult RequestHandler::SetSceneItemIndex(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!(sceneItem && request.ValidateNumber("sceneItemIndex", statusCode, comment, 0, 8192))) if (!(sceneItem && request.ValidateNumber("sceneItemIndex", statusCode, comment, 0, 8192)))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -737,7 +746,8 @@ RequestResult RequestHandler::GetSceneItemBlendMode(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!sceneItem) if (!sceneItem)
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -770,7 +780,8 @@ RequestResult RequestHandler::SetSceneItemBlendMode(const Request &request)
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!(sceneItem && request.ValidateString("sceneItemBlendMode", statusCode, comment))) if (!(sceneItem && request.ValidateString("sceneItemBlendMode", statusCode, comment)))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -789,7 +800,8 @@ RequestResult RequestHandler::GetSceneItemPrivateSettings(const Request &request
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!sceneItem) if (!sceneItem)
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);
@ -806,7 +818,8 @@ RequestResult RequestHandler::SetSceneItemPrivateSettings(const Request &request
{ {
RequestStatus::RequestStatus statusCode; RequestStatus::RequestStatus statusCode;
std::string comment; std::string comment;
OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); OBSSceneItemAutoRelease sceneItem =
request.ValidateSceneItem(statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP);
if (!sceneItem || !request.ValidateObject("sceneItemSettings", statusCode, comment, true)) if (!sceneItem || !request.ValidateObject("sceneItemSettings", statusCode, comment, true))
return RequestResult::Error(statusCode, comment); return RequestResult::Error(statusCode, comment);

View File

@ -211,8 +211,8 @@ bool Request::ValidateArray(const std::string &keyName, RequestStatus::RequestSt
return true; return true;
} }
obs_source_t *Request::ValidateSource(const std::string &nameKeyName, const std::string &uuidKeyName, RequestStatus::RequestStatus &statusCode, obs_source_t *Request::ValidateSource(const std::string &nameKeyName, const std::string &uuidKeyName,
std::string &comment) const RequestStatus::RequestStatus &statusCode, std::string &comment) const
{ {
if (ValidateString(nameKeyName, statusCode, comment)) { if (ValidateString(nameKeyName, statusCode, comment)) {
std::string sourceName = RequestData[nameKeyName]; std::string sourceName = RequestData[nameKeyName];
@ -237,11 +237,13 @@ obs_source_t *Request::ValidateSource(const std::string &nameKeyName, const std:
} }
statusCode = RequestStatus::MissingRequestField; statusCode = RequestStatus::MissingRequestField;
comment = std::string("Your request must contain at least one of the following fields: `") + nameKeyName + "` or `" + uuidKeyName + "`."; comment = std::string("Your request must contain at least one of the following fields: `") + nameKeyName + "` or `" +
uuidKeyName + "`.";
return nullptr; return nullptr;
} }
obs_source_t *Request::ValidateScene(RequestStatus::RequestStatus &statusCode, std::string &comment, const ObsWebSocketSceneFilter filter) const obs_source_t *Request::ValidateScene(RequestStatus::RequestStatus &statusCode, std::string &comment,
const ObsWebSocketSceneFilter filter) const
{ {
obs_source_t *ret = ValidateSource("sceneName", "sceneUuid", statusCode, comment); obs_source_t *ret = ValidateSource("sceneName", "sceneUuid", statusCode, comment);
if (!ret) if (!ret)
@ -270,7 +272,8 @@ obs_source_t *Request::ValidateScene(RequestStatus::RequestStatus &statusCode, s
return ret; return ret;
} }
obs_scene_t *Request::ValidateScene2(RequestStatus::RequestStatus &statusCode, std::string &comment, const ObsWebSocketSceneFilter filter) const obs_scene_t *Request::ValidateScene2(RequestStatus::RequestStatus &statusCode, std::string &comment,
const ObsWebSocketSceneFilter filter) const
{ {
OBSSourceAutoRelease sceneSource = ValidateSource("sceneName", "sceneUuid", statusCode, comment); OBSSourceAutoRelease sceneSource = ValidateSource("sceneName", "sceneUuid", statusCode, comment);
if (!sceneSource) if (!sceneSource)
@ -338,7 +341,8 @@ FilterPair Request::ValidateFilter(RequestStatus::RequestStatus &statusCode, std
return FilterPair{source, filter}; return FilterPair{source, filter};
} }
obs_sceneitem_t *Request::ValidateSceneItem(RequestStatus::RequestStatus &statusCode, std::string &comment, const ObsWebSocketSceneFilter filter) const obs_sceneitem_t *Request::ValidateSceneItem(RequestStatus::RequestStatus &statusCode, std::string &comment,
const ObsWebSocketSceneFilter filter) const
{ {
OBSSceneAutoRelease scene = ValidateScene2(statusCode, comment, filter); OBSSceneAutoRelease scene = ValidateScene2(statusCode, comment, filter);
if (!scene) if (!scene)
@ -353,7 +357,8 @@ obs_sceneitem_t *Request::ValidateSceneItem(RequestStatus::RequestStatus &status
if (!sceneItem) { if (!sceneItem) {
std::string sceneName = obs_source_get_name(obs_scene_get_source(scene)); std::string sceneName = obs_source_get_name(obs_scene_get_source(scene));
statusCode = RequestStatus::ResourceNotFound; statusCode = RequestStatus::ResourceNotFound;
comment = std::string("No scene items were found in scene `") + sceneName + "` with the ID `" + std::to_string(sceneItemId) + "`."; comment = std::string("No scene items were found in scene `") + sceneName + "` with the ID `" +
std::to_string(sceneItemId) + "`.";
return nullptr; return nullptr;
} }

View File

@ -64,13 +64,18 @@ struct Request {
const bool allowEmpty = false) const; const bool allowEmpty = false) const;
// All return values have incremented refcounts // All return values have incremented refcounts
obs_source_t *ValidateSource(const std::string &nameKeyName, const std::string &uuidKeyName, RequestStatus::RequestStatus &statusCode, std::string &comment) const; obs_source_t *ValidateSource(const std::string &nameKeyName, const std::string &uuidKeyName,
obs_source_t *ValidateScene(RequestStatus::RequestStatus &statusCode, std::string &comment, const ObsWebSocketSceneFilter filter = OBS_WEBSOCKET_SCENE_FILTER_SCENE_ONLY) const; RequestStatus::RequestStatus &statusCode, std::string &comment) const;
obs_scene_t *ValidateScene2(RequestStatus::RequestStatus &statusCode, std::string &comment, const ObsWebSocketSceneFilter filter = OBS_WEBSOCKET_SCENE_FILTER_SCENE_ONLY) const; obs_source_t *ValidateScene(RequestStatus::RequestStatus &statusCode, std::string &comment,
const ObsWebSocketSceneFilter filter = OBS_WEBSOCKET_SCENE_FILTER_SCENE_ONLY) const;
obs_scene_t *ValidateScene2(RequestStatus::RequestStatus &statusCode, std::string &comment,
const ObsWebSocketSceneFilter filter = OBS_WEBSOCKET_SCENE_FILTER_SCENE_ONLY) const;
obs_source_t *ValidateInput(RequestStatus::RequestStatus &statusCode, std::string &comment) const; obs_source_t *ValidateInput(RequestStatus::RequestStatus &statusCode, std::string &comment) const;
FilterPair ValidateFilter(RequestStatus::RequestStatus &statusCode, std::string &comment) const; FilterPair ValidateFilter(RequestStatus::RequestStatus &statusCode, std::string &comment) const;
obs_sceneitem_t *ValidateSceneItem(RequestStatus::RequestStatus &statusCode, std::string &comment, const ObsWebSocketSceneFilter filter = OBS_WEBSOCKET_SCENE_FILTER_SCENE_ONLY) const; obs_sceneitem_t *ValidateSceneItem(RequestStatus::RequestStatus &statusCode, std::string &comment,
obs_output_t *ValidateOutput(const std::string &keyName, RequestStatus::RequestStatus &statusCode, std::string &comment) const; const ObsWebSocketSceneFilter filter = OBS_WEBSOCKET_SCENE_FILTER_SCENE_ONLY) const;
obs_output_t *ValidateOutput(const std::string &keyName, RequestStatus::RequestStatus &statusCode,
std::string &comment) const;
std::string RequestType; std::string RequestType;
bool HasRequestData; bool HasRequestData;

View File

@ -21,6 +21,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
RequestBatchRequest::RequestBatchRequest(const std::string &requestType, const json &requestData, RequestBatchRequest::RequestBatchRequest(const std::string &requestType, const json &requestData,
RequestBatchExecutionType::RequestBatchExecutionType executionType, RequestBatchExecutionType::RequestBatchExecutionType executionType,
const json &inputVariables, const json &outputVariables) const json &inputVariables, const json &outputVariables)
: Request(requestType, requestData, executionType), InputVariables(inputVariables), OutputVariables(outputVariables) : Request(requestType, requestData, executionType),
InputVariables(inputVariables),
OutputVariables(outputVariables)
{ {
} }

View File

@ -20,7 +20,10 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "RequestResult.h" #include "RequestResult.h"
RequestResult::RequestResult(RequestStatus::RequestStatus statusCode, json responseData, std::string comment) RequestResult::RequestResult(RequestStatus::RequestStatus statusCode, json responseData, std::string comment)
: StatusCode(statusCode), ResponseData(responseData), Comment(comment), SleepFrames(0) : StatusCode(statusCode),
ResponseData(responseData),
Comment(comment),
SleepFrames(0)
{ {
} }

View File

@ -77,5 +77,8 @@ namespace RequestBatchExecutionType {
Parallel = 2, Parallel = 2,
}; };
inline bool IsValid(int8_t executionType) { return executionType >= None && executionType <= Parallel; } inline bool IsValid(int8_t executionType)
{
return executionType >= None && executionType <= Parallel;
}
} }

View File

@ -185,7 +185,8 @@ bool Utils::Json::GetJsonFileContent(std::string fileName, json &content)
try { try {
content = json::parse(f); content = json::parse(f);
} catch (json::parse_error &e) { } catch (json::parse_error &e) {
blog(LOG_WARNING, "[Utils::Json::GetJsonFileContent] Failed to decode content of JSON file `%s`. Error: %s", fileName.c_str(), e.what()); blog(LOG_WARNING, "[Utils::Json::GetJsonFileContent] Failed to decode content of JSON file `%s`. Error: %s",
fileName.c_str(), e.what());
return false; return false;
} }
@ -200,7 +201,8 @@ bool Utils::Json::SetJsonFileContent(std::string fileName, const json &content,
if (!ec && !std::filesystem::exists(p, ec)) if (!ec && !std::filesystem::exists(p, ec))
std::filesystem::create_directories(p, ec); std::filesystem::create_directories(p, ec);
if (ec) { if (ec) {
blog(LOG_ERROR, "[Utils::Json::SetJsonFileContent] Failed to create path directories: %s", ec.message().c_str()); blog(LOG_ERROR, "[Utils::Json::SetJsonFileContent] Failed to create path directories: %s",
ec.message().c_str());
return false; return false;
} }
} }

View File

@ -77,6 +77,9 @@ namespace Utils {
json ObsDataToJson(obs_data_t *d, bool includeDefault = false); json ObsDataToJson(obs_data_t *d, bool includeDefault = false);
bool GetJsonFileContent(std::string fileName, json &content); bool GetJsonFileContent(std::string fileName, json &content);
bool SetJsonFileContent(std::string fileName, const json &content, bool makeDirs = true); bool SetJsonFileContent(std::string fileName, const json &content, bool makeDirs = true);
static inline bool Contains(const json &j, std::string key) { return j.contains(key) && !j[key].is_null(); } static inline bool Contains(const json &j, std::string key)
{
return j.contains(key) && !j[key].is_null();
}
} }
} }

View File

@ -35,7 +35,8 @@ obs_hotkey_t *Utils::Obs::SearchHelper::GetHotkeyByName(std::string name, std::s
auto type = obs_hotkey_get_registerer_type(hotkey); auto type = obs_hotkey_get_registerer_type(hotkey);
if (type == OBS_HOTKEY_REGISTERER_SOURCE) { if (type == OBS_HOTKEY_REGISTERER_SOURCE) {
OBSSourceAutoRelease source = obs_weak_source_get_source((obs_weak_source_t *)obs_hotkey_get_registerer(hotkey)); OBSSourceAutoRelease source =
obs_weak_source_get_source((obs_weak_source_t *)obs_hotkey_get_registerer(hotkey));
if (!source) if (!source)
continue; continue;
@ -43,7 +44,8 @@ obs_hotkey_t *Utils::Obs::SearchHelper::GetHotkeyByName(std::string name, std::s
continue; continue;
} else if (type == OBS_HOTKEY_REGISTERER_OUTPUT) { } else if (type == OBS_HOTKEY_REGISTERER_OUTPUT) {
OBSOutputAutoRelease output = obs_weak_output_get_output((obs_weak_output_t *)obs_hotkey_get_registerer(hotkey)); OBSOutputAutoRelease output =
obs_weak_output_get_output((obs_weak_output_t *)obs_hotkey_get_registerer(hotkey));
if (!output) if (!output)
continue; continue;
@ -51,7 +53,8 @@ obs_hotkey_t *Utils::Obs::SearchHelper::GetHotkeyByName(std::string name, std::s
continue; continue;
} else if (type == OBS_HOTKEY_REGISTERER_ENCODER) { } else if (type == OBS_HOTKEY_REGISTERER_ENCODER) {
OBSEncoderAutoRelease encoder = obs_weak_encoder_get_encoder((obs_weak_encoder_t *)obs_hotkey_get_registerer(hotkey)); OBSEncoderAutoRelease encoder =
obs_weak_encoder_get_encoder((obs_weak_encoder_t *)obs_hotkey_get_registerer(hotkey));
if (!encoder) if (!encoder)
continue; continue;
@ -59,13 +62,13 @@ obs_hotkey_t *Utils::Obs::SearchHelper::GetHotkeyByName(std::string name, std::s
continue; continue;
} else if (type == OBS_HOTKEY_REGISTERER_SERVICE) { } else if (type == OBS_HOTKEY_REGISTERER_SERVICE) {
OBSServiceAutoRelease service = obs_weak_service_get_service((obs_weak_service_t *)obs_hotkey_get_registerer(hotkey)); OBSServiceAutoRelease service =
obs_weak_service_get_service((obs_weak_service_t *)obs_hotkey_get_registerer(hotkey));
if (!service) if (!service)
continue; continue;
if (context != obs_service_get_name(service)) if (context != obs_service_get_name(service))
continue; continue;
} }
return hotkey; return hotkey;
} }

View File

@ -238,7 +238,9 @@ void Utils::Obs::VolumeMeter::Meter::InputVolumeCallback(void *priv_data, callda
} }
Utils::Obs::VolumeMeter::Handler::Handler(UpdateCallback cb, uint64_t updatePeriod) Utils::Obs::VolumeMeter::Handler::Handler(UpdateCallback cb, uint64_t updatePeriod)
: _updateCallback(cb), _updatePeriod(updatePeriod), _running(false) : _updateCallback(cb),
_updatePeriod(updatePeriod),
_running(false)
{ {
signal_handler_t *sh = obs_get_signal_handler(); signal_handler_t *sh = obs_get_signal_handler();
if (!sh) if (!sh)

View File

@ -61,10 +61,7 @@ public:
// Callback for when a client subscribes or unsubscribes. `true` for sub, `false` for unsub // Callback for when a client subscribes or unsubscribes. `true` for sub, `false` for unsub
typedef std::function<void(bool, uint64_t)> ClientSubscriptionCallback; // bool type, uint64_t eventSubscriptions typedef std::function<void(bool, uint64_t)> ClientSubscriptionCallback; // bool type, uint64_t eventSubscriptions
inline void SetClientSubscriptionCallback(ClientSubscriptionCallback cb) inline void SetClientSubscriptionCallback(ClientSubscriptionCallback cb) { _clientSubscriptionCallback = cb; }
{
_clientSubscriptionCallback = cb;
}
inline bool IsListening() { return _server.is_listening(); } inline bool IsListening() { return _server.is_listening(); }

View File

@ -122,5 +122,8 @@ namespace WebSocketOpCode {
RequestBatchResponse = 9, RequestBatchResponse = 9,
}; };
inline bool IsValid(uint8_t opCode) { return opCode >= Hello && opCode <= RequestBatchResponse; } inline bool IsValid(uint8_t opCode)
{
return opCode >= Hello && opCode <= RequestBatchResponse;
}
} }