sil-kit
sil-kit copied to clipboard
Participant parameters
Get the actual values of SIL Kit parameters that are set by public API and possibly overwritten by the participant configuration.
Instead of a seperate interface per parameter, a enum is handed in specifying which parameter should be obtained:
auto GetParameter(SilKit::Parameter parameter) -> const std::string& override;
Currently, the participantName and registryURI are available:#
enum class Parameter : SilKit_Parameter
{
//! An undefined parameter
Undefined = SilKit_Parameter_Undefined,
//! The name of the participant
ParticipantName = SilKit_Parameter_ParticipantName,
//! The registry URI
RegistryUri = SilKit_Parameter_ReistryUri,
};
Any more parameters?
How to deal with non-string parameters?
I committed an updated version with the suggested pattern.
The inOutParameterValueSize includes null-termination, as this is what the user has to allocate.
Not sure about the inOut prefix, I think this is the first appearance of a two-way argument in the C API.
SilKit_ReturnCode SilKitCALL SilKit_Participant_GetParameter(char* outParameterValue, size_t* inOutParameterValueSize,
SilKit_Parameter parameter,
SilKit_Participant* participant)
try
{
ASSERT_VALID_OUT_PARAMETER(inOutParameterValueSize);
ASSERT_VALID_POINTER_PARAMETER(participant);
auto cppParticipant = reinterpret_cast<SilKit::IParticipant*>(participant);
auto cppParameter = static_cast<SilKit::Parameter>(parameter);
auto parameterValue = cppParticipant->GetParameter(cppParameter);
// outParameterValue == nullptr indicates a size-check only, otherwise copy
if (outParameterValue != nullptr)
{
size_t sizeToCopy;
if (*inOutParameterValueSize >= parameterValue.size() + 1)
{
// Don't copy more than we actually have
sizeToCopy = parameterValue.size();
}
else
{
// Don't copy more than the given size
sizeToCopy = *inOutParameterValueSize - 1;
}
parameterValue.copy(outParameterValue, sizeToCopy);
outParameterValue[sizeToCopy] = '\0';
}
*inOutParameterValueSize = parameterValue.size() + 1;
return SilKit_ReturnCode_SUCCESS;
}
CAPI_CATCH_EXCEPTIONS
Usage in C++:
auto ParameterProvider::GetParameter(SilKit_Participant* participant, Parameter parameter) -> std::string
{
std::vector<char> buffer;
size_t size = 0;
SilKit_Parameter cParameter = static_cast<SilKit_Parameter>(parameter);
{
const auto returnCode = SilKit_Participant_GetParameter(nullptr, &size, cParameter, participant);
ThrowOnError(returnCode);
}
while (size > buffer.size())
{
buffer.resize(size);
const auto returnCode = SilKit_Participant_GetParameter(buffer.data(), &size, cParameter, participant);
ThrowOnError(returnCode);
}
buffer.resize(size);
return std::string{buffer.data()};
}