From b598ca85946640af6c6fbf8ae2b397ddf110257b Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Fri, 7 Nov 2025 14:59:28 -0400 Subject: [PATCH] libs: Add smohook for getting cmdline opts --- commonLibs/livoxProto1/broadcastListener.cpp | 3 ++- commonLibs/livoxProto1/core.cpp | 2 +- commonLibs/livoxProto1/device.cpp | 12 ++++++------ include/user/senseApiDesc.h | 11 +++++++++++ smocore/stimBuffApis/stimBuffApiManager.cpp | 9 ++++++++- stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp | 4 ++-- stimBuffApis/livoxGen1/livoxGen1.cpp | 8 ++++---- 7 files changed, 34 insertions(+), 15 deletions(-) diff --git a/commonLibs/livoxProto1/broadcastListener.cpp b/commonLibs/livoxProto1/broadcastListener.cpp index 675868f..c5cfb0d 100644 --- a/commonLibs/livoxProto1/broadcastListener.cpp +++ b/commonLibs/livoxProto1/broadcastListener.cpp @@ -3,6 +3,7 @@ #include #include #include "broadcastListener.h" +#include "core.h" namespace livoxProto1 { namespace comms { @@ -96,7 +97,7 @@ void BroadcastListener::broadcastMsgInd( if (deviceExists(broadcastCode)) { // Device already exists, just log the update - if (OptionParser::getOptions().verbose) + if (getProtoState().smoCallbacks.OptionParser_getOptions().verbose) { std::cout << __func__ << ": Received broadcast from known device: " diff --git a/commonLibs/livoxProto1/core.cpp b/commonLibs/livoxProto1/core.cpp index 1bbebd0..3323bbe 100644 --- a/commonLibs/livoxProto1/core.cpp +++ b/commonLibs/livoxProto1/core.cpp @@ -114,7 +114,7 @@ public: // Connection successful, add device to collection context->deviceManager.devices.push_back(context->pendingDevice); - if (OptionParser::getOptions().verbose) + if (getProtoState().smoCallbacks.OptionParser_getOptions().verbose) { std::cout << __func__ << ": Successfully connected and added device " << context->pendingDevice->discoveredDevice.deviceIdentifier diff --git a/commonLibs/livoxProto1/device.cpp b/commonLibs/livoxProto1/device.cpp index a3ada96..028f150 100644 --- a/commonLibs/livoxProto1/device.cpp +++ b/commonLibs/livoxProto1/device.cpp @@ -150,7 +150,7 @@ public: // Fail early - if handshake failed, try next method if (!success) { - if (OptionParser::getOptions().verbose) + if (getProtoState().smoCallbacks.OptionParser_getOptions().verbose) { std::cout << __func__ << ": Trying to connect to device by " << "identifier" << "\n"; @@ -222,7 +222,7 @@ void Device::connectReq(smo::Callback callback) auto request = std::make_shared(*this, std::move(callback)); // Try connecting to known device first - if (OptionParser::getOptions().verbose) { + if (getProtoState().smoCallbacks.OptionParser_getOptions().verbose) { std::cout << __func__ << ": Trying to connect to known device" << "\n"; } @@ -316,7 +316,7 @@ void Device::connectToKnownDeviceReq( return; } - if (OptionParser::getOptions().verbose) + if (getProtoState().smoCallbacks.OptionParser_getOptions().verbose) { std::cout << __func__ << ": Detected SMO listening IP for known device " << request->device.discoveredDevice.deviceIdentifier @@ -402,7 +402,7 @@ void Device::connectByDeviceIdentifierReq( // For heuristic construction, always use the provided smoIp. request->device.detectedSmoListeningIp = request->device.smoIp; - if (OptionParser::getOptions().verbose) + if (getProtoState().smoCallbacks.OptionParser_getOptions().verbose) { std::cout << __func__ << ": About to try to connect to device by " << "identifier (" << discoveredDevice.deviceIdentifier << ")" @@ -720,7 +720,7 @@ private: return; } - if (OptionParser::getOptions().verbose) + if (getProtoState().smoCallbacks.OptionParser_getOptions().verbose) { std::cout << __func__ << ": Handshake successful with " << deviceIP << "(" @@ -1512,7 +1512,7 @@ protected: response->command.cmd_id == 0x04 && response->ret_code == 0x00)) { - if (OptionParser::getOptions().verbose) + if (getProtoState().smoCallbacks.OptionParser_getOptions().verbose) { std::cout << __func__ << ": Failed to en/disable pcloud data " "for device " diff --git a/include/user/senseApiDesc.h b/include/user/senseApiDesc.h index 55e3b17..23e2145 100644 --- a/include/user/senseApiDesc.h +++ b/include/user/senseApiDesc.h @@ -10,6 +10,8 @@ #include #include +class OptionParser; + namespace smo { class ComponentThread; @@ -81,6 +83,15 @@ struct SmoCallbacks * equivalent to calling ComponentThread::getSelf(). */ std::shared_ptr (*ComponentThread_getSelf)(void); + + /** + * @brief Get the OptionParser singleton instance + * @return Reference to the OptionParser singleton + * + * This function provides access to the OptionParser singleton instance, + * equivalent to calling OptionParser::getOptions(). + */ + OptionParser& (*OptionParser_getOptions)(void); }; struct Sal_Mgmt_LibOps diff --git a/smocore/stimBuffApis/stimBuffApiManager.cpp b/smocore/stimBuffApis/stimBuffApiManager.cpp index 81fc374..a2b2805 100644 --- a/smocore/stimBuffApis/stimBuffApiManager.cpp +++ b/smocore/stimBuffApis/stimBuffApiManager.cpp @@ -79,13 +79,20 @@ static std::shared_ptr ComponentThread_getSelf() return ComponentThread::getSelf(); } +/* Local static function to wrap OptionParser::getOptions for SmoCallbacks */ +static OptionParser& OptionParser_getOptions() +{ + return OptionParser::getOptions(); +} + /* Hooks to be provided to stimBuffApiLibs, enabling them to call into Salmanoff * code. */ static SmoCallbacks smoCallbacks = { .searchForLibInSmoSearchPaths = searchForLibInSmoSearchPaths, - .ComponentThread_getSelf = ComponentThread_getSelf + .ComponentThread_getSelf = ComponentThread_getSelf, + .OptionParser_getOptions = OptionParser_getOptions }; /* Static file-scope threading model object for senseApi libraries */ diff --git a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp index 59925be..4a51006 100644 --- a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp +++ b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp @@ -329,7 +329,7 @@ void IoUringAssemblyEngine::stop(bool doAcquireLock) } } - if (!sawCancelCqe && OptionParser::getOptions().verbose) { + if (!sawCancelCqe && smoHooksPtr->OptionParser_getOptions().verbose) { std::cerr << __func__ << ": no CQE seen for cancel operation\n"; } } @@ -483,7 +483,7 @@ public: return; } - if (OptionParser::getOptions().verbose) + if (smoHooksPtr->OptionParser_getOptions().verbose) { std::cerr << __func__ << ": Invalid state: nSucceeded (" << context->loop.nSucceeded.load() diff --git a/stimBuffApis/livoxGen1/livoxGen1.cpp b/stimBuffApis/livoxGen1/livoxGen1.cpp index 44c6310..007cd1e 100644 --- a/stimBuffApis/livoxGen1/livoxGen1.cpp +++ b/stimBuffApis/livoxGen1/livoxGen1.cpp @@ -107,7 +107,7 @@ public: // Stash device pointer until after getReturnMode succeeds context->deviceTmp = dev; - if (1 || OptionParser::getOptions().verbose) + if (1 || smoHooksPtr->OptionParser_getOptions().verbose) { std::cout << __func__ << ": Successfully attached/found Livox " "device: " << context->spec->deviceSelector << " (ID: " @@ -205,7 +205,7 @@ public: pcloudStimBuff->start(); - if (1 || OptionParser::getOptions().verbose) + if (1 || smoHooksPtr->OptionParser_getOptions().verbose) { std::cout << __func__ << ": Got return mode (" << (int)mode << ") for device: " << context->spec->deviceSelector @@ -264,7 +264,7 @@ public: return; } - if (1 || OptionParser::getOptions().verbose) + if (1 || smoHooksPtr->OptionParser_getOptions().verbose) { std::cout << __func__ << ": Enabled pcloud data for device: " << context->spec->deviceSelector << std::endl; @@ -372,7 +372,7 @@ public: return; } - if (1 || OptionParser::getOptions().verbose) + if (1 || smoHooksPtr->OptionParser_getOptions().verbose) { std::cout << __func__ << ": Successfully detached pcloud stimbuff " "for device " << context->spec->deviceSelector