DevMgr: Add DeviceRoles; attachedDevices unrelated to device state now

We've decided to add a separate notion of a DeviceRole to track attached
device roles now. We no longer use the collection of deviceSpecs to
track which roles have been attached. Rather, this list will simply
collate all known deviceAttachment specs which are expected to be
maintained in an attached state.

SMO can periodically scan through these and cross-reference this
collection with the collection of attachedDeviceRoles. Then it can
re-try to attach those which aren't currently attached at any given
moment. This will give resilience against device attachment failures
or device resets/malfunctions, at runtime.
This commit is contained in:
2025-09-28 00:50:05 -04:00
parent e6b8d3e85d
commit 1a56e2a107
5 changed files with 62 additions and 32 deletions
@@ -87,7 +87,6 @@ interoceptor_spec:
*static_cast<smo::device::InteroceptorDevAttachmentSpec *>($3));
spec->sensorType = $1;
smo::device::DeviceManager::interoceptorDeviceSpecs.push_back(spec);
smo::device::DeviceManager::deviceAttachmentSpecs.push_back(spec);
delete $3;
@@ -100,7 +99,6 @@ extrospector_spec:
*static_cast<smo::device::ExtrospectorDevAttachmentSpec *>($3));
spec->sensorType = $1;
smo::device::DeviceManager::extrospectorDeviceSpecs.push_back(spec);
smo::device::DeviceManager::deviceAttachmentSpecs.push_back(spec);
delete $3;
+31 -21
View File
@@ -17,25 +17,19 @@
namespace smo {
namespace device {
std::vector<std::shared_ptr<InteroceptorDevAttachmentSpec>>
DeviceManager::interoceptorDeviceSpecs;
std::vector<std::shared_ptr<ExtrospectorDevAttachmentSpec>>
DeviceManager::extrospectorDeviceSpecs;
std::vector<std::shared_ptr<DeviceAttachmentSpec>>
DeviceManager::deviceAttachmentSpecs;
std::vector<std::shared_ptr<Device>>
DeviceManager::devices;
std::vector<std::shared_ptr<DeviceRole>>
DeviceManager::attachedDeviceRoles;
const std::string DeviceManager::stringifyDeviceSpecs(void)
{
std::ostringstream oss;
for (const auto& spec : DeviceManager::interoceptorDeviceSpecs) {
oss << "Interoceptor " << spec->stringify();
}
for (const auto& spec : DeviceManager::extrospectorDeviceSpecs) {
oss << "Extrospector " << spec->stringify();
for (const auto& spec : DeviceManager::deviceAttachmentSpecs) {
oss << "Device Attachment Spec: " << spec->stringify();
}
return oss.str();
@@ -111,14 +105,13 @@ public:
devices.push_back(device);
}
// Add DeviceAttachmentSpec to device's list
device->deviceAttachmentSpecs.push_back(spec);
// Add DeviceAttachmentSpec to DeviceManager's list
deviceAttachmentSpecs.push_back(spec);
// Create DeviceRole and add it to both DeviceManager's and Device's collections
auto deviceRole = std::make_shared<DeviceRole>(spec);
attachedDeviceRoles.push_back(deviceRole);
device->deviceRoles.push_back(deviceRole);
// Callback with success
callOriginalCb(true, device, spec);
callOriginalCb(true, deviceRole, spec);
} catch (const std::exception& e) {
// Attach failed, callback with error
callOriginalCb(false, nullptr, spec);
@@ -130,13 +123,30 @@ void DeviceManager::newDeviceAttachmentSpecInd(
std::shared_ptr<DeviceAttachmentSpec> spec,
Callback<newDeviceAttachmentSpecIndCbFn> callback)
{
// Check if a DeviceAttachmentSpec already matches
// First, add the spec to deviceAttachmentSpecs if it's not already there
bool specExists = false;
for (const auto& existingSpec : deviceAttachmentSpecs)
{
if (!(*existingSpec == *spec)) { continue; }
// Already exists, callback with error
callback.callbackFn(false, nullptr, spec);
return;
if (*existingSpec == *spec)
{
specExists = true;
break;
}
}
if (!specExists) {
deviceAttachmentSpecs.push_back(spec);
}
// Check if a DeviceRole w/ this spec already exists in attachedDeviceRoles
for (const auto& existingDeviceRole : attachedDeviceRoles)
{
if (*existingDeviceRole->deviceAttachmentSpec == *spec)
{
// Already attached, callback with success
callback.callbackFn(true, existingDeviceRole, spec);
return;
}
}
// Create async continuation