Rename: Sense API => Stim Buff API

This commit is contained in:
2025-10-01 18:47:42 -04:00
parent 56b8e83a09
commit eb5875fe0d
26 changed files with 309 additions and 306 deletions
@@ -61,15 +61,15 @@ public:
Callback<removeDeviceAttachmentSpecReqCbFn> callback);
// Device attachment/detachment methods moved from SenseApiManager
typedef sense_api::sal_mlo_attachDeviceReqCbFn attachSenseDeviceReqCbFn;
typedef sense_api::sal_mlo_detachDeviceReqCbFn detachSenseDeviceReqCbFn;
typedef stim_buff::sal_mlo_attachDeviceReqCbFn attachStimBuffDeviceReqCbFn;
typedef stim_buff::sal_mlo_detachDeviceReqCbFn detachStimBuffDeviceReqCbFn;
void attachSenseDeviceReq(
void attachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<attachSenseDeviceReqCbFn> cb);
void detachSenseDeviceReq(
Callback<attachStimBuffDeviceReqCbFn> cb);
void detachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<detachSenseDeviceReqCbFn> cb);
Callback<detachStimBuffDeviceReqCbFn> cb);
typedef std::function<void(AsynchronousLoop &results)>
attachAllUnattachedDevicesFromReqCbFn;
@@ -108,8 +108,8 @@ private:
class NewDeviceAttachmentSpecInd;
class RemoveDeviceAttachmentSpecReq;
class AttachSenseDeviceReq;
typedef AttachSenseDeviceReq DetachSenseDeviceReq;
class AttachStimBuffDeviceReq;
typedef AttachStimBuffDeviceReq DetachStimBuffDeviceReq;
class AttachAllUnattachedDevicesFromReq;
class AttachAllUnattachedDevicesFromKnownListReq;
class DetachAllAttachedDeviceRoles;
@@ -1,78 +0,0 @@
#ifndef SENSE_API_MANAGER_H
#define SENSE_API_MANAGER_H
#include <config.h>
#include <memory>
#include <vector>
#include <string>
#include <optional>
#include <functional>
#include <componentThread.h>
#include <asynchronousLoop.h>
#include <senseApis/senseApiLib.h>
#include <user/deviceAttachmentSpec.h>
#include <callback.h>
#include <qutex.h>
namespace smo {
namespace sense_api {
class SenseApiManager
{
public:
static SenseApiManager& getInstance()
{
static SenseApiManager instance;
return instance;
}
void initialize(void)
{};
void finalize(void)
{};
SenseApiLib& loadSenseApiLib(
const std::string& libraryPath,
const std::shared_ptr<ComponentThread>& componentThread);
std::optional<std::shared_ptr<SenseApiLib>> getSenseApiLib(
const std::string& libraryPath);
std::optional<std::shared_ptr<SenseApiLib>> getSenseApiLibByApiName(
const std::string& apiName);
void unloadSenseApiLib(const std::string& libraryPath);
void initializeSenseApiLib(SenseApiLib& lib);
void finalizeSenseApiLib(SenseApiLib& lib);
void loadAllSenseApiLibsFromOptions(
const std::shared_ptr<ComponentThread>& componentThread);
void unloadAllSenseApiLibs(void);
void initializeAllSenseApiLibs(void);
void finalizeAllSenseApiLibs(void);
std::string stringifyLibs() const;
private:
SenseApiManager()
: qutex("SenseApiManager")
{}
~SenseApiManager() = default;
SenseApiManager(const SenseApiManager&) = delete;
SenseApiManager& operator=(const SenseApiManager&) = delete;
std::vector<std::shared_ptr<SenseApiLib>> senseApiLibs;
public:
Qutex qutex;
public:
static std::optional<std::string> searchForLibInSmoSearchPaths(
const std::string& libraryPath);
};
} // namespace sense_api
} // namespace smo
#endif // SENSE_API_MANAGER_H
@@ -11,12 +11,12 @@
#include <qutex.h>
namespace smo {
namespace sense_api {
namespace stim_buff {
class SenseApiLib
class StimBuffApiLib
{
private:
friend class SenseApiManager;
friend class StimBuffApiManager;
struct DlCloser
{
void operator()(void* handle) const
@@ -28,24 +28,25 @@ private:
};
public:
SenseApiLib(
StimBuffApiLib(
const std::string& path, void *_dlopen_handle,
SMO_GET_SENSE_API_DESC_FN_TYPEDEF *descFn)
: libraryPath(path), qutex("SenseApiLib-" + path), isBeingDestroyed(false),
SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF *descFn)
: libraryPath(path), qutex("StimBuffApiLib-" + path),
isBeingDestroyed(false),
dlopen_handle(_dlopen_handle, DlCloser()),
SMO_GET_SENSE_API_DESC_FN_NAME(descFn)
SMO_GET_STIM_BUFF_API_DESC_FN_NAME(descFn)
{}
void setSenseApiDesc(const SenseApiDesc &desc)
void setStimBuffApiDesc(const StimBuffApiDesc &desc)
{
if (!SenseApiDesc::sanityCheck(desc))
if (!StimBuffApiDesc::sanityCheck(desc))
{
throw std::runtime_error(
std::string(__func__) + ": Sanity check failed for sense API "
std::string(__func__) + ": Sanity check failed for stim buff API "
"descriptor in library '" + libraryPath + "'");
}
senseApiDesc = desc;
stimBuffApiDesc = desc;
}
public:
@@ -54,36 +55,36 @@ public:
std::atomic<bool> isBeingDestroyed;
std::unique_ptr<void, DlCloser> dlopen_handle;
/* UNIMPLEMENTED: API-specific cmdline options. These affect this specific
* sense api lib's behaviour globally.
* stim buff api lib's behaviour globally.
*/
std::vector<std::string> options;
/**
* @brief Every sense API lib is required to provide a function that returns
* a SenseApiDesc struct. This struct states which API the lib uses to
* connect Salmanoff to the sense provider it supports.
* @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_SENSE_API_DESC_FN_TYPEDEF>
SMO_GET_SENSE_API_DESC_FN_NAME;
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_SENSE_API_DESC_FN_NAME` getter
* @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.
*/
SenseApiDesc senseApiDesc;
StimBuffApiDesc stimBuffApiDesc;
std::string stringify() const {
std::string result = "Library Path: " + libraryPath + "\n";
result += "Sense API Descriptor: " + senseApiDesc.stringify() + "\n";
result += "Stim Buff API Descriptor: " + stimBuffApiDesc.stringify() + "\n";
return result;
}
};
} // namespace sense_api
} // namespace stim_buff
} // namespace smo
#endif // SENSE_API_PROVIDER_DESC_H
@@ -0,0 +1,78 @@
#ifndef SENSE_API_MANAGER_H
#define SENSE_API_MANAGER_H
#include <config.h>
#include <memory>
#include <vector>
#include <string>
#include <optional>
#include <functional>
#include <componentThread.h>
#include <asynchronousLoop.h>
#include <stimBuffApis/stimBuffApiLib.h>
#include <user/deviceAttachmentSpec.h>
#include <callback.h>
#include <qutex.h>
namespace smo {
namespace stim_buff {
class StimBuffApiManager
{
public:
static StimBuffApiManager& getInstance()
{
static StimBuffApiManager instance;
return instance;
}
void initialize(void)
{};
void finalize(void)
{};
StimBuffApiLib& loadStimBuffApiLib(
const std::string& libraryPath,
const std::shared_ptr<ComponentThread>& componentThread);
std::optional<std::shared_ptr<StimBuffApiLib>> getStimBuffApiLib(
const std::string& libraryPath);
std::optional<std::shared_ptr<StimBuffApiLib>> getStimBuffApiLibByApiName(
const std::string& apiName);
void unloadStimBuffApiLib(const std::string& libraryPath);
void initializeStimBuffApiLib(StimBuffApiLib& lib);
void finalizeStimBuffApiLib(StimBuffApiLib& lib);
void loadAllStimBuffApiLibsFromOptions(
const std::shared_ptr<ComponentThread>& componentThread);
void unloadAllStimBuffApiLibs(void);
void initializeAllStimBuffApiLibs(void);
void finalizeAllStimBuffApiLibs(void);
std::string stringifyLibs() const;
private:
StimBuffApiManager()
: qutex("StimBuffApiManager")
{}
~StimBuffApiManager() = default;
StimBuffApiManager(const StimBuffApiManager&) = delete;
StimBuffApiManager& operator=(const StimBuffApiManager&) = delete;
std::vector<std::shared_ptr<StimBuffApiLib>> stimBuffApiLibs;
public:
Qutex qutex;
public:
static std::optional<std::string> searchForLibInSmoSearchPaths(
const std::string& libraryPath);
};
} // namespace stim_buff
} // namespace smo
#endif // SENSE_API_MANAGER_H