Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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)
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
51
53#include "lib/diff/gen-node.hpp"
54#include "include/logging.h"
55#include "lib/format-string.hpp"
56#include "lib/depend.hpp"
57#include "lib/util.hpp"
58
59extern "C" {
61}
62
63#include <utility>
64#include <string>
65
66
72using util::_Fmt;
73
74using std::string;
75using std::move;
76
77
78namespace stage {
79
80
85 void
87 {
88 dispatch_->event ([=,this]
89 {
90 ctrl::BusTerm::mark (uiElement, uiMessage);
91 });
92 }
93
94
95 void
96 NotificationService::displayInfo (NotifyLevel severity, string const& text)
97 {
98 ID errorLogID = interact::Wizard::getErrorLogID();
99 switch (severity) {
100 case NOTE_ERROR:
101 markError (errorLogID, text);
102 break;
103 case NOTE_INFO:
104 markNote (errorLogID, text);
105 break;
106 case NOTE_WARN:
107 mark (errorLogID, GenNode{string{MARK_Warning}, text});
108 break;
109 default:
110 throw lumiera::error::Logic (_Fmt{"UI Notification with invalid severity %d encountered. "
111 "Given message text was '%s'"} % severity % text);
112 } }
113
114
115 void
116 NotificationService::markError (ID uiElement, string const& text)
117 {
118 dispatchMsg (uiElement, GenNode{string{MARK_Error}, text});
119 }
120
121
122 void
123 NotificationService::markNote (ID uiElement, string const& text)
124 {
125 dispatchMsg (uiElement, GenNode{string{MARK_Message}, text});
126 }
127
128
129 void
130 NotificationService::mark (ID uiElement, GenNode&& stateMarkMsg)
131 {
132 dispatchMsg (uiElement, move (stateMarkMsg));
133 }
134
135
136 void
138 {
139 dispatch_->event ([=,this]
140 { // apply and consume diff message stored within closure
141 this->change (uiElement, move(unConst(diff)));
142 });
143 }
144
145
146 void
148 {
149 NOTICE (stage, "@GUI: shutdown triggered with explanation '%s'....", cStr(cause));
150 displayInfo (NOTE_ERROR, cause);
151 dispatch_->event ([this]()
152 {
154 });
155 }
156
157
158
159 namespace { // facade implementation details
160
161
162 /* ================== define an lumieraorg_GuiNotification instance ======================= */
163
164 LUMIERA_INTERFACE_INSTANCE (lumieraorg_interfacedescriptor, 0
165 ,lumieraorg_GuiNotificationFacade_descriptor
166 , NULL, NULL, NULL
167 , LUMIERA_INTERFACE_INLINE (name,
168 const char*, (LumieraInterface ifa),
169 { (void)ifa; return "GuiNotification"; }
170 )
171 , LUMIERA_INTERFACE_INLINE (brief,
172 const char*, (LumieraInterface ifa),
173 { (void)ifa; return "Stage Interface: push state update and notification of events into the GUI"; }
174 )
175 , LUMIERA_INTERFACE_INLINE (homepage,
176 const char*, (LumieraInterface ifa),
177 { (void)ifa; return "http://www.lumiera.org/develompent.html" ;}
178 )
179 , LUMIERA_INTERFACE_INLINE (version,
180 const char*, (LumieraInterface ifa),
181 { (void)ifa; return "0.1~pre"; }
182 )
183 , LUMIERA_INTERFACE_INLINE (author,
184 const char*, (LumieraInterface ifa),
185 { (void)ifa; return "Hermann Vosseler"; }
186 )
187 , LUMIERA_INTERFACE_INLINE (email,
188 const char*, (LumieraInterface ifa),
189 { (void)ifa; return "Ichthyostega@web.de"; }
190 )
191 , LUMIERA_INTERFACE_INLINE (copyright,
192 const char*, (LumieraInterface ifa),
193 {
194 (void)ifa;
195 return
196 "Copyright (C)\n"
197 " 2008, Hermann Vosseler <Ichthyostega@web.de>";
198 }
199 )
200 , LUMIERA_INTERFACE_INLINE (license,
201 const char*, (LumieraInterface ifa),
202 {
203 (void)ifa;
204 return
205 "**Lumiera** is free software; you can redistribute it and/or modify it\n"
206 "under the terms of the GNU General Public License as published by the\n"
207 "Free Software Foundation; either version 2 of the License, or (at your\n"
208 "option) any later version. See the file COPYING for further details."
209 ;
210 }
211 )
212 , LUMIERA_INTERFACE_INLINE (state,
213 int, (LumieraInterface ifa),
214 {(void)ifa; return LUMIERA_INTERFACE_EXPERIMENTAL; }
215 )
216 , LUMIERA_INTERFACE_INLINE (versioncmp,
217 int, (const char* a, const char* b),
218 {(void)a;(void)b; return 0;}
219 )
220 );
221
222
223
224
225
226 using LERR_(LIFECYCLE);
227
229
230
231
232 LUMIERA_INTERFACE_INSTANCE (lumieraorg_GuiNotification, 0
233 ,lumieraorg_GuiNotificationService
234 , LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_GuiNotificationFacade_descriptor)
235 , NULL /* on open */
236 , NULL /* on close */
237 , LUMIERA_INTERFACE_INLINE (displayInfo,
238 void, (uint severity, const char* text),
239 {
240 if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, text);
241 else
242 _instance().displayInfo (NotifyLevel(severity), text);
243 }
244 )
245 , LUMIERA_INTERFACE_INLINE (markError,
246 void, (const void* element, const char* text),
247 {
248 if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, text);
249 else
250 _instance().markError (*static_cast<lib::idi::BareEntryID const*> (element), text);
251 }
252 )
253 , LUMIERA_INTERFACE_INLINE (markNote,
254 void, (const void* element, const char* text),
255 {
256 if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, text);
257 else
258 _instance().markNote (*static_cast<lib::idi::BareEntryID const*> (element), text);
259 }
260 )
261 , LUMIERA_INTERFACE_INLINE (mark,
262 void, (const void* element, void* stateMark),
263 {
264 if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, "passing state mark");
265 else
266 _instance().mark (*static_cast<lib::idi::BareEntryID const*> (element), move(*reinterpret_cast<GenNode*> (stateMark)));
267 }
268 )
269 , LUMIERA_INTERFACE_INLINE (mutate,
270 void, (const void* element, void* diff),
271 {
272 if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, "passing diff message");
273 else
274 _instance().mutate (*static_cast<lib::idi::BareEntryID const*> (element), move(*reinterpret_cast<MutationMessage*> (diff)));
275 }
276 )
277 , LUMIERA_INTERFACE_INLINE (triggerGuiShutdown,
278 void, (const char* cause),
279 {
280 if (!_instance) lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, cause);
281 else
282 _instance().triggerGuiShutdown (cause);
283 }
284 )
285 );
286
287 } //(END) facade implementation details
288
289
290
291
301 : BusTerm{lib::idi::EntryID<NotificationService>{}, upLink}
302 , dispatch_{new UiDispatcher{[this](string msg){ displayInfo (NOTE_ERROR, msg); }}}
303 , uiManager_{uiManager}
304 , serviceInstance_( LUMIERA_INTERFACE_REF (lumieraorg_GuiNotification, 0,lumieraorg_GuiNotificationService))
305 {
306 INFO (stage, "GuiNotification Facade opened.");
307 }
308
309
310 NotificationService::~NotificationService() { } // emit dtors of embedded objects here...
311
312
313} // namespace stage
Access point to singletons and other kinds of dependencies designated by type.
Definition depend.hpp:281
Customisable intermediary to abstract mutating operations on arbitrary, hierarchical object-like data...
type erased baseclass for building a combined hash and symbolic ID.
Definition entry-id.hpp:134
Actual implementation of the GuiNotification service within the Lumiera GTK GUI.
void mutate(ID uiElement, MutationMessage &&) override
void triggerGuiShutdown(string const &cause) override
causes the GUI to shut down unconditionally
void markError(ID uiElement, string const &text) override
NotificationService(ctrl::BusTerm &upLink, ctrl::UiManager &uiManager)
When started, NotificationService connects to the UI-Bus via the provided connection.
void mark(ID uiElement, GenNode &&) override
void displayInfo(NotifyLevel, string const &text) override
push a user visible notification text
void markNote(ID uiElement, string const &text) override
std::unique_ptr< ctrl::UiDispatcher > dispatch_
void dispatchMsg(ID, lib::diff::GenNode &&)
connection point at the UI-Bus.
Definition bus-term.hpp:98
virtual bool mark(ID subject, GenNode const &mark)
route a state update or notification to the given subject.
Definition ui-bus.cpp:151
virtual bool change(ID subject, MutationMessage &&diff)
alter and reshape the designated subject by applying the given diff message.
Definition ui-bus.cpp:185
EntryID const & ID
Definition bus-term.hpp:107
Helper to dispatch code blocks into the UI event thread for execution.
The Lumiera UI framework and backbone object.
void terminateUI()
Cause the main event loop to terminate, so the application as a whole unwinds.
static ID getErrorLogID()
Definition wizard.hpp:90
A front-end for using printf-style formatting.
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:96
#define LERR_(_NAME_)
Definition error.hpp:45
Front-end for printf-style string template interpolation.
Generic building block for tree shaped (meta)data structures.
unsigned int uint
Definition integral.hpp:29
A data record to describe interface, interface instances and plug-in instances.
@ LUMIERA_INTERFACE_EXPERIMENTAL
Not finished development code.
#define LUMIERA_INTERFACE_REF(iname, version, dname)
Return a reference (pointer) to an interface implementation.
Definition interface.h:119
#define LUMIERA_INTERFACE_INSTANCE(iname, version, name, descriptor, acquire, release,...)
Define an interface instance.
Definition interface.h:185
lumiera_interface * LumieraInterface
Definition interface.h:355
return NULL
Definition llist.h:586
This header is for including and configuring NoBug.
Generic Message with an embedded diff, to describe changes to model elements.
Implementation namespace for support and library code.
LumieraError< LERR_(LOGIC)> Logic
Definition error.hpp:207
lib::Depend< NotificationService > _instance
a backdoor for the C Language impl to access the actual SessionCommand implementation....
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
@ NOTE_INFO
possibly interesting info that can be safely ignored
@ NOTE_ERROR
severe condition to be indicated prominently
@ NOTE_WARN
something to be aware of, to be indicated unobtrusively
const Symbol MARK_Message
const Symbol MARK_Error
const Symbol MARK_Warning
A public service provided by the GUI, implementing the stage::GuiNotification facade interface.
generic data element node within a tree
Definition gen-node.hpp:224
Opaque message to effect a structural change on a target, which is likewise only known in an abstract...
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
Definition symbol.hpp:60
Allow dispatch of self-contained code blocks (lambdas) into the main UI event thread.
Manager for global user interface concerns, framework integration and global state.
Hard wired key constants and basic definitions for communication with the GUI.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Global help controller.