diff --git a/include/user/senseApiDesc.h b/include/user/senseApiDesc.h index fcafa13..d57caff 100644 --- a/include/user/senseApiDesc.h +++ b/include/user/senseApiDesc.h @@ -6,14 +6,17 @@ #include #include #include +#include namespace smo { namespace sense_api { typedef int (sal_mlo_initializeIndFn)(void); typedef int (sal_mlo_finalizeIndFn)(void); -typedef int (sal_mlo_attachDeviceReqFn)(const device::SenseDeviceSpec &desc); -typedef int (sal_mlo_detachDeviceReqFn)(const device::SenseDeviceSpec &desc); +typedef int (sal_mlo_attachDeviceReqFn)( + const std::shared_ptr& desc); +typedef int (sal_mlo_detachDeviceReqFn)( + const std::shared_ptr& desc); /** * @brief Hooks provided by Salmanoff to senseApi libraries. diff --git a/senseApis/xcbWindow/xcbWindow.cpp b/senseApis/xcbWindow/xcbWindow.cpp index 70521c2..eaad492 100644 --- a/senseApis/xcbWindow/xcbWindow.cpp +++ b/senseApis/xcbWindow/xcbWindow.cpp @@ -54,7 +54,9 @@ std::string WindowSelector::stringify() const return os.str(); } -AttachedWindow::AttachedWindow(const smo::device::SenseDeviceSpec& spec) +AttachedWindow::AttachedWindow( + const std::shared_ptr& spec + ) : deviceSpec(spec) { // Validate required function pointers are available @@ -66,9 +68,9 @@ AttachedWindow::AttachedWindow(const smo::device::SenseDeviceSpec& spec) ": Required xcbXorg function pointers not available"); } - windowSelector.display = getRequiredParamAsInt(spec, "display"); - windowSelector.screen = getRequiredParamAsInt(spec, "screen"); - parseWindowSelector(spec); + windowSelector.display = getRequiredParamAsInt(*spec, "display"); + windowSelector.screen = getRequiredParamAsInt(*spec, "screen"); + parseWindowSelector(*spec); // Get connection from libxcbXorg std::shared_ptr conn = @@ -293,7 +295,9 @@ static int xcbWindow_finalizeInd(void) return 0; } -static int xcbWindow_attachDeviceReq(const smo::device::SenseDeviceSpec& desc) +static int xcbWindow_attachDeviceReq( + const std::shared_ptr& desc + ) { g_attachedWindows.emplace_back( std::make_unique(desc)); @@ -304,7 +308,9 @@ static int xcbWindow_attachDeviceReq(const smo::device::SenseDeviceSpec& desc) return 0; } -static int xcbWindow_detachDeviceReq(const smo::device::SenseDeviceSpec& spec) +static int xcbWindow_detachDeviceReq( + const std::shared_ptr& spec + ) { auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(), [&spec](const std::unique_ptr& window) { @@ -315,13 +321,13 @@ static int xcbWindow_detachDeviceReq(const smo::device::SenseDeviceSpec& spec) if (it == g_attachedWindows.end()) { std::cerr << __func__ << ": Device not found for detachment:\n" - << spec.stringify() << "\n"; + << spec->stringify() << "\n"; return -1; } g_attachedWindows.erase(it); std::cout << __func__ << ": Detached X11 window device:\n" - << spec.stringify() << "\n"; + << spec->stringify() << "\n"; return 0; } diff --git a/senseApis/xcbWindow/xcbWindow.h b/senseApis/xcbWindow/xcbWindow.h index 5aab84a..e3f1bc8 100644 --- a/senseApis/xcbWindow/xcbWindow.h +++ b/senseApis/xcbWindow/xcbWindow.h @@ -30,10 +30,11 @@ struct WindowSelector class AttachedWindow { public: - AttachedWindow(const smo::device::SenseDeviceSpec& spec); + AttachedWindow(const std::shared_ptr& spec); ~AttachedWindow(); - const smo::device::SenseDeviceSpec& getDeviceSpec() const { return deviceSpec; } + const std::shared_ptr& getDeviceSpec() const + { return deviceSpec; } const WindowSelector& getWindowSelector() const { return windowSelector; } const std::string& getActualWindowName() const { return actualWindowName; } void* getXcbConnection() const { return xcbConnectionShared.get(); } @@ -41,10 +42,11 @@ public: private: void parseWindowSelector(const smo::device::SenseDeviceSpec& spec); - int getRequiredParamAsInt(const smo::device::SenseDeviceSpec& spec, - const std::string& paramName); + int getRequiredParamAsInt( + const smo::device::SenseDeviceSpec& spec, + const std::string& paramName); - smo::device::SenseDeviceSpec deviceSpec; + std::shared_ptr deviceSpec; WindowSelector windowSelector; std::string actualWindowName; std::shared_ptr xcbConnectionShared; diff --git a/smocore/include/senseApis/senseApiManager.h b/smocore/include/senseApis/senseApiManager.h index cf17fb4..8689327 100644 --- a/smocore/include/senseApis/senseApiManager.h +++ b/smocore/include/senseApis/senseApiManager.h @@ -38,8 +38,10 @@ public: void finalizeAllSenseApiLibs(void); void attachAllSenseDevicesFromSpecs(void); - void attachSenseDevice(const device::SenseDeviceSpec& spec); - void detachSenseDevice(const device::SenseDeviceSpec& spec); + void attachSenseDevice( + const std::shared_ptr& spec); + void detachSenseDevice( + const std::shared_ptr& spec); void detachAllSenseDevices(void); std::string stringifyLibs() const; diff --git a/smocore/senseApis/senseApiManager.cpp b/smocore/senseApis/senseApiManager.cpp index 056991e..dddaf1d 100644 --- a/smocore/senseApis/senseApiManager.cpp +++ b/smocore/senseApis/senseApiManager.cpp @@ -231,14 +231,16 @@ void SenseApiManager::finalizeAllSenseApiLibs(void) } } -void SenseApiManager::attachSenseDevice(const device::SenseDeviceSpec& spec) +void SenseApiManager::attachSenseDevice( + const std::shared_ptr& spec + ) { - auto libOpt = getSenseApiLibByApiName(spec.api); + auto libOpt = getSenseApiLibByApiName(spec->api); if (!libOpt) { throw std::runtime_error( std::string(__func__) + ": No library found for API '" - + spec.api + "'"); + + spec->api + "'"); } auto& lib = libOpt.value().get(); if (!lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq) @@ -250,14 +252,16 @@ void SenseApiManager::attachSenseDevice(const device::SenseDeviceSpec& spec) lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq(spec); } -void SenseApiManager::detachSenseDevice(const device::SenseDeviceSpec& spec) +void SenseApiManager::detachSenseDevice( + const std::shared_ptr& spec + ) { - auto libOpt = getSenseApiLibByApiName(spec.api); + auto libOpt = getSenseApiLibByApiName(spec->api); if (!libOpt) { throw std::runtime_error( std::string(__func__) + ": No library found for API '" - + spec.api + "'"); + + spec->api + "'"); } auto& lib = libOpt.value().get(); if (!lib.senseApiDesc.sal_mgmt_libOps.detachDeviceReq) @@ -272,14 +276,14 @@ void SenseApiManager::detachSenseDevice(const device::SenseDeviceSpec& spec) void SenseApiManager::attachAllSenseDevicesFromSpecs(void) { for (const auto& spec : device::DeviceManager::senseDeviceSpecs) { - attachSenseDevice(*spec); + attachSenseDevice(spec); } } void SenseApiManager::detachAllSenseDevices(void) { for (const auto& spec : device::DeviceManager::senseDeviceSpecs) { - detachSenseDevice(*spec); + detachSenseDevice(spec); } }