decouple freeing shared and model objects from the synth with PlugInCmd

This should give much stronger guarantees that the server and client 
agree about what exists. It would be neat if the server could delete its 
own node as well, but I haven't worked out how to do this yet
nix
Owen Green 6 years ago
parent 188f0f9133
commit 3777057995

@ -586,13 +586,16 @@ struct LifetimePolicy<Client, Wrapper,std::true_type, std::false_type>
static void setup(InterfaceTable* ft, const char* name) static void setup(InterfaceTable* ft, const char* name)
{ {
ft->fDefineUnitCmd(name, "free", [](Unit* unit, sc_msg_iter*) auto freeName = std::stringstream();
freeName << "free" << name;
ft->fDefinePlugInCmd(freeName.str().c_str(),
[](World*,void*,sc_msg_iter* args, void*/*replyAddr*/)
{ {
//This ABSOLUTELY ASSUMES the client is going to also delete auto objectID = args->geti();
//the Unit by calling Synth.free. auto pos = mRegistry.find(objectID);
auto wrapper = static_cast<Wrapper*>(unit); if(pos != mRegistry.end()) mRegistry.erase(objectID);
mRegistry.erase(wrapper->uid); }, &mRegistry);
});
} }
private: private:
@ -641,12 +644,19 @@ struct LifetimePolicy<Client, Wrapper,std::false_type, std::true_type>
static void setup(InterfaceTable* ft, const char* name) static void setup(InterfaceTable* ft, const char* name)
{ {
ft->fDefineUnitCmd(name, "free", [](Unit* unit, sc_msg_iter*)
auto freeName = std::stringstream();
freeName << "free" << name;
ft->fDefinePlugInCmd(freeName.str().c_str(),
[](World*,void*,sc_msg_iter* args, void* /*replyAddr*/)
{ {
auto clientRef = getClientPointer(static_cast<Wrapper*>(unit)); auto objectName = std::string(args->gets());
auto clientRef = SharedType::lookup(objectName);
auto pos = mRegistry.find(clientRef); auto pos = mRegistry.find(clientRef);
if(pos != mRegistry.end()) mRegistry.erase(clientRef); if(pos != mRegistry.end()) mRegistry.erase(clientRef);
}); }, &mRegistry);
} }
private: private:
static ClientPointer getClientPointer(Wrapper* wrapper) static ClientPointer getClientPointer(Wrapper* wrapper)

Loading…
Cancel
Save