diff --git a/smocore/deviceManager/deviceAttachmentPipeSpecp.yy b/smocore/deviceManager/deviceAttachmentPipeSpecp.yy index 9da1f27..3422eab 100644 --- a/smocore/deviceManager/deviceAttachmentPipeSpecp.yy +++ b/smocore/deviceManager/deviceAttachmentPipeSpecp.yy @@ -87,7 +87,6 @@ interoceptor_spec: *static_cast($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($3)); spec->sensorType = $1; - smo::device::DeviceManager::extrospectorDeviceSpecs.push_back(spec); smo::device::DeviceManager::deviceAttachmentSpecs.push_back(spec); delete $3; diff --git a/smocore/deviceManager/deviceManager.cpp b/smocore/deviceManager/deviceManager.cpp index 641fc17..bd741f6 100644 --- a/smocore/deviceManager/deviceManager.cpp +++ b/smocore/deviceManager/deviceManager.cpp @@ -17,25 +17,19 @@ namespace smo { namespace device { -std::vector> - DeviceManager::interoceptorDeviceSpecs; -std::vector> - DeviceManager::extrospectorDeviceSpecs; std::vector> DeviceManager::deviceAttachmentSpecs; std::vector> DeviceManager::devices; +std::vector> + 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(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 spec, Callback 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 diff --git a/smocore/include/deviceManager/device.h b/smocore/include/deviceManager/device.h index d21836c..3052721 100644 --- a/smocore/include/deviceManager/device.h +++ b/smocore/include/deviceManager/device.h @@ -6,6 +6,7 @@ #include #include #include +#include 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> deviceAttachmentSpecs; + std::vector> deviceRoles; }; } // namespace device diff --git a/smocore/include/deviceManager/deviceManager.h b/smocore/include/deviceManager/deviceManager.h index 82c5094..f195881 100644 --- a/smocore/include/deviceManager/deviceManager.h +++ b/smocore/include/deviceManager/deviceManager.h @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace smo { @@ -39,7 +40,7 @@ public: // New async function for device attachment typedef std::function device, + bool success, std::shared_ptr deviceRole, std::shared_ptr deviceSpec)> newDeviceAttachmentSpecIndCbFn; void newDeviceAttachmentSpecInd( @@ -75,13 +76,10 @@ private: public: std::string allDapSpecs; - static std::vector> - interoceptorDeviceSpecs; - static std::vector> - extrospectorDeviceSpecs; static std::vector> deviceAttachmentSpecs; static std::vector> devices; + static std::vector> attachedDeviceRoles; private: class NewDeviceAttachmentSpecInd; diff --git a/smocore/include/deviceManager/deviceRole.h b/smocore/include/deviceManager/deviceRole.h new file mode 100644 index 0000000..046fd15 --- /dev/null +++ b/smocore/include/deviceManager/deviceRole.h @@ -0,0 +1,23 @@ +#ifndef DEVICEROLE_H +#define DEVICEROLE_H + +#include +#include + +namespace smo { +namespace device { + +class DeviceRole +{ +public: + DeviceRole(std::shared_ptr spec) + : deviceAttachmentSpec(spec) + {} + + std::shared_ptr deviceAttachmentSpec; +}; + +} // namespace device +} // namespace smo + +#endif // DEVICEROLE_H