2025-01-12 14:31:33 -04:00
|
|
|
#ifndef SENSORDEVICESPEC_H
|
|
|
|
|
#define SENSORDEVICESPEC_H
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <iostream>
|
2025-01-13 07:05:05 -04:00
|
|
|
#include <sstream>
|
2025-09-06 21:12:43 -04:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <stdexcept>
|
2025-01-12 14:31:33 -04:00
|
|
|
|
2025-07-22 06:48:04 -04:00
|
|
|
namespace smo {
|
2025-01-13 21:57:11 -04:00
|
|
|
namespace device {
|
2025-01-12 14:31:33 -04:00
|
|
|
|
2025-08-29 15:16:11 -04:00
|
|
|
class DeviceAttachmentSpec
|
2025-01-13 21:57:11 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2025-01-12 14:31:33 -04:00
|
|
|
friend std::ostream& operator<<(
|
2025-08-29 15:16:11 -04:00
|
|
|
std::ostream& os, const DeviceAttachmentSpec& spec)
|
2025-01-13 21:57:11 -04:00
|
|
|
{
|
|
|
|
|
os << spec.stringify();
|
|
|
|
|
return os;
|
|
|
|
|
}
|
2025-01-13 07:05:05 -04:00
|
|
|
|
2025-08-29 15:16:11 -04:00
|
|
|
bool operator==(const DeviceAttachmentSpec& other) const
|
2025-01-13 07:05:05 -04:00
|
|
|
{
|
2025-08-29 15:16:11 -04:00
|
|
|
return deviceIdentifier == other.deviceIdentifier &&
|
|
|
|
|
sensorType == other.sensorType &&
|
2025-10-01 18:10:58 -04:00
|
|
|
qualeIfaceApi == other.qualeIfaceApi &&
|
|
|
|
|
stimBuffApi == other.stimBuffApi &&
|
2025-01-13 07:05:05 -04:00
|
|
|
provider == other.provider &&
|
|
|
|
|
deviceSelector == other.deviceSelector;
|
|
|
|
|
}
|
2025-01-12 14:31:33 -04:00
|
|
|
|
2025-01-13 21:57:11 -04:00
|
|
|
public:
|
2025-08-29 15:16:11 -04:00
|
|
|
std::string deviceIdentifier;
|
2025-01-13 21:57:11 -04:00
|
|
|
char sensorType;
|
2025-10-01 18:10:58 -04:00
|
|
|
std::string qualeIfaceApi;
|
2025-11-01 00:57:04 -04:00
|
|
|
std::vector<std::pair<std::string,std::string>> qualeIfaceApiParams;
|
2025-10-01 18:10:58 -04:00
|
|
|
std::string stimBuffApi;
|
|
|
|
|
std::vector<std::pair<std::string,std::string>> stimBuffApiParams;
|
2025-01-13 21:57:11 -04:00
|
|
|
std::string provider;
|
2025-01-14 14:09:35 -04:00
|
|
|
std::vector<std::pair<std::string,std::string>> providerParams;
|
2025-01-13 21:57:11 -04:00
|
|
|
std::string deviceSelector;
|
2025-01-13 07:05:05 -04:00
|
|
|
|
|
|
|
|
std::string stringify() const
|
|
|
|
|
{
|
|
|
|
|
std::ostringstream os;
|
2025-08-29 15:16:11 -04:00
|
|
|
os << "Device Identifier: " << deviceIdentifier
|
|
|
|
|
<< ", Sensor Type: " << sensorType
|
2025-11-01 00:57:04 -04:00
|
|
|
<< ", QualeIface API: " << qualeIfaceApi << ", QualeIface API Params: (";
|
|
|
|
|
for (const auto& param : qualeIfaceApiParams)
|
|
|
|
|
{
|
|
|
|
|
os << param.first;
|
|
|
|
|
if (!param.second.empty()) {
|
|
|
|
|
os << "=" << param.second;
|
|
|
|
|
}
|
|
|
|
|
os << " ";
|
|
|
|
|
}
|
|
|
|
|
os << "), StimBuff API: " << stimBuffApi
|
2025-10-01 18:10:58 -04:00
|
|
|
<< ", StimBuff API Params: (";
|
|
|
|
|
for (const auto& param : stimBuffApiParams)
|
2025-01-13 07:05:05 -04:00
|
|
|
{
|
2025-01-14 14:09:35 -04:00
|
|
|
os << param.first;
|
|
|
|
|
if (!param.second.empty()) {
|
|
|
|
|
os << "=" << param.second;
|
|
|
|
|
}
|
|
|
|
|
os << " ";
|
2025-01-13 07:05:05 -04:00
|
|
|
}
|
2025-01-13 21:57:11 -04:00
|
|
|
os << "), Provider: " << provider << ", Provider Params: (";
|
|
|
|
|
for (const auto& param : providerParams)
|
2025-01-13 07:05:05 -04:00
|
|
|
{
|
2025-01-14 14:09:35 -04:00
|
|
|
os << param.first;
|
|
|
|
|
if (!param.second.empty()) {
|
|
|
|
|
os << "=" << param.second;
|
|
|
|
|
}
|
|
|
|
|
os << " ";
|
2025-01-13 07:05:05 -04:00
|
|
|
}
|
2025-01-13 21:57:11 -04:00
|
|
|
os << "), Device Selector: " << deviceSelector << std::endl;
|
2025-01-13 07:05:05 -04:00
|
|
|
|
|
|
|
|
return os.str();
|
|
|
|
|
}
|
2025-09-06 21:12:43 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Parse a required integer parameter from provider parameters
|
|
|
|
|
* @param spec The device attachment specification
|
|
|
|
|
* @param paramName The name of the parameter to parse
|
|
|
|
|
* @return The parsed integer value
|
|
|
|
|
* @throws std::runtime_error if parameter is not found or cannot be parsed
|
|
|
|
|
*/
|
|
|
|
|
static int parseRequiredParamAsInt(
|
|
|
|
|
const DeviceAttachmentSpec& spec, const std::string& paramName
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
auto it = std::find_if(
|
|
|
|
|
spec.providerParams.begin(),
|
|
|
|
|
spec.providerParams.end(),
|
|
|
|
|
[¶mName](const auto& param) {
|
|
|
|
|
return param.first == paramName;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (it == spec.providerParams.end())
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
"No " + paramName + " specified in provider params");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return std::stoi(it->second);
|
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
"Failed to parse '" + paramName + "' param value '"
|
|
|
|
|
+ it->second + "' as integer: " + e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-13 21:57:11 -04:00
|
|
|
};
|
2025-01-13 11:53:38 -04:00
|
|
|
|
2025-08-29 15:16:11 -04:00
|
|
|
class InteroceptorDevAttachmentSpec : public DeviceAttachmentSpec
|
2025-01-13 21:57:11 -04:00
|
|
|
{
|
2025-01-12 14:31:33 -04:00
|
|
|
};
|
|
|
|
|
|
2025-08-29 15:16:11 -04:00
|
|
|
class ExtrospectorDevAttachmentSpec : public DeviceAttachmentSpec
|
2025-01-13 07:05:05 -04:00
|
|
|
{
|
2025-01-13 21:57:11 -04:00
|
|
|
};
|
2025-01-13 07:05:05 -04:00
|
|
|
|
2025-01-13 21:57:11 -04:00
|
|
|
} // namespace device
|
2025-07-22 06:48:04 -04:00
|
|
|
} // namespace smo
|
2025-01-12 14:31:33 -04:00
|
|
|
|
|
|
|
|
#endif // SENSORDEVICESPEC_H
|