SenseApis: Add threading model info to initialization info

We provide access to a thread whose event queue the sense API
libs can use for device-independent event management.
This commit is contained in:
2025-09-04 17:35:49 -04:00
parent 1d9b8a2cf6
commit e5a3c41c20
7 changed files with 68 additions and 13 deletions
+22 -5
View File
@@ -74,13 +74,21 @@ static SalmanoffCallbacks salmanoffCallbacks =
.searchForLibInSmoSearchPaths = searchForLibInSmoSearchPaths
};
/* Static file-scope threading model object for senseApi libraries */
static SmoThreadingModelDesc smoThreadingModelDesc = {
.componentThread = nullptr
};
std::optional<std::string> SenseApiManager::searchForLibInSmoSearchPaths(
const std::string& libraryPath)
{
return ::smo::sense_api::searchForLibInSmoSearchPaths(libraryPath);
}
SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath)
SenseApiLib& SenseApiManager::loadSenseApiLib(
const std::string& libraryPath,
std::shared_ptr<ComponentThread>& componentThread
)
{
std::optional<std::string> fullPath = searchForLibInSmoSearchPaths(
libraryPath);
@@ -121,8 +129,15 @@ SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath)
+ libraryPath + "'");
}
const SenseApiDesc &libApiDesc = func(salmanoffCallbacks);
auto lib = std::make_shared<SenseApiLib>(
// Check if the static threading model obj is null and initialize if needed
if (!smoThreadingModelDesc.componentThread) {
smoThreadingModelDesc.componentThread = componentThread;
}
const SenseApiDesc &libApiDesc = func(
salmanoffCallbacks, smoThreadingModelDesc);
auto lib = std::make_shared<SenseApiLib>(
libraryPath, dlopen_handle.release(), func);
lib->setSenseApiDesc(libApiDesc);
senseApiLibs.push_back(lib);
@@ -178,11 +193,13 @@ void SenseApiManager::unloadAllSenseApiLibs(void)
senseApiLibs.clear();
}
void SenseApiManager::loadAllSenseApiLibsFromOptions()
void SenseApiManager::loadAllSenseApiLibsFromOptions(
std::shared_ptr<ComponentThread>& componentThread
)
{
const auto& options = OptionParser::getOptions();
for (const auto& libPath : options.senseApiLibs) {
loadSenseApiLib(libPath);
loadSenseApiLib(libPath, componentThread);
}
}