Lumiera  0.pre.03
»edit your freedom«
notification-service.cpp
Go to the documentation of this file.
1 /*
2  NotificationService - public service allowing to push information into the GUI
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
59 #include "include/ui-protocol.hpp"
60 
62 #include "lib/diff/gen-node.hpp"
63 #include "include/logging.h"
64 #include "lib/format-string.hpp"
65 #include "lib/depend.hpp"
66 #include "lib/util.hpp"
67 
68 extern "C" {
70 }
71 
72 #include <utility>
73 #include <string>
74 
75 
76 using lib::diff::GenNode;
81 using util::_Fmt;
82 
83 using std::string;
84 using std::move;
85 
86 
87 namespace stage {
88 
89 
94  void
96  {
97  dispatch_->event ([=]()
98  {
99  ctrl::BusTerm::mark (uiElement, uiMessage);
100  });
101  }
102 
103 
104  void
105  NotificationService::displayInfo (NotifyLevel severity, string const& text)
106  {
107  ID errorLogID = interact::Wizard::getErrorLogID();
108  switch (severity) {
109  case NOTE_ERROR:
110  markError (errorLogID, text);
111  break;
112  case NOTE_INFO:
113  markNote (errorLogID, text);
114  break;
115  case NOTE_WARN:
116  mark (errorLogID, GenNode{string{MARK_Warning}, text});
117  break;
118  default:
119  throw lumiera::error::Logic (_Fmt{"UI Notification with invalid severity %d encountered. "
120  "Given message text was '%s'"} % severity % text);
121  } }
122 
123 
124  void
125  NotificationService::markError (ID uiElement, string const& text)
126  {
127  dispatchMsg (uiElement, GenNode{string{MARK_Error}, text});
128  }
129 
130 
131  void
132  NotificationService::markNote (ID uiElement, string const& text)
133  {
134  dispatchMsg (uiElement, GenNode{string{MARK_Message}, text});
135  }
136 
137 
138  void
139  NotificationService::mark (ID uiElement, GenNode&& stateMarkMsg)
140  {
141  dispatchMsg (uiElement, move (stateMarkMsg));
142  }
143 
144 
145  void
146  NotificationService::mutate (ID uiElement, MutationMessage&& diff)
147  {
148  dispatch_->event ([=]()
149  { // apply and consume diff message stored within closure
150  this->change (uiElement, move(unConst(diff)));
151  });
152  }
153 
154 
155  void
157  {
158  NOTICE (stage, "@GUI: shutdown triggered with explanation '%s'....", cStr(cause));
159  displayInfo (NOTE_ERROR, cause);
160  dispatch_->event ([this]()
161  {
162  uiManager_.terminateUI();
163  });
164  }
165 
166 
167 
168  namespace { // facade implementation details
169 
170 
171  /* ================== define an lumieraorg_GuiNotification instance ======================= */
172 
173  LUMIERA_INTERFACE_INSTANCE (lumieraorg_interfacedescriptor, 0
174  ,lumieraorg_GuiNotificationFacade_descriptor
175  , NULL, NULL, NULL
176  , LUMIERA_INTERFACE_INLINE (name,
177  const char*, (LumieraInterface ifa),
178  { (void)ifa; return "GuiNotification"; }
179  )
180  , LUMIERA_INTERFACE_INLINE (brief,
181  const char*, (LumieraInterface ifa),
182  { (void)ifa; return "Stage Interface: push state update and notification of events into the GUI"; }
183  )
184  , LUMIERA_INTERFACE_INLINE (homepage,
185  const char*, (LumieraInterface ifa),
186  { (void)ifa; return "http://www.lumiera.org/develompent.html" ;}
187  )
188  , LUMIERA_INTERFACE_INLINE (version,
189  const char*, (LumieraInterface ifa),
190  { (void)ifa; return "0.1~pre"; }
191  )
192  , LUMIERA_INTERFACE_INLINE (author,
193  const char*, (LumieraInterface ifa),
194  { (void)ifa; return "Hermann Vosseler"; }
195  )
196  , LUMIERA_INTERFACE_INLINE (email,
197  const char*, (LumieraInterface ifa),
198  { (void)ifa; return "Ichthyostega@web.de"; }
199  )
200  , LUMIERA_INTERFACE_INLINE (copyright,
201  const char*, (LumieraInterface ifa),
202  {
203  (void)ifa;
204  return
205  "Copyright (C) Lumiera.org\n"
206  " 2008 Hermann Vosseler <Ichthyostega@web.de>";
207  }
208  )
209  , LUMIERA_INTERFACE_INLINE (license,
210  const char*, (LumieraInterface ifa),
211  {
212  (void)ifa;
213  return
214  "This program is free software; you can redistribute it and/or modify\n"
215  "it under the terms of the GNU General Public License as published by\n"
216  "the Free Software Foundation; either version 2 of the License, or\n"
217  "(at your option) any later version.\n"
218  "\n"
219  "This program is distributed in the hope that it will be useful,\n"
220  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
221  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
222  "GNU General Public License for more details.\n"
223  "\n"
224  "You should have received a copy of the GNU General Public License\n"
225  "along with this program; if not, write to the Free Software\n"
226  "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA";
227  }
228  )
229  , LUMIERA_INTERFACE_INLINE (state,
230  int, (LumieraInterface ifa),
231  {(void)ifa; return LUMIERA_INTERFACE_EXPERIMENTAL; }
232  )
233  , LUMIERA_INTERFACE_INLINE (versioncmp,
234  int, (const char* a, const char* b),
235  {(void)a;(void)b; return 0;}
236  )
237  );
238 
239 
240 
241 
242 
243  using LERR_(LIFECYCLE);
244 
246 
247 
248 
249  LUMIERA_INTERFACE_INSTANCE (lumieraorg_GuiNotification, 0
250  ,lumieraorg_GuiNotificationService
251  , LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_GuiNotificationFacade_descriptor)
252  , NULL /* on open */
253  , NULL /* on close */
254  , LUMIERA_INTERFACE_INLINE (displayInfo,
255  void, (uint severity, const char* text),
256  {
257  if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, text);
258  else
259  _instance().displayInfo (NotifyLevel(severity), text);
260  }
261  )
262  , LUMIERA_INTERFACE_INLINE (markError,
263  void, (const void* element, const char* text),
264  {
265  if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, text);
266  else
267  _instance().markError (*static_cast<lib::idi::BareEntryID const*> (element), text);
268  }
269  )
270  , LUMIERA_INTERFACE_INLINE (markNote,
271  void, (const void* element, const char* text),
272  {
273  if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, text);
274  else
275  _instance().markNote (*static_cast<lib::idi::BareEntryID const*> (element), text);
276  }
277  )
278  , LUMIERA_INTERFACE_INLINE (mark,
279  void, (const void* element, void* stateMark),
280  {
281  if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, "passing state mark");
282  else
283  _instance().mark (*static_cast<lib::idi::BareEntryID const*> (element), move(*reinterpret_cast<GenNode*> (stateMark)));
284  }
285  )
286  , LUMIERA_INTERFACE_INLINE (mutate,
287  void, (const void* element, void* diff),
288  {
289  if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, "passing diff message");
290  else
291  _instance().mutate (*static_cast<lib::idi::BareEntryID const*> (element), move(*reinterpret_cast<MutationMessage*> (diff)));
292  }
293  )
294  , LUMIERA_INTERFACE_INLINE (triggerGuiShutdown,
295  void, (const char* cause),
296  {
297  if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, cause);
298  else
299  _instance().triggerGuiShutdown (cause);
300  }
301  )
302  );
303 
304  } //(END) facade implementation details
305 
306 
307 
308 
319  , dispatch_{new UiDispatcher{[this](string msg){ displayInfo (NOTE_ERROR, msg); }}}
320  , uiManager_{uiManager}
321  , serviceInstance_( LUMIERA_INTERFACE_REF (lumieraorg_GuiNotification, 0,lumieraorg_GuiNotificationService))
322  {
323  INFO (stage, "GuiNotification Facade opened.");
324  }
325 
326 
327  NotificationService::~NotificationService() { } // emit dtors of embedded objects here...
328 
329 
330 } // namespace stage
Generic Message with an embedded diff, to describe changes to model elements.
Global help controller.
Hard wired key constants and basic definitions for communication with the GUI.
connection point at the UI-Bus.
Definition: bus-term.hpp:105
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
Definition: symbol.hpp:68
NotificationService(ctrl::BusTerm &upLink, ctrl::UiManager &uiManager)
When started, NotificationService connects to the UI-Bus via the provided connection.
void dispatchMsg(ID, lib::diff::GenNode &&)
void terminateUI()
Cause the main event loop to terminate, so the application as a whole unwinds.
Definition: ui-manager.cpp:156
Front-end for printf-style string template interpolation.
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:135
A public service provided by the GUI, implementing the stage::GuiNotification facade interface...
void triggerGuiShutdown(string const &cause) override
causes the GUI to shut down unconditionally
This header is for including and configuring NoBug.
Helper to dispatch code blocks into the UI event thread for execution.
something to be aware of, to be indicated unobtrusively
Opaque message to effect a structural change on a target, which is likewise only known in an abstract...
A front-end for using printf-style formatting.
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:289
Not finished development code.
#define LUMIERA_INTERFACE_INSTANCE(iname, version, name, descriptor, acquire, release,...)
Define an interface instance.
Definition: interface.h:194
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
Manager for global user interface concerns, framework integration and global state.
virtual bool mark(ID subject, GenNode const &mark)
route a state update or notification to the given subject.
Definition: ui-bus.cpp:177
#define LUMIERA_INTERFACE_REF(iname, version, dname)
Return a reference (pointer) to an interface implementation.
Definition: interface.h:128
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
virtual bool change(ID subject, MutationMessage &&diff)
alter and reshape the designated subject by applying the given diff message.
Definition: ui-bus.cpp:211
Generic building block for tree shaped (meta)data structures.
Allow dispatch of self-contained code blocks (lambdas) into the main UI event thread.
Singleton services and Dependency Injection.
lumiera_err lumiera_error_set(lumiera_err nerr, const char *extra)
Set error state for the current thread.
Definition: error-state.c:105
A data record to describe interface, interface instances and plug-in instances.
The Lumiera UI framework and backbone object.
Definition: ui-manager.hpp:97
severe condition to be indicated prominently
possibly interesting info that can be safely ignored
void displayInfo(NotifyLevel, string const &text) override
push a user visible notification text
lib::Depend< NotificationService > _instance
a backdoor for the C Language impl to access the actual SessionCommand implementation...
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption
generic data element node within a tree
Definition: gen-node.hpp:231
Customisable intermediary to abstract mutating operations on arbitrary, hierarchical object-like data...