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?
This commit is contained in:
Fischlurch 2017-04-09 03:58:38 +02:00
parent 0dad15209d
commit 45f86e42e4
5 changed files with 78 additions and 29 deletions

View file

@ -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;

View file

@ -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)

View file

@ -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)}
{

View file

@ -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 === */

View file

@ -11798,7 +11798,26 @@
<node CREATED="1491659191155" ID="ID_586991718" MODIFIED="1491659216131" TEXT="Nutzung des Instance-Managers ist optional"/>
<node CREATED="1491659194283" ID="ID_1169808852" MODIFIED="1491659203949" TEXT="direkter Zugriff auf Commands bleibt offen"/>
<node CREATED="1491659224630" ID="ID_837055372" MODIFIED="1491659238608" TEXT="Entscheidung anhand der Command-ID"/>
<node CREATED="1491659382161" ID="ID_948768193" MODIFIED="1491659462652" TEXT="Performance: maybeGet">
<node CREATED="1491694300867" ID="ID_1838809343" MODIFIED="1491702954154" TEXT="Festlegung: CommandID wird als Symbol entgegengenommen">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
....k&#252;nftige Weiterung:
</p>
<p>
auch in EntryID k&#246;nnte ein Symbol-Stecken,
</p>
<p>
mithin in der GenNode::ID
</p>
</body>
</html>
</richcontent>
</node>
<node CREATED="1491659382161" ID="ID_948768193" MODIFIED="1491702871022" TEXT="Performance: maybeGet">
<richcontent TYPE="NOTE"><html>
<head>
@ -11823,25 +11842,22 @@
</html>
</richcontent>
<icon BUILTIN="idea"/>
<icon BUILTIN="stop-sign"/>
<node CREATED="1491702872058" ID="ID_487194706" MODIFIED="1491702875613" TEXT="keine gute Idee"/>
<node CREATED="1491702876137" ID="ID_141674543" MODIFIED="1491702880476" TEXT="doppelt das Interface"/>
<node CREATED="1491702881160" ID="ID_1657270200" MODIFIED="1491702949548" TEXT="Taschenspielerei">
<arrowlink COLOR="#a71f6e" DESTINATION="ID_1776414678" ENDARROW="Default" ENDINCLINATION="-59;-44;" ID="Arrow_ID_559634306" STARTARROW="None" STARTINCLINATION="126;32;"/>
<icon BUILTIN="smily_bad"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1491702805203" HGAP="26" ID="ID_1776414678" MODIFIED="1491702949548" TEXT="Performance / Standard-Fall" VSHIFT="22">
<linktarget COLOR="#a71f6e" DESTINATION="ID_1776414678" ENDARROW="Default" ENDINCLINATION="-59;-44;" ID="Arrow_ID_559634306" SOURCE="ID_1657270200" STARTARROW="None" STARTINCLINATION="126;32;"/>
<icon BUILTIN="flag-yellow"/>
<node CREATED="1491702822568" ID="ID_1028353876" MODIFIED="1491702830531" TEXT="wir suchen stets zuerst eine Instanz"/>
<node CREATED="1491702831023" ID="ID_184396015" MODIFIED="1491702840810" TEXT="wir fallen auf die globale Registry zur&#xfc;ck"/>
<node CREATED="1491702841453" ID="ID_1707474386" MODIFIED="1491702856185" TEXT="das kann der InstanceManager am Besten selber!">
<icon BUILTIN="idea"/>
</node>
<node CREATED="1491694300867" ID="ID_1838809343" MODIFIED="1491694391567" TEXT="Festlegung: CommandID wird als Symbol entgegengenommen">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
....k&#252;nftige Weiterung:
</p>
<p>
auch in EntryID k&#246;nnte ein Symbol-Stecken,
</p>
<p>
mithin in der GenNode::ID
</p>
</body>
</html>
</richcontent>
</node>
</node>
<node CREATED="1491692398913" ID="ID_1349137025" MODIFIED="1491692404050" TEXT="in UI-Bus">