SenseApiMgr: Refcount device spec objects

This commit is contained in:
2025-08-29 09:50:26 -04:00
parent cd63593ae5
commit f3f2384f9b
5 changed files with 42 additions and 25 deletions
+14 -8
View File
@@ -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<smo::device::SenseDeviceSpec>& 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<xcb_xorg::XcbConnection> 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<smo::device::SenseDeviceSpec>& desc
)
{
g_attachedWindows.emplace_back(
std::make_unique<xcb_window::AttachedWindow>(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<smo::device::SenseDeviceSpec>& spec
)
{
auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(),
[&spec](const std::unique_ptr<xcb_window::AttachedWindow>& 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;
}
+7 -5
View File
@@ -30,10 +30,11 @@ struct WindowSelector
class AttachedWindow
{
public:
AttachedWindow(const smo::device::SenseDeviceSpec& spec);
AttachedWindow(const std::shared_ptr<smo::device::SenseDeviceSpec>& spec);
~AttachedWindow();
const smo::device::SenseDeviceSpec& getDeviceSpec() const { return deviceSpec; }
const std::shared_ptr<smo::device::SenseDeviceSpec>& 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<smo::device::SenseDeviceSpec> deviceSpec;
WindowSelector windowSelector;
std::string actualWindowName;
std::shared_ptr<xcb_xorg::XcbConnection> xcbConnectionShared;