147 lines
3.6 KiB
C++
147 lines
3.6 KiB
C++
#ifndef SENSORDEVICESPEC_H
|
|
#define SENSORDEVICESPEC_H
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#ifdef __cplusplus
|
|
#include <vector>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#endif // __cplusplus
|
|
|
|
#ifdef __cplusplus
|
|
struct SenseDeviceSpec
|
|
{
|
|
char sensorType;
|
|
std::string implexor;
|
|
std::string api;
|
|
std::vector<std::string> apiParams;
|
|
std::string provider;
|
|
std::vector<std::string> providerParams;
|
|
std::string deviceSelector;
|
|
|
|
friend std::ostream& operator<<(
|
|
std::ostream& os, const SenseDeviceSpec& spec);
|
|
|
|
bool operator==(const SenseDeviceSpec& other) const
|
|
{
|
|
return sensorType == other.sensorType &&
|
|
provider == other.provider &&
|
|
deviceSelector == other.deviceSelector;
|
|
}
|
|
};
|
|
|
|
struct InteroceptorDeviceSpec : public SenseDeviceSpec
|
|
{
|
|
};
|
|
|
|
struct ExtrospectorDeviceSpec : public SenseDeviceSpec
|
|
{
|
|
};
|
|
#endif // __cplusplus
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct CSenseDeviceSpec
|
|
{
|
|
#ifdef __cplusplus
|
|
CSenseDeviceSpec(const SenseDeviceSpec& spec)
|
|
: sensorType(spec.sensorType),
|
|
implexor(strdup(spec.implexor.c_str())),
|
|
api(strdup(spec.api.c_str())),
|
|
provider(strdup(spec.provider.c_str())),
|
|
deviceSelector(strdup(spec.deviceSelector.c_str()))
|
|
{
|
|
apiParams = new char*[spec.apiParams.size() + 1];
|
|
for (size_t i = 0; i < spec.apiParams.size(); ++i)
|
|
{
|
|
apiParams[i] = strdup(spec.apiParams[i].c_str());
|
|
}
|
|
apiParams[spec.apiParams.size()] = nullptr;
|
|
|
|
providerParams = new char*[spec.providerParams.size() + 1];
|
|
for (size_t i = 0; i < spec.providerParams.size(); ++i)
|
|
{
|
|
providerParams[i] = strdup(spec.providerParams[i].c_str());
|
|
}
|
|
providerParams[spec.providerParams.size()] = nullptr;
|
|
}
|
|
|
|
~CSenseDeviceSpec(void)
|
|
{
|
|
free(implexor);
|
|
free(api);
|
|
free(provider);
|
|
free(deviceSelector);
|
|
|
|
if (apiParams)
|
|
{
|
|
for (size_t i = 0; apiParams[i] != nullptr; ++i) {
|
|
free(apiParams[i]);
|
|
}
|
|
}
|
|
delete[] apiParams;
|
|
|
|
if (providerParams)
|
|
{
|
|
for (size_t i = 0; providerParams[i] != nullptr; ++i) {
|
|
free(providerParams[i]);
|
|
}
|
|
}
|
|
delete[] providerParams;
|
|
}
|
|
|
|
std::string stringify() const
|
|
{
|
|
std::ostringstream os;
|
|
os << "Device: " << sensorType << ", Implexor: "
|
|
<< (implexor ? implexor : "NULL") << ", API: "
|
|
<< (api ? api : "NULL") << ", API Params: (";
|
|
if (apiParams)
|
|
{
|
|
for (size_t i = 0; apiParams[i] != nullptr; ++i)
|
|
{
|
|
os << apiParams[i] << (apiParams[i + 1] == nullptr ? "" : " ");
|
|
}
|
|
}
|
|
os << "), Provider: " << (provider ? provider : "NULL")
|
|
<< ", Provider Params: (";
|
|
if (providerParams)
|
|
{
|
|
for (size_t i = 0; providerParams[i] != nullptr; ++i)
|
|
{
|
|
os << providerParams[i] << (providerParams[i + 1] == nullptr ? "" : " ");
|
|
}
|
|
}
|
|
os << "), Device Selector: "
|
|
<< (deviceSelector ? deviceSelector : "NULL") << std::endl;
|
|
|
|
return os.str();
|
|
}
|
|
#endif
|
|
|
|
char sensorType;
|
|
char *implexor;
|
|
char *api;
|
|
char **apiParams;
|
|
char *provider;
|
|
char **providerParams;
|
|
char *deviceSelector;
|
|
};
|
|
|
|
inline std::ostream& operator<<(std::ostream& os, const CSenseDeviceSpec& spec)
|
|
{
|
|
os << spec.stringify();
|
|
return os;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // SENSORDEVICESPEC_H
|