Build: Add XCB_LIBS; Skeleton: mlo_initializeInd, mlo_attachDeviceReq
* Renamed some of the Sense API lib classes (CSensorDeviceDesc=>CSenseDeviceDesc, SensorDeviceDesc=>SenseDeviceDesc). * Moved SenseApiDesc into /include/user/senseApiDesc. * Add conversion constructor to convert from SenseDeviceDesc to * Wireframe mlo_initializeInd to call xcb_connect(). * Add $(XCB_LIBS) to libxcbXorg_LDFLAGS. * Wireframe mlo_attachDeviceReq().
This commit is contained in:
@@ -8,15 +8,15 @@
|
||||
#include <opts.h>
|
||||
#include <deviceManager/deviceManager.h>
|
||||
|
||||
std::vector<std::unique_ptr<DeviceManager::InteroceptorDeviceSpec>>
|
||||
std::vector<std::unique_ptr<InteroceptorDeviceSpec>>
|
||||
DeviceManager::interoceptorDeviceSpecs;
|
||||
std::vector<std::unique_ptr<DeviceManager::ExtrospectorDeviceSpec>>
|
||||
std::vector<std::unique_ptr<ExtrospectorDeviceSpec>>
|
||||
DeviceManager::extrospectorDeviceSpecs;
|
||||
std::vector<std::reference_wrapper<DeviceManager::SensorDeviceSpec>>
|
||||
DeviceManager::sensorDeviceSpecs;
|
||||
std::vector<std::reference_wrapper<SenseDeviceSpec>>
|
||||
DeviceManager::senseDeviceSpecs;
|
||||
|
||||
std::ostream& operator<<(
|
||||
std::ostream& os, const DeviceManager::SensorDeviceSpec& spec)
|
||||
std::ostream& os, const SenseDeviceSpec& spec)
|
||||
{
|
||||
os << "Device: " << spec.sensorType << ", Implexor: "
|
||||
<< spec.implexor << ", API: " << spec.api
|
||||
|
||||
@@ -38,9 +38,9 @@ void yyerror(const char *message)
|
||||
%union {
|
||||
char* str;
|
||||
char chr;
|
||||
DeviceManager::SensorDeviceSpec* sensorSpec;
|
||||
DeviceManager::InteroceptorDeviceSpec* interoceptorSpec;
|
||||
DeviceManager::ExtrospectorDeviceSpec* extrospectorSpec;
|
||||
SenseDeviceSpec* sensorSpec;
|
||||
InteroceptorDeviceSpec* interoceptorSpec;
|
||||
ExtrospectorDeviceSpec* extrospectorSpec;
|
||||
std::vector<std::string>* stringVector;
|
||||
}
|
||||
|
||||
@@ -72,31 +72,31 @@ sensor_spec:
|
||||
|
||||
interoceptor_spec:
|
||||
KEYWORD_SPECTYPE_INTEROSPECTOR PIPE spec_body {
|
||||
auto spec = std::make_unique<DeviceManager::InteroceptorDeviceSpec>(
|
||||
*static_cast<DeviceManager::InteroceptorDeviceSpec *>($3));
|
||||
auto spec = std::make_unique<InteroceptorDeviceSpec>(
|
||||
*static_cast<InteroceptorDeviceSpec *>($3));
|
||||
|
||||
spec->sensorType = $1;
|
||||
DeviceManager::interoceptorDeviceSpecs.push_back(std::move(spec));
|
||||
DeviceManager::sensorDeviceSpecs.push_back(*spec);
|
||||
DeviceManager::senseDeviceSpecs.push_back(*spec);
|
||||
delete $3;
|
||||
}
|
||||
;
|
||||
|
||||
extrospector_spec:
|
||||
KEYWORD_SPECTYPE_EXTROSPECTOR PIPE spec_body {
|
||||
auto spec = std::make_unique<DeviceManager::ExtrospectorDeviceSpec>(
|
||||
*static_cast<DeviceManager::ExtrospectorDeviceSpec *>($3));
|
||||
auto spec = std::make_unique<ExtrospectorDeviceSpec>(
|
||||
*static_cast<ExtrospectorDeviceSpec *>($3));
|
||||
|
||||
spec->sensorType = $1;
|
||||
DeviceManager::extrospectorDeviceSpecs.push_back(std::move(spec));
|
||||
DeviceManager::sensorDeviceSpecs.push_back(*spec);
|
||||
DeviceManager::senseDeviceSpecs.push_back(*spec);
|
||||
delete $3;
|
||||
}
|
||||
;
|
||||
|
||||
spec_body:
|
||||
STRING PIPE STRING LPAREN opt_params RPAREN PIPE STRING LPAREN opt_params RPAREN PIPE STRING {
|
||||
$$ = new DeviceManager::SensorDeviceSpec();
|
||||
$$ = new SenseDeviceSpec();
|
||||
$$->sensorType = '\0';
|
||||
$$->implexor = std::string($1);
|
||||
$$->api = std::string($3);
|
||||
|
||||
@@ -7,32 +7,11 @@
|
||||
#include <opts.h>
|
||||
#include <utility>
|
||||
#include <iostream>
|
||||
#include <user/senseDeviceSpec.h>
|
||||
|
||||
class DeviceManager
|
||||
{
|
||||
public:
|
||||
struct SensorDeviceSpec
|
||||
{
|
||||
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 SensorDeviceSpec& spec);
|
||||
};
|
||||
|
||||
struct InteroceptorDeviceSpec : public SensorDeviceSpec
|
||||
{
|
||||
};
|
||||
|
||||
struct ExtrospectorDeviceSpec : public SensorDeviceSpec
|
||||
{
|
||||
};
|
||||
|
||||
static DeviceManager& getInstance()
|
||||
{
|
||||
static DeviceManager instance;
|
||||
@@ -56,8 +35,8 @@ public:
|
||||
interoceptorDeviceSpecs;
|
||||
static std::vector<std::unique_ptr<ExtrospectorDeviceSpec>>
|
||||
extrospectorDeviceSpecs;
|
||||
static std::vector<std::reference_wrapper<SensorDeviceSpec>>
|
||||
sensorDeviceSpecs;
|
||||
static std::vector<std::reference_wrapper<SenseDeviceSpec>>
|
||||
senseDeviceSpecs;
|
||||
};
|
||||
|
||||
#endif // DEVICEMANAGER_H
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
#include <senseApis/senseApiLib.h>
|
||||
#include <user/senseDeviceSpec.h>
|
||||
|
||||
namespace hk {
|
||||
namespace sense_api {
|
||||
@@ -24,6 +25,8 @@ public:
|
||||
SenseApiLib& loadSenseApiLib(const std::string& libraryPath);
|
||||
std::optional<std::reference_wrapper<SenseApiLib>> getSenseApiLib(
|
||||
const std::string& libraryPath);
|
||||
std::optional<std::reference_wrapper<SenseApiLib>> getSenseApiLibByApiName(
|
||||
const std::string& apiName);
|
||||
void unloadSenseApiLib(const std::string& libraryPath);
|
||||
|
||||
void initializeSenseApiLib(SenseApiLib& lib);
|
||||
@@ -34,6 +37,11 @@ public:
|
||||
void initializeAllSenseApiLibs(void);
|
||||
void finalizeAllSenseApiLibs(void);
|
||||
|
||||
void attachAllSenseDevicesFromSpecs(void);
|
||||
void attachSenseDevice(const SenseDeviceSpec& spec);
|
||||
void detachSenseDevice(const SenseDeviceSpec& spec);
|
||||
void detachAllSenseDevices(void);
|
||||
|
||||
std::string stringifyLibs() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <senseApis/senseApiLib.h>
|
||||
#include <opts.h>
|
||||
#include <user/senseApiDesc.h>
|
||||
#include <deviceManager/deviceManager.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -117,6 +118,19 @@ SenseApiManager::getSenseApiLib(const std::string& libraryPath)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::reference_wrapper<SenseApiLib>>
|
||||
SenseApiManager::getSenseApiLibByApiName(const std::string& apiName)
|
||||
{
|
||||
auto it = std::find_if(senseApiLibs.begin(), senseApiLibs.end(),
|
||||
[&apiName](const std::unique_ptr<SenseApiLib>& lib) {
|
||||
return lib->getSenseApiDesc()->name == apiName;
|
||||
}
|
||||
);
|
||||
|
||||
if (it != senseApiLibs.end()) { return **it; }
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void SenseApiManager::unloadSenseApiLib(const std::string& libraryPath)
|
||||
{
|
||||
auto it = std::find_if(senseApiLibs.begin(), senseApiLibs.end(),
|
||||
@@ -193,5 +207,61 @@ void SenseApiManager::finalizeAllSenseApiLibs(void)
|
||||
}
|
||||
}
|
||||
|
||||
void SenseApiManager::attachSenseDevice(
|
||||
const SenseDeviceSpec& spec)
|
||||
{
|
||||
auto libOpt = getSenseApiLibByApiName(spec.api);
|
||||
if (!libOpt)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": No library found for API '"
|
||||
+ spec.api + "'");
|
||||
}
|
||||
auto& lib = libOpt.value().get();
|
||||
if (!lib.getSenseApiDesc()->sal_mgmt_libOps->attachDeviceReq)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": attachDeviceReq() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
CSenseDeviceSpec cSpec(spec);
|
||||
lib.getSenseApiDesc()->sal_mgmt_libOps->attachDeviceReq(&cSpec);
|
||||
}
|
||||
|
||||
void SenseApiManager::detachSenseDevice(
|
||||
const SenseDeviceSpec& spec)
|
||||
{
|
||||
auto libOpt = getSenseApiLibByApiName(spec.api);
|
||||
if (!libOpt)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": No library found for API '"
|
||||
+ spec.api + "'");
|
||||
}
|
||||
auto& lib = libOpt.value().get();
|
||||
if (!lib.getSenseApiDesc()->sal_mgmt_libOps->detachDeviceReq)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": detachDeviceReq() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
CSenseDeviceSpec cSpec(spec);
|
||||
lib.getSenseApiDesc()->sal_mgmt_libOps->detachDeviceReq(&cSpec);
|
||||
}
|
||||
|
||||
void SenseApiManager::attachAllSenseDevicesFromSpecs(void)
|
||||
{
|
||||
for (const auto& spec : DeviceManager::senseDeviceSpecs) {
|
||||
attachSenseDevice(spec.get());
|
||||
}
|
||||
}
|
||||
|
||||
void SenseApiManager::detachAllSenseDevices(void)
|
||||
{
|
||||
for (const auto& spec : DeviceManager::senseDeviceSpecs) {
|
||||
detachSenseDevice(spec.get());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sense_api
|
||||
} // namespace hk
|
||||
|
||||
Reference in New Issue
Block a user