2009-08-09 21:55:47 +02:00
|
|
|
|
/*
|
2009-09-21 03:11:46 +02:00
|
|
|
|
HANDLILNG-PATTERNS.hpp - Collection of predefined command handling patterns
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
2009-08-09 21:55:47 +02:00
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
2009-08-09 21:55:47 +02:00
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
2009-08-09 21:55:47 +02:00
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
2009-08-09 21:55:47 +02:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
2009-08-09 21:55:47 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @file handling-patterns.hpp
|
|
|
|
|
|
** A hard wired collection of predefined command handling patterns.
|
|
|
|
|
|
** There is a small number of different possibilities to handle execution
|
|
|
|
|
|
** and UNDO of proc-Layer commands. Each of these is defined as a subclass
|
|
|
|
|
|
** in this header and then hard wired into a small table. Handling patterns
|
2013-10-14 01:18:56 +02:00
|
|
|
|
** are stateless singleton objects, thus we build using multiple Singleton
|
2009-08-09 21:55:47 +02:00
|
|
|
|
** factory objects and configure them hard wired with the respective
|
|
|
|
|
|
** implementation classes. The index positions in this table match
|
|
|
|
|
|
** the sequence within the enum HandlingPattern::ID; all of this
|
|
|
|
|
|
** is done hard wired and without any dynamic configuration.
|
|
|
|
|
|
**
|
|
|
|
|
|
** @see ProcDispatcher
|
|
|
|
|
|
** @see Session
|
|
|
|
|
|
**
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONTROL_HANDLING_PATTERNS_DEF_H
|
|
|
|
|
|
#define CONTROL_HANDLING_PATTERNS_DEF_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/error.hpp"
|
2009-10-01 01:00:21 +02:00
|
|
|
|
#include "lib/multifact.hpp"
|
2009-08-09 21:55:47 +02:00
|
|
|
|
#include "proc/control/handling-pattern.hpp"
|
2009-09-21 03:11:46 +02:00
|
|
|
|
#include "proc/control/command-impl.hpp"
|
2009-08-09 21:55:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
|
namespace proc {
|
2009-08-09 21:55:47 +02:00
|
|
|
|
namespace control {
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // concrete command handling patterns
|
2009-10-01 13:29:53 +02:00
|
|
|
|
|
2009-08-09 21:55:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-10-01 13:29:53 +02:00
|
|
|
|
* Handling Pattern Foundation: invoke command directly and without
|
|
|
|
|
|
* any external intervention. This pattern is intended as implementation
|
|
|
|
|
|
* base class, but can be used as-is for unit tests.
|
2009-08-09 21:55:47 +02:00
|
|
|
|
*/
|
2009-10-01 13:29:53 +02:00
|
|
|
|
class BasicHandlingPattern
|
2009-08-09 21:55:47 +02:00
|
|
|
|
: public HandlingPattern
|
|
|
|
|
|
{
|
2009-10-01 13:29:53 +02:00
|
|
|
|
bool isValid() const { return true; }
|
|
|
|
|
|
|
2009-08-09 21:55:47 +02:00
|
|
|
|
void
|
2016-01-22 15:25:08 +01:00
|
|
|
|
performExec (CommandImpl& command) const override
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
2009-10-01 13:29:53 +02:00
|
|
|
|
REQUIRE (command.canExec());
|
|
|
|
|
|
command.invokeCapture();
|
|
|
|
|
|
command.invokeOperation();
|
2009-08-09 21:55:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2009-10-01 01:51:10 +02:00
|
|
|
|
void
|
2016-01-22 15:25:08 +01:00
|
|
|
|
performUndo (CommandImpl& command) const override
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
2009-10-01 13:29:53 +02:00
|
|
|
|
REQUIRE (command.canUndo());
|
|
|
|
|
|
command.invokeUndo();
|
2009-08-09 21:55:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-10-01 13:29:53 +02:00
|
|
|
|
* Handling Pattern: invoke blocking, translate exceptions into an error state
|
2009-08-09 21:55:47 +02:00
|
|
|
|
* @todo describe this pattern in more detail....
|
2016-01-22 15:25:08 +01:00
|
|
|
|
* @todo unimplemented... //////////////////////////////////////////////////////////TICKET #210
|
2009-08-09 21:55:47 +02:00
|
|
|
|
*/
|
2009-10-01 13:29:53 +02:00
|
|
|
|
class InvokeSyncNoThrow
|
|
|
|
|
|
: public BasicHandlingPattern
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
void
|
2016-01-22 15:25:08 +01:00
|
|
|
|
performExec (CommandImpl& command) const override
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("actually invoke a command, according to this pattern");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-10-01 01:51:10 +02:00
|
|
|
|
void
|
2016-01-22 15:25:08 +01:00
|
|
|
|
performUndo (CommandImpl& command) const override
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
2009-10-01 01:51:10 +02:00
|
|
|
|
UNIMPLEMENTED ("actually undo the effect of a command, according to this pattern");
|
2009-08-09 21:55:47 +02:00
|
|
|
|
}
|
2009-08-11 06:32:29 +02:00
|
|
|
|
|
|
|
|
|
|
bool
|
2016-01-22 15:25:08 +01:00
|
|
|
|
isValid() const override
|
2009-08-11 06:32:29 +02:00
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("is this pattern currently able to handle commands?");
|
|
|
|
|
|
}
|
2009-08-09 21:55:47 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-10-01 13:29:53 +02:00
|
|
|
|
* Handling Pattern: invoke blocking, propagating any exceptions immediately
|
2009-10-02 15:26:11 +02:00
|
|
|
|
* @todo is throwing here helpful, and how to integrate it into ExecResult...?
|
2009-08-09 21:55:47 +02:00
|
|
|
|
* @todo describe this pattern in more detail....
|
2016-01-22 15:25:08 +01:00
|
|
|
|
* @todo unimplemented... //////////////////////////////////////////////////////////TICKET #210
|
2009-08-09 21:55:47 +02:00
|
|
|
|
*/
|
2009-10-01 13:29:53 +02:00
|
|
|
|
class InvokeSyncThrow
|
|
|
|
|
|
: public BasicHandlingPattern
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
void
|
2016-01-22 15:25:08 +01:00
|
|
|
|
performExec (CommandImpl& command) const override
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("actually invoke a command, according to this pattern");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-10-01 01:51:10 +02:00
|
|
|
|
void
|
2016-01-22 15:25:08 +01:00
|
|
|
|
performUndo (CommandImpl& command) const override
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
2009-10-01 01:51:10 +02:00
|
|
|
|
UNIMPLEMENTED ("actually undo the effect of a command, according to this pattern");
|
2009-08-09 21:55:47 +02:00
|
|
|
|
}
|
2009-08-11 06:32:29 +02:00
|
|
|
|
|
|
|
|
|
|
bool
|
2016-01-22 15:25:08 +01:00
|
|
|
|
isValid() const override
|
2009-08-11 06:32:29 +02:00
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("is this pattern currently able to handle commands?");
|
|
|
|
|
|
}
|
2009-08-09 21:55:47 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-01 01:51:47 +02:00
|
|
|
|
/**
|
2009-10-01 13:29:53 +02:00
|
|
|
|
* Handling Pattern: just schedule command to be invoked asynchronously
|
2009-10-02 15:26:11 +02:00
|
|
|
|
* @todo clarify what "async" means and if we need it.....
|
2009-10-01 13:29:53 +02:00
|
|
|
|
* @todo describe this pattern in more detail....
|
2016-01-22 15:25:08 +01:00
|
|
|
|
* @todo unimplemented... //////////////////////////////////////////////////////////TICKET #210
|
2009-10-01 01:51:47 +02:00
|
|
|
|
*/
|
2009-10-01 13:29:53 +02:00
|
|
|
|
class InvokeAsync
|
|
|
|
|
|
: public BasicHandlingPattern
|
2009-10-01 01:51:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
void
|
2016-01-22 15:25:08 +01:00
|
|
|
|
performExec (CommandImpl& command) const override
|
2009-10-01 01:51:47 +02:00
|
|
|
|
{
|
2009-10-01 13:29:53 +02:00
|
|
|
|
UNIMPLEMENTED ("actually invoke a command, according to this pattern");
|
2009-10-01 01:51:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2016-01-22 15:25:08 +01:00
|
|
|
|
performUndo (CommandImpl& command) const override
|
2009-10-01 01:51:47 +02:00
|
|
|
|
{
|
2009-10-01 13:29:53 +02:00
|
|
|
|
UNIMPLEMENTED ("actually undo the effect of a command, according to this pattern");
|
2009-10-01 01:51:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2016-01-22 15:25:08 +01:00
|
|
|
|
isValid() const override
|
2009-10-01 01:51:47 +02:00
|
|
|
|
{
|
2009-10-01 13:29:53 +02:00
|
|
|
|
UNIMPLEMENTED ("is this pattern currently able to handle commands?");
|
2009-10-01 01:51:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-09 21:55:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ======== Handling Pattern Table ========== */
|
|
|
|
|
|
|
2014-09-14 23:58:05 +02:00
|
|
|
|
typedef lib::factory::MultiFact<HandlingPattern&, HandlingPattern::ID> HandlingPatternFactory;
|
2009-08-09 21:55:47 +02:00
|
|
|
|
|
2009-10-01 13:29:53 +02:00
|
|
|
|
/** holds singleton pattern instances by ID */
|
2009-10-01 01:00:21 +02:00
|
|
|
|
HandlingPatternFactory patternTable;
|
|
|
|
|
|
|
2009-10-01 13:29:53 +02:00
|
|
|
|
HandlingPatternFactory::Singleton<InvokeSyncNoThrow> holder1 (patternTable, HandlingPattern::SYNC);
|
|
|
|
|
|
HandlingPatternFactory::Singleton<InvokeSyncThrow> holder2 (patternTable, HandlingPattern::SYNC_THROW);
|
|
|
|
|
|
HandlingPatternFactory::Singleton<InvokeAsync> holder3 (patternTable, HandlingPattern::ASYNC);
|
|
|
|
|
|
HandlingPatternFactory::Singleton<BasicHandlingPattern> holder4 (patternTable, HandlingPattern::DUMMY);
|
2009-08-09 21:55:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** access the singleton instance for a given ID */
|
2009-08-11 08:35:37 +02:00
|
|
|
|
inline HandlingPattern const&
|
2009-10-01 01:00:21 +02:00
|
|
|
|
getPatternInstance (HandlingPattern::ID id)
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
2009-10-01 01:00:21 +02:00
|
|
|
|
REQUIRE (patternTable.contains(id));
|
2009-08-09 21:55:47 +02:00
|
|
|
|
|
2009-10-01 01:00:21 +02:00
|
|
|
|
return patternTable (id);
|
2009-08-09 21:55:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-01 01:00:21 +02:00
|
|
|
|
} // (END) definition of concrete handling patterns
|
2009-08-09 21:55:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
|
}} // namespace proc::control
|
2009-08-09 21:55:47 +02:00
|
|
|
|
#endif
|