7eda755c15
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>
88 lines
2.4 KiB
C++
88 lines
2.4 KiB
C++
#ifndef SENSE_API_PROVIDER_DESC_H
|
|
#define SENSE_API_PROVIDER_DESC_H
|
|
|
|
#include <string>
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <user/senseApiDesc.h>
|
|
#include <loadableLib/loadableLibraryManager.h>
|
|
#include <spinscale/co/coQutex.h>
|
|
#include <spinscale/sharedResourceGroup.h>
|
|
|
|
namespace smo {
|
|
namespace stim_buff {
|
|
|
|
class StimBuffApiLib
|
|
{
|
|
private:
|
|
friend class StimBuffApiManager;
|
|
|
|
public:
|
|
StimBuffApiLib(
|
|
std::shared_ptr<loadable_lib::LoadableLibraryManager::LoadedSharedLibrary>
|
|
_loadedSharedLibrary,
|
|
SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF *descFn)
|
|
: loadedSharedLibrary(std::move(_loadedSharedLibrary)),
|
|
SMO_GET_STIM_BUFF_API_DESC_FN_NAME(descFn),
|
|
s("StimBuffApiLib-" + loadedSharedLibrary->libraryPath)
|
|
{}
|
|
|
|
void setStimBuffApiDesc(const StimBuffApiDesc &desc)
|
|
{
|
|
if (!StimBuffApiDesc::sanityCheck(desc))
|
|
{
|
|
throw std::runtime_error(
|
|
std::string(__func__) + ": Sanity check failed for stim buff API "
|
|
"descriptor in library '"
|
|
+ loadedSharedLibrary->libraryPath + "'");
|
|
}
|
|
|
|
stimBuffApiDesc = desc;
|
|
}
|
|
|
|
public:
|
|
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;
|
|
|
|
/**
|
|
* @brief Each stim buff API library must provide a function returning a
|
|
* StimBuffApiDesc. This struct specifies which API the library uses to
|
|
* connect Salmanoff to its supported stim buff provider.
|
|
*
|
|
* This getter function should be visible to dlsym() so that Salmanoff can
|
|
* find it in the lib after loading it, and call it.
|
|
*/
|
|
std::function<SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF>
|
|
SMO_GET_STIM_BUFF_API_DESC_FN_NAME;
|
|
|
|
/**
|
|
* @brief Salmanoff will call the `SMO_GET_STIM_BUFF_API_DESC_FN_NAME` getter
|
|
* function and use the data it provides in order to fill out this
|
|
* descriptor.
|
|
*/
|
|
StimBuffApiDesc stimBuffApiDesc;
|
|
|
|
struct StimBuffApiLibResources
|
|
{};
|
|
|
|
sscl::SharedResourceGroup<sscl::co::CoQutex, StimBuffApiLibResources> s;
|
|
|
|
std::string stringify() const
|
|
{
|
|
std::string result = "Library Path: "
|
|
+ loadedSharedLibrary->libraryPath + "\n";
|
|
result += "Stim Buff API Descriptor: " + stimBuffApiDesc.stringify() + "\n";
|
|
return result;
|
|
}
|
|
};
|
|
|
|
} // namespace stim_buff
|
|
} // namespace smo
|
|
|
|
#endif // SENSE_API_PROVIDER_DESC_H
|