diff --git a/hcore/deviceManager/deviceSpecParser.cpp b/hcore/deviceManager/deviceSpecParser.cpp index c4fcd8b..0470a4f 100644 --- a/hcore/deviceManager/deviceSpecParser.cpp +++ b/hcore/deviceManager/deviceSpecParser.cpp @@ -4,43 +4,53 @@ #include #include #include -#include -#include +#include +#include +#include +#include "deviceSpecp.hh" +#include "deviceSpecl.hh" -std::vector readDeviceFile(const std::string& filename) +std::string DeviceManager::readDeviceFile(const std::string& filename) { - std::vector deviceStrings; -std::cerr <<"Here in readDeviceFile" << std::endl; std::ifstream file(filename); -std::cerr <<"Here in readDeviceFile after opening ifstream" << std::endl; if (!file.is_open()) { - throw std::runtime_error("Could not open device file: " + filename); + throw std::runtime_error("Could not open file: " + filename); } - std::string line; - while (std::getline(file, line)) { - if (!line.empty()) { - deviceStrings.push_back(line); - } - } + std::string content( + (std::istreambuf_iterator(file)), + std::istreambuf_iterator()); - return deviceStrings; + return content; } -std::vector> parseDeviceSpecifiers( - const std::vector& deviceStrings) +void DeviceManager::collateAllDeviceSpecs(const OptionParser& options) { - std::vector> deviceSpecifiers; - for (const auto& deviceString : deviceStrings) { - auto pos = deviceString.find(':'); - if (pos != std::string::npos) { - std::string deviceName = deviceString.substr(0, pos); - std::string deviceSpec = deviceString.substr(pos + 1); - deviceSpecifiers.emplace_back(deviceName, deviceSpec); - } else { - throw std::invalid_argument("Invalid device specifier: " + - deviceString); + allDeviceSpecs = options.deviceSpecs; + + for (const auto& file : options.deviceSpecFiles) + { + std::string fileContent = readDeviceFile(file); + if (!allDeviceSpecs.empty()) { + allDeviceSpecs += "||"; } + allDeviceSpecs += fileContent; + } +} + +void DeviceManager::parseAllDeviceSpecs(void) +{ + std::unique_ptr input( + fmemopen((void*)allDeviceSpecs.c_str(), + allDeviceSpecs.size(), "r"), + &fclose); + + if (!input) { + throw std::runtime_error("Failed to open memory as file"); + } + + deviceSpeclin = input.get(); + if (deviceSpecpparse()) { + throw std::runtime_error("Failed to parse device specs"); } - return deviceSpecifiers; } diff --git a/hcore/include/deviceManager/deviceManager.h b/hcore/include/deviceManager/deviceManager.h index aed1bbe..f7760d6 100644 --- a/hcore/include/deviceManager/deviceManager.h +++ b/hcore/include/deviceManager/deviceManager.h @@ -4,23 +4,55 @@ #include #include #include +#include +#include class DeviceManager { public: + struct SensorDeviceSpec + { + char sensorType; + std::string implexor; + std::string api; + std::vector apiParams; + std::string server; + std::vector serverParams; + std::string deviceSelector; + + friend std::ostream& operator<<( + std::ostream& os, const SensorDeviceSpec& spec); + }; + + struct InteroceptorDeviceSpec : public SensorDeviceSpec + { + }; + + struct ExtrospectorDeviceSpec : public SensorDeviceSpec + { + }; + static DeviceManager& getInstance() { static DeviceManager instance; return instance; } - void handleDeviceSpecifiers(const OptionParser& options); + std::string readDeviceFile(const std::string& filename); + void collateAllDeviceSpecs(const OptionParser& options); + void parseAllDeviceSpecs(void); + static const std::string printDeviceSpecs(); private: DeviceManager() = default; ~DeviceManager() = default; DeviceManager(const DeviceManager&) = delete; DeviceManager& operator=(const DeviceManager&) = delete; + +public: + std::string allDeviceSpecs; + static std::vector interoceptorDeviceSpecs; + static std::vector extrospectorDeviceSpecs; }; #endif // DEVICEMANAGER_H diff --git a/hcore/include/deviceManager/deviceSpecParser.h b/hcore/include/deviceManager/deviceSpecParser.h deleted file mode 100644 index 1b3a27b..0000000 --- a/hcore/include/deviceManager/deviceSpecParser.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef DEVICESPECPARSER_H -#define DEVICESPECPARSER_H - -#include -#include -#include - -std::vector readDeviceFile(const std::string& filename); -std::vector> parseDeviceSpecifiers( - const std::vector& deviceStrings); - -#endif // DEVICESPECPARSER_H