DeviceManager: Initial class with DeviceSpecParser
Hopefully by the end of tonight we should be done with the dev spec parser.
This commit is contained in:
+1
-1
@@ -4,4 +4,4 @@ AM_CPPFLAGS+= -I"$(top_srcdir)/hcore/include"
|
|||||||
|
|
||||||
bin_PROGRAMS = harikoff
|
bin_PROGRAMS = harikoff
|
||||||
harikoff_SOURCES = main.cpp
|
harikoff_SOURCES = main.cpp
|
||||||
harikoff_LDADD = hcore/libhcore.a
|
harikoff_LDADD = hcore/libhcore.a hcore/deviceManager/libdeviceManager.a
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ AC_SUBST([AM_CPPFLAGS])
|
|||||||
AC_CONFIG_HEADERS([include/config.h])
|
AC_CONFIG_HEADERS([include/config.h])
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile hcore/Makefile
|
Makefile hcore/Makefile
|
||||||
|
hcore/deviceManager/Makefile
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_CONFIG_COMMANDS_POST([
|
AC_CONFIG_COMMANDS_POST([
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
SUBDIRS = deviceManager
|
||||||
AM_CPPFLAGS+= -I"$(top_srcdir)/hcore/include"
|
AM_CPPFLAGS+= -I"$(top_srcdir)/hcore/include"
|
||||||
|
|
||||||
noinst_LIBRARIES = libhcore.a
|
noinst_LIBRARIES = libhcore.a
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
AM_CPPFLAGS+= -I"$(top_srcdir)/hcore/include"
|
||||||
|
|
||||||
|
noinst_LIBRARIES = libdeviceManager.a
|
||||||
|
libdeviceManager_a_SOURCES = deviceManager.cpp deviceSpecParser.cpp
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <opts.h>
|
||||||
|
#include <deviceManager/deviceSpecParser.h>
|
||||||
|
#include <deviceManager/deviceManager.h>
|
||||||
|
|
||||||
|
void DeviceManager::handleDeviceSpecifiers(const OptionParser& options)
|
||||||
|
{
|
||||||
|
std::vector<std::string> deviceStrings;
|
||||||
|
deviceStrings.insert(deviceStrings.end(), options.extro.begin(),
|
||||||
|
options.extro.end());
|
||||||
|
deviceStrings.insert(deviceStrings.end(), options.intero.begin(),
|
||||||
|
options.intero.end());
|
||||||
|
deviceStrings.insert(deviceStrings.end(), options.actuator.begin(),
|
||||||
|
options.actuator.end());
|
||||||
|
|
||||||
|
for (const auto& file : options.deviceSpecFiles) {
|
||||||
|
std::vector<std::string> fileDeviceStrings = readDeviceFile(file);
|
||||||
|
deviceStrings.insert(deviceStrings.end(), fileDeviceStrings.begin(),
|
||||||
|
fileDeviceStrings.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, std::string>> deviceSpecifiers =
|
||||||
|
parseDeviceSpecifiers(deviceStrings);
|
||||||
|
|
||||||
|
// Use deviceSpecifiers with the device manager
|
||||||
|
for (const auto& specifier : deviceSpecifiers) {
|
||||||
|
std::cout << "Device: " << specifier.first << ", Specifier: "
|
||||||
|
<< specifier.second << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <utility>
|
||||||
|
#include <deviceManager/deviceSpecParser.h>
|
||||||
|
|
||||||
|
std::vector<std::string> readDeviceFile(const std::string& filename)
|
||||||
|
{
|
||||||
|
std::vector<std::string> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(file, line)) {
|
||||||
|
if (!line.empty()) {
|
||||||
|
deviceStrings.push_back(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return deviceStrings;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, std::string>> parseDeviceSpecifiers(
|
||||||
|
const std::vector<std::string>& deviceStrings)
|
||||||
|
{
|
||||||
|
std::vector<std::pair<std::string, std::string>> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceSpecifiers;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef DEVICEMANAGER_H
|
||||||
|
#define DEVICEMANAGER_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <opts.h>
|
||||||
|
|
||||||
|
class DeviceManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static DeviceManager& getInstance()
|
||||||
|
{
|
||||||
|
static DeviceManager instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleDeviceSpecifiers(const OptionParser& options);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DeviceManager() = default;
|
||||||
|
~DeviceManager() = default;
|
||||||
|
DeviceManager(const DeviceManager&) = delete;
|
||||||
|
DeviceManager& operator=(const DeviceManager&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICEMANAGER_H
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef DEVICESPECPARSER_H
|
||||||
|
#define DEVICESPECPARSER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
std::vector<std::string> readDeviceFile(const std::string& filename);
|
||||||
|
std::vector<std::pair<std::string, std::string>> parseDeviceSpecifiers(
|
||||||
|
const std::vector<std::string>& deviceStrings);
|
||||||
|
|
||||||
|
#endif // DEVICESPECPARSER_H
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
#include <opts.h>
|
#include <opts.h>
|
||||||
#include <mind.h>
|
#include <mind.h>
|
||||||
#include "deviceManager/deviceManager.h"
|
#include <deviceManager/deviceManager.h>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@@ -26,6 +26,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
options.dumpOptions();
|
options.dumpOptions();
|
||||||
|
DeviceManager::getInstance().handleDeviceSpecifiers(options);
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
std::cerr << "Unknown exception occurred" << std::endl;
|
std::cerr << "Unknown exception occurred" << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user