Lumiera  0.pre.03
»edit your freedom«
gtk-lumiera.cpp
Go to the documentation of this file.
1 /*
2  GtkLumiera - entry point for the lumiera GUI loaded as shared module
3 
4  Copyright (C)
5  2007-2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6  2009, Hermann Vosseler <Ichthyostega@web.de>
7  2016,2017 Hermann Vosseler <Ichthyostega@web.de>
8 
9   **Lumiera** is free software; you can redistribute it and/or modify it
10   under the terms of the GNU General Public License as published by the
11   Free Software Foundation; either version 2 of the License, or (at your
12   option) any later version. See the file COPYING for further details.
13 
14 * *****************************************************************/
15 
16 
40 #include "stage/gtk-base.hpp"
41 
42 #include "lib/error.hpp"
43 #include "lib/thread.hpp"
44 #include "stage/ui-bus.hpp"
45 #include "stage/guifacade.hpp"
47 #include "common/subsys.hpp"
48 #include "lib/nocopy.hpp"
49 
50 extern "C" {
51 #include "common/interface.h"
53 }
54 
55 #include <string>
56 
57 
58 
59 using lumiera::Subsys;
61 using lumiera::error::LUMIERA_ERROR_STATE;
62 using stage::LUMIERA_INTERFACE_INAME(lumieraorg_Gui, 1);
63 
64 using std::string;
65 
66 
67 namespace lumiera {
68 namespace error {
69  /* == definition common error marks for the UI, declared in gtk-base.hpp == */
70  LUMIERA_ERROR_DEFINE (UIWIRING, "GUI state contradicts assumptions in signal wiring");
71 }}
72 
73 
74 namespace stage {
75 
76  namespace { // implementation details
77 
78  using ctrl::UiManager;
79 
80 
81  /**************************************************************************/
87  class GtkLumiera
89  {
90  UiBus uiBus_;
91  UiManager uiManager_;
92 
93  public:
94  GtkLumiera ()
95  : uiBus_{}
96  , uiManager_{uiBus_}
97  { }
98 
99 
100  string
101  run()
102  {
103  string errorMsgBuff;
104  try
105  {
106  // execute the GTK Event Loop____________
107  uiManager_.createApplicationWindow();
108  uiManager_.performMainLoop();
109  } // all went well, regular shutdown
110 
111  catch (lumiera::Error& problem)
112  {
113  errorMsgBuff = problem.what();
114  lumiera_error(); // clear error flag
115  }
116  catch (...)
117  {
118  errorMsgBuff = "unexpected error terminated the GUI.";
119  }
120  if (lumiera_error_peek())
121  errorMsgBuff = string{lumiera_error()};
122 
123  return errorMsgBuff;
124  }
125  };
126  //(End) GUI-Thread.
127  }//(End) impl details
128 
129 
130 
131 
132  bool
133  launchUI (Subsys::SigTerm& reportOnTermination)
134  {
135  try
136  {
137  launchDetached ("GUI-Main"
138  , [reportOnTermination]
139  {
140  string shutdownLog = GtkLumiera{}.run();
141  // inform main thread that the GUI has been shut down...
142  reportOnTermination (&shutdownLog);
143  });
144  return true; // if we reach this line...
145  }
146  catch(...)
147  {
148  const char* errID = lumiera_error(); // clear C-style error flag
149  WARN (stage, "Unexpected error while starting the GUI thread.");
150  if (errID)
151  TRACE (stage, "Error flag was: %s", errID);
152  return false;
153  }
154  }
155 
156 } // namespace stage
157 
158 
159 
160 
161 
162 
163 extern "C" { /* ================== define a lumieraorg_Gui instance ======================= */
164 
165 
166  LUMIERA_INTERFACE_INSTANCE (lumieraorg_interfacedescriptor, 0
167  ,lumieraorg_GuiStarterPlugin_descriptor
168  , NULL, NULL, NULL
169  , LUMIERA_INTERFACE_INLINE (name,
170  const char*, (LumieraInterface ifa),
171  { (void)ifa; return "GuiStarterPlugin"; }
172  )
173  , LUMIERA_INTERFACE_INLINE (brief,
174  const char*, (LumieraInterface ifa),
175  { (void)ifa; return "entry point to start up the Lumiera GTK GUI contained in this dynamic module"; }
176  )
177  , LUMIERA_INTERFACE_INLINE (homepage,
178  const char*, (LumieraInterface ifa),
179  { (void)ifa; return "http://www.lumiera.org/develompent.html" ;}
180  )
181  , LUMIERA_INTERFACE_INLINE (version,
182  const char*, (LumieraInterface ifa),
183  { (void)ifa; return "0.1~pre"; }
184  )
185  , LUMIERA_INTERFACE_INLINE (author,
186  const char*, (LumieraInterface ifa),
187  { (void)ifa; return "Joel Holdsworth, Christian Thaeter, Hermann Vosseler"; }
188  )
189  , LUMIERA_INTERFACE_INLINE (email,
190  const char*, (LumieraInterface ifa),
191  { (void)ifa; return "Lumiera@lists.lumiera.org"; }
192  )
193  , LUMIERA_INTERFACE_INLINE (copyright,
194  const char*, (LumieraInterface ifa),
195  {
196  (void)ifa;
197  return
198  "Copyright (C)\n"
199  " 2007-2008, Joel Holdsworth <joel@airwebreathe.org.uk>\n"
200  " 2009, Christian Thaeter <ct@pipapo.org>\n"
201  " 2009, Hermann Vosseler <Ichthyostega@web.de>"
202  " 2016,2017, Hermann Vosseler <Ichthyostega@web.de>";
203  }
204  )
205  , LUMIERA_INTERFACE_INLINE (license,
206  const char*, (LumieraInterface ifa),
207  {
208  (void)ifa;
209  return
210  "**Lumiera** is free software; you can redistribute it and/or modify it\n"
211  "under the terms of the GNU General Public License as published by the\n"
212  "Free Software Foundation; either version 2 of the License, or (at your\n"
213  "option) any later version. See the file COPYING for further details."
214  ;
215  }
216  )
217  , LUMIERA_INTERFACE_INLINE (state,
218  int, (LumieraInterface ifa),
219  {(void)ifa; return LUMIERA_INTERFACE_EXPERIMENTAL; }
220  )
221  , LUMIERA_INTERFACE_INLINE (versioncmp,
222  int, (const char* a, const char* b),
223  {(void)a;(void)b; return 0;}
224  )
225  );
226 
227 
228  LUMIERA_EXPORT( /* ===================== PLUGIN EXPORTS ================================== */
229 
230  LUMIERA_INTERFACE_DEFINE (lumieraorg_Gui, 1
231  ,lumieraorg_GuiStarterPlugin
232  , LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_GuiStarterPlugin_descriptor)
233  , NULL /* on open */
234  , NULL /* on close */
235  , LUMIERA_INTERFACE_INLINE (launchUI,
236  bool, (void* termSig),
237  {
238  return stage::launchUI (*reinterpret_cast<Subsys::SigTerm *> (termSig));
239  }
240  )
241  )
242  );
243 
244 } // extern "C"
void performMainLoop()
start the GTK Main loop and thus activate the UI.
Definition: ui-manager.cpp:129
Dependencies and lifecycle of a partially independent Subsystem of the Application.
Definition: subsys.hpp:61
lumiera_err lumiera_error_peek(void)
Check current error state without clearing it Please avoid this function and use lumiera_error() if p...
Definition: error-state.c:133
void createApplicationWindow()
Set up the first top-level application window.
Definition: ui-manager.cpp:112
Under construction: the top level UI controller.
LUMIERA_EXPORT(LUMIERA_INTERFACE_DEFINE(lumieraorg_interface, 0, lumieraorg_interface, NULL, NULL, NULL, LUMIERA_INTERFACE_MAP(open, lumiera_interface_open), LUMIERA_INTERFACE_MAP(close, lumiera_interface_close), LUMIERA_INTERFACE_MAP(version, lumiera_interface_version),))
Definition of &#39;the mother of all interfaces&#39; since this interface is singleton and required for any c...
Definition: interface.c:309
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
virtual CStr what() const noexcept override
std::exception interface : yield a diagnostic message
Implement the necessary steps for actually making the Lumiera UI available.
Definition: gtk-lumiera.cpp:87
Backbone of the Lumiera GTK GUI.
Definition: ui-bus.hpp:150
Not finished development code.
#define LUMIERA_INTERFACE_INSTANCE(iname, version, name, descriptor, acquire, release,...)
Define an interface instance.
Definition: interface.h:185
Lumiera interface macros and structures.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Manager for global user interface concerns, framework integration and global state.
Describing dependencies and lifecycle of the application&#39;s primary parts.
#define LUMIERA_INTERFACE_REF(iname, version, dname)
Return a reference (pointer) to an interface implementation.
Definition: interface.h:119
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
lumiera_err lumiera_error(void)
Get and clear current error state.
Definition: error-state.c:115
void launchDetached(ThreadHookable::Launch &&launchBuilder)
Launch an autonomous self-managing thread (and forget about it).
Definition: thread.hpp:742
Convenience front-end to simplify and codify basic thread handling.
Lumiera error handling (C++ interface).
#define LUMIERA_INTERFACE_INAME(name, version)
Construct a type identifier for an interface.
Definition: interface.h:93
A data record to describe interface, interface instances and plug-in instances.
Lumiera public interface.
Definition: advice.cpp:104
The Lumiera UI framework and backbone object.
Definition: ui-manager.hpp:88
Interface for the GUI loader and for accessing the GUI interface from the lower layers of Lumiera...
A set of basic GTK includes for the UI.
Interface and Base definition for all Lumiera Exceptions.
Definition: error.hpp:62
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:71