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:
@@ -1,9 +1,12 @@
|
||||
#ifndef _SALMANOFF_H
|
||||
#define _SALMANOFF_H
|
||||
|
||||
#include <memory>
|
||||
#include <componentThread.h>
|
||||
|
||||
namespace smo {
|
||||
|
||||
void initializeSalmanoff(void);
|
||||
void initializeSalmanoff(std::shared_ptr<ComponentThread>& componentThread);
|
||||
void shutdownSalmanoff(void);
|
||||
|
||||
} // namespace smo
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
#include <componentThread.h>
|
||||
#include <senseApis/senseApiLib.h>
|
||||
#include <user/deviceAttachmentSpec.h>
|
||||
|
||||
@@ -22,7 +23,10 @@ public:
|
||||
return instance;
|
||||
}
|
||||
|
||||
SenseApiLib& loadSenseApiLib(const std::string& libraryPath);
|
||||
SenseApiLib& loadSenseApiLib(
|
||||
const std::string& libraryPath,
|
||||
std::shared_ptr<ComponentThread>& componentThread);
|
||||
|
||||
std::optional<std::shared_ptr<SenseApiLib>> getSenseApiLib(
|
||||
const std::string& libraryPath);
|
||||
std::optional<std::shared_ptr<SenseApiLib>> getSenseApiLibByApiName(
|
||||
@@ -32,7 +36,9 @@ public:
|
||||
void initializeSenseApiLib(SenseApiLib& lib);
|
||||
void finalizeSenseApiLib(SenseApiLib& lib);
|
||||
|
||||
void loadAllSenseApiLibsFromOptions(void);
|
||||
void loadAllSenseApiLibsFromOptions(
|
||||
std::shared_ptr<ComponentThread>& componentThread);
|
||||
|
||||
void unloadAllSenseApiLibs(void);
|
||||
void initializeAllSenseApiLibs(void);
|
||||
void finalizeAllSenseApiLibs(void);
|
||||
|
||||
@@ -75,7 +75,7 @@ void ComponentThread::marionetteMain(ComponentThread& self)
|
||||
throw JustPrintUsageNoError(options);
|
||||
}
|
||||
|
||||
initializeSalmanoff();
|
||||
initializeSalmanoff(mrntt::mrntt);
|
||||
self.getIoService().post([]()
|
||||
{
|
||||
// Initialize the global Mind object
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
|
||||
namespace smo {
|
||||
|
||||
void initializeSalmanoff(void)
|
||||
void initializeSalmanoff(std::shared_ptr<ComponentThread>& componentThread)
|
||||
{
|
||||
std::cout << __func__ << ": Entered." << std::endl;
|
||||
|
||||
device::DeviceManager::getInstance().collateAllDapSpecs();
|
||||
device::DeviceManager::getInstance().parseAllDapSpecs();
|
||||
std::cout << device::DeviceManager::stringifyDeviceSpecs() << std::endl;
|
||||
sense_api::SenseApiManager::getInstance().loadAllSenseApiLibsFromOptions();
|
||||
sense_api::SenseApiManager::getInstance().loadAllSenseApiLibsFromOptions(componentThread);
|
||||
std::cout << sense_api::SenseApiManager::getInstance().stringifyLibs()
|
||||
<< std::endl;
|
||||
std::cerr << "About to initializeAllSenseApiLibs" << std::endl;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user