Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
handling-pattern.cpp
Go to the documentation of this file.
1/*
2 HandlingPattern - A skeleton for executing commands, including standard implementations
3
4 Copyright (C)
5 2008, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
22#include "lib/error.hpp"
25#include "lib/format-string.hpp"
26#include "lib/util.hpp"
27
28
29using util::isnil;
30using util::_Fmt;
31
32
33namespace steam {
34namespace control {
35 namespace error = lumiera::error;
36
37 HandlingPattern const&
39 {
40 return getPatternInstance(id);
41 }
42
43
47 {
48 CStr cmdName = cStr(id);
49 TRACE (proc_dbg, "invoking %s...", cmdName);
50 static _Fmt err_pre ("Error state detected, %s *NOT* invoked.");
51 static _Fmt err_post ("Error state after %s invocation.");
52 static _Fmt err_fatal ("Execution of %s raised unknown error.");
53 try
54 {
56 if (errID_pre)
58
59 // execute or undo it...
60 (this->*action) (command);
61
63 if (errID)
65 else
66 return ExecResult();
67 }
68
69
70 catch (lumiera::Error& problem)
71 {
73 WARN (command, "Invocation of %s failed: %s", cmdName, problem.what());
74 TRACE (proc_dbg, "Error flag was: %s", errID.c());
75 return ExecResult (problem);
76 }
77 catch (std::exception& library_problem)
78 {
80 WARN (command, "Invocation of %s failed: %s", cmdName, library_problem.what());
81 TRACE (proc_dbg, "Error flag was: %s", errID.c());
83 }
84 catch (...)
85 {
87 ERROR (command, "Invocation of %s failed with unknown exception; error flag is: %s", cmdName, errID.c());
89 }
90 }
91
92
93
94 /* ====== execution result state object ======= */
95
96
101 : log_(problem.what())
102 {
103 lumiera_error(); // ensure error flag is cleared
104 }
105
106
107 bool
109 {
110 return isnil(log_);
111 }
112
113
114 void
116 {
117 if (!isnil (log_))
118 throw error::Logic ("Command execution failed: "+log_);
119 }
120
121
122}} // namespace steam::control
Token or Atom with distinct identity.
Definition symbol.hpp:120
Interface and Base definition for all Lumiera Exceptions.
Definition error.hpp:65
Steam-Layer Command implementation.
Result (Status) of command execution.
ExecResult()
default: command executed successfully
static HandlingPattern const & get(ID id)
retrieve the pre-configured pattern
ExecResult invoke(CommandImpl &, string id, Action) const
A front-end for using printf-style formatting.
lumiera_err lumiera_error(void)
Get and clear current error state.
Lumiera error handling (C++ interface).
const char * CStr
Definition error.hpp:42
Front-end for printf-style string template interpolation.
Pre-defined command execution skeletons.
A hard wired collection of predefined command handling patterns.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
LumieraError< LERR_(STATE)> State
Definition error.hpp:209
LumieraError< LERR_(FATAL), Logic > Fatal
Definition error.hpp:208
LumieraError< LERR_(LOGIC)> Logic
Definition error.hpp:207
LumieraError< LERR_(EXTERNAL)> External
Definition error.hpp:213
Steam-Layer implementation namespace root.
bool isnil(lib::time::Duration const &dur)
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
Definition symbol.hpp:60
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...