From 45f86e42e4843a11347954e8b04e1f639e6a4458 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 9 Apr 2017 03:58:38 +0200 Subject: [PATCH] Commands: Instance management integrated in SessionCommandService but I am not happy with the implementation yet: the maybeGet just doesn't feel right. Likely it will be a better idea to push that fallback mechanism generally down into the CommandInstanceManager? --- src/proc/control/command-instance-manager.hpp | 1 + src/proc/control/command-setup.cpp | 16 ++++++ src/proc/control/session-command-service.cpp | 32 +++++++---- src/proc/control/session-command-service.hpp | 4 ++ wiki/thinkPad.ichthyo.mm | 54 ++++++++++++------- 5 files changed, 78 insertions(+), 29 deletions(-) diff --git a/src/proc/control/command-instance-manager.hpp b/src/proc/control/command-instance-manager.hpp index 0b624185e..2d92e5c30 100644 --- a/src/proc/control/command-instance-manager.hpp +++ b/src/proc/control/command-instance-manager.hpp @@ -104,6 +104,7 @@ namespace control { Symbol newInstance (Symbol prototypeID, string const& invocationID); Command& getInstance(Symbol instanceID); + Command& maybeGetInstance (Symbol instanceID); void dispatch (Symbol instanceID); bool contains (Symbol instanceID) const; diff --git a/src/proc/control/command-setup.cpp b/src/proc/control/command-setup.cpp index 372d10d6e..01eb7533f 100644 --- a/src/proc/control/command-setup.cpp +++ b/src/proc/control/command-setup.cpp @@ -205,6 +205,22 @@ namespace control { } + /** try to retrieve an currently active instance, but tolerate unknown IDs */ + Command& + CommandInstanceManager::maybeGetInstance (Symbol instanceID) + { + static Command NOT_FOUND; + auto entry = table_.find(instanceID); + if (entry == table_.end()) + return NOT_FOUND; + if (not entry->second) + throw error::Invalid (_Fmt{"Command instance '%s' is not (yet/anymore) active"} + % instanceID + , LUMIERA_ERROR_INVALID_COMMAND); + return entry->second; + } + + /** hand over the designated command instance to the dispatcher installed on construction */ void CommandInstanceManager::dispatch (Symbol instanceID) diff --git a/src/proc/control/session-command-service.cpp b/src/proc/control/session-command-service.cpp index bc88a2cb9..3468f71e6 100644 --- a/src/proc/control/session-command-service.cpp +++ b/src/proc/control/session-command-service.cpp @@ -54,14 +54,22 @@ namespace control { using std::string; using util::cStr; - namespace { - - /** @throw error::Invalid when no suitable command definition exists */ - Command - retrieveCommand (Symbol cmdID) - { - return Command::get (cmdID); - } + + /** + * @internal access the command instance for further processing. + * The standard use case is to get an anonymous command instance, + * which was previously opened within the CommandInstanceManager. + * But for exceptional cases, we also allow to access a global + * command instance by name. + * @param cmdID either the instanceID or the global cmdID + * @throw error::Invalid when no suitable command definition exists + */ + Command + SessionCommandService::retrieveCommand (Symbol cmdID) + { + Command cmdFound = instanceManager_.maybeGetInstance (cmdID); + return cmdFound? cmdFound + : Command::get(cmdID); } @@ -69,7 +77,7 @@ namespace control { Symbol SessionCommandService::cycle (Symbol cmdID, string const& invocationID) { - UNIMPLEMENTED ("Command instance management"); + return instanceManager_.newInstance(cmdID, invocationID); } @@ -83,7 +91,10 @@ namespace control { void SessionCommandService::invoke (Symbol cmdID) { - dispatcher_.enqueue (retrieveCommand(cmdID)); + if (instanceManager_.contains (cmdID)) + instanceManager_.dispatch(cmdID); + else + dispatcher_.enqueue (Command::get(cmdID)); } @@ -210,6 +221,7 @@ namespace control { SessionCommandService::SessionCommandService (CommandDispatch& dispatcherLoopInterface) : dispatcher_{dispatcherLoopInterface} + , instanceManager_{dispatcher_} , implInstance_{this,_instance} , serviceInstance_{ LUMIERA_INTERFACE_REF (lumieraorg_SessionCommand, 0, lumieraorg_SessionCommandService)} { diff --git a/src/proc/control/session-command-service.hpp b/src/proc/control/session-command-service.hpp index fe836997d..c31b4e306 100644 --- a/src/proc/control/session-command-service.hpp +++ b/src/proc/control/session-command-service.hpp @@ -43,6 +43,7 @@ #include "include/session-command-facade.h" #include "proc/control/command-dispatch.hpp" +#include "proc/control/command-instance-manager.hpp" #include "common/instancehandle.hpp" #include "lib/singleton-ref.hpp" #include "lib/diff/gen-node.hpp" @@ -75,6 +76,9 @@ namespace control { , boost::noncopyable { CommandDispatch& dispatcher_; + CommandInstanceManager instanceManager_; + + Command retrieveCommand (Symbol); /* === Implementation of the Facade Interface === */ diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 11f44fa1b..569fd99e6 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -11798,7 +11798,26 @@ - + + + + + + +

+ ....künftige Weiterung: +

+

+ auch in EntryID könnte ein Symbol-Stecken, +

+

+ mithin in der GenNode::ID +

+ + +
+
+ @@ -11823,25 +11842,22 @@ + + + + + + + + + + + + + + + - - - - - - -

- ....künftige Weiterung: -

-

- auch in EntryID könnte ein Symbol-Stecken, -

-

- mithin in der GenNode::ID -

- - -