diff --git a/hcore/deviceManager/deviceManager.cpp b/hcore/deviceManager/deviceManager.cpp index 2b2857a..a8b31b5 100644 --- a/hcore/deviceManager/deviceManager.cpp +++ b/hcore/deviceManager/deviceManager.cpp @@ -15,33 +15,16 @@ std::vector> std::vector> DeviceManager::senseDeviceSpecs; -std::ostream& operator<<( - std::ostream& os, const SenseDeviceSpec& spec) -{ - os << "Device: " << spec.sensorType << ", Implexor: " - << spec.implexor << ", API: " << spec.api - << ", API Params: ("; - for (auto it = spec.apiParams.begin(); it != spec.apiParams.end(); ++it) { - os << *it << (it + 1 == spec.apiParams.end() ? "" : " "); - } - os << "), Provider: " << spec.provider << ", Provider Params: ("; - for (auto it = spec.providerParams.begin(); it != spec.providerParams.end(); ++it) { - os << *it << (it + 1 == spec.providerParams.end() ? "" : " "); - } - os << "), Device Selector: " << spec.deviceSelector << std::endl; - return os; -} - const std::string DeviceManager::stringifyDeviceSpecs(void) { std::ostringstream oss; for (const auto& spec : DeviceManager::interoceptorDeviceSpecs) { - oss << "Interoceptor " << *spec; + oss << "Interoceptor " << CSenseDeviceSpec(*spec); } for (const auto& spec : DeviceManager::extrospectorDeviceSpecs) { - oss << "Extrospector " << *spec; + oss << "Extrospector " << CSenseDeviceSpec(*spec); } return oss.str(); diff --git a/include/user/senseDeviceSpec.h b/include/user/senseDeviceSpec.h index 1735b3c..000fb74 100644 --- a/include/user/senseDeviceSpec.h +++ b/include/user/senseDeviceSpec.h @@ -8,6 +8,7 @@ #include #include #include +#include #endif // __cplusplus #ifdef __cplusplus @@ -23,6 +24,13 @@ struct SenseDeviceSpec 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 @@ -70,18 +78,50 @@ struct CSenseDeviceSpec free(provider); free(deviceSelector); - for (size_t i = 0; apiParams[i] != nullptr; ++i) + if (apiParams) { - free(apiParams[i]); + for (size_t i = 0; apiParams[i] != nullptr; ++i) { + free(apiParams[i]); + } } delete[] apiParams; - for (size_t i = 0; providerParams[i] != nullptr; ++i) + if (providerParams) { - free(providerParams[i]); + 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; @@ -93,6 +133,12 @@ struct CSenseDeviceSpec char *deviceSelector; }; +inline std::ostream& operator<<(std::ostream& os, const CSenseDeviceSpec& spec) +{ + os << spec.stringify(); + return os; +} + #ifdef __cplusplus } #endif