NRT Wrapper: signal completion via cache

for (hopefully) greater reliability
nix
Owen Green 5 years ago
parent bbe715287e
commit 012ce483c5

@ -35,11 +35,12 @@ namespace impl {
struct CacheEntry struct CacheEntry
{ {
CacheEntry(Params& p):mParams{p},mClient{mParams} CacheEntry(const Params& p):mParams{p},mClient{mParams}
{} {}
Params mParams; Params mParams;
Client mClient; Client mClient;
bool mDone{false};
}; };
using CacheEntryPointer = std::shared_ptr<CacheEntry>; using CacheEntryPointer = std::shared_ptr<CacheEntry>;
@ -59,12 +60,12 @@ namespace impl {
return lookup == mCache.end() ? WeakCacheEntryPointer() : lookup->second; return lookup == mCache.end() ? WeakCacheEntryPointer() : lookup->second;
} }
static WeakCacheEntryPointer add(index id, CacheEntry&& entry) static WeakCacheEntryPointer add(index id, const Params& params)
{ {
if(isNull(get(id))) if(isNull(get(id)))
{ {
auto result = mCache.emplace(id, auto result = mCache.emplace(id,
std::make_shared<CacheEntry>(std::move(entry))); std::make_shared<CacheEntry>(params));
return result.second ? (result.first)->second : WeakCacheEntryPointer(); //sob return result.second ? (result.first)->second : WeakCacheEntryPointer(); //sob
} }
@ -175,7 +176,7 @@ namespace impl {
bool stage2(World*) bool stage2(World*)
{ {
// auto entry = ; // auto entry = ;
mResult = (!isNull(add(NRTCommand::mID, CacheEntry{mParams}))); mResult = (!isNull(add(NRTCommand::mID, mParams)));
//Sigh. The cache entry above has both the client instance and main params instance. //Sigh. The cache entry above has both the client instance and main params instance.
// The client is linked to the params by reference; I've not got the in-place constrction // The client is linked to the params by reference; I've not got the in-place constrction
@ -267,6 +268,7 @@ namespace impl {
std::cout << Wrapper::getName() std::cout << Wrapper::getName()
<< ": Processing cancelled" << ": Processing cancelled"
<< std::endl; << std::endl;
ptr->mDone = true;
return false; return false;
} }
@ -275,8 +277,13 @@ namespace impl {
if (!r.ok()) if (!r.ok())
{ {
Wrapper::printResult(world,r); Wrapper::printResult(world,r);
if(r.status() == Result::Status::kError) return false; if(r.status() == Result::Status::kError)
{
ptr->mDone = true;
return false;
}
} }
return true; return true;
} }
} }
@ -304,7 +311,7 @@ namespace impl {
{ {
NRTCommand::sendReply(name(),mSuccess); NRTCommand::sendReply(name(),mSuccess);
} }
ptr->mDone = true;
return true; return true;
} }
return false; return false;
@ -367,6 +374,7 @@ namespace impl {
if(auto ptr = get(NRTCommand::mID).lock()) if(auto ptr = get(NRTCommand::mID).lock())
{ {
ptr->mDone = false;
ptr->mParams.template setParameterValuesRT<ParamsFromOSC>(nullptr, world, ar); ptr->mParams.template setParameterValuesRT<ParamsFromOSC>(nullptr, world, ar);
mSynchronous = static_cast<bool>(ar.geti()); mSynchronous = static_cast<bool>(ar.geti());
} //if this fails, we'll hear about it in stage2 anyway } //if this fails, we'll hear about it in stage2 anyway
@ -417,7 +425,11 @@ namespace impl {
{ {
mResult = client.process(); mResult = client.process();
Wrapper::printResult(world,mResult); Wrapper::printResult(world,mResult);
return mSynchronous && mResult.ok();
bool error =mResult.status() == Result::Status::kError;
if(error) ptr->mDone = true;
return mSynchronous && !error;
} }
} }
} }
@ -451,7 +463,7 @@ namespace impl {
if(NRTCommand::mID >= 0 && mSynchronous) if(NRTCommand::mID >= 0 && mSynchronous)
NRTCommand::sendReply(name(), mResult.ok()); NRTCommand::sendReply(name(), mResult.ok());
ptr->mDone = true;
return true; return true;
} }
return false; return false;
@ -752,7 +764,6 @@ namespace impl {
if(trigger) if(trigger)
{ {
mDone = 0; mDone = 0;
client.resetDone();
mControlsIterator.reset(1 + mInBuf); //add one for ID mControlsIterator.reset(1 + mInBuf); //add one for ID
auto& params = ptr->mParams; auto& params = ptr->mParams;
Wrapper::setParams(this,params,mControlsIterator,true,false); Wrapper::setParams(this,params,mControlsIterator,true,false);
@ -763,7 +774,7 @@ namespace impl {
} }
else else
{ {
mDone = mRunCount && client.done() ; mDone = ptr->mDone;
out0(0) = mDone ? 1 : static_cast<float>(client.progress()); out0(0) = mDone ? 1 : static_cast<float>(client.progress());
} }
} }

Loading…
Cancel
Save