2025-07-28 07:20:44 -04:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <deviceManager/deviceManager.h>
|
|
|
|
|
#include <senseApis/senseApiManager.h>
|
2025-09-10 18:12:08 -04:00
|
|
|
#include <asynchronousContinuation.h>
|
|
|
|
|
#include <salmanoff.h>
|
|
|
|
|
|
2025-07-28 07:20:44 -04:00
|
|
|
|
|
|
|
|
namespace smo {
|
|
|
|
|
|
2025-09-10 18:12:08 -04:00
|
|
|
class InitializeSalmanoffReq
|
|
|
|
|
: public AsynchronousContinuation<initializeSalmanoffCbFn>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
InitializeSalmanoffReq(initializeSalmanoffCbFn cb)
|
|
|
|
|
: AsynchronousContinuation(std::move(cb))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
// Callback methods for the initialization sequence
|
|
|
|
|
void initializeSalmanoffReq1(
|
|
|
|
|
std::shared_ptr<InitializeSalmanoffReq> context,
|
|
|
|
|
smo::AsynchronousLoop &results
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
std::cout << __func__ << ": Done. " << results.nSucceeded
|
|
|
|
|
<< " succeeded, " << results.nFailed << " failed." << std::endl;
|
|
|
|
|
context->originalCbFn(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void initializeSalmanoff(
|
|
|
|
|
initializeSalmanoffCbFn callback)
|
2025-07-28 07:20:44 -04:00
|
|
|
{
|
|
|
|
|
std::cout << __func__ << ": Entered." << std::endl;
|
|
|
|
|
|
2025-09-10 18:12:08 -04:00
|
|
|
std::shared_ptr<ComponentThread> mrntt = ComponentThread::getMrntt();
|
|
|
|
|
auto request = std::make_shared<InitializeSalmanoffReq>(
|
|
|
|
|
std::move(callback));
|
|
|
|
|
|
2025-08-29 16:12:30 -04:00
|
|
|
device::DeviceManager::getInstance().collateAllDapSpecs();
|
|
|
|
|
device::DeviceManager::getInstance().parseAllDapSpecs();
|
2025-07-28 07:20:44 -04:00
|
|
|
std::cout << device::DeviceManager::stringifyDeviceSpecs() << std::endl;
|
2025-09-10 18:12:08 -04:00
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
*
|
|
|
|
|
* Right now we use Marionette, but there's a strong argument for using
|
|
|
|
|
* Body instead since it's meant to handle device-management operations.
|
|
|
|
|
*/
|
2025-09-04 17:47:00 -04:00
|
|
|
sense_api::SenseApiManager::getInstance().loadAllSenseApiLibsFromOptions(
|
2025-09-10 18:12:08 -04:00
|
|
|
mrntt);
|
|
|
|
|
|
2025-07-28 07:20:44 -04:00
|
|
|
std::cout << sense_api::SenseApiManager::getInstance().stringifyLibs()
|
|
|
|
|
<< std::endl;
|
2025-09-10 18:12:08 -04:00
|
|
|
|
|
|
|
|
if (OptionParser::getOptions().verbose) {
|
|
|
|
|
std::cout << __func__ << ": About to initializeAllSenseApiLibs" << '\n';
|
|
|
|
|
}
|
2025-07-28 07:20:44 -04:00
|
|
|
sense_api::SenseApiManager::getInstance().initializeAllSenseApiLibs();
|
|
|
|
|
|
2025-09-10 18:12:08 -04:00
|
|
|
if (OptionParser::getOptions().verbose) {
|
|
|
|
|
std::cout << __func__ << ": About to attachAllSenseDevicesFromSpecs" << '\n';
|
|
|
|
|
}
|
|
|
|
|
sense_api::SenseApiManager::getInstance().attachAllSenseDevicesFromSpecsReq(
|
|
|
|
|
std::bind(
|
|
|
|
|
&InitializeSalmanoffReq::initializeSalmanoffReq1,
|
|
|
|
|
request.get(), request,
|
|
|
|
|
std::placeholders::_1));
|
2025-07-28 07:20:44 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-10 18:12:08 -04:00
|
|
|
class ShutdownSalmanoffReq
|
|
|
|
|
: public InitializeSalmanoffReq
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using InitializeSalmanoffReq::InitializeSalmanoffReq;
|
|
|
|
|
|
|
|
|
|
// Callback methods for the shutdown sequence
|
|
|
|
|
void shutdownSalmanoffReq1(
|
|
|
|
|
std::shared_ptr<ShutdownSalmanoffReq> context,
|
|
|
|
|
smo::AsynchronousLoop &results
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
sense_api::SenseApiManager::getInstance().finalizeAllSenseApiLibs();
|
|
|
|
|
std::cout << __func__ << ": Done. " << results.nSucceeded
|
|
|
|
|
<< " succeeded, " << results.nFailed << " failed." << std::endl;
|
|
|
|
|
context->originalCbFn(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void shutdownSalmanoff(shutdownSalmanoffCbFn callback)
|
2025-07-30 10:07:52 -04:00
|
|
|
{
|
|
|
|
|
std::cout << __func__ << ": Entered." << std::endl;
|
|
|
|
|
|
2025-09-10 18:12:08 -04:00
|
|
|
// Create the shutdown request object to hold state and callbacks
|
|
|
|
|
auto request = std::make_shared<ShutdownSalmanoffReq>(std::move(callback));
|
2025-07-30 10:07:52 -04:00
|
|
|
|
2025-09-10 18:12:08 -04:00
|
|
|
sense_api::SenseApiManager::getInstance().detachAllSenseDevicesReq(
|
|
|
|
|
std::bind(
|
|
|
|
|
&ShutdownSalmanoffReq::shutdownSalmanoffReq1,
|
|
|
|
|
request.get(), request,
|
|
|
|
|
std::placeholders::_1));
|
2025-07-30 10:07:52 -04:00
|
|
|
}
|
|
|
|
|
|
2025-07-28 07:20:44 -04:00
|
|
|
} // namespace smo
|