#include #include #include #include #include #include #include #include #include #include namespace smo { namespace device { std::vector> DeviceManager::interoceptorDeviceSpecs; std::vector> DeviceManager::extrospectorDeviceSpecs; std::vector> DeviceManager::deviceAttachmentSpecs; std::vector> DeviceManager::devices; // Async continuation structure struct DeviceAttachmentContinuation { std::shared_ptr spec; std::function device, std::shared_ptr deviceSpec) > callback; DeviceAttachmentContinuation( std::shared_ptr s, std::function device, std::shared_ptr deviceSpec) > cb) : spec(s), callback(cb) {} void callOriginalCallback( bool success, std::shared_ptr device, std::shared_ptr deviceSpec) { callback(success, device, deviceSpec); } }; 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(); } return oss.str(); } #if 0 void DeviceManager::newDeviceAttachmentSpecInd( std::shared_ptr spec, std::function device, std::shared_ptr deviceSpec) > callback) { // Create async continuation auto continuation = std::make_shared( spec, callback); // Check if a DeviceAttachmentSpec already matches for (const auto& existingSpec : deviceAttachmentSpecs) { if (!(*existingSpec == *spec)) { continue; } // Already exists, callback with error continuation->callOriginalCallback(false, nullptr, nullptr); return; } // Try to attach the sense device try { sense_api::SenseApiManager::getInstance().attachSenseDevice(spec); // Look for existing Device with same identifier std::shared_ptr device = nullptr; for (const auto& existingDevice : devices) { if (existingDevice->deviceIdentifier != spec->deviceIdentifier) { continue; } device = existingDevice; break; } // If device doesn't exist, create a new one and add it if (!device) { device = std::make_shared(spec->deviceIdentifier); 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); // Callback with success continuation->callOriginalCallback(true, device, spec); } catch (const std::exception& e) { // Attach failed, callback with error continuation->callOriginalCallback(false, nullptr, nullptr); } } #endif } // namespace device } // namespace smo