DevMgr: Implement a wrapper around the yacc parser.
This wrapper reads the -d <devfile> arguments, collates them into one big string and then feeds them into yacc.
This commit is contained in:
@@ -4,43 +4,53 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <utility>
|
#include <memory>
|
||||||
#include <deviceManager/deviceSpecParser.h>
|
#include <cstdio>
|
||||||
|
#include <deviceManager/deviceManager.h>
|
||||||
|
#include "deviceSpecp.hh"
|
||||||
|
#include "deviceSpecl.hh"
|
||||||
|
|
||||||
std::vector<std::string> readDeviceFile(const std::string& filename)
|
std::string DeviceManager::readDeviceFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::vector<std::string> deviceStrings;
|
|
||||||
std::cerr <<"Here in readDeviceFile" << std::endl;
|
|
||||||
std::ifstream file(filename);
|
std::ifstream file(filename);
|
||||||
std::cerr <<"Here in readDeviceFile after opening ifstream" << std::endl;
|
|
||||||
if (!file.is_open()) {
|
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;
|
std::string content(
|
||||||
while (std::getline(file, line)) {
|
(std::istreambuf_iterator<char>(file)),
|
||||||
if (!line.empty()) {
|
std::istreambuf_iterator<char>());
|
||||||
deviceStrings.push_back(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return deviceStrings;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<std::string, std::string>> parseDeviceSpecifiers(
|
void DeviceManager::collateAllDeviceSpecs(const OptionParser& options)
|
||||||
const std::vector<std::string>& deviceStrings)
|
|
||||||
{
|
{
|
||||||
std::vector<std::pair<std::string, std::string>> deviceSpecifiers;
|
allDeviceSpecs = options.deviceSpecs;
|
||||||
for (const auto& deviceString : deviceStrings) {
|
|
||||||
auto pos = deviceString.find(':');
|
for (const auto& file : options.deviceSpecFiles)
|
||||||
if (pos != std::string::npos) {
|
{
|
||||||
std::string deviceName = deviceString.substr(0, pos);
|
std::string fileContent = readDeviceFile(file);
|
||||||
std::string deviceSpec = deviceString.substr(pos + 1);
|
if (!allDeviceSpecs.empty()) {
|
||||||
deviceSpecifiers.emplace_back(deviceName, deviceSpec);
|
allDeviceSpecs += "||";
|
||||||
} else {
|
|
||||||
throw std::invalid_argument("Invalid device specifier: " +
|
|
||||||
deviceString);
|
|
||||||
}
|
}
|
||||||
|
allDeviceSpecs += fileContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceManager::parseAllDeviceSpecs(void)
|
||||||
|
{
|
||||||
|
std::unique_ptr<FILE, decltype(&fclose)> 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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,23 +4,55 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <opts.h>
|
#include <opts.h>
|
||||||
|
#include <utility>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
class DeviceManager
|
class DeviceManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct SensorDeviceSpec
|
||||||
|
{
|
||||||
|
char sensorType;
|
||||||
|
std::string implexor;
|
||||||
|
std::string api;
|
||||||
|
std::vector<std::string> apiParams;
|
||||||
|
std::string server;
|
||||||
|
std::vector<std::string> 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& getInstance()
|
||||||
{
|
{
|
||||||
static DeviceManager instance;
|
static DeviceManager instance;
|
||||||
return 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:
|
private:
|
||||||
DeviceManager() = default;
|
DeviceManager() = default;
|
||||||
~DeviceManager() = default;
|
~DeviceManager() = default;
|
||||||
DeviceManager(const DeviceManager&) = delete;
|
DeviceManager(const DeviceManager&) = delete;
|
||||||
DeviceManager& operator=(const DeviceManager&) = delete;
|
DeviceManager& operator=(const DeviceManager&) = delete;
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string allDeviceSpecs;
|
||||||
|
static std::vector<InteroceptorDeviceSpec> interoceptorDeviceSpecs;
|
||||||
|
static std::vector<ExtrospectorDeviceSpec> extrospectorDeviceSpecs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEMANAGER_H
|
#endif // DEVICEMANAGER_H
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
#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
|
|
||||||
Reference in New Issue
Block a user