Commands: Instance management implementation finished (#1089)

This commit is contained in:
Fischlurch 2017-04-08 15:42:51 +02:00
parent f495a069aa
commit a4527c5e75
3 changed files with 59 additions and 34 deletions

View file

@ -29,14 +29,19 @@
** be formed during an extended time period, non-deterministically -- since the actual context
** depends on the user interactions. Within the UI, there is a dedicated mechanism to form such
** command invocations similar to forming sentences of a language (with subject, predication and
** possibly some further objects). The UI manages several InteractionStateManager instances to
** observe and pick up contextual state, finally leading to a complete parametrisation of a command.
** possibly some further objects). The UI manages several InteractionStateManager instances to observe
** and pick up contextual state, finally leading to a complete parametrisation of a command.
** The CommandInstanceManager is a service to support this process; it prepares command instances
** and provides dedicated instance IDs, which can be stored in the UI and later used to retrieve
** those instances for invocation. These IDs are created by decorating a base command ID, allowing
** for several competing invocations to exist at the same time. When finally a given invocation is
** about to happen, a corresponding registration handle is transfered to the ProcDispatcher, where
** it is enqueued for execution.
** it is enqueued for execution.
** \par lifecycle
** There CommandInstanceManager is maintained by the SessionCommandService, which in turn is
** installed and removed by the implementation within ProcDispatcher. Its lifecycle is thus tied
** to the opening / closing of the Proc-Layer interface, as dictated by the Session lifecycle.
** When the current session is closed, all command instances "underway" will thus be discarded.
**
** @see command-setup.cpp service implementation
** @see command.hpp
@ -55,7 +60,6 @@
#include "lib/error.hpp"
#include "proc/control/command-dispatch.hpp"
#include "lib/symbol.hpp"
//#include "proc/common.hpp"
#include <boost/noncopyable.hpp>
#include <unordered_map>
@ -63,18 +67,30 @@
namespace proc {
namespace control {
using std::string;
using lib::Symbol;
//using std::shared_ptr;
/**
* @todo write type comment
* Maintain a _current command instance_ for parametrisation.
* The definition of a *Proc-Layer command* is used like a prototype.
* For invocation, an anonymous clone copy is created from the definition
* by calling #newInstance. Several competing usages of the same command can be
* kept apart with the help of the `invocationID`, which is used to decorate the basic
* command-ID to form a distinct _`instanceID`_. After #newInstance has "opened" an instance
* this way and returned the instanceID, the actual \ref Command handle can be retrieved with
* #getInstance. It represents an _anonymous instance_ kept alive solely by the CommandInstanceManager
* (i.e. there is no registration of a command under that instanceID in the global CommandRegistry).
* When done with the parametrisation, by calling #dispatch, this anonymous instance will be handed
* over to the [Dispatcher](CommandDispatch) (installed on construction). Typically, this will in fact
* be the proc::control::ProcDispatcher, which runs in a dedicated thread ("session loop thread") and
* maintains a queue of commands to be dispatched towards the current session. Since Command is a smart
* handle, the enqueued instance will stay alive until execution and then go out of scope. But, after
* #dispatch, it is no longer accessible from the CommandInstanceManger, and while it is still waiting
* in the execution queue, the next instance for the same invocationID might already be opened.
*/
class CommandInstanceManager
: boost::noncopyable
@ -91,17 +107,9 @@ namespace control {
void dispatch (Symbol instanceID);
bool contains (Symbol instanceID) const;
private:
};
/** */
}} // namespace proc::control
#endif /*CONTROL_COMMAND_INSTANCE_MANAGER_H*/

View file

@ -23,10 +23,12 @@
/** @file command-setup.cpp
** Implementation details of instance management for command invocation by the GUI.
** This translation unit combines the implementation code of several facilities
** related to definition and instantiation of concrete command instances.
**
** @see command-setup.hpp
** @see command-instance-manager.hpp
** @see TODO_CommandInstanceManager_test
** @see CommandInstanceManager_test
** @see command.hpp
** @see command-registry.hpp
**
@ -155,13 +157,21 @@ namespace control {
// emit dtors of embedded objects here....
CommandInstanceManager::~CommandInstanceManager() { }
/** create a CommandInstanceManager and wire it with the given CommandDispatch implementation.
* Typically, this is done in SessionCommandService. The embedded hash table for pending
* command instances is sized in relation to the number of registered global Command definitions.
*/
CommandInstanceManager::CommandInstanceManager (CommandDispatch& dispatcher)
: dispatcher_{dispatcher}
, table_{2 * Command::definition_count()}
{ }
/** @todo more to come here...*/
/** Create and thus "open" a new anonymous command instance.
* @param prototypeID the underlying Command definition to create a clone copy
* @param invocationID used to decorate the prototypeID to from an unique instanceID
* @throws error::Logic in case an instance is for this ID combination is already "open"
*/
Symbol
CommandInstanceManager::newInstance (Symbol prototypeID, string invocationID)
{
@ -182,6 +192,7 @@ namespace control {
}
/** @return handle to the currently "opened" instance with the given ID */
Command&
CommandInstanceManager::getInstance (Symbol instanceID)
{
@ -194,7 +205,7 @@ namespace control {
}
/** */
/** hand over the designated command instance to the dispatcher installed on construction */
void
CommandInstanceManager::dispatch (Symbol instanceID)
{

View file

@ -11706,9 +11706,9 @@
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1491005426763" ID="ID_1575553505" MODIFIED="1491005475262" TEXT="zu kl&#xe4;ren: duplikate Instanz">
<node CREATED="1491005426763" ID="ID_1575553505" MODIFIED="1491618872104" TEXT="zu kl&#xe4;ren: duplikate Instanz">
<arrowlink COLOR="#ca978d" DESTINATION="ID_1805144008" ENDARROW="Default" ENDINCLINATION="594;0;" ID="Arrow_ID_191915626" STARTARROW="None" STARTINCLINATION="594;0;"/>
<icon BUILTIN="flag-yellow"/>
<icon BUILTIN="button_ok"/>
<node CREATED="1491005509448" ID="ID_709599195" MODIFIED="1491005512147" TEXT="Fehler?"/>
<node CREATED="1491005514015" ID="ID_66770459" MODIFIED="1491495268579" TEXT="bestehende Instanz &#xfc;berb&#xfc;geln"/>
<node CREATED="1491495244653" ID="ID_1710448495" MODIFIED="1491495254015" TEXT="stillschweigend die bestehende Instanz verwenden"/>
@ -11716,7 +11716,8 @@
<icon BUILTIN="forward"/>
</node>
</node>
<node CREATED="1491008040105" ID="ID_662216926" MODIFIED="1491008043901" TEXT="Implementierung">
<node CREATED="1491008040105" ID="ID_662216926" MODIFIED="1491618848217" TEXT="Implementierung">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1491008045936" ID="ID_1071153669" MODIFIED="1491008146180" TEXT="CommandInstanceManager_test">
<icon BUILTIN="button_ok"/>
</node>
@ -11729,8 +11730,8 @@
<node COLOR="#338800" CREATED="1491008073989" ID="ID_1954195404" MODIFIED="1491008148995" TEXT="Symbol-Tabelle">
<icon BUILTIN="button_ok"/>
</node>
<node CREATED="1491008079676" ID="ID_1262786130" MODIFIED="1491008142008" TEXT="Test">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1491008079676" ID="ID_1262786130" MODIFIED="1491618841600" TEXT="Test">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1491008088699" ID="ID_1501876595" MODIFIED="1491109806224" TEXT="Basisfall l&#xe4;uft noch nicht">
<richcontent TYPE="NOTE"><html>
<head>
@ -11744,9 +11745,9 @@
</html></richcontent>
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1491008118695" ID="ID_1595821007" MODIFIED="1491498915313" STYLE="fork" TEXT="Invocation abdecken">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1491498978878" ID="ID_1001760576" MODIFIED="1491499003761" TEXT="nicht direkt">
<node COLOR="#338800" CREATED="1491008118695" ID="ID_1595821007" MODIFIED="1491618830886" TEXT="Invocation abdecken">
<icon BUILTIN="button_ok"/>
<node CREATED="1491498978878" ID="ID_1001760576" MODIFIED="1491618830202" TEXT="nicht direkt">
<richcontent TYPE="NOTE"><html>
<head>
@ -11762,7 +11763,7 @@
</html>
</richcontent>
</node>
<node CREATED="1491499005954" ID="ID_1944400975" MODIFIED="1491499049847" TEXT="aber im Hinblick auf den Lebenszyklus">
<node CREATED="1491499005954" ID="ID_1944400975" MODIFIED="1491618830202" TEXT="aber im Hinblick auf den Lebenszyklus">
<richcontent TYPE="NOTE"><html>
<head>
@ -11782,14 +11783,17 @@
</richcontent>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1491008124550" ID="ID_249252999" MODIFIED="1491008138788" TEXT="Duplikate abdecken">
<node COLOR="#338800" CREATED="1491008124550" ID="ID_249252999" MODIFIED="1491618833169" TEXT="Duplikate abdecken">
<icon BUILTIN="button_ok"/>
</node>
<node COLOR="#338800" CREATED="1491008129165" ID="ID_118623494" MODIFIED="1491618835441" TEXT="Lebenszyklus-Fehler">
<icon BUILTIN="button_ok"/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1491656361886" ID="ID_1269299900" MODIFIED="1491656365558" TEXT="Einbindung">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1491008129165" ID="ID_118623494" MODIFIED="1491008139405" TEXT="Lebenszyklus-Fehler">
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1489191252503" ID="ID_1621107057" MODIFIED="1489191308469" TEXT="#1090 Command access for UI-Elements">
<arrowlink COLOR="#758ba4" DESTINATION="ID_827179653" ENDARROW="Default" ENDINCLINATION="173;83;" ID="Arrow_ID_57938013" STARTARROW="None" STARTINCLINATION="550;-93;"/>
@ -12324,6 +12328,8 @@
</node>
<node CREATED="1490985748207" ID="ID_1314513556" MODIFIED="1490985751457" TEXT="Instanzbildung">
<node CREATED="1490985756381" ID="ID_1346029720" MODIFIED="1490985767448" TEXT="wird durch ID-Dekoration getrieben"/>
<node CREATED="1491656301121" ID="ID_566719122" MODIFIED="1491656320281" TEXT="es ist stets nur eine Instanz offen"/>
<node CREATED="1491656321252" ID="ID_1903067692" MODIFIED="1491656336277" TEXT="Widerspr&#xfc;che sind Hiweis auf Fehlfunktion"/>
</node>
</node>
</node>