3e19d39853
SenseApiDesc's exported API now uses coro pointers instead of CPS fn pointers. * Do not build this version of SMO with the Livox drivers enabled, because SMO has been changed at the smocore level to use coros when calling into stimbuffAPI libs. But the Livox drivers haven't yet been ported from CPS to coros. xcbWindow has been ported to expose coros to SMO in its senseApiDesc exported iface.
114 lines
3.5 KiB
C++
114 lines
3.5 KiB
C++
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <opts.h>
|
|
#include <body/body.h>
|
|
#include <body/bodyThread.h>
|
|
#include <componentThread.h>
|
|
#include <deviceManager/deviceManager.h>
|
|
#include <mind.h>
|
|
#include <stimBuffApis/stimBuffApiManager.h>
|
|
|
|
namespace smo {
|
|
namespace body {
|
|
|
|
Body::Body(Mind &parent, const std::shared_ptr<sscl::PuppetThread> &thread)
|
|
: MindComponent(static_cast<sscl::PuppetApplication&>(parent), thread)
|
|
{
|
|
}
|
|
|
|
BodyViralPostingInvoker<bool> Body::initializeCReq()
|
|
{
|
|
auto self = sscl::ComponentThread::getSelf();
|
|
if (self->id != SmoThreadId::BODY)
|
|
{
|
|
throw std::runtime_error(std::string(__func__)
|
|
+ ": Must be executed on Body thread");
|
|
}
|
|
|
|
/** EXPLANATION:
|
|
* The ComponentThread instance we pass in here is the one that will be
|
|
* used by Senseapi libs to perform device-independent background
|
|
* operations.
|
|
* For example, liblivoxProto1's BroadcastListener will use this thread
|
|
* to listen for UDP broadcast dgrams from Livox devices.
|
|
*
|
|
* We used to use Marionette, but there's a strong argument for using
|
|
* Body instead since it's meant to handle device-management operations.
|
|
*/
|
|
// Upcast to Mind to access Mind-specific members
|
|
Mind &mind = static_cast<Mind&>(parent);
|
|
stim_buff::StimBuffApiManager::getInstance()
|
|
.loadAllStimBuffApiLibsFromOptions(mind.body.thread);
|
|
|
|
/** EXPLANATION:
|
|
* Consider body::initializeCReq to have been called if even one of its
|
|
* operations was executed at all, whether successfully or
|
|
* unsuccessfully.
|
|
*/
|
|
mind.bodyComponentInitialized = true;
|
|
|
|
std::cout << stim_buff::StimBuffApiManager::getInstance().stringifyLibs()
|
|
<< std::endl;
|
|
|
|
if (OptionParser::getOptions().verbose)
|
|
{
|
|
std::cout << __func__ << ": About to initializeAllStimBuffApiLibs"
|
|
<< '\n';
|
|
}
|
|
co_await stim_buff::StimBuffApiManager::getInstance()
|
|
.initializeAllStimBuffApiLibsCReq();
|
|
|
|
if (OptionParser::getOptions().verbose)
|
|
{
|
|
std::cout << __func__ << ": About to attachAllUnattachedDevicesFromCmdline"
|
|
<< '\n';
|
|
}
|
|
|
|
sscl::MultiOperationResultSet attachResults = co_await
|
|
device::DeviceManager::getInstance()
|
|
.attachAllUnattachedDevicesFromCmdlineCReq();
|
|
std::cout << "Mrntt: attached "
|
|
<< attachResults.nSucceeded << " of " << attachResults.nTotal
|
|
<< " sense devices." << "\n";
|
|
|
|
co_return attachResults.nSucceeded > 0;
|
|
}
|
|
|
|
BodyViralPostingInvoker<bool> Body::finalizeCReq()
|
|
{
|
|
auto self = sscl::ComponentThread::getSelf();
|
|
if (self->id != SmoThreadId::BODY)
|
|
{
|
|
throw std::runtime_error(std::string(__func__)
|
|
+ ": Must be executed on Body thread");
|
|
}
|
|
|
|
// Upcast to Mind to access Mind-specific members
|
|
Mind &mind = static_cast<Mind&>(parent);
|
|
if (!mind.bodyComponentInitialized)
|
|
{
|
|
std::cout << "Mrntt: Body component not initialized. "
|
|
<< "Skipping finalization." << "\n";
|
|
co_return true;
|
|
}
|
|
|
|
std::cout << "Mrntt: About to detach all sense devices." << "\n";
|
|
sscl::MultiOperationResultSet detachResults = co_await
|
|
device::DeviceManager::getInstance().detachAllAttachedDeviceRolesCReq();
|
|
std::cout << "Mrntt: Successfully detached "
|
|
<< detachResults.nSucceeded << " of " << detachResults.nTotal
|
|
<< " sense devices." << "\n";
|
|
|
|
std::cout << "Mrntt: About to finalize all stim buff api libs." << "\n";
|
|
co_await stim_buff::StimBuffApiManager::getInstance()
|
|
.finalizeAllStimBuffApiLibsCReq();
|
|
|
|
std::cout << "Mrntt: About to unload all stim buff api libs." << "\n";
|
|
stim_buff::StimBuffApiManager::getInstance().unloadAllStimBuffApiLibs();
|
|
|
|
co_return detachResults.nSucceeded == detachResults.nTotal;
|
|
}
|
|
|
|
} // namespace body
|
|
} // namespace smo
|