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
+1 -1
View File
@@ -88,7 +88,7 @@ endif()
# Add core components # Add core components
add_subdirectory(smocore) add_subdirectory(smocore)
add_subdirectory(commonLibs) add_subdirectory(commonLibs)
add_subdirectory(senseApis) add_subdirectory(stimBuffApis)
add_subdirectory(wilzorApis) add_subdirectory(wilzorApis)
add_subdirectory(devices) add_subdirectory(devices)
+1 -1
View File
@@ -245,7 +245,7 @@ void DeviceManager::destroyDeviceReq(
} }
void main(const std::shared_ptr<smo::ComponentThread> &componentThread, void main(const std::shared_ptr<smo::ComponentThread> &componentThread,
const smo::sense_api::SmoCallbacks& smoCallbacks) const smo::stim_buff::SmoCallbacks& smoCallbacks)
{ {
if (protoState.isInitialized) { if (protoState.isInitialized) {
return; return;
+2 -2
View File
@@ -58,7 +58,7 @@ public:
void main( void main(
const std::shared_ptr<smo::ComponentThread> &componentThread, const std::shared_ptr<smo::ComponentThread> &componentThread,
const smo::sense_api::SmoCallbacks& smoCallbacks); const smo::stim_buff::SmoCallbacks& smoCallbacks);
void exit(void); void exit(void);
// Global state structure // Global state structure
@@ -67,7 +67,7 @@ struct ProtoState
bool isInitialized = false; bool isInitialized = false;
std::shared_ptr<smo::ComponentThread> componentThread; std::shared_ptr<smo::ComponentThread> componentThread;
std::unique_ptr<DeviceManager> deviceManager; std::unique_ptr<DeviceManager> deviceManager;
smo::sense_api::SmoCallbacks smoCallbacks; smo::stim_buff::SmoCallbacks smoCallbacks;
}; };
// Access to global state for extern "C" functions // Access to global state for extern "C" functions
+1 -1
View File
@@ -52,7 +52,7 @@ void livoxProto1_destroyDeviceReq(
void livoxProto1_main( void livoxProto1_main(
const std::shared_ptr<smo::ComponentThread>& componentThread, const std::shared_ptr<smo::ComponentThread>& componentThread,
const smo::sense_api::SmoCallbacks& smoCallbacks) const smo::stim_buff::SmoCallbacks& smoCallbacks)
{ {
livoxProto1::main(componentThread, smoCallbacks); livoxProto1::main(componentThread, smoCallbacks);
} }
+2 -2
View File
@@ -9,7 +9,7 @@
// Forward declarations // Forward declarations
namespace smo { namespace smo {
namespace sense_api { namespace stim_buff {
struct SmoCallbacks; struct SmoCallbacks;
} }
class ComponentThread; class ComponentThread;
@@ -30,7 +30,7 @@ extern "C" {
*/ */
typedef void livoxProto1_mainFn( typedef void livoxProto1_mainFn(
const std::shared_ptr<smo::ComponentThread>& componentThread, const std::shared_ptr<smo::ComponentThread>& componentThread,
const smo::sense_api::SmoCallbacks& smoCallbacks); const smo::stim_buff::SmoCallbacks& smoCallbacks);
/** /**
* Cleanup the Livox protocol library * Cleanup the Livox protocol library
+1 -3
View File
@@ -1,3 +1 @@
+edev|avia0| +edev|avia0|structural-qualeiface|livoxGen1()|livoxProto1()|3JEDK380010Z39
structural-implexor|livoxGen1()|livoxProto1()
|3JEDK380010Z39
+1 -3
View File
@@ -1,3 +1 @@
+edev|win0| +edev|win0|visual-qualeiface|xcb(dev-substring)|xorg(display=1|screen=0)|mut
visual-implexor|xcb(dev-substring)|xorg(display=1|screen=0)
|mut
+10 -9
View File
@@ -26,15 +26,16 @@
#cmakedefine CONFIG_LIB_XCBXORG_ENABLED #cmakedefine CONFIG_LIB_XCBXORG_ENABLED
#cmakedefine CONFIG_LIB_ALSA_ENABLED #cmakedefine CONFIG_LIB_ALSA_ENABLED
/* Sense APIs */ /* Stim Buff APIs */
#cmakedefine CONFIG_SENSEAPI_XCBWINDOW_ENABLED #cmakedefine CONFIG_STIMBUFFAPI_XCBWINDOW_ENABLED
#cmakedefine CONFIG_SENSEAPI_V4L_ENABLED #cmakedefine CONFIG_STIMBUFFAPI_LIVOXGEN1_ENABLED
#cmakedefine CONFIG_SENSEAPI_ALSAMIC_ENABLED #cmakedefine CONFIG_STIMBUFFAPI_V4L_ENABLED
#cmakedefine CONFIG_SENSEAPI_LIVOX_ENABLED #cmakedefine CONFIG_STIMBUFFAPI_ALSAMIC_ENABLED
#cmakedefine CONFIG_SENSEAPI_R3LIVE_ENABLED #cmakedefine CONFIG_STIMBUFFAPI_LIVOX_ENABLED
#cmakedefine CONFIG_SENSEAPI_FASTLIO2_ENABLED #cmakedefine CONFIG_STIMBUFFAPI_R3LIVE_ENABLED
#cmakedefine CONFIG_SENSEAPI_ADALIO2_ENABLED #cmakedefine CONFIG_STIMBUFFAPI_FASTLIO2_ENABLED
#cmakedefine CONFIG_SENSEAPI_DEEPLIO2_ENABLED #cmakedefine CONFIG_STIMBUFFAPI_ADALIO2_ENABLED
#cmakedefine CONFIG_STIMBUFFAPI_DEEPLIO2_ENABLED
/* Wilzor APIs */ /* Wilzor APIs */
#cmakedefine CONFIG_WILZORAPI_XCBMOUSE_ENABLED #cmakedefine CONFIG_WILZORAPI_XCBMOUSE_ENABLED
+15 -15
View File
@@ -11,7 +11,7 @@
#include <callback.h> #include <callback.h>
namespace smo { namespace smo {
namespace sense_api { namespace stim_buff {
/** /**
* @brief Threading model descriptor for senseApi libraries. * @brief Threading model descriptor for senseApi libraries.
@@ -82,7 +82,7 @@ struct SmoCallbacks
struct Sal_Mgmt_LibOps struct Sal_Mgmt_LibOps
{ {
/* When Salmanoff loads a sense API lib, it calls this function to initialize /* When Salmanoff loads a stim buff API lib, it calls this function to initialize
* the lib. When this returns, the lib should be ready to attach devices. * the lib. When this returns, the lib should be ready to attach devices.
*/ */
sal_mlo_initializeIndFn *initializeInd; sal_mlo_initializeIndFn *initializeInd;
@@ -109,10 +109,10 @@ struct Sal_Mgmt_LibOps
} }
}; };
/* Exported by all sense API Libraries to tell Salmanoff what API the lib uses /* Exported by all stim buff API Libraries to tell Salmanoff what API the lib uses
* to connect to providers; and also to state which quale-iface APIs it exports. * to connect to providers; and also to state which quale-iface APIs it exports.
*/ */
class SenseApiDesc class StimBuffApiDesc
{ {
public: public:
class ExportedQualeIfaceApiDesc class ExportedQualeIfaceApiDesc
@@ -139,7 +139,7 @@ public:
return result; return result;
} }
static bool sanityCheck(const SenseApiDesc &desc) static bool sanityCheck(const StimBuffApiDesc &desc)
{ {
if (desc.name.empty() || desc.exportedQualeIfaceApis.empty()) { if (desc.name.empty() || desc.exportedQualeIfaceApis.empty()) {
return false; return false;
@@ -159,18 +159,18 @@ public:
}; };
#define SMO_GET_SENSE_API_DESC_FN_NAME getSenseApiDesc #define SMO_GET_STIM_BUFF_API_DESC_FN_NAME getStimBuffApiDesc
#define SMO_GET_SENSE_API_DESC_FN_NAME_STR \ #define SMO_GET_STIM_BUFF_API_DESC_FN_NAME_STR \
SMO_QUOTE(SMO_GET_SENSE_API_DESC_FN_NAME) SMO_QUOTE(SMO_GET_STIM_BUFF_API_DESC_FN_NAME)
#define SMO_GET_SENSE_API_DESC_FN_TYPEDEF \ #define SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF \
SMO_CONCAT(SMO_GET_SENSE_API_DESC_FN_NAME, Fn) SMO_CONCAT(SMO_GET_STIM_BUFF_API_DESC_FN_NAME, Fn)
/* Every Sense API library must define a global instance of this /* Every Stim Buff API library must define a global instance of this
* function. Salmanoff will search for it and invoke it via dlsym(). * function. Salmanoff will search for it and invoke it via dlsym().
* *
* The function must return a SenseApiDesc struct that Smo will tell * The function must return a StimBuffApiDesc struct that Smo will tell
* Smo what quale-iface APIs can be used with it & what APIs it exports. * Smo what quale-iface APIs can be used with it & what APIs it exports.
* The SenseApiDesc struct also gives Smo pointers to API functions * The StimBuffApiDesc struct also gives Smo pointers to API functions
* to invoke for communication between Smo and the library. * to invoke for communication between Smo and the library.
* *
* The SmoCallbacks parameter provides the library with access to * The SmoCallbacks parameter provides the library with access to
@@ -178,11 +178,11 @@ public:
* The SmoThreadingModelDesc parameter provides the library with access to * The SmoThreadingModelDesc parameter provides the library with access to
* the io_service for network operations and event handling. * the io_service for network operations and event handling.
*/ */
typedef const SenseApiDesc &(SMO_GET_SENSE_API_DESC_FN_TYPEDEF)( typedef const StimBuffApiDesc &(SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF)(
const SmoCallbacks& callbacks, const SmoCallbacks& callbacks,
const SmoThreadingModelDesc& threadingModel); const SmoThreadingModelDesc& threadingModel);
} // namespace sense_api } // namespace stim_buff
} // namespace smo } // namespace smo
#endif // __USER_SENSE_API_LIB_H__ #endif // __USER_SENSE_API_LIB_H__
+1 -1
View File
@@ -29,7 +29,7 @@ add_library(smocore STATIC
${YACC_OUTPUT} ${YACC_OUTPUT}
# SenseApis # SenseApis
senseApis/senseApiManager.cpp stimBuffApis/stimBuffApiManager.cpp
# MindManager # MindManager
mindManager/mindManager.cpp mindManager/mindManager.cpp
+11 -10
View File
@@ -6,7 +6,7 @@
#include <body/body.h> #include <body/body.h>
#include <componentThread.h> #include <componentThread.h>
#include <mind.h> #include <mind.h>
#include <senseApis/senseApiManager.h> #include <stimBuffApis/stimBuffApiManager.h>
#include <deviceManager/deviceManager.h> #include <deviceManager/deviceManager.h>
namespace smo { namespace smo {
@@ -53,8 +53,8 @@ public:
* Right now we use Marionette, but there's a strong argument for using * Right now we use Marionette, but there's a strong argument for using
* Body instead since it's meant to handle device-management operations. * Body instead since it's meant to handle device-management operations.
*/ */
sense_api::SenseApiManager::getInstance() stim_buff::StimBuffApiManager::getInstance()
.loadAllSenseApiLibsFromOptions(caller); .loadAllStimBuffApiLibsFromOptions(caller);
/** EXPLANATION: /** EXPLANATION:
* Consider body::initializeReq to have been called if even one of its * Consider body::initializeReq to have been called if even one of its
@@ -63,15 +63,16 @@ public:
*/ */
context->parent.bodyComponentInitialized = true; context->parent.bodyComponentInitialized = true;
std::cout << sense_api::SenseApiManager::getInstance().stringifyLibs() std::cout << stim_buff::StimBuffApiManager::getInstance().stringifyLibs()
<< std::endl; << std::endl;
if (OptionParser::getOptions().verbose) if (OptionParser::getOptions().verbose)
{ {
std::cout << __func__ << ": About to initializeAllSenseApiLibs" std::cout << __func__ << ": About to initializeAllStimBuffApiLibs"
<< '\n'; << '\n';
} }
sense_api::SenseApiManager::getInstance().initializeAllSenseApiLibs(); stim_buff::StimBuffApiManager::getInstance()
.initializeAllStimBuffApiLibs();
if (OptionParser::getOptions().verbose) if (OptionParser::getOptions().verbose)
{ {
@@ -134,11 +135,11 @@ public:
<< results.nSucceeded << " of " << results.nTotal << results.nSucceeded << " of " << results.nTotal
<< " sense devices." << "\n"; << " sense devices." << "\n";
std::cout << "Mrntt: About to finalize all sense api libs." << "\n"; std::cout << "Mrntt: About to finalize all stim buff api libs." << "\n";
sense_api::SenseApiManager::getInstance().finalizeAllSenseApiLibs(); stim_buff::StimBuffApiManager::getInstance().finalizeAllStimBuffApiLibs();
std::cout << "Mrntt: About to unload all sense api libs." << "\n"; std::cout << "Mrntt: About to unload all stim buff api libs." << "\n";
sense_api::SenseApiManager::getInstance().unloadAllSenseApiLibs(); stim_buff::StimBuffApiManager::getInstance().unloadAllStimBuffApiLibs();
callOriginalCb(results.nSucceeded == results.nTotal); callOriginalCb(results.nSucceeded == results.nTotal);
} }
}; };
+59 -56
View File
@@ -12,7 +12,7 @@
#include <componentThread.h> #include <componentThread.h>
#include <deviceManager/deviceManager.h> #include <deviceManager/deviceManager.h>
#include <deviceManager/deviceReattacher.h> #include <deviceManager/deviceReattacher.h>
#include <senseApis/senseApiManager.h> #include <stimBuffApis/stimBuffApiManager.h>
#include <marionette/marionette.h> #include <marionette/marionette.h>
#include <mind.h> #include <mind.h>
@@ -132,7 +132,7 @@ public:
return; return;
} }
DeviceManager::getInstance().attachSenseDeviceReq( DeviceManager::getInstance().attachStimBuffDeviceReq(
specPtr, specPtr,
{context, std::bind( {context, std::bind(
&NewDeviceAttachmentSpecInd::newDeviceAttachmentSpecInd2, &NewDeviceAttachmentSpecInd::newDeviceAttachmentSpecInd2,
@@ -209,8 +209,8 @@ public:
return; return;
} }
// Call detachSenseDeviceReq first - only clean up metadata if this succeeds // Call detachStimBuffDeviceReq first - only clean up metadata if this succeeds
DeviceManager::getInstance().detachSenseDeviceReq( DeviceManager::getInstance().detachStimBuffDeviceReq(
specPtr, specPtr,
{context, std::bind( {context, std::bind(
&RemoveDeviceAttachmentSpecReq::removeDeviceAttachmentSpecReq2, &RemoveDeviceAttachmentSpecReq::removeDeviceAttachmentSpecReq2,
@@ -329,24 +329,25 @@ void DeviceManager::removeDeviceAttachmentSpecReq(
request.get(), request)); request.get(), request));
} }
class DeviceManager::AttachSenseDeviceReq class DeviceManager::AttachStimBuffDeviceReq
: public SerializedAsynchronousContinuation<attachSenseDeviceReqCbFn> : public SerializedAsynchronousContinuation<
DeviceManager::attachStimBuffDeviceReqCbFn>
{ {
public: public:
AttachSenseDeviceReq( AttachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec, const std::shared_ptr<DeviceAttachmentSpec>& spec,
const std::shared_ptr<ComponentThread> &caller, const std::shared_ptr<ComponentThread> &caller,
Callback<attachSenseDeviceReqCbFn> cb, Callback<DeviceManager::attachStimBuffDeviceReqCbFn> cb,
std::shared_ptr<sense_api::SenseApiLib> &senseApiLib, std::shared_ptr<stim_buff::StimBuffApiLib> &stimBuffApiLib,
std::vector<std::reference_wrapper<Qutex>> requiredLocks) std::vector<std::reference_wrapper<Qutex>> requiredLocks)
: SerializedAsynchronousContinuation<attachSenseDeviceReqCbFn>( : SerializedAsynchronousContinuation<attachStimBuffDeviceReqCbFn>(
caller, cb, requiredLocks), caller, cb, requiredLocks),
spec(spec), senseApiLib(senseApiLib) spec(spec), stimBuffApiLib(stimBuffApiLib)
{} {}
public: public:
void attachSenseDeviceReq1_posted( void attachStimBuffDeviceReq1_posted(
[[maybe_unused]] std::shared_ptr<AttachSenseDeviceReq> context [[maybe_unused]] std::shared_ptr<AttachStimBuffDeviceReq> context
) )
{ {
if (caller->id != ComponentThread::MRNTT) if (caller->id != ComponentThread::MRNTT)
@@ -358,7 +359,7 @@ public:
return; return;
} }
if (senseApiLib->isBeingDestroyed.load()) if (stimBuffApiLib->isBeingDestroyed.load())
{ {
std::cerr << std::string(__func__) + ": Library is being destroyed" std::cerr << std::string(__func__) + ": Library is being destroyed"
<< " for API '" << spec->stimBuffApi << "'. Bailing out.\n"; << " for API '" << spec->stimBuffApi << "'. Bailing out.\n";
@@ -366,15 +367,16 @@ public:
return; return;
} }
if (!senseApiLib->senseApiDesc.sal_mgmt_libOps.attachDeviceReq) if (!stimBuffApiLib->stimBuffApiDesc.sal_mgmt_libOps.attachDeviceReq)
{ {
std::cerr << std::string(__func__) + ": attachDeviceReq() is NULL " std::cerr << std::string(__func__) + ": attachDeviceReq() is NULL "
"for library '" << senseApiLib->libraryPath << "'" << std::endl; "for library '" << stimBuffApiLib->libraryPath << "'"
<< std::endl;
callOriginalCb(false, spec); callOriginalCb(false, spec);
return; return;
} }
releaseQutexEarly(sense_api::SenseApiManager::getInstance().qutex); releaseQutexEarly(stim_buff::StimBuffApiManager::getInstance().qutex);
/** EXPLANATION: /** EXPLANATION:
* We pass in either the body or world thread here, depending on whether * We pass in either the body or world thread here, depending on whether
@@ -397,16 +399,16 @@ public:
<< spec->deviceIdentifier << " to body thread" << "\n"; << spec->deviceIdentifier << " to body thread" << "\n";
} }
senseApiLib->senseApiDesc.sal_mgmt_libOps.attachDeviceReq( stimBuffApiLib->stimBuffApiDesc.sal_mgmt_libOps.attachDeviceReq(
spec, threadForAttachment, spec, threadForAttachment,
{context, std::bind( {context, std::bind(
&AttachSenseDeviceReq::attachSenseDeviceReq2, &AttachStimBuffDeviceReq::attachStimBuffDeviceReq2,
context.get(), context, context.get(), context,
std::placeholders::_1, std::placeholders::_2)}); std::placeholders::_1, std::placeholders::_2)});
} }
void attachSenseDeviceReq2( void attachStimBuffDeviceReq2(
[[maybe_unused]] std::shared_ptr<AttachSenseDeviceReq> context, [[maybe_unused]] std::shared_ptr<AttachStimBuffDeviceReq> context,
bool success, bool success,
std::shared_ptr<DeviceAttachmentSpec> deviceSpec std::shared_ptr<DeviceAttachmentSpec> deviceSpec
) )
@@ -414,8 +416,8 @@ public:
callOriginalCb(success, deviceSpec); callOriginalCb(success, deviceSpec);
} }
void detachSenseDeviceReq1_posted( void detachStimBuffDeviceReq1_posted(
[[maybe_unused]] std::shared_ptr<DetachSenseDeviceReq> context [[maybe_unused]] std::shared_ptr<AttachStimBuffDeviceReq> context
) )
{ {
if (caller->id != ComponentThread::MRNTT) if (caller->id != ComponentThread::MRNTT)
@@ -427,7 +429,7 @@ public:
return; return;
} }
if (senseApiLib->isBeingDestroyed.load()) if (stimBuffApiLib->isBeingDestroyed.load())
{ {
std::cerr << std::string(__func__) + ": Library is being destroyed" std::cerr << std::string(__func__) + ": Library is being destroyed"
<< " for API '" << spec->stimBuffApi << "'. Bailing out.\n"; << " for API '" << spec->stimBuffApi << "'. Bailing out.\n";
@@ -435,26 +437,27 @@ public:
return; return;
} }
if (!senseApiLib->senseApiDesc.sal_mgmt_libOps.detachDeviceReq) if (!stimBuffApiLib->stimBuffApiDesc.sal_mgmt_libOps.detachDeviceReq)
{ {
std::cerr << std::string(__func__) + ": detachDeviceReq() is NULL " std::cerr << std::string(__func__) + ": detachDeviceReq() is NULL "
"for library '" << senseApiLib->libraryPath << "'" << std::endl; "for library '" << stimBuffApiLib->libraryPath << "'"
<< std::endl;
callOriginalCb(false, spec); callOriginalCb(false, spec);
return; return;
} }
releaseQutexEarly(sense_api::SenseApiManager::getInstance().qutex); releaseQutexEarly(stim_buff::StimBuffApiManager::getInstance().qutex);
senseApiLib->senseApiDesc.sal_mgmt_libOps.detachDeviceReq( stimBuffApiLib->stimBuffApiDesc.sal_mgmt_libOps.detachDeviceReq(
spec, spec,
{context, std::bind( {context, std::bind(
&DetachSenseDeviceReq::detachSenseDeviceReq2, &AttachStimBuffDeviceReq::detachStimBuffDeviceReq2,
context.get(), context, context.get(), context,
std::placeholders::_1, std::placeholders::_2)}); std::placeholders::_1, std::placeholders::_2)});
} }
void detachSenseDeviceReq2( void detachStimBuffDeviceReq2(
[[maybe_unused]] std::shared_ptr<DetachSenseDeviceReq> context, [[maybe_unused]] std::shared_ptr<AttachStimBuffDeviceReq> context,
bool success, bool success,
std::shared_ptr<DeviceAttachmentSpec> deviceSpec std::shared_ptr<DeviceAttachmentSpec> deviceSpec
) )
@@ -464,23 +467,23 @@ public:
public: public:
std::shared_ptr<DeviceAttachmentSpec> spec; std::shared_ptr<DeviceAttachmentSpec> spec;
std::shared_ptr<sense_api::SenseApiLib> senseApiLib; std::shared_ptr<stim_buff::StimBuffApiLib> stimBuffApiLib;
}; };
void DeviceManager::attachSenseDeviceReq( void DeviceManager::attachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec, const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<attachSenseDeviceReqCbFn> cb Callback<attachStimBuffDeviceReqCbFn> cb
) )
{ {
const auto& caller = ComponentThread::getSelf(); const auto& caller = ComponentThread::getSelf();
// Get the sense API lib's qutex // Get the stim buff API lib's qutex
auto libOpt = sense_api::SenseApiManager::getInstance() auto libOpt = stim_buff::StimBuffApiManager::getInstance()
.getSenseApiLibByApiName(spec->stimBuffApi); .getStimBuffApiLibByApiName(spec->stimBuffApi);
if (!libOpt) if (!libOpt)
{ {
std::cerr << "attachSenseDeviceReq: No library found for API '" std::cerr << "attachStimBuffDeviceReq: No library found for API '"
<< spec->stimBuffApi << "'" << std::endl; << spec->stimBuffApi << "'" << std::endl;
cb.callbackFn(false, spec); cb.callbackFn(false, spec);
return; return;
@@ -488,34 +491,34 @@ void DeviceManager::attachSenseDeviceReq(
auto& lib = *libOpt.value(); auto& lib = *libOpt.value();
auto request = std::make_shared<AttachSenseDeviceReq>( auto request = std::make_shared<AttachStimBuffDeviceReq>(
spec, caller, cb, libOpt.value(), spec, caller, cb, libOpt.value(),
LockSet<attachSenseDeviceReqCbFn>::Set{ LockSet<attachStimBuffDeviceReqCbFn>::Set{
std::ref(sense_api::SenseApiManager::getInstance().qutex), std::ref(stim_buff::StimBuffApiManager::getInstance().qutex),
std::ref(lib.qutex) std::ref(lib.qutex)
}); });
AttachSenseDeviceReq::LockerAndInvoker lockvoker( AttachStimBuffDeviceReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread, *request, mrntt::mrntt.thread,
std::bind( std::bind(
&AttachSenseDeviceReq::attachSenseDeviceReq1_posted, &AttachStimBuffDeviceReq::attachStimBuffDeviceReq1_posted,
request.get(), request)); request.get(), request));
} }
void DeviceManager::detachSenseDeviceReq( void DeviceManager::detachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec, const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<detachSenseDeviceReqCbFn> cb Callback<detachStimBuffDeviceReqCbFn> cb
) )
{ {
const auto& caller = ComponentThread::getSelf(); const auto& caller = ComponentThread::getSelf();
// Get the sense API lib's qutex // Get the stim buff API lib's qutex
auto libOpt = sense_api::SenseApiManager::getInstance() auto libOpt = stim_buff::StimBuffApiManager::getInstance()
.getSenseApiLibByApiName(spec->stimBuffApi); .getStimBuffApiLibByApiName(spec->stimBuffApi);
if (!libOpt) if (!libOpt)
{ {
std::cerr << "detachSenseDeviceReq: No library found for API '" std::cerr << "detachStimBuffDeviceReq: No library found for API '"
<< spec->stimBuffApi << "'" << std::endl; << spec->stimBuffApi << "'" << std::endl;
cb.callbackFn(false, spec); cb.callbackFn(false, spec);
return; return;
@@ -523,17 +526,17 @@ void DeviceManager::detachSenseDeviceReq(
auto& lib = *libOpt.value(); auto& lib = *libOpt.value();
auto request = std::make_shared<DetachSenseDeviceReq>( auto request = std::make_shared<DetachStimBuffDeviceReq>(
spec, caller, cb, libOpt.value(), spec, caller, cb, libOpt.value(),
LockSet<detachSenseDeviceReqCbFn>::Set{ LockSet<detachStimBuffDeviceReqCbFn>::Set{
std::ref(sense_api::SenseApiManager::getInstance().qutex), std::ref(stim_buff::StimBuffApiManager::getInstance().qutex),
std::ref(lib.qutex) std::ref(lib.qutex)
}); });
DetachSenseDeviceReq::LockerAndInvoker lockvoker( DetachStimBuffDeviceReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread, *request, mrntt::mrntt.thread,
std::bind( std::bind(
&DetachSenseDeviceReq::detachSenseDeviceReq1_posted, &DetachStimBuffDeviceReq::detachStimBuffDeviceReq1_posted,
request.get(), request)); request.get(), request));
} }
@@ -746,7 +749,7 @@ public:
{ {
for (const auto& deviceRole : DeviceManager::attachedDeviceRoles) for (const auto& deviceRole : DeviceManager::attachedDeviceRoles)
{ {
DeviceManager::getInstance().detachSenseDeviceReq( DeviceManager::getInstance().detachStimBuffDeviceReq(
deviceRole->deviceAttachmentSpec, deviceRole->deviceAttachmentSpec,
{context, std::bind( {context, std::bind(
&DetachAllAttachedDeviceRoles::detachAllAttachedDeviceRoles2, &DetachAllAttachedDeviceRoles::detachAllAttachedDeviceRoles2,
@@ -61,15 +61,15 @@ public:
Callback<removeDeviceAttachmentSpecReqCbFn> callback); Callback<removeDeviceAttachmentSpecReqCbFn> callback);
// Device attachment/detachment methods moved from SenseApiManager // Device attachment/detachment methods moved from SenseApiManager
typedef sense_api::sal_mlo_attachDeviceReqCbFn attachSenseDeviceReqCbFn; typedef stim_buff::sal_mlo_attachDeviceReqCbFn attachStimBuffDeviceReqCbFn;
typedef sense_api::sal_mlo_detachDeviceReqCbFn detachSenseDeviceReqCbFn; typedef stim_buff::sal_mlo_detachDeviceReqCbFn detachStimBuffDeviceReqCbFn;
void attachSenseDeviceReq( void attachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec, const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<attachSenseDeviceReqCbFn> cb); Callback<attachStimBuffDeviceReqCbFn> cb);
void detachSenseDeviceReq( void detachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec, const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<detachSenseDeviceReqCbFn> cb); Callback<detachStimBuffDeviceReqCbFn> cb);
typedef std::function<void(AsynchronousLoop &results)> typedef std::function<void(AsynchronousLoop &results)>
attachAllUnattachedDevicesFromReqCbFn; attachAllUnattachedDevicesFromReqCbFn;
@@ -108,8 +108,8 @@ private:
class NewDeviceAttachmentSpecInd; class NewDeviceAttachmentSpecInd;
class RemoveDeviceAttachmentSpecReq; class RemoveDeviceAttachmentSpecReq;
class AttachSenseDeviceReq; class AttachStimBuffDeviceReq;
typedef AttachSenseDeviceReq DetachSenseDeviceReq; typedef AttachStimBuffDeviceReq DetachStimBuffDeviceReq;
class AttachAllUnattachedDevicesFromReq; class AttachAllUnattachedDevicesFromReq;
class AttachAllUnattachedDevicesFromKnownListReq; class AttachAllUnattachedDevicesFromKnownListReq;
class DetachAllAttachedDeviceRoles; 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> #include <qutex.h>
namespace smo { namespace smo {
namespace sense_api { namespace stim_buff {
class SenseApiLib class StimBuffApiLib
{ {
private: private:
friend class SenseApiManager; friend class StimBuffApiManager;
struct DlCloser struct DlCloser
{ {
void operator()(void* handle) const void operator()(void* handle) const
@@ -28,24 +28,25 @@ private:
}; };
public: public:
SenseApiLib( StimBuffApiLib(
const std::string& path, void *_dlopen_handle, const std::string& path, void *_dlopen_handle,
SMO_GET_SENSE_API_DESC_FN_TYPEDEF *descFn) SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF *descFn)
: libraryPath(path), qutex("SenseApiLib-" + path), isBeingDestroyed(false), : libraryPath(path), qutex("StimBuffApiLib-" + path),
isBeingDestroyed(false),
dlopen_handle(_dlopen_handle, DlCloser()), 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( 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 + "'"); "descriptor in library '" + libraryPath + "'");
} }
senseApiDesc = desc; stimBuffApiDesc = desc;
} }
public: public:
@@ -54,36 +55,36 @@ public:
std::atomic<bool> isBeingDestroyed; std::atomic<bool> isBeingDestroyed;
std::unique_ptr<void, DlCloser> dlopen_handle; std::unique_ptr<void, DlCloser> dlopen_handle;
/* UNIMPLEMENTED: API-specific cmdline options. These affect this specific /* 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; std::vector<std::string> options;
/** /**
* @brief Every sense API lib is required to provide a function that returns * @brief Each stim buff API library must provide a function returning a
* a SenseApiDesc struct. This struct states which API the lib uses to * StimBuffApiDesc. This struct specifies which API the library uses to
* connect Salmanoff to the sense provider it supports. * connect Salmanoff to its supported stim buff provider.
* *
* This getter function should be visible to dlsym() so that Salmanoff can * This getter function should be visible to dlsym() so that Salmanoff can
* find it in the lib after loading it, and call it. * find it in the lib after loading it, and call it.
*/ */
std::function<SMO_GET_SENSE_API_DESC_FN_TYPEDEF> std::function<SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF>
SMO_GET_SENSE_API_DESC_FN_NAME; 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 * function and use the data it provides in order to fill out this
* descriptor. * descriptor.
*/ */
SenseApiDesc senseApiDesc; StimBuffApiDesc stimBuffApiDesc;
std::string stringify() const { std::string stringify() const {
std::string result = "Library Path: " + libraryPath + "\n"; std::string result = "Library Path: " + libraryPath + "\n";
result += "Sense API Descriptor: " + senseApiDesc.stringify() + "\n"; result += "Stim Buff API Descriptor: " + stimBuffApiDesc.stringify() + "\n";
return result; return result;
} }
}; };
} // namespace sense_api } // namespace stim_buff
} // namespace smo } // namespace smo
#endif // SENSE_API_PROVIDER_DESC_H #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
+3 -3
View File
@@ -1,7 +1,7 @@
#include <iostream> #include <iostream>
#include <mindManager/mindManager.h> #include <mindManager/mindManager.h>
#include <deviceManager/deviceManager.h> #include <deviceManager/deviceManager.h>
#include <senseApis/senseApiManager.h> #include <stimBuffApis/stimBuffApiManager.h>
#include <salmanoff.h> #include <salmanoff.h>
@@ -12,7 +12,7 @@ void initializeSalmanoff(void)
std::cout << __func__ << ": Entered." << std::endl; std::cout << __func__ << ": Entered." << std::endl;
mind::MindManager::getInstance().initialize(); mind::MindManager::getInstance().initialize();
sense_api::SenseApiManager::getInstance().initialize(); stim_buff::StimBuffApiManager::getInstance().initialize();
device::DeviceManager::getInstance().initialize(); device::DeviceManager::getInstance().initialize();
device::DeviceManager::getInstance().collateAllDapSpecs(); device::DeviceManager::getInstance().collateAllDapSpecs();
device::DeviceManager::getInstance().parseAllDapSpecs(); device::DeviceManager::getInstance().parseAllDapSpecs();
@@ -23,7 +23,7 @@ void shutdownSalmanoff(void)
{ {
std::cout << __func__ << ": Entered." << std::endl; std::cout << __func__ << ": Entered." << std::endl;
device::DeviceManager::getInstance().finalize(); device::DeviceManager::getInstance().finalize();
sense_api::SenseApiManager::getInstance().finalize(); stim_buff::StimBuffApiManager::getInstance().finalize();
mind::MindManager::getInstance().finalize(); mind::MindManager::getInstance().finalize();
} }
+1 -1
View File
@@ -7,7 +7,7 @@
#include <componentThread.h> #include <componentThread.h>
#include <director/director.h> #include <director/director.h>
#include <simulator/simulator.h> #include <simulator/simulator.h>
#include <senseApis/senseApiManager.h> #include <stimBuffApis/stimBuffApiManager.h>
#include <marionette/marionette.h> #include <marionette/marionette.h>
namespace smo { namespace smo {
+2 -2
View File
@@ -129,12 +129,12 @@ std::string OptionParser::stringifyOptions(void) const
} }
oss << std::endl; oss << std::endl;
oss << "Sense API Library Paths: "; oss << "Stim Buff API Library Paths: ";
for (const auto& path : senseApiLibPath) { for (const auto& path : senseApiLibPath) {
oss << path << " "; oss << path << " ";
} }
oss << std::endl; oss << std::endl;
oss << "Sense API Libraries: "; oss << "Stim Buff API Libraries: ";
for (const auto& lib : senseApiLibs) { for (const auto& lib : senseApiLibs) {
oss << lib << " "; oss << lib << " ";
} }
@@ -2,8 +2,8 @@
#include <stdexcept> #include <stdexcept>
#include <optional> #include <optional>
#include <filesystem> #include <filesystem>
#include <senseApis/senseApiManager.h> #include <stimBuffApis/stimBuffApiManager.h>
#include <senseApis/senseApiLib.h> #include <stimBuffApis/stimBuffApiLib.h>
#include <opts.h> #include <opts.h>
#include <asynchronousBridge.h> #include <asynchronousBridge.h>
#include <asynchronousContinuation.h> #include <asynchronousContinuation.h>
@@ -18,7 +18,7 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
namespace smo { namespace smo {
namespace sense_api { namespace stim_buff {
/** /**
* @brief Searches for a library in predefined locations * @brief Searches for a library in predefined locations
@@ -45,7 +45,7 @@ static std::optional<std::string> searchForLibInSmoSearchPaths(
const auto& options = OptionParser::getOptions(); const auto& options = OptionParser::getOptions();
if (!options.senseApiLibPath.empty()) if (!options.senseApiLibPath.empty())
{ {
// Insert all sense API library paths at the beginning of search paths // Insert all stim buff API library paths at the beginning of search paths
searchPaths.insert( searchPaths.insert(
searchPaths.begin(), searchPaths.begin(),
options.senseApiLibPath.begin(), options.senseApiLibPath.begin(),
@@ -79,7 +79,7 @@ static std::shared_ptr<ComponentThread> ComponentThread_getSelf()
return ComponentThread::getSelf(); return ComponentThread::getSelf();
} }
/* Hooks to be provided to senseApiLibs, enabling them to call into Salmanoff /* Hooks to be provided to stimBuffApiLibs, enabling them to call into Salmanoff
* code. * code.
*/ */
static SmoCallbacks smoCallbacks = static SmoCallbacks smoCallbacks =
@@ -93,13 +93,13 @@ static SmoThreadingModelDesc smoThreadingModelDesc = {
.componentThread = nullptr .componentThread = nullptr
}; };
std::optional<std::string> SenseApiManager::searchForLibInSmoSearchPaths( std::optional<std::string> StimBuffApiManager::searchForLibInSmoSearchPaths(
const std::string& libraryPath) const std::string& libraryPath)
{ {
return ::smo::sense_api::searchForLibInSmoSearchPaths(libraryPath); return ::smo::stim_buff::searchForLibInSmoSearchPaths(libraryPath);
} }
SenseApiLib& SenseApiManager::loadSenseApiLib( StimBuffApiLib& StimBuffApiManager::loadStimBuffApiLib(
const std::string& libraryPath, const std::string& libraryPath,
const std::shared_ptr<ComponentThread>& componentThread const std::shared_ptr<ComponentThread>& componentThread
) )
@@ -110,7 +110,7 @@ SenseApiLib& SenseApiManager::loadSenseApiLib(
// Clear any existing error // Clear any existing error
dlerror(); dlerror();
auto dlopen_handle = std::unique_ptr<void, SenseApiLib::DlCloser>( auto dlopen_handle = std::unique_ptr<void, StimBuffApiLib::DlCloser>(
dlopen(resolvedPath.c_str(), RTLD_LAZY)); dlopen(resolvedPath.c_str(), RTLD_LAZY));
if (!dlopen_handle && fullPath.has_value()) if (!dlopen_handle && fullPath.has_value())
{ {
@@ -133,13 +133,13 @@ SenseApiLib& SenseApiManager::loadSenseApiLib(
} }
// Initialize getSenseApiDescriptor // Initialize getSenseApiDescriptor
auto func = reinterpret_cast<SMO_GET_SENSE_API_DESC_FN_TYPEDEF *>( auto func = reinterpret_cast<SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF *>(
dlsym(dlopen_handle.get(), SMO_GET_SENSE_API_DESC_FN_NAME_STR)); dlsym(dlopen_handle.get(), SMO_GET_STIM_BUFF_API_DESC_FN_NAME_STR));
if (!func) if (!func)
{ {
throw std::runtime_error( throw std::runtime_error(
std::string(__func__) + ": dlsym('" std::string(__func__) + ": dlsym('"
SMO_GET_SENSE_API_DESC_FN_NAME_STR "') failed for library '" SMO_GET_STIM_BUFF_API_DESC_FN_NAME_STR "') failed for library '"
+ libraryPath + "'"); + libraryPath + "'");
} }
@@ -148,53 +148,53 @@ SenseApiLib& SenseApiManager::loadSenseApiLib(
smoThreadingModelDesc.componentThread = componentThread; smoThreadingModelDesc.componentThread = componentThread;
} }
const SenseApiDesc &libApiDesc = func( const StimBuffApiDesc &libApiDesc = func(
smoCallbacks, smoThreadingModelDesc); smoCallbacks, smoThreadingModelDesc);
auto lib = std::make_shared<SenseApiLib>( auto lib = std::make_shared<StimBuffApiLib>(
libraryPath, dlopen_handle.release(), func); libraryPath, dlopen_handle.release(), func);
lib->setSenseApiDesc(libApiDesc); lib->setStimBuffApiDesc(libApiDesc);
senseApiLibs.push_back(lib); stimBuffApiLibs.push_back(lib);
return *senseApiLibs.back(); return *stimBuffApiLibs.back();
} }
std::optional<std::shared_ptr<SenseApiLib>> std::optional<std::shared_ptr<StimBuffApiLib>>
SenseApiManager::getSenseApiLib(const std::string& libraryPath) StimBuffApiManager::getStimBuffApiLib(const std::string& libraryPath)
{ {
auto it = std::find_if(senseApiLibs.begin(), senseApiLibs.end(), auto it = std::find_if(stimBuffApiLibs.begin(), stimBuffApiLibs.end(),
[&libPath = libraryPath](const std::shared_ptr<SenseApiLib>& lib) { [&libPath = libraryPath](const std::shared_ptr<StimBuffApiLib>& lib) {
return lib->libraryPath == libPath; return lib->libraryPath == libPath;
} }
); );
if (it != senseApiLibs.end()) { return *it; } if (it != stimBuffApiLibs.end()) { return *it; }
return std::nullopt; return std::nullopt;
} }
std::optional<std::shared_ptr<SenseApiLib>> std::optional<std::shared_ptr<StimBuffApiLib>>
SenseApiManager::getSenseApiLibByApiName(const std::string& apiName) StimBuffApiManager::getStimBuffApiLibByApiName(const std::string& apiName)
{ {
auto it = std::find_if(senseApiLibs.begin(), senseApiLibs.end(), auto it = std::find_if(stimBuffApiLibs.begin(), stimBuffApiLibs.end(),
[&apiName](const std::shared_ptr<SenseApiLib>& lib) { [&apiName](const std::shared_ptr<StimBuffApiLib>& lib) {
return lib->senseApiDesc.name == apiName; return lib->stimBuffApiDesc.name == apiName;
} }
); );
if (it != senseApiLibs.end()) { return *it; } if (it != stimBuffApiLibs.end()) { return *it; }
return std::nullopt; return std::nullopt;
} }
void SenseApiManager::unloadSenseApiLib(const std::string& libraryPath) void StimBuffApiManager::unloadStimBuffApiLib(const std::string& libraryPath)
{ {
auto it = std::find_if(senseApiLibs.begin(), senseApiLibs.end(), auto it = std::find_if(stimBuffApiLibs.begin(), stimBuffApiLibs.end(),
[&lpath = libraryPath](const std::shared_ptr<SenseApiLib>& lib) { [&lpath = libraryPath](const std::shared_ptr<StimBuffApiLib>& lib) {
return lib->libraryPath == lpath; return lib->libraryPath == lpath;
} }
); );
if (it != senseApiLibs.end()) if (it != stimBuffApiLibs.end())
{ {
senseApiLibs.erase(it); stimBuffApiLibs.erase(it);
return; return;
} }
@@ -202,75 +202,75 @@ void SenseApiManager::unloadSenseApiLib(const std::string& libraryPath)
<< libraryPath << '\n'; << libraryPath << '\n';
} }
void SenseApiManager::unloadAllSenseApiLibs(void) void StimBuffApiManager::unloadAllStimBuffApiLibs(void)
{ {
senseApiLibs.clear(); stimBuffApiLibs.clear();
} }
void SenseApiManager::loadAllSenseApiLibsFromOptions( void StimBuffApiManager::loadAllStimBuffApiLibsFromOptions(
const std::shared_ptr<ComponentThread>& componentThread const std::shared_ptr<ComponentThread>& componentThread
) )
{ {
const auto& options = OptionParser::getOptions(); const auto& options = OptionParser::getOptions();
for (const auto& libPath : options.senseApiLibs) { for (const auto& libPath : options.senseApiLibs) {
loadSenseApiLib(libPath, componentThread); loadStimBuffApiLib(libPath, componentThread);
} }
} }
std::string SenseApiManager::stringifyLibs() const std::string StimBuffApiManager::stringifyLibs() const
{ {
std::string result; std::string result;
for (const auto& lib : senseApiLibs) { for (const auto& lib : stimBuffApiLibs) {
result += lib->stringify() + "\n"; result += lib->stringify() + "\n";
} }
return result; return result;
} }
void SenseApiManager::initializeSenseApiLib(SenseApiLib& lib) void StimBuffApiManager::initializeStimBuffApiLib(StimBuffApiLib& lib)
{ {
/** FIXME: /** FIXME:
* When we eventually make this method async, this method should acquire * When we eventually make this method async, this method should acquire
* the SenseApiManager's main CRUD qutex. * the StimBuffApiManager's main CRUD qutex.
*/ */
if (!lib.senseApiDesc.sal_mgmt_libOps.initializeInd) if (!lib.stimBuffApiDesc.sal_mgmt_libOps.initializeInd)
{ {
throw std::runtime_error( throw std::runtime_error(
std::string(__func__) + ": initializeInd() is NULL for library '" std::string(__func__) + ": initializeInd() is NULL for library '"
+ lib.libraryPath + "'"); + lib.libraryPath + "'");
} }
lib.senseApiDesc.sal_mgmt_libOps.initializeInd(); lib.stimBuffApiDesc.sal_mgmt_libOps.initializeInd();
} }
void SenseApiManager::finalizeSenseApiLib(SenseApiLib& lib) void StimBuffApiManager::finalizeStimBuffApiLib(StimBuffApiLib& lib)
{ {
/** FIXME: /** FIXME:
* When we eventually make this method async, this flag should only be set * When we eventually make this method async, this flag should only be set
* after acquiring the SenseApiManager's main CRUD qutex. * after acquiring the StimBuffApiManager's main CRUD qutex.
*/ */
lib.isBeingDestroyed.store(true); lib.isBeingDestroyed.store(true);
if (!lib.senseApiDesc.sal_mgmt_libOps.finalizeInd) if (!lib.stimBuffApiDesc.sal_mgmt_libOps.finalizeInd)
{ {
throw std::runtime_error( throw std::runtime_error(
std::string(__func__) + ": finalizeInd() is NULL for library '" std::string(__func__) + ": finalizeInd() is NULL for library '"
+ lib.libraryPath + "'"); + lib.libraryPath + "'");
} }
lib.senseApiDesc.sal_mgmt_libOps.finalizeInd(); lib.stimBuffApiDesc.sal_mgmt_libOps.finalizeInd();
} }
void SenseApiManager::initializeAllSenseApiLibs(void) void StimBuffApiManager::initializeAllStimBuffApiLibs(void)
{ {
for (auto& lib : senseApiLibs) { for (auto& lib : stimBuffApiLibs) {
initializeSenseApiLib(*lib); initializeStimBuffApiLib(*lib);
} }
} }
void SenseApiManager::finalizeAllSenseApiLibs(void) void StimBuffApiManager::finalizeAllStimBuffApiLibs(void)
{ {
for (auto& lib : senseApiLibs) { for (auto& lib : stimBuffApiLibs) {
finalizeSenseApiLib(*lib); finalizeStimBuffApiLib(*lib);
} }
} }
} // namespace sense_api } // namespace stim_buff
} // namespace smo } // namespace smo
@@ -1,14 +1,15 @@
cmake_dependent_option(ENABLE_SENSEAPI_livoxGen1 cmake_dependent_option(ENABLE_STIMBUFFAPI_livoxGen1
"Enable Livox Gen1 LiDAR sense API" ON "Enable Livox Gen1 LiDAR stim buff API" ON
"ENABLE_LIB_livoxProto1" OFF) "ENABLE_LIB_livoxProto1" OFF)
if(ENABLE_SENSEAPI_livoxGen1) if(ENABLE_STIMBUFFAPI_livoxGen1)
# Set CONFIG variable for config.h
set(CONFIG_STIMBUFFAPI_LIVOXGEN1_ENABLED 1)
add_library(livoxGen1 SHARED add_library(livoxGen1 SHARED
livoxGen1.cpp livoxGen1.cpp
) )
# Set config define for header generation
add_compile_definitions(CONFIG_SENSEAPI_LIVOXGEN1_ENABLED)
target_include_directories(livoxGen1 PUBLIC target_include_directories(livoxGen1 PUBLIC
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/commonLibs ${CMAKE_SOURCE_DIR}/commonLibs
@@ -16,9 +16,9 @@
namespace smo { namespace smo {
namespace sense_api { namespace stim_buff {
// Salmanoff hooks, obtained from SMO_GET_SENSE_API_DESC_FN_NAME(). // Salmanoff hooks, obtained from SMO_GET_STIM_BUFF_API_DESC_FN_NAME().
static const SmoCallbacks* smoHooksPtr = nullptr; static const SmoCallbacks* smoHooksPtr = nullptr;
static SmoThreadingModelDesc smoThreadingModelDesc; static SmoThreadingModelDesc smoThreadingModelDesc;
@@ -157,8 +157,8 @@ extern "C" sal_mlo_finalizeIndFn livoxGen1_finalizeInd;
extern "C" sal_mlo_attachDeviceReqFn livoxGen1_attachDeviceReq; extern "C" sal_mlo_attachDeviceReqFn livoxGen1_attachDeviceReq;
extern "C" sal_mlo_detachDeviceReqFn livoxGen1_detachDeviceReq; extern "C" sal_mlo_detachDeviceReqFn livoxGen1_detachDeviceReq;
// Sense API descriptor // Stim Buff API descriptor
static const SenseApiDesc livoxGen1ApiDesc = { static const StimBuffApiDesc livoxGen1ApiDesc = {
.name = "livoxGen1", .name = "livoxGen1",
.exportedQualeIfaceApis = { .exportedQualeIfaceApis = {
{.name = "pcloud"}, {.name = "pcloud"},
@@ -253,7 +253,7 @@ extern "C" int livoxGen1_finalizeInd(void)
extern "C" void livoxGen1_attachDeviceReq( extern "C" void livoxGen1_attachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc, const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
const std::shared_ptr<smo::ComponentThread>& componentThread, const std::shared_ptr<smo::ComponentThread>& componentThread,
Callback<smo::sense_api::sal_mlo_attachDeviceReqCbFn> cb Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
) )
{ {
if (!livoxProto1.livoxProto1_getOrCreateDeviceReq) if (!livoxProto1.livoxProto1_getOrCreateDeviceReq)
@@ -360,7 +360,7 @@ extern "C" void livoxGen1_attachDeviceReq(
extern "C" void livoxGen1_detachDeviceReq( extern "C" void livoxGen1_detachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc, const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
Callback<smo::sense_api::sal_mlo_detachDeviceReqCbFn> cb Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
) )
{ {
// Find and remove the device from our collection // Find and remove the device from our collection
@@ -399,12 +399,12 @@ extern "C" void livoxGen1_detachDeviceReq(
} }
// Exported function // Exported function
extern "C" smo::sense_api::SMO_GET_SENSE_API_DESC_FN_TYPEDEF extern "C" smo::stim_buff::SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF
SMO_GET_SENSE_API_DESC_FN_NAME; SMO_GET_STIM_BUFF_API_DESC_FN_NAME;
const smo::sense_api::SenseApiDesc& SMO_GET_SENSE_API_DESC_FN_NAME( const smo::stim_buff::StimBuffApiDesc& SMO_GET_STIM_BUFF_API_DESC_FN_NAME(
const smo::sense_api::SmoCallbacks& callbacks, const smo::stim_buff::SmoCallbacks& callbacks,
const smo::sense_api::SmoThreadingModelDesc& threadingModel) const smo::stim_buff::SmoThreadingModelDesc& threadingModel)
{ {
smoHooksPtr = &callbacks; smoHooksPtr = &callbacks;
smoThreadingModelDesc = threadingModel; smoThreadingModelDesc = threadingModel;
@@ -412,5 +412,5 @@ const smo::sense_api::SenseApiDesc& SMO_GET_SENSE_API_DESC_FN_NAME(
return livoxGen1ApiDesc; return livoxGen1ApiDesc;
} }
} // namespace sense_api } // namespace stim_buff
} // namespace smo } // namespace smo
@@ -1,9 +1,12 @@
# XCB/Xorg Window Attaching SenseAPI backend # XCB/Xorg Window Attaching StimBuffAPI backend
cmake_dependent_option(ENABLE_SENSEAPI_xcbWindow cmake_dependent_option(ENABLE_STIMBUFFAPI_xcbWindow
"Enable XCB/Xorg Window Attaching SenseAPI backend" ON "Enable XCB/Xorg Window Attaching StimBuffAPI backend" ON
"ENABLE_LIB_xcbXorg" OFF) "ENABLE_LIB_xcbXorg" OFF)
if(ENABLE_SENSEAPI_xcbWindow) if(ENABLE_STIMBUFFAPI_xcbWindow)
# Set CONFIG variable for config.h
set(CONFIG_STIMBUFFAPI_XCBWINDOW_ENABLED 1)
add_library(xcbWindow SHARED add_library(xcbWindow SHARED
xcbWindow.cpp xcbWindow.cpp
) )
@@ -19,9 +22,6 @@ if(ENABLE_SENSEAPI_xcbWindow)
pkg_check_modules(XCB REQUIRED xcb) pkg_check_modules(XCB REQUIRED xcb)
target_link_libraries(xcbWindow ${XCB_LIBRARIES}) target_link_libraries(xcbWindow ${XCB_LIBRARIES})
# Set config define for header generation
add_compile_definitions(CONFIG_SENSEAPI_XCBWINDOW_ENABLED)
# Install rules # Install rules
install(TARGETS xcbWindow DESTINATION lib) install(TARGETS xcbWindow DESTINATION lib)
endif() endif()
@@ -28,9 +28,9 @@ struct XcbXorgDllState
static XcbXorgDllState xcbXorg; static XcbXorgDllState xcbXorg;
// Salmanoff hooks, obtained from SMO_GET_SENSE_API_DESC_FN_NAME(). // Salmanoff hooks, obtained from SMO_GET_STIM_BUFF_API_DESC_FN_NAME().
static const smo::sense_api::SmoCallbacks* smoHooksPtr = nullptr; static const smo::stim_buff::SmoCallbacks* smoHooksPtr = nullptr;
static smo::sense_api::SmoThreadingModelDesc smoThreadingModelDesc; static smo::stim_buff::SmoThreadingModelDesc smoThreadingModelDesc;
// Attached windows. // Attached windows.
static std::vector<std::unique_ptr<xcb_window::AttachedWindow>> static std::vector<std::unique_ptr<xcb_window::AttachedWindow>>
@@ -277,7 +277,7 @@ static int xcbWindow_finalizeInd(void)
static void xcbWindow_attachDeviceReq( static void xcbWindow_attachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc, const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
const std::shared_ptr<smo::ComponentThread>& componentThread, const std::shared_ptr<smo::ComponentThread>& componentThread,
smo::Callback<smo::sense_api::sal_mlo_attachDeviceReqCbFn> cb smo::Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
) )
{ {
// Not used yet, but may be used later. // Not used yet, but may be used later.
@@ -302,7 +302,7 @@ static void xcbWindow_attachDeviceReq(
static void xcbWindow_detachDeviceReq( static void xcbWindow_detachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec, const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
smo::Callback<smo::sense_api::sal_mlo_detachDeviceReqCbFn> cb smo::Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
) )
{ {
auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(), auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(),
@@ -328,7 +328,7 @@ static void xcbWindow_detachDeviceReq(
} }
// SenseApi descriptor // SenseApi descriptor
static smo::sense_api::SenseApiDesc xcbWindowApiDesc = { static smo::stim_buff::StimBuffApiDesc xcbWindowApiDesc = {
.name = "xcb", .name = "xcb",
.exportedQualeIfaceApis = { { "visual-qualeiface" } }, .exportedQualeIfaceApis = { { "visual-qualeiface" } },
.sal_mgmt_libOps = { .sal_mgmt_libOps = {
@@ -340,12 +340,12 @@ static smo::sense_api::SenseApiDesc xcbWindowApiDesc = {
}; };
// Exported function // Exported function
extern "C" smo::sense_api::SMO_GET_SENSE_API_DESC_FN_TYPEDEF extern "C" smo::stim_buff::SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF
SMO_GET_SENSE_API_DESC_FN_NAME; SMO_GET_STIM_BUFF_API_DESC_FN_NAME;
const smo::sense_api::SenseApiDesc& SMO_GET_SENSE_API_DESC_FN_NAME( const smo::stim_buff::StimBuffApiDesc& SMO_GET_STIM_BUFF_API_DESC_FN_NAME(
const smo::sense_api::SmoCallbacks& callbacks, const smo::stim_buff::SmoCallbacks& callbacks,
const smo::sense_api::SmoThreadingModelDesc& threadingModel) const smo::stim_buff::SmoThreadingModelDesc& threadingModel)
{ {
smoHooksPtr = &callbacks; smoHooksPtr = &callbacks;
smoThreadingModelDesc = threadingModel; smoThreadingModelDesc = threadingModel;