Libspinscale: Initial top-level SMO port to coroutine framework
We haven't ported everything. Just the top-level methods. We'll dig in to the leaf stuff later. Surprisingly, this all went without any real difficulties. Runs like a charm on first try.
This commit is contained in:
@@ -5,10 +5,6 @@
|
||||
#include <stimBuffApis/stimBuffApiManager.h>
|
||||
#include <stimBuffApis/stimBuffApiLib.h>
|
||||
#include <opts.h>
|
||||
#include <spinscale/asynchronousBridge.h>
|
||||
#include <spinscale/asynchronousContinuation.h>
|
||||
#include <spinscale/asynchronousLoop.h>
|
||||
#include <spinscale/callback.h>
|
||||
#include <user/senseApiDesc.h>
|
||||
#include <mind.h>
|
||||
#include <deviceManager/deviceManager.h>
|
||||
@@ -198,47 +194,50 @@ StimBuffApiLib& StimBuffApiManager::loadStimBuffApiLib(
|
||||
auto lib = std::make_shared<StimBuffApiLib>(
|
||||
libraryPath, dlopen_handle.release(), func);
|
||||
lib->setStimBuffApiDesc(libApiDesc);
|
||||
stimBuffApiLibs.push_back(lib);
|
||||
return *stimBuffApiLibs.back();
|
||||
getInstance().s.rsrc.stimBuffApiLibs.push_back(lib);
|
||||
return *getInstance().s.rsrc.stimBuffApiLibs.back();
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<StimBuffApiLib>>
|
||||
StimBuffApiManager::getStimBuffApiLib(const std::string& libraryPath)
|
||||
{
|
||||
auto it = std::find_if(stimBuffApiLibs.begin(), stimBuffApiLibs.end(),
|
||||
auto &libs = getInstance().s.rsrc.stimBuffApiLibs;
|
||||
auto it = std::find_if(libs.begin(), libs.end(),
|
||||
[&libPath = libraryPath](const std::shared_ptr<StimBuffApiLib>& lib) {
|
||||
return lib->libraryPath == libPath;
|
||||
}
|
||||
);
|
||||
|
||||
if (it != stimBuffApiLibs.end()) { return *it; }
|
||||
if (it != libs.end()) { return *it; }
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<StimBuffApiLib>>
|
||||
StimBuffApiManager::getStimBuffApiLibByApiName(const std::string& apiName)
|
||||
{
|
||||
auto it = std::find_if(stimBuffApiLibs.begin(), stimBuffApiLibs.end(),
|
||||
auto &libs = getInstance().s.rsrc.stimBuffApiLibs;
|
||||
auto it = std::find_if(libs.begin(), libs.end(),
|
||||
[&apiName](const std::shared_ptr<StimBuffApiLib>& lib) {
|
||||
return lib->stimBuffApiDesc.name == apiName;
|
||||
}
|
||||
);
|
||||
|
||||
if (it != stimBuffApiLibs.end()) { return *it; }
|
||||
if (it != libs.end()) { return *it; }
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void StimBuffApiManager::unloadStimBuffApiLib(const std::string& libraryPath)
|
||||
{
|
||||
auto it = std::find_if(stimBuffApiLibs.begin(), stimBuffApiLibs.end(),
|
||||
auto &libs = getInstance().s.rsrc.stimBuffApiLibs;
|
||||
auto it = std::find_if(libs.begin(), libs.end(),
|
||||
[&lpath = libraryPath](const std::shared_ptr<StimBuffApiLib>& lib) {
|
||||
return lib->libraryPath == lpath;
|
||||
}
|
||||
);
|
||||
|
||||
if (it != stimBuffApiLibs.end())
|
||||
if (it != libs.end())
|
||||
{
|
||||
stimBuffApiLibs.erase(it);
|
||||
libs.erase(it);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -248,7 +247,7 @@ void StimBuffApiManager::unloadStimBuffApiLib(const std::string& libraryPath)
|
||||
|
||||
void StimBuffApiManager::unloadAllStimBuffApiLibs(void)
|
||||
{
|
||||
stimBuffApiLibs.clear();
|
||||
getInstance().s.rsrc.stimBuffApiLibs.clear();
|
||||
}
|
||||
|
||||
void StimBuffApiManager::loadAllStimBuffApiLibsFromOptions(
|
||||
@@ -264,7 +263,7 @@ void StimBuffApiManager::loadAllStimBuffApiLibsFromOptions(
|
||||
std::string StimBuffApiManager::stringifyLibs() const
|
||||
{
|
||||
std::string result;
|
||||
for (const auto& lib : stimBuffApiLibs) {
|
||||
for (const auto& lib : getInstance().s.rsrc.stimBuffApiLibs) {
|
||||
result += lib->stringify() + "\n";
|
||||
}
|
||||
return result;
|
||||
@@ -303,14 +302,14 @@ void StimBuffApiManager::finalizeStimBuffApiLib(StimBuffApiLib& lib)
|
||||
|
||||
void StimBuffApiManager::initializeAllStimBuffApiLibs(void)
|
||||
{
|
||||
for (auto& lib : stimBuffApiLibs) {
|
||||
for (auto& lib : getInstance().s.rsrc.stimBuffApiLibs) {
|
||||
initializeStimBuffApiLib(*lib);
|
||||
}
|
||||
}
|
||||
|
||||
void StimBuffApiManager::finalizeAllStimBuffApiLibs(void)
|
||||
{
|
||||
for (auto& lib : stimBuffApiLibs) {
|
||||
for (auto& lib : getInstance().s.rsrc.stimBuffApiLibs) {
|
||||
finalizeStimBuffApiLib(*lib);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user