From b58427e49ffc58f2973615680de0f2d7ef1361c9 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 25 Dec 2016 21:46:58 +0100 Subject: [PATCH] Command-Framework: mark anonymous commands It turns out we *do* support the use of anonymous commands (while it is not clear yet if we really need this feature). Basically, client code may either create and register a new instance from another command used as prototype, by invoking Command::storeDef(ID). Or, alternatively it may just invoke newInstance() on the command, which creates a new handle and a valid new implementation (managed by the handle as smart-ptr), but never stores this implementation into the CommandRegistry. In that case, client code may use such a command just fine, as long as it cares to hold onto that handle; but it is not possible to retrieve this command instance later by symbolic ID. In the light of this (possible) usage pattern, it doesn't make sense to throw when accessing a command-ID. Rather, we now return a placeholder-Symbol ("_anonymous_") --- .../control/command-impl-clone-builder.hpp | 17 +++-------- src/proc/control/command.cpp | 30 ++++++++++++------- src/proc/control/command.hpp | 1 + tests/45controller.tests | 2 +- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/proc/control/command-impl-clone-builder.hpp b/src/proc/control/command-impl-clone-builder.hpp index 3f68fdcee..ce18a24a2 100644 --- a/src/proc/control/command-impl-clone-builder.hpp +++ b/src/proc/control/command-impl-clone-builder.hpp @@ -29,10 +29,10 @@ ** command implementation need to be cloned and re-wired with the cloned partners, ** which requires re-creating the specifically typed context used at initial setup. ** - ** Ticket #301 : it may well be that the need for such a facility is a symptom of - ** misaligned design, but I rather doubt so -- because both the memento holder and + ** @todo Ticket #301 : it may well be that the need for such a facility is a symptom + ** of misaligned design, but I rather doubt so -- because both the memento holder and ** the command closure need a specifically typed context, and there is no reason - ** for combining them into a single facility. + ** for combining them into a single facility. ** ** @see CommandRegistry#createCloneImpl ** @see CommandImpl @@ -46,26 +46,17 @@ #ifndef CONTROL_COMMAND_IMPL_CLONE_BUILDER_H #define CONTROL_COMMAND_IMPL_CLONE_BUILDER_H -//#include "proc/control/command.hpp" -//#include "proc/control/command-closure.hpp" #include "proc/control/command-mutation.hpp" #include "lib/typed-allocation-manager.hpp" #include "lib/opaque-holder.hpp" -//#include "lib/bool-checkable.hpp" #include -//#include - -//#include -//#include namespace proc { namespace control { using lib::TypedAllocationManager; -// using std::function; -// using std::shared_ptr; using lib::InPlaceBuffer; @@ -159,7 +150,7 @@ namespace control { { REQUIRE (!newContext_->isValid(), "Lifecycle-Error"); - newContext_.create (origArgHolder, allocator_); + newContext_.create (origArgHolder, allocator_); } diff --git a/src/proc/control/command.cpp b/src/proc/control/command.cpp index c4abfcbc6..d0abdfd19 100644 --- a/src/proc/control/command.cpp +++ b/src/proc/control/command.cpp @@ -349,14 +349,29 @@ namespace control { } + namespace { + const Symbol ANONYMOUS_CMD_SYMBOL("_anonymous_"); + } + Symbol Command::getID() const { + ////////////////////////////////////////////////////////////////////TODO do we need no-throw guarantee here? Symbol id = CommandRegistry::instance().findDefinition (*this); - if (!id) - throw error::State("Encountered a NIL command handle while expecting a bound one." - ,error::LUMIERA_ERROR_BOTTOM_VALUE); - return id; + return id? id + : ANONYMOUS_CMD_SYMBOL; + } + + + /** @return `true` when this command (front-end) was never registered + * with the CommandRegistry; typically this is the case with instances + * created from a prototype, when calling Command::newInstance instead + * of invoking Command::storeDef(Symbol). + */ + bool + Command::isAnonymous() const + { + return not CommandRegistry::instance().findDefinition (*this); } @@ -367,13 +382,8 @@ namespace control { Command::operator string() const { ostringstream repr; - repr << "Command"; ////////////////////////////////////////////////////////////////////TODO do we need no-throw guarantee here? - Symbol id = CommandRegistry::instance().findDefinition (*this); - if (id) - repr << "(\""<