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
|
2009-08-09 21:55:47 +02:00
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @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
|
2009-09-21 03:11:46 +02:00
|
|
|
|
** are stateless singleton objects, thus we build using SingletonSubclass
|
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 "pre.hpp"
|
|
|
|
|
|
#include "lib/error.hpp"
|
|
|
|
|
|
#include "lib/singleton-subclass.hpp"
|
|
|
|
|
|
#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
|
|
|
|
#include "proc/mobject/session.hpp"
|
|
|
|
|
|
#include "include/lifecycle.h"
|
|
|
|
|
|
//#include "include/symbol.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
//#include <tr1/memory>
|
|
|
|
|
|
//#include <string>
|
|
|
|
|
|
#include<vector>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace control {
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // concrete command handling patterns
|
|
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
// using std::string;
|
|
|
|
|
|
// using lumiera::Symbol;
|
|
|
|
|
|
// using std::tr1::shared_ptr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Handling Pattern: invoke blocking, translate exceptions into an error state
|
|
|
|
|
|
* @todo describe this pattern in more detail....
|
|
|
|
|
|
*/
|
|
|
|
|
|
class InvokeSyncNoThrow
|
|
|
|
|
|
: public HandlingPattern
|
|
|
|
|
|
{
|
|
|
|
|
|
void
|
2009-09-21 03:11:46 +02:00
|
|
|
|
perform (CommandImpl& command) const
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("actually invoke a command, according to this pattern");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HandlingPattern const&
|
|
|
|
|
|
defineUNDO() const
|
|
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("yield a handling pattern suitable for UNDOing a command, according to this pattern");
|
|
|
|
|
|
}
|
2009-08-11 06:32:29 +02:00
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
isValid() const
|
|
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("is this pattern currently able to handle commands?");
|
|
|
|
|
|
}
|
2009-08-09 21:55:47 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Handling Pattern: invoke blocking, propagating any exceptions immediately
|
|
|
|
|
|
* @todo describe this pattern in more detail....
|
|
|
|
|
|
*/
|
|
|
|
|
|
class InvokeSyncThrow
|
|
|
|
|
|
: public HandlingPattern
|
|
|
|
|
|
{
|
|
|
|
|
|
void
|
2009-09-21 03:11:46 +02:00
|
|
|
|
perform (CommandImpl& command) const
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("actually invoke a command, according to this pattern");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HandlingPattern const&
|
|
|
|
|
|
defineUNDO() const
|
|
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("yield a handling pattern suitable for UNDOing a command, according to this pattern");
|
|
|
|
|
|
}
|
2009-08-11 06:32:29 +02:00
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
isValid() const
|
|
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("is this pattern currently able to handle commands?");
|
|
|
|
|
|
}
|
2009-08-09 21:55:47 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Handling Pattern: just schedule command to be invoked asynchronously
|
|
|
|
|
|
* @todo describe this pattern in more detail....
|
|
|
|
|
|
*/
|
|
|
|
|
|
class InvokeAsync
|
|
|
|
|
|
: public HandlingPattern
|
|
|
|
|
|
{
|
|
|
|
|
|
void
|
2009-09-21 03:11:46 +02:00
|
|
|
|
perform (CommandImpl& command) const
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("actually invoke a command, according to this pattern");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HandlingPattern const&
|
|
|
|
|
|
defineUNDO() const
|
|
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("yield a handling pattern suitable for UNDOing a command, according to this pattern");
|
|
|
|
|
|
}
|
2009-08-11 06:32:29 +02:00
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
isValid() const
|
|
|
|
|
|
{
|
|
|
|
|
|
UNIMPLEMENTED ("is this pattern currently able to handle commands?");
|
|
|
|
|
|
}
|
2009-08-09 21:55:47 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ======== Handling Pattern Table ========== */
|
|
|
|
|
|
|
|
|
|
|
|
typedef lumiera::SingletonSub<HandlingPattern> SingletonFac;
|
|
|
|
|
|
|
|
|
|
|
|
/** Table of available command handling patterns */
|
|
|
|
|
|
vector<SingletonFac> patternTable;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** access the singleton instance for a given ID */
|
2009-08-11 08:35:37 +02:00
|
|
|
|
inline HandlingPattern const&
|
2009-08-10 01:32:33 +02:00
|
|
|
|
getPatternInstance (size_t id)
|
2009-08-09 21:55:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
REQUIRE (id < patternTable.size());
|
|
|
|
|
|
return patternTable[id] ();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** populate the handling pattern table.
|
|
|
|
|
|
* This init-function will be invoked each time
|
|
|
|
|
|
* a new session is created or loaded.
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
prepareCommandHandlingPatterns()
|
|
|
|
|
|
{
|
|
|
|
|
|
using lumiera::singleton::UseSubclass;
|
|
|
|
|
|
|
2009-09-21 03:11:46 +02:00
|
|
|
|
patternTable[HandlingPattern::SYNC ] = SingletonFac(UseSubclass<InvokeSyncNoThrow>());
|
2009-08-09 21:55:47 +02:00
|
|
|
|
patternTable[HandlingPattern::SYNC_THROW] = SingletonFac(UseSubclass<InvokeSyncThrow>());
|
2009-09-21 03:11:46 +02:00
|
|
|
|
patternTable[HandlingPattern::ASYNC ] = SingletonFac(UseSubclass<InvokeAsync>());
|
2009-08-09 21:55:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lumiera::LifecycleHook _schedule (mobject::ON_SESSION_START, &prepareCommandHandlingPatterns);
|
|
|
|
|
|
|
|
|
|
|
|
} // (END) definition of concrete handling patterns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace control
|
|
|
|
|
|
#endif
|