Files

88 lines
2.3 KiB
C++
Raw Permalink Normal View History

#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>
2025-07-22 06:48:04 -04:00
namespace smo {
2025-10-01 18:47:42 -04:00
namespace stim_buff {
2025-10-01 18:47:42 -04:00
class StimBuffApiLib
{
2025-01-12 09:44:08 -04:00
private:
2025-10-01 18:47:42 -04:00
friend class StimBuffApiManager;
2025-01-12 09:44:08 -04:00
public:
2025-10-01 18:47:42 -04:00
StimBuffApiLib(
std::shared_ptr<loadable_lib::LoadableLibraryManager::LoadedSharedLibrary>
_loadedSharedLibrary,
2025-10-01 18:47:42 -04:00
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)
2025-09-30 01:15:02 -04:00
{}
2025-10-01 18:47:42 -04:00
void setStimBuffApiDesc(const StimBuffApiDesc &desc)
2025-09-30 01:15:02 -04:00
{
2025-10-01 18:47:42 -04:00
if (!StimBuffApiDesc::sanityCheck(desc))
2025-09-30 01:15:02 -04:00
{
throw std::runtime_error(
2025-10-01 18:47:42 -04:00
std::string(__func__) + ": Sanity check failed for stim buff API "
"descriptor in library '"
+ loadedSharedLibrary->libraryPath + "'");
2025-09-30 01:15:02 -04:00
}
2025-10-01 18:47:42 -04:00
stimBuffApiDesc = desc;
2025-09-30 01:15:02 -04:00
}
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.
*/
2025-09-30 01:15:02 -04:00
std::vector<std::string> options;
2025-09-30 01:15:02 -04:00
/**
2025-10-01 18:47:42 -04:00
* @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.
2025-09-30 01:15:02 -04:00
*
* This getter function should be visible to dlsym() so that Salmanoff can
* find it in the lib after loading it, and call it.
*/
2025-10-01 18:47:42 -04:00
std::function<SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF>
SMO_GET_STIM_BUFF_API_DESC_FN_NAME;
2025-09-30 01:15:02 -04:00
/**
2025-10-01 18:47:42 -04:00
* @brief Salmanoff will call the `SMO_GET_STIM_BUFF_API_DESC_FN_NAME` getter
2025-09-30 01:15:02 -04:00
* function and use the data it provides in order to fill out this
* descriptor.
*/
2025-10-01 18:47:42 -04:00
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();
2025-09-30 01:15:02 -04:00
return result;
}
};
2025-10-01 18:47:42 -04:00
} // namespace stim_buff
2025-07-22 06:48:04 -04:00
} // namespace smo
#endif // SENSE_API_PROVIDER_DESC_H