Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
ui-dispatcher.hpp
Go to the documentation of this file.
1/*
2 UI-DISPATCHER.hpp - dispatch invocations into the UI event thread
3
4 Copyright (C)
5 2017, 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
66#ifndef STAGE_CTRL_UI_DISPATCHER_H
67#define STAGE_CTRL_UI_DISPATCHER_H
68
69#include "stage/gtk-base.hpp"
70#include "lib/call-queue.hpp"
71#include "lib/format-string.hpp"
72#include "lib/nocopy.hpp"
73
74#include <utility>
75
76
77namespace stage {
78namespace ctrl {
79
80 using std::move;
81 using ::util::_Fmt;
82
83 namespace {
85 inline string
86 generateErrorResponse (lib::Literal problem = "unexpected problem")
87 {
88 static _Fmt messageTemplate{"asynchronous UI response failed: %s (error flag was: %s)"};
89 string response{messageTemplate % problem % lumiera_error()};
90 WARN (stage, "%s", response.c_str());
91 return response;
92 }
93 }
94
95
104 {
106 Glib::Dispatcher dispatcher_;
107
109
110 public:
111 template<class FUN>
112 UiDispatcher(FUN notification)
113 : queue_{}
114 , dispatcher_{}
115 {
116 dispatcher_.connect([=,this]
117 {try {
118 queue_.invoke();
119 }
120 catch (std::exception& problem)
121 {
122 notification (generateErrorResponse(problem.what()));
123 }
124 catch (...)
125 {
126 notification (generateErrorResponse());
127 }
128 });
129 }
130
138 void
140 {
141 queue_.feed (move(op));
142 dispatcher_.emit();
143 }
144 };
145
146
147
148}}// namespace stage::ctrl
149#endif /*STAGE_CTRL_UI_DISPATCHER_H*/
A Queue for function invocations, allowing them to be dispatched on demand.
A threadsafe queue for bound void(void) functors.
CallQueue & feed(Operation &&op)
CallQueue & invoke()
std::function< void(void)> Operation
Inline string literal.
Definition symbol.hpp:78
Helper to dispatch code blocks into the UI event thread for execution.
void event(Operation &&op)
move the given operation into our private dispatcher queue and then schedule dequeuing and invocation...
UiDispatcher(FUN notification)
lib::CallQueue::Operation Operation
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
A front-end for using printf-style formatting.
lumiera_err lumiera_error(void)
Get and clear current error state.
Front-end for printf-style string template interpolation.
A set of basic GTK includes for the UI.
string generateErrorResponse(lib::Literal problem="unexpected problem")
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
Mix-Ins to allow or prohibit various degrees of copying and cloning.