DevMgr: Make vectors hold sh_ptr and not uniq_ptr

This allows us to mirror the contents of the two lists into the unified
list much more easily.
This commit is contained in:
2025-01-13 08:02:59 -04:00
parent edf51a4441
commit 660f0f0e73
6 changed files with 21 additions and 44 deletions
+3 -3
View File
@@ -8,11 +8,11 @@
#include <opts.h> #include <opts.h>
#include <deviceManager/deviceManager.h> #include <deviceManager/deviceManager.h>
std::vector<std::unique_ptr<InteroceptorDeviceSpec>> std::vector<std::shared_ptr<InteroceptorDeviceSpec>>
DeviceManager::interoceptorDeviceSpecs; DeviceManager::interoceptorDeviceSpecs;
std::vector<std::unique_ptr<ExtrospectorDeviceSpec>> std::vector<std::shared_ptr<ExtrospectorDeviceSpec>>
DeviceManager::extrospectorDeviceSpecs; DeviceManager::extrospectorDeviceSpecs;
std::vector<std::reference_wrapper<SenseDeviceSpec>> std::vector<std::shared_ptr<SenseDeviceSpec>>
DeviceManager::senseDeviceSpecs; DeviceManager::senseDeviceSpecs;
const std::string DeviceManager::stringifyDeviceSpecs(void) const std::string DeviceManager::stringifyDeviceSpecs(void)
+9 -31
View File
@@ -34,32 +34,6 @@ void yyerror(const char *message)
+ std::string(message)); + std::string(message));
} }
void mirrorDeviceSpecs() {
for (const auto& interoSpec : DeviceManager::interoceptorDeviceSpecs) {
auto it = std::find_if(
DeviceManager::senseDeviceSpecs.begin(),
DeviceManager::senseDeviceSpecs.end(),
[&interoSpec](const SenseDeviceSpec& spec) {
return spec == *interoSpec;
});
if (it == DeviceManager::senseDeviceSpecs.end()) {
DeviceManager::senseDeviceSpecs.push_back(*interoSpec);
}
}
for (const auto& extroSpec : DeviceManager::extrospectorDeviceSpecs) {
auto it = std::find_if(
DeviceManager::senseDeviceSpecs.begin(),
DeviceManager::senseDeviceSpecs.end(),
[&extroSpec](const SenseDeviceSpec& spec) {
return spec == *extroSpec;
});
if (it == DeviceManager::senseDeviceSpecs.end()) {
DeviceManager::senseDeviceSpecs.push_back(*extroSpec);
}
}
}
%} %}
%union { %union {
@@ -84,7 +58,7 @@ void mirrorDeviceSpecs() {
%% %%
file: /* NOTHING */ file: /* NOTHING */
| sensor_specs { mirrorDeviceSpecs(); } | sensor_specs
; ;
sensor_specs: sensor_specs:
@@ -99,22 +73,26 @@ sensor_spec:
interoceptor_spec: interoceptor_spec:
KEYWORD_SPECTYPE_INTEROSPECTOR PIPE spec_body { KEYWORD_SPECTYPE_INTEROSPECTOR PIPE spec_body {
auto spec = std::make_unique<InteroceptorDeviceSpec>( auto spec = std::make_shared<InteroceptorDeviceSpec>(
*static_cast<InteroceptorDeviceSpec *>($3)); *static_cast<InteroceptorDeviceSpec *>($3));
spec->sensorType = $1; spec->sensorType = $1;
DeviceManager::interoceptorDeviceSpecs.push_back(std::move(spec)); DeviceManager::interoceptorDeviceSpecs.push_back(spec);
DeviceManager::senseDeviceSpecs.push_back(spec);
delete $3; delete $3;
} }
; ;
extrospector_spec: extrospector_spec:
KEYWORD_SPECTYPE_EXTROSPECTOR PIPE spec_body { KEYWORD_SPECTYPE_EXTROSPECTOR PIPE spec_body {
auto spec = std::make_unique<ExtrospectorDeviceSpec>( auto spec = std::make_shared<ExtrospectorDeviceSpec>(
*static_cast<ExtrospectorDeviceSpec *>($3)); *static_cast<ExtrospectorDeviceSpec *>($3));
spec->sensorType = $1; spec->sensorType = $1;
DeviceManager::extrospectorDeviceSpecs.push_back(std::move(spec)); DeviceManager::extrospectorDeviceSpecs.push_back(spec);
DeviceManager::senseDeviceSpecs.push_back(spec);
delete $3; delete $3;
} }
; ;
+3 -3
View File
@@ -31,11 +31,11 @@ private:
public: public:
std::string allDeviceSpecs; std::string allDeviceSpecs;
static std::vector<std::unique_ptr<InteroceptorDeviceSpec>> static std::vector<std::shared_ptr<InteroceptorDeviceSpec>>
interoceptorDeviceSpecs; interoceptorDeviceSpecs;
static std::vector<std::unique_ptr<ExtrospectorDeviceSpec>> static std::vector<std::shared_ptr<ExtrospectorDeviceSpec>>
extrospectorDeviceSpecs; extrospectorDeviceSpecs;
static std::vector<std::reference_wrapper<SenseDeviceSpec>> static std::vector<std::shared_ptr<SenseDeviceSpec>>
senseDeviceSpecs; senseDeviceSpecs;
}; };
+4 -6
View File
@@ -207,8 +207,7 @@ void SenseApiManager::finalizeAllSenseApiLibs(void)
} }
} }
void SenseApiManager::attachSenseDevice( void SenseApiManager::attachSenseDevice(const SenseDeviceSpec& spec)
const SenseDeviceSpec& spec)
{ {
auto libOpt = getSenseApiLibByApiName(spec.api); auto libOpt = getSenseApiLibByApiName(spec.api);
if (!libOpt) if (!libOpt)
@@ -228,8 +227,7 @@ void SenseApiManager::attachSenseDevice(
lib.getSenseApiDesc()->sal_mgmt_libOps->attachDeviceReq(&cSpec); lib.getSenseApiDesc()->sal_mgmt_libOps->attachDeviceReq(&cSpec);
} }
void SenseApiManager::detachSenseDevice( void SenseApiManager::detachSenseDevice(const SenseDeviceSpec& spec)
const SenseDeviceSpec& spec)
{ {
auto libOpt = getSenseApiLibByApiName(spec.api); auto libOpt = getSenseApiLibByApiName(spec.api);
if (!libOpt) if (!libOpt)
@@ -252,14 +250,14 @@ void SenseApiManager::detachSenseDevice(
void SenseApiManager::attachAllSenseDevicesFromSpecs(void) void SenseApiManager::attachAllSenseDevicesFromSpecs(void)
{ {
for (const auto& spec : DeviceManager::senseDeviceSpecs) { for (const auto& spec : DeviceManager::senseDeviceSpecs) {
attachSenseDevice(spec.get()); attachSenseDevice(*spec);
} }
} }
void SenseApiManager::detachAllSenseDevices(void) void SenseApiManager::detachAllSenseDevices(void)
{ {
for (const auto& spec : DeviceManager::senseDeviceSpecs) { for (const auto& spec : DeviceManager::senseDeviceSpecs) {
detachSenseDevice(spec.get()); detachSenseDevice(*spec);
} }
} }
+1
View File
@@ -93,6 +93,7 @@ static int initializeHarikoff(int argc, char **argv, char **envp)
std::cout << sense_api::SenseApiManager::getInstance().stringifyLibs() std::cout << sense_api::SenseApiManager::getInstance().stringifyLibs()
<< std::endl; << std::endl;
sense_api::SenseApiManager::getInstance().initializeAllSenseApiLibs(); sense_api::SenseApiManager::getInstance().initializeAllSenseApiLibs();
sense_api::SenseApiManager::getInstance().attachAllSenseDevicesFromSpecs();
/* Start the threads */ /* Start the threads */
for (const auto& [id, componentThread] for (const auto& [id, componentThread]
+1 -1
View File
@@ -82,7 +82,7 @@ int xcbXorg_finalizeInd(void)
static sal_mlo_attachDeviceReqFn xcbXorg_attachDeviceReq; static sal_mlo_attachDeviceReqFn xcbXorg_attachDeviceReq;
int xcbXorg_attachDeviceReq(const CSenseDeviceSpec *const desc) int xcbXorg_attachDeviceReq(const CSenseDeviceSpec *const desc)
{ {
std::cout << __func__ << "\n"; std::cout << __func__ << ": Attaching device spec: " << *desc << "\n";
return 0; return 0;
} }