2025-01-08 11:49:28 -04:00
|
|
|
#ifndef __USER_SENSE_API_LIB_H__
|
|
|
|
|
#define __USER_SENSE_API_LIB_H__
|
|
|
|
|
|
2025-01-09 06:03:43 -04:00
|
|
|
#include <stdbool.h>
|
2025-07-24 02:12:31 -04:00
|
|
|
#include <optional>
|
|
|
|
|
#include <string>
|
2025-10-17 16:19:25 -04:00
|
|
|
#include <functional>
|
2025-08-29 09:50:26 -04:00
|
|
|
#include <memory>
|
2025-11-19 22:33:30 -04:00
|
|
|
#include <vector>
|
2025-08-29 15:16:11 -04:00
|
|
|
#include <preprocessor.h>
|
|
|
|
|
#include <user/deviceAttachmentSpec.h>
|
2026-06-10 21:16:55 -04:00
|
|
|
#include <user/smoHooks.h>
|
2026-05-31 07:13:53 -04:00
|
|
|
#include <spinscale/co/dynamicPostingInvoker.h>
|
2026-05-25 08:21:46 -04:00
|
|
|
#include <spinscale/co/invokers.h>
|
2026-05-31 07:13:53 -04:00
|
|
|
#include <spinscale/co/postTarget.h>
|
2025-12-27 16:21:22 -04:00
|
|
|
#include <spinscale/componentThread.h>
|
2025-11-07 14:59:28 -04:00
|
|
|
|
2025-07-22 06:48:04 -04:00
|
|
|
namespace smo {
|
2025-10-16 02:15:16 -04:00
|
|
|
|
2025-10-01 18:47:42 -04:00
|
|
|
namespace stim_buff {
|
2025-01-08 11:49:28 -04:00
|
|
|
|
2026-05-25 08:21:46 -04:00
|
|
|
struct StimBuffDeviceOpResult
|
|
|
|
|
{
|
|
|
|
|
bool success = false;
|
|
|
|
|
std::shared_ptr<device::DeviceAttachmentSpec> deviceSpec;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using sal_mlo_initializeCIndFn = sscl::co::ViralNonPostingInvoker<int>(void);
|
|
|
|
|
using sal_mlo_finalizeCIndFn = sscl::co::ViralNonPostingInvoker<int>(void);
|
2026-05-31 07:13:53 -04:00
|
|
|
using sal_mlo_attachDeviceCReqFn =
|
|
|
|
|
sscl::co::DynamicViralPostingInvoker<StimBuffDeviceOpResult>(
|
|
|
|
|
sscl::co::ExplicitPostTarget postTarget,
|
2026-05-25 08:21:46 -04:00
|
|
|
const std::shared_ptr<device::DeviceAttachmentSpec>& desc,
|
|
|
|
|
const std::shared_ptr<sscl::ComponentThread>& componentThread);
|
2026-05-31 07:13:53 -04:00
|
|
|
using sal_mlo_detachDeviceCReqFn =
|
|
|
|
|
sscl::co::DynamicViralPostingInvoker<StimBuffDeviceOpResult>(
|
|
|
|
|
sscl::co::ExplicitPostTarget postTarget,
|
2026-05-25 08:21:46 -04:00
|
|
|
const std::shared_ptr<device::DeviceAttachmentSpec>& desc);
|
2025-01-09 17:18:24 -04:00
|
|
|
|
2025-01-13 21:57:11 -04:00
|
|
|
struct Sal_Mgmt_LibOps
|
2025-01-09 06:03:43 -04:00
|
|
|
{
|
2025-10-01 18:47:42 -04:00
|
|
|
/* When Salmanoff loads a stim buff API lib, it calls this function to initialize
|
2025-01-09 06:03:43 -04:00
|
|
|
* the lib. When this returns, the lib should be ready to attach devices.
|
|
|
|
|
*/
|
2026-05-25 08:21:46 -04:00
|
|
|
sal_mlo_initializeCIndFn *initializeCInd;
|
2025-07-22 06:48:04 -04:00
|
|
|
/* Salmanoff calls this to finalize the lib and free its internal
|
2025-01-09 06:03:43 -04:00
|
|
|
* resources. When this returns, the lib should be ready to be unloaded.
|
|
|
|
|
*/
|
2026-05-25 08:21:46 -04:00
|
|
|
sal_mlo_finalizeCIndFn *finalizeCInd;
|
2025-07-22 06:48:04 -04:00
|
|
|
/* Salmanoff calls this to attach a device to the lib. When it returns, the
|
2025-10-01 18:20:59 -04:00
|
|
|
* device should be attached and ready to present its stimbuff.
|
2025-01-09 06:03:43 -04:00
|
|
|
*/
|
2026-05-25 08:21:46 -04:00
|
|
|
sal_mlo_attachDeviceCReqFn *attachDeviceCReq;
|
2025-01-09 06:03:43 -04:00
|
|
|
// When this returns, the device should be detached.
|
2026-05-25 08:21:46 -04:00
|
|
|
sal_mlo_detachDeviceCReqFn *detachDeviceCReq;
|
2025-01-09 06:03:43 -04:00
|
|
|
|
2025-01-13 21:57:11 -04:00
|
|
|
static bool sanityCheck(const Sal_Mgmt_LibOps &ops)
|
|
|
|
|
{
|
2026-05-25 08:21:46 -04:00
|
|
|
if (!ops.initializeCInd || !ops.finalizeCInd
|
|
|
|
|
|| !ops.attachDeviceCReq || !ops.detachDeviceCReq)
|
2025-01-13 21:57:11 -04:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-01-08 11:49:28 -04:00
|
|
|
};
|
|
|
|
|
|
2025-10-01 18:47:42 -04:00
|
|
|
/* Exported by all stim buff API Libraries to tell Salmanoff what API the lib uses
|
2025-10-01 18:10:58 -04:00
|
|
|
* to connect to providers; and also to state which quale-iface APIs it exports.
|
2025-01-13 21:57:11 -04:00
|
|
|
*/
|
2025-10-01 18:47:42 -04:00
|
|
|
class StimBuffApiDesc
|
2025-01-09 06:03:43 -04:00
|
|
|
{
|
2025-01-13 21:57:11 -04:00
|
|
|
public:
|
2025-10-01 18:10:58 -04:00
|
|
|
class ExportedQualeIfaceApiDesc
|
2025-01-13 21:57:11 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2025-10-01 18:10:58 -04:00
|
|
|
static bool sanityCheck(const ExportedQualeIfaceApiDesc &desc)
|
2025-01-13 21:57:11 -04:00
|
|
|
{
|
|
|
|
|
if (desc.name.empty()) { return false; }
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::string name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::string stringify() const
|
2025-01-09 06:03:43 -04:00
|
|
|
{
|
2025-01-13 21:57:11 -04:00
|
|
|
std::string result = "Name: " + name + "\n";
|
2025-10-01 18:10:58 -04:00
|
|
|
result += "Exported QualeIface APIs:\n";
|
|
|
|
|
for (const auto& api : exportedQualeIfaceApis) {
|
2025-01-13 21:57:11 -04:00
|
|
|
result += " - " + api.name + "\n";
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2025-01-09 06:03:43 -04:00
|
|
|
}
|
|
|
|
|
|
2025-10-01 18:47:42 -04:00
|
|
|
static bool sanityCheck(const StimBuffApiDesc &desc)
|
2025-01-09 06:03:43 -04:00
|
|
|
{
|
2025-10-01 18:10:58 -04:00
|
|
|
if (desc.name.empty() || desc.exportedQualeIfaceApis.empty()) {
|
2025-01-13 21:57:11 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2025-01-09 06:03:43 -04:00
|
|
|
|
2025-10-01 18:10:58 -04:00
|
|
|
for (const auto& api : desc.exportedQualeIfaceApis) {
|
|
|
|
|
if (!ExportedQualeIfaceApiDesc::sanityCheck(api)) { return false; }
|
2025-01-13 21:57:11 -04:00
|
|
|
}
|
2025-01-09 06:03:43 -04:00
|
|
|
|
2025-01-13 21:57:11 -04:00
|
|
|
return Sal_Mgmt_LibOps::sanityCheck(desc.sal_mgmt_libOps);
|
2025-01-09 06:03:43 -04:00
|
|
|
}
|
|
|
|
|
|
2025-01-13 21:57:11 -04:00
|
|
|
std::string name;
|
2025-10-01 18:10:58 -04:00
|
|
|
// These are the quale-iface APIs this lib exports.
|
|
|
|
|
std::vector<ExportedQualeIfaceApiDesc> exportedQualeIfaceApis;
|
2025-01-13 21:57:11 -04:00
|
|
|
Sal_Mgmt_LibOps sal_mgmt_libOps;
|
|
|
|
|
};
|
2025-01-09 06:03:43 -04:00
|
|
|
|
2025-01-18 10:16:02 -04:00
|
|
|
|
2025-10-01 18:47:42 -04:00
|
|
|
#define SMO_GET_STIM_BUFF_API_DESC_FN_NAME getStimBuffApiDesc
|
|
|
|
|
#define SMO_GET_STIM_BUFF_API_DESC_FN_NAME_STR \
|
|
|
|
|
SMO_QUOTE(SMO_GET_STIM_BUFF_API_DESC_FN_NAME)
|
|
|
|
|
#define SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF \
|
|
|
|
|
SMO_CONCAT(SMO_GET_STIM_BUFF_API_DESC_FN_NAME, Fn)
|
2025-01-08 17:16:49 -04:00
|
|
|
|
2025-10-01 18:47:42 -04:00
|
|
|
/* Every Stim Buff API library must define a global instance of this
|
2025-07-22 06:48:04 -04:00
|
|
|
* function. Salmanoff will search for it and invoke it via dlsym().
|
2025-01-18 10:16:02 -04:00
|
|
|
*
|
2025-10-01 18:47:42 -04:00
|
|
|
* The function must return a StimBuffApiDesc struct that Smo will tell
|
2025-10-01 18:10:58 -04:00
|
|
|
* Smo what quale-iface APIs can be used with it & what APIs it exports.
|
2025-10-01 18:47:42 -04:00
|
|
|
* The StimBuffApiDesc struct also gives Smo pointers to API functions
|
2025-07-22 06:48:04 -04:00
|
|
|
* to invoke for communication between Smo and the library.
|
2025-07-24 02:12:31 -04:00
|
|
|
*
|
2025-09-04 17:45:11 -04:00
|
|
|
* The SmoCallbacks parameter provides the library with access to
|
2025-07-24 02:12:31 -04:00
|
|
|
* Salmanoff's hooks.
|
2025-09-04 17:35:49 -04:00
|
|
|
* The SmoThreadingModelDesc parameter provides the library with access to
|
2026-05-30 11:59:42 -04:00
|
|
|
* the io_context for network operations and event handling.
|
2025-01-18 10:16:02 -04:00
|
|
|
*/
|
2025-10-01 18:47:42 -04:00
|
|
|
typedef const StimBuffApiDesc &(SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF)(
|
2025-09-04 17:45:11 -04:00
|
|
|
const SmoCallbacks& callbacks,
|
2025-09-04 17:35:49 -04:00
|
|
|
const SmoThreadingModelDesc& threadingModel);
|
2025-01-08 17:16:49 -04:00
|
|
|
|
2025-10-01 18:47:42 -04:00
|
|
|
} // namespace stim_buff
|
2025-07-22 06:48:04 -04:00
|
|
|
} // namespace smo
|
2025-01-08 17:16:49 -04:00
|
|
|
|
2025-01-08 11:49:28 -04:00
|
|
|
#endif // __USER_SENSE_API_LIB_H__
|