Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/JSON-RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,14 @@ Parameters:

| Name | Type | Description |
| --- | --- | --- |
| params.directoryType | string | The directory type as a string (see EDirectoryType and DeserializeDirectoryType). |
| params.directoryType | string | The directory type as a string. One of: none, any_genre_1, any_genre_2, any_genre_asia, genre_rock, genre_jazz, genre_classical_folk, genre_choral_barbershop, custom. The value is matched exactly: it is case-sensitive and is not trimmed. An unrecognised value is rejected. |
| [params.directoryAddress] | string | (optional) The directory address, required if `directoryType` is "custom". |

Results:

| Name | Type | Description |
| --- | --- | --- |
| result | string | Always "ok". |
| result | string | "ok" on success. An unrecognised `directoryType` returns error -32602 and leaves the directory setting unchanged. |


### jamulusserver/setRecordingDirectory
Expand Down
24 changes: 17 additions & 7 deletions src/serverrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,12 @@ CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* pare

/// @rpc_method jamulusserver/setDirectory
/// @brief Set the directory type and, for custom, the directory address.
/// @param {string} params.directoryType - The directory type as a string (see EDirectoryType and DeserializeDirectoryType).
/// @param {string} params.directoryType - The directory type as a string. One of: none, any_genre_1, any_genre_2,
/// any_genre_asia, genre_rock, genre_jazz, genre_classical_folk, genre_choral_barbershop, custom.
/// The value is matched exactly: it is case-sensitive and is not trimmed. An unrecognised value is rejected.
/// @param {string} [params.directoryAddress] - (optional) The directory address, required if `directoryType` is "custom".
/// @result {string} result - Always "ok".
/// @result {string} result - "ok" on success. An unrecognised `directoryType` returns error -32602 and leaves the
/// directory setting unchanged.
pRpcServer->HandleMethod ( "jamulusserver/setDirectory", [=] ( const QJsonObject& params, QJsonObject& response ) {
auto jsonDirectoryType = params["directoryType"];
auto directoryAddress = params["directoryAddress"];
Expand All @@ -264,9 +267,15 @@ CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* pare
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: directory type is not a string" );
return;
}
else

const QString strDirectoryType = jsonDirectoryType.toString();

if ( !DeserializeDirectoryType ( strDirectoryType.toStdString(), directoryType ) )
{
directoryType = DeserializeDirectoryType ( jsonDirectoryType.toString().toStdString() );
response["error"] =
CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams,
QString ( "Invalid params: unrecognised directoryType \"%1\"" ).arg ( strDirectoryType ) );
return;
}

if ( !directoryAddress.isUndefined() )
Expand Down Expand Up @@ -424,13 +433,14 @@ const std::unordered_map<std::string, EDirectoryType> CServerRpc::sumStringToDir
{ "custom", EDirectoryType::AT_CUSTOM },
};

inline EDirectoryType CServerRpc::DeserializeDirectoryType ( std::string sAddrType )
inline bool CServerRpc::DeserializeDirectoryType ( const std::string& sAddrType, EDirectoryType& eAddrType )
{
auto found = sumStringToDirectoryType.find ( sAddrType );
if ( found == sumStringToDirectoryType.end() )
return AT_DEFAULT;
return false;

return found->second;
eAddrType = found->second;
return true;
}

#if defined( Q_OS_MACOS ) && QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
Expand Down
6 changes: 3 additions & 3 deletions src/serverrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CServerRpc : public QObject
const static std::unordered_map<ESvrRegStatus, std::string> sumSvrRegStatusToString;
#endif

QJsonValue SerializeDirectoryType ( EDirectoryType eAddrType );
EDirectoryType DeserializeDirectoryType ( std::string sAddrType );
QJsonValue SerializeRegistrationStatus ( ESvrRegStatus eSvrRegStatus );
QJsonValue SerializeDirectoryType ( EDirectoryType eAddrType );
bool DeserializeDirectoryType ( const std::string& sAddrType, EDirectoryType& eAddrType );
QJsonValue SerializeRegistrationStatus ( ESvrRegStatus eSvrRegStatus );
};
Loading