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:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <user/deviceAttachmentSpec.h>
|
||||
#include <deviceManager/deviceRole.h>
|
||||
|
||||
namespace smo {
|
||||
namespace device {
|
||||
@@ -19,16 +20,16 @@ public:
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Device Identifier: " << deviceIdentifier
|
||||
<< ", Attachment Specs: " << deviceAttachmentSpecs.size() << std::endl;
|
||||
for (const auto& spec : deviceAttachmentSpecs) {
|
||||
os << " " << spec->stringify();
|
||||
<< ", Device Roles: " << deviceRoles.size() << std::endl;
|
||||
for (const auto& deviceRole : deviceRoles) {
|
||||
os << " " << deviceRole->deviceAttachmentSpec->stringify();
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
public:
|
||||
std::string deviceIdentifier;
|
||||
std::vector<std::shared_ptr<DeviceAttachmentSpec>> deviceAttachmentSpecs;
|
||||
std::vector<std::shared_ptr<DeviceRole>> deviceRoles;
|
||||
};
|
||||
|
||||
} // namespace device
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <user/deviceAttachmentSpec.h>
|
||||
#include <asynchronousLoop.h>
|
||||
#include <deviceManager/device.h>
|
||||
#include <deviceManager/deviceRole.h>
|
||||
#include <callback.h>
|
||||
|
||||
namespace smo {
|
||||
@@ -39,7 +40,7 @@ public:
|
||||
|
||||
// New async function for device attachment
|
||||
typedef std::function<void(
|
||||
bool success, std::shared_ptr<Device> device,
|
||||
bool success, std::shared_ptr<DeviceRole> deviceRole,
|
||||
std::shared_ptr<DeviceAttachmentSpec> deviceSpec)>
|
||||
newDeviceAttachmentSpecIndCbFn;
|
||||
void newDeviceAttachmentSpecInd(
|
||||
@@ -75,13 +76,10 @@ private:
|
||||
|
||||
public:
|
||||
std::string allDapSpecs;
|
||||
static std::vector<std::shared_ptr<InteroceptorDevAttachmentSpec>>
|
||||
interoceptorDeviceSpecs;
|
||||
static std::vector<std::shared_ptr<ExtrospectorDevAttachmentSpec>>
|
||||
extrospectorDeviceSpecs;
|
||||
static std::vector<std::shared_ptr<DeviceAttachmentSpec>>
|
||||
deviceAttachmentSpecs;
|
||||
static std::vector<std::shared_ptr<Device>> devices;
|
||||
static std::vector<std::shared_ptr<DeviceRole>> attachedDeviceRoles;
|
||||
|
||||
private:
|
||||
class NewDeviceAttachmentSpecInd;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef DEVICEROLE_H
|
||||
#define DEVICEROLE_H
|
||||
|
||||
#include <memory>
|
||||
#include <user/deviceAttachmentSpec.h>
|
||||
|
||||
namespace smo {
|
||||
namespace device {
|
||||
|
||||
class DeviceRole
|
||||
{
|
||||
public:
|
||||
DeviceRole(std::shared_ptr<DeviceAttachmentSpec> spec)
|
||||
: deviceAttachmentSpec(spec)
|
||||
{}
|
||||
|
||||
std::shared_ptr<DeviceAttachmentSpec> deviceAttachmentSpec;
|
||||
};
|
||||
|
||||
} // namespace device
|
||||
} // namespace smo
|
||||
|
||||
#endif // DEVICEROLE_H
|
||||
Reference in New Issue
Block a user