From db8f047322bb0259e6862062343ef71cb82732ab Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Mon, 15 Sep 2025 12:47:37 -0400 Subject: [PATCH] SApiMgr:attDevReq: use body||world thread for i/e-devs We now pass in the correct ComponentThread based on the type of device that's being attached. --- include/user/senseApiDesc.h | 1 + senseApis/livoxGen1/livoxGen1.cpp | 15 ++++++--------- senseApis/xcbWindow/xcbWindow.cpp | 4 ++++ smocore/senseApis/senseApiManager.cpp | 25 ++++++++++++++++++++++++- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/user/senseApiDesc.h b/include/user/senseApiDesc.h index 17bf1b2..52e081c 100644 --- a/include/user/senseApiDesc.h +++ b/include/user/senseApiDesc.h @@ -43,6 +43,7 @@ typedef int (sal_mlo_initializeIndFn)(void); typedef int (sal_mlo_finalizeIndFn)(void); typedef void (sal_mlo_attachDeviceReqFn)( const std::shared_ptr& desc, + const std::shared_ptr& componentThread, sal_mlo_attachDeviceReqCbFn cb); typedef void (sal_mlo_detachDeviceReqFn)( const std::shared_ptr& desc, diff --git a/senseApis/livoxGen1/livoxGen1.cpp b/senseApis/livoxGen1/livoxGen1.cpp index 7a566ad..47a30da 100644 --- a/senseApis/livoxGen1/livoxGen1.cpp +++ b/senseApis/livoxGen1/livoxGen1.cpp @@ -51,14 +51,10 @@ static LivoxProto1DllState livoxProto1; static std::vector> g_attachedDevices; // Callback function declarations -extern "C" int livoxGen1_initializeInd(void); -extern "C" int livoxGen1_finalizeInd(void); -extern "C" void livoxGen1_attachDeviceReq( - const std::shared_ptr& desc, - smo::sense_api::sal_mlo_attachDeviceReqCbFn cb); -extern "C" void livoxGen1_detachDeviceReq( - const std::shared_ptr& desc, - smo::sense_api::sal_mlo_detachDeviceReqCbFn cb); +extern "C" sal_mlo_initializeIndFn livoxGen1_initializeInd; +extern "C" sal_mlo_finalizeIndFn livoxGen1_finalizeInd; +extern "C" sal_mlo_attachDeviceReqFn livoxGen1_attachDeviceReq; +extern "C" sal_mlo_detachDeviceReqFn livoxGen1_detachDeviceReq; // Sense API descriptor static const SenseApiDesc livoxGen1ApiDesc = { @@ -155,6 +151,7 @@ extern "C" int livoxGen1_finalizeInd(void) extern "C" void livoxGen1_attachDeviceReq( const std::shared_ptr& desc, + const std::shared_ptr& componentThread, smo::sense_api::sal_mlo_attachDeviceReqCbFn cb ) { @@ -249,7 +246,7 @@ extern "C" void livoxGen1_attachDeviceReq( (*livoxProto1.livoxProto1_getOrCreateDeviceReq)( desc->deviceSelector, // deviceIdentifier (broadcast code) - smoThreadingModelDesc.componentThread, + componentThread, handshakeTimeoutMs, retryDelayMs, smoIp, smoSubnetNbits, dataPort, cmdPort, imuPort, diff --git a/senseApis/xcbWindow/xcbWindow.cpp b/senseApis/xcbWindow/xcbWindow.cpp index 97c8112..a6ed750 100644 --- a/senseApis/xcbWindow/xcbWindow.cpp +++ b/senseApis/xcbWindow/xcbWindow.cpp @@ -275,9 +275,13 @@ static int xcbWindow_finalizeInd(void) static void xcbWindow_attachDeviceReq( const std::shared_ptr& desc, + const std::shared_ptr& componentThread, smo::sense_api::sal_mlo_attachDeviceReqCbFn cb ) { + // Not used yet, but may be used later. + (void)componentThread; + g_attachedWindows.emplace_back( std::make_unique(desc)); diff --git a/smocore/senseApis/senseApiManager.cpp b/smocore/senseApis/senseApiManager.cpp index 0618393..e9561db 100644 --- a/smocore/senseApis/senseApiManager.cpp +++ b/smocore/senseApis/senseApiManager.cpp @@ -283,7 +283,30 @@ void SenseApiManager::attachSenseDeviceReq( std::string(__func__) + ": attachDeviceReq() is NULL for library '" + lib.libraryPath + "'"); } - lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq(spec, cb); + + /** EXPLANATION: + * We pass in either the body or world thread here, depending on whether + * the device is an introspector (idev) or extrospector (edev). + * + * Introspectors are attached to the body thread; extrospectors are attached + * to the world thread. + */ + std::shared_ptr threadForAttachment; + if (spec->sensorType == 'e') + { + threadForAttachment = mind::globalMind->world.thread; + std::cout << __func__ << ": Attaching edev " << spec->deviceIdentifier + << " to world thread" << "\n"; + } + else + { + threadForAttachment = mind::globalMind->body.thread; + std::cout << __func__ << ": Attaching non-edev " + << spec->deviceIdentifier << " to body thread" << "\n"; + } + + lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq( + spec, threadForAttachment, cb); } void SenseApiManager::detachSenseDeviceReq(