Add LoadableLibraryManager and refactor StimBuffApiManager to use it.
Centralize dlopen/search in LoadableLibraryManager so typed library managers can share one loaded-shlib registry without duplicating load/unload logic. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,11 +3,10 @@
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <dlfcn.h>
|
||||
#include <functional>
|
||||
#include <user/senseApiDesc.h>
|
||||
#include <loadableLib/loadableLibraryManager.h>
|
||||
#include <spinscale/co/coQutex.h>
|
||||
#include <spinscale/sharedResourceGroup.h>
|
||||
|
||||
@@ -18,25 +17,15 @@ class StimBuffApiLib
|
||||
{
|
||||
private:
|
||||
friend class StimBuffApiManager;
|
||||
struct DlCloser
|
||||
{
|
||||
void operator()(void* handle) const
|
||||
{
|
||||
if (handle) {
|
||||
dlclose(handle);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
StimBuffApiLib(
|
||||
const std::string& path, void *_dlopen_handle,
|
||||
std::shared_ptr<loadable_lib::LoadableLibraryManager::LoadedSharedLibrary>
|
||||
_loadedSharedLibrary,
|
||||
SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF *descFn)
|
||||
: libraryPath(path),
|
||||
isBeingDestroyed(false),
|
||||
dlopen_handle(_dlopen_handle, DlCloser()),
|
||||
SMO_GET_STIM_BUFF_API_DESC_FN_NAME(descFn),
|
||||
s("StimBuffApiLib-" + path)
|
||||
: loadedSharedLibrary(std::move(_loadedSharedLibrary)),
|
||||
SMO_GET_STIM_BUFF_API_DESC_FN_NAME(descFn),
|
||||
s("StimBuffApiLib-" + loadedSharedLibrary->libraryPath)
|
||||
{}
|
||||
|
||||
void setStimBuffApiDesc(const StimBuffApiDesc &desc)
|
||||
@@ -45,19 +34,19 @@ public:
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": Sanity check failed for stim buff API "
|
||||
"descriptor in library '" + libraryPath + "'");
|
||||
"descriptor in library '"
|
||||
+ loadedSharedLibrary->libraryPath + "'");
|
||||
}
|
||||
|
||||
stimBuffApiDesc = desc;
|
||||
}
|
||||
|
||||
public:
|
||||
std::string libraryPath;
|
||||
std::atomic<bool> isBeingDestroyed;
|
||||
std::unique_ptr<void, DlCloser> dlopen_handle;
|
||||
/* UNIMPLEMENTED: API-specific cmdline options. These affect this specific
|
||||
* stim buff api lib's behaviour globally.
|
||||
*/
|
||||
std::shared_ptr<loadable_lib::LoadableLibraryManager::LoadedSharedLibrary>
|
||||
loadedSharedLibrary;
|
||||
/* UNIMPLEMENTED: API-specific cmdline options. These affect this specific
|
||||
* stim buff api lib's behaviour globally.
|
||||
*/
|
||||
std::vector<std::string> options;
|
||||
|
||||
/**
|
||||
@@ -80,11 +69,13 @@ public:
|
||||
|
||||
struct StimBuffApiLibResources
|
||||
{};
|
||||
|
||||
|
||||
sscl::SharedResourceGroup<sscl::co::CoQutex, StimBuffApiLibResources> s;
|
||||
|
||||
std::string stringify() const {
|
||||
std::string result = "Library Path: " + libraryPath + "\n";
|
||||
std::string stringify() const
|
||||
{
|
||||
std::string result = "Library Path: "
|
||||
+ loadedSharedLibrary->libraryPath + "\n";
|
||||
result += "Stim Buff API Descriptor: " + stimBuffApiDesc.stringify() + "\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user