lumiera_/src/proc/control/handling-pattern.hpp

139 lines
3.6 KiB
C++
Raw Normal View History

2009-06-08 04:46:07 +02:00
/*
HANDLILNG-PATTERN.hpp - A skeleton for executing commands, including standard implementations
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-pattern.hpp
** Pre-defined command execution templates.
** Any command can be configured to use a specific handling pattern
** on invocation. Moreover, there is a default handling pattern for commands.
** These patterns define the steps necessary for getting the command actually
** invoked (template method pattern). A pattern may cause the command to be
** enqueued, registered for UNDO or dispatched into a background thread.
** To carry out the work, HandlingPattern implementations are allowed to
** invoke the CommandImpl API directly.
**
** @todo it is not clear what's the difference between "throw" and "no-throw" pattern
** @todo any integration with the (yet undefined as of 9/09) ProcDispatcher is missing.
2009-06-08 04:46:07 +02:00
**
** @see ProcDispatcher
** @see Session
**
*/
#ifndef CONTROL_HANDLING_PATTERN_H
#define CONTROL_HANDLING_PATTERN_H
//#include "pre.hpp"
2009-07-26 02:00:47 +02:00
#include "lib/error.hpp"
#include "lib/bool-checkable.hpp"
#include "lib/symbol.hpp"
2009-06-08 04:46:07 +02:00
//#include <tr1/memory>
#include <string>
2009-06-08 04:46:07 +02:00
namespace control {
using std::string;
using lib::Symbol;
2009-06-08 04:46:07 +02:00
// using std::tr1::shared_ptr;
class CommandImpl;
2009-06-08 04:46:07 +02:00
/**
* @todo Type-comment
*/
class ExecResult
: public lib::BoolCheckable<ExecResult>
{
const string log_;
public:
bool isValid() const;
void maybeThrow() const;
protected:
ExecResult () { } ///< default: command executed successfully
ExecResult (lumiera::Error const&); ///< this result marks a failed execution
friend class HandlingPattern;
};
2009-06-08 04:46:07 +02:00
/**
* @todo Type-comment
*/
class HandlingPattern
2009-08-11 06:32:29 +02:00
: public lib::BoolCheckable<HandlingPattern>
2009-06-08 04:46:07 +02:00
{
public:
2009-07-26 02:00:47 +02:00
enum ID
{ SYNC
, SYNC_THROW
, ASYNC
, DUMMY
, NUM_IDS
2009-07-26 02:00:47 +02:00
};
static ID defaultID() { return SYNC; }
2009-07-26 02:00:47 +02:00
static HandlingPattern const& get (ID id);
2009-07-24 17:50:14 +02:00
virtual ~HandlingPattern() {}
/** main functionality: invoke a command, detect errors.
* @return ExecResult object, which might later be used to
* detect errors on execution */
ExecResult invoke (CommandImpl& command, Symbol name) const;
/** @return HandlingPatter describing how the UNDO operation is to be performed */
HandlingPattern const& howtoUNDO() const;
2009-08-11 06:32:29 +02:00
virtual bool isValid() const =0;
protected:
virtual void perform (CommandImpl& command) const =0;
virtual HandlingPattern const& defineUNDO() const =0;
2009-07-24 17:50:14 +02:00
2009-08-11 06:32:29 +02:00
2009-06-08 04:46:07 +02:00
};
////////////////TODO currently just fleshing out the API....
} // namespace control
#endif