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
+59 -56
View File
@@ -12,7 +12,7 @@
#include <componentThread.h>
#include <deviceManager/deviceManager.h>
#include <deviceManager/deviceReattacher.h>
#include <senseApis/senseApiManager.h>
#include <stimBuffApis/stimBuffApiManager.h>
#include <marionette/marionette.h>
#include <mind.h>
@@ -132,7 +132,7 @@ public:
return;
}
DeviceManager::getInstance().attachSenseDeviceReq(
DeviceManager::getInstance().attachStimBuffDeviceReq(
specPtr,
{context, std::bind(
&NewDeviceAttachmentSpecInd::newDeviceAttachmentSpecInd2,
@@ -209,8 +209,8 @@ public:
return;
}
// Call detachSenseDeviceReq first - only clean up metadata if this succeeds
DeviceManager::getInstance().detachSenseDeviceReq(
// Call detachStimBuffDeviceReq first - only clean up metadata if this succeeds
DeviceManager::getInstance().detachStimBuffDeviceReq(
specPtr,
{context, std::bind(
&RemoveDeviceAttachmentSpecReq::removeDeviceAttachmentSpecReq2,
@@ -329,24 +329,25 @@ void DeviceManager::removeDeviceAttachmentSpecReq(
request.get(), request));
}
class DeviceManager::AttachSenseDeviceReq
: public SerializedAsynchronousContinuation<attachSenseDeviceReqCbFn>
class DeviceManager::AttachStimBuffDeviceReq
: public SerializedAsynchronousContinuation<
DeviceManager::attachStimBuffDeviceReqCbFn>
{
public:
AttachSenseDeviceReq(
AttachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec,
const std::shared_ptr<ComponentThread> &caller,
Callback<attachSenseDeviceReqCbFn> cb,
std::shared_ptr<sense_api::SenseApiLib> &senseApiLib,
Callback<DeviceManager::attachStimBuffDeviceReqCbFn> cb,
std::shared_ptr<stim_buff::StimBuffApiLib> &stimBuffApiLib,
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
: SerializedAsynchronousContinuation<attachSenseDeviceReqCbFn>(
: SerializedAsynchronousContinuation<attachStimBuffDeviceReqCbFn>(
caller, cb, requiredLocks),
spec(spec), senseApiLib(senseApiLib)
spec(spec), stimBuffApiLib(stimBuffApiLib)
{}
public:
void attachSenseDeviceReq1_posted(
[[maybe_unused]] std::shared_ptr<AttachSenseDeviceReq> context
void attachStimBuffDeviceReq1_posted(
[[maybe_unused]] std::shared_ptr<AttachStimBuffDeviceReq> context
)
{
if (caller->id != ComponentThread::MRNTT)
@@ -358,7 +359,7 @@ public:
return;
}
if (senseApiLib->isBeingDestroyed.load())
if (stimBuffApiLib->isBeingDestroyed.load())
{
std::cerr << std::string(__func__) + ": Library is being destroyed"
<< " for API '" << spec->stimBuffApi << "'. Bailing out.\n";
@@ -366,15 +367,16 @@ public:
return;
}
if (!senseApiLib->senseApiDesc.sal_mgmt_libOps.attachDeviceReq)
if (!stimBuffApiLib->stimBuffApiDesc.sal_mgmt_libOps.attachDeviceReq)
{
std::cerr << std::string(__func__) + ": attachDeviceReq() is NULL "
"for library '" << senseApiLib->libraryPath << "'" << std::endl;
"for library '" << stimBuffApiLib->libraryPath << "'"
<< std::endl;
callOriginalCb(false, spec);
return;
}
releaseQutexEarly(sense_api::SenseApiManager::getInstance().qutex);
releaseQutexEarly(stim_buff::StimBuffApiManager::getInstance().qutex);
/** EXPLANATION:
* We pass in either the body or world thread here, depending on whether
@@ -397,16 +399,16 @@ public:
<< spec->deviceIdentifier << " to body thread" << "\n";
}
senseApiLib->senseApiDesc.sal_mgmt_libOps.attachDeviceReq(
stimBuffApiLib->stimBuffApiDesc.sal_mgmt_libOps.attachDeviceReq(
spec, threadForAttachment,
{context, std::bind(
&AttachSenseDeviceReq::attachSenseDeviceReq2,
&AttachStimBuffDeviceReq::attachStimBuffDeviceReq2,
context.get(), context,
std::placeholders::_1, std::placeholders::_2)});
}
void attachSenseDeviceReq2(
[[maybe_unused]] std::shared_ptr<AttachSenseDeviceReq> context,
void attachStimBuffDeviceReq2(
[[maybe_unused]] std::shared_ptr<AttachStimBuffDeviceReq> context,
bool success,
std::shared_ptr<DeviceAttachmentSpec> deviceSpec
)
@@ -414,8 +416,8 @@ public:
callOriginalCb(success, deviceSpec);
}
void detachSenseDeviceReq1_posted(
[[maybe_unused]] std::shared_ptr<DetachSenseDeviceReq> context
void detachStimBuffDeviceReq1_posted(
[[maybe_unused]] std::shared_ptr<AttachStimBuffDeviceReq> context
)
{
if (caller->id != ComponentThread::MRNTT)
@@ -427,7 +429,7 @@ public:
return;
}
if (senseApiLib->isBeingDestroyed.load())
if (stimBuffApiLib->isBeingDestroyed.load())
{
std::cerr << std::string(__func__) + ": Library is being destroyed"
<< " for API '" << spec->stimBuffApi << "'. Bailing out.\n";
@@ -435,26 +437,27 @@ public:
return;
}
if (!senseApiLib->senseApiDesc.sal_mgmt_libOps.detachDeviceReq)
if (!stimBuffApiLib->stimBuffApiDesc.sal_mgmt_libOps.detachDeviceReq)
{
std::cerr << std::string(__func__) + ": detachDeviceReq() is NULL "
"for library '" << senseApiLib->libraryPath << "'" << std::endl;
"for library '" << stimBuffApiLib->libraryPath << "'"
<< std::endl;
callOriginalCb(false, spec);
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,
{context, std::bind(
&DetachSenseDeviceReq::detachSenseDeviceReq2,
&AttachStimBuffDeviceReq::detachStimBuffDeviceReq2,
context.get(), context,
std::placeholders::_1, std::placeholders::_2)});
}
}
void detachSenseDeviceReq2(
[[maybe_unused]] std::shared_ptr<DetachSenseDeviceReq> context,
void detachStimBuffDeviceReq2(
[[maybe_unused]] std::shared_ptr<AttachStimBuffDeviceReq> context,
bool success,
std::shared_ptr<DeviceAttachmentSpec> deviceSpec
)
@@ -464,23 +467,23 @@ public:
public:
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,
Callback<attachSenseDeviceReqCbFn> cb
Callback<attachStimBuffDeviceReqCbFn> cb
)
{
const auto& caller = ComponentThread::getSelf();
// Get the sense API lib's qutex
auto libOpt = sense_api::SenseApiManager::getInstance()
.getSenseApiLibByApiName(spec->stimBuffApi);
// Get the stim buff API lib's qutex
auto libOpt = stim_buff::StimBuffApiManager::getInstance()
.getStimBuffApiLibByApiName(spec->stimBuffApi);
if (!libOpt)
{
std::cerr << "attachSenseDeviceReq: No library found for API '"
std::cerr << "attachStimBuffDeviceReq: No library found for API '"
<< spec->stimBuffApi << "'" << std::endl;
cb.callbackFn(false, spec);
return;
@@ -488,34 +491,34 @@ void DeviceManager::attachSenseDeviceReq(
auto& lib = *libOpt.value();
auto request = std::make_shared<AttachSenseDeviceReq>(
auto request = std::make_shared<AttachStimBuffDeviceReq>(
spec, caller, cb, libOpt.value(),
LockSet<attachSenseDeviceReqCbFn>::Set{
std::ref(sense_api::SenseApiManager::getInstance().qutex),
LockSet<attachStimBuffDeviceReqCbFn>::Set{
std::ref(stim_buff::StimBuffApiManager::getInstance().qutex),
std::ref(lib.qutex)
});
AttachSenseDeviceReq::LockerAndInvoker lockvoker(
AttachStimBuffDeviceReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread,
std::bind(
&AttachSenseDeviceReq::attachSenseDeviceReq1_posted,
&AttachStimBuffDeviceReq::attachStimBuffDeviceReq1_posted,
request.get(), request));
}
void DeviceManager::detachSenseDeviceReq(
void DeviceManager::detachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<detachSenseDeviceReqCbFn> cb
Callback<detachStimBuffDeviceReqCbFn> cb
)
{
const auto& caller = ComponentThread::getSelf();
// Get the sense API lib's qutex
auto libOpt = sense_api::SenseApiManager::getInstance()
.getSenseApiLibByApiName(spec->stimBuffApi);
// Get the stim buff API lib's qutex
auto libOpt = stim_buff::StimBuffApiManager::getInstance()
.getStimBuffApiLibByApiName(spec->stimBuffApi);
if (!libOpt)
{
std::cerr << "detachSenseDeviceReq: No library found for API '"
std::cerr << "detachStimBuffDeviceReq: No library found for API '"
<< spec->stimBuffApi << "'" << std::endl;
cb.callbackFn(false, spec);
return;
@@ -523,17 +526,17 @@ void DeviceManager::detachSenseDeviceReq(
auto& lib = *libOpt.value();
auto request = std::make_shared<DetachSenseDeviceReq>(
auto request = std::make_shared<DetachStimBuffDeviceReq>(
spec, caller, cb, libOpt.value(),
LockSet<detachSenseDeviceReqCbFn>::Set{
std::ref(sense_api::SenseApiManager::getInstance().qutex),
LockSet<detachStimBuffDeviceReqCbFn>::Set{
std::ref(stim_buff::StimBuffApiManager::getInstance().qutex),
std::ref(lib.qutex)
});
DetachSenseDeviceReq::LockerAndInvoker lockvoker(
DetachStimBuffDeviceReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread,
std::bind(
&DetachSenseDeviceReq::detachSenseDeviceReq1_posted,
&DetachStimBuffDeviceReq::detachStimBuffDeviceReq1_posted,
request.get(), request));
}
@@ -746,7 +749,7 @@ public:
{
for (const auto& deviceRole : DeviceManager::attachedDeviceRoles)
{
DeviceManager::getInstance().detachSenseDeviceReq(
DeviceManager::getInstance().detachStimBuffDeviceReq(
deviceRole->deviceAttachmentSpec,
{context, std::bind(
&DetachAllAttachedDeviceRoles::detachAllAttachedDeviceRoles2,