Provide dlopen() path searching hook to senseApi libs

This commit is contained in:
2025-07-24 02:12:31 -04:00
parent 064dc43fbc
commit 1bf5f46404
4 changed files with 58 additions and 6 deletions
@@ -52,6 +52,10 @@ private:
SenseApiManager& operator=(const SenseApiManager&) = delete;
std::vector<std::unique_ptr<SenseApiLib>> senseApiLibs;
public:
static std::optional<std::string> searchForLibInSmoSearchPaths(
const std::string& libraryPath);
};
} // namespace sense_api
+19 -3
View File
@@ -13,6 +13,15 @@ namespace fs = std::filesystem;
namespace smo {
namespace sense_api {
/* Hooks to be provided to senseApiLibs, enabling them to call into Salmanoff
* code.
*/
static SalmanoffCallbacks salmanoffCallbacks =
{
.searchForLibInSmoSearchPaths = &SenseApiManager
::searchForLibInSmoSearchPaths
};
/**
* @brief Searches for a library in predefined locations
* @param libraryPath The name or path of the library to find
@@ -27,7 +36,7 @@ namespace sense_api {
* If the library is not found in any of these locations, returns nullopt and
* falls back to system default library search paths (LD_LIBRARY_PATH, etc.)
*/
static std::optional<std::string> findLibraryPath(
static std::optional<std::string> searchForLibInSmoSearchPaths(
const std::string& libraryPath)
{
std::vector<std::string> searchPaths = {
@@ -66,9 +75,16 @@ static std::optional<std::string> findLibraryPath(
return std::nullopt;
}
std::optional<std::string> SenseApiManager::searchForLibInSmoSearchPaths(
const std::string& libraryPath)
{
return ::smo::sense_api::searchForLibInSmoSearchPaths(libraryPath);
}
SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath)
{
std::optional<std::string> fullPath = findLibraryPath(libraryPath);
std::optional<std::string> fullPath = searchForLibInSmoSearchPaths(
libraryPath);
std::string resolvedPath = fullPath.value_or(libraryPath);
// Clear any existing error
@@ -106,7 +122,7 @@ SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath)
+ libraryPath + "'");
}
const SenseApiDesc &libApiDesc = func();
const SenseApiDesc &libApiDesc = func(salmanoffCallbacks);
auto lib = std::make_unique<SenseApiLib>(
libraryPath, dlopen_handle.release(), func);
lib->setSenseApiDesc(libApiDesc);