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) Lumiera.org
5  2007-2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6  2009, Hermann Vosseler <Ichthyostega@web.de>
7  Christian Thaeter <ct@pipapo.org>
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of
12  the License, or (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 
23 * *****************************************************/
24 
25 
49 #include "stage/gtk-base.hpp"
50 
51 #include "lib/error.hpp"
52 #include "lib/thread.hpp"
53 #include "stage/ui-bus.hpp"
54 #include "stage/guifacade.hpp"
56 #include "common/subsys.hpp"
57 #include "lib/nocopy.hpp"
58 
59 extern "C" {
60 #include "common/interface.h"
62 }
63 
64 #include <string>
65 
66 
67 
68 using lumiera::Subsys;
70 using lumiera::error::LUMIERA_ERROR_STATE;
71 using stage::LUMIERA_INTERFACE_INAME(lumieraorg_Gui, 1);
72 
73 using std::string;
74 
75 
76 namespace lumiera {
77 namespace error {
78  /* == definition common error marks for the UI, declared in gtk-base.hpp == */
79  LUMIERA_ERROR_DEFINE (UIWIRING, "GUI state contradicts assumptions in signal wiring");
80 }}
81 
82 
83 namespace stage {
84 
85  namespace { // implementation details
86 
87  using ctrl::UiManager;
88 
89 
90  /**************************************************************************/
96  class GtkLumiera
98  {
99  UiBus uiBus_;
100  UiManager uiManager_;
101 
102  public:
103  GtkLumiera ()
104  : uiBus_{}
105  , uiManager_{uiBus_}
106  { }
107 
108 
109  string
110  run()
111  {
112  string errorMsgBuff;
113  try
114  {
115  // execute the GTK Event Loop____________
116  uiManager_.createApplicationWindow();
117  uiManager_.performMainLoop();
118  } // all went well, regular shutdown
119 
120  catch (lumiera::Error& problem)
121  {
122  errorMsgBuff = problem.what();
123  lumiera_error(); // clear error flag
124  }
125  catch (...)
126  {
127  errorMsgBuff = "unexpected error terminated the GUI.";
128  }
129  if (lumiera_error_peek())
130  errorMsgBuff = string{lumiera_error()};
131 
132  return errorMsgBuff;
133  }
134  };
135  //(End) GUI-Thread.
136  }//(End) impl details
137 
138 
139 
140 
141  bool
142  launchUI (Subsys::SigTerm& reportOnTermination)
143  {
144  try
145  {
146  launchDetached ("GUI-Main"
147  , [reportOnTermination]
148  {
149  string shutdownLog = GtkLumiera{}.run();
150  // inform main thread that the GUI has been shut down...
151  reportOnTermination (&shutdownLog);
152  });
153  return true; // if we reach this line...
154  }
155  catch(...)
156  {
157  const char* errID = lumiera_error(); // clear C-style error flag
158  WARN (stage, "Unexpected error while starting the GUI thread.");
159  if (errID)
160  TRACE (stage, "Error flag was: %s", errID);
161  return false;
162  }
163  }
164 
165 } // namespace stage
166 
167 
168 
169 
170 
171 
172 extern "C" { /* ================== define a lumieraorg_Gui instance ======================= */
173 
174 
175  LUMIERA_INTERFACE_INSTANCE (lumieraorg_interfacedescriptor, 0
176  ,lumieraorg_GuiStarterPlugin_descriptor
177  , NULL, NULL, NULL
178  , LUMIERA_INTERFACE_INLINE (name,
179  const char*, (LumieraInterface ifa),
180  { (void)ifa; return "GuiStarterPlugin"; }
181  )
182  , LUMIERA_INTERFACE_INLINE (brief,
183  const char*, (LumieraInterface ifa),
184  { (void)ifa; return "entry point to start up the Lumiera GTK GUI contained in this dynamic module"; }
185  )
186  , LUMIERA_INTERFACE_INLINE (homepage,
187  const char*, (LumieraInterface ifa),
188  { (void)ifa; return "http://www.lumiera.org/develompent.html" ;}
189  )
190  , LUMIERA_INTERFACE_INLINE (version,
191  const char*, (LumieraInterface ifa),
192  { (void)ifa; return "0.1~pre"; }
193  )
194  , LUMIERA_INTERFACE_INLINE (author,
195  const char*, (LumieraInterface ifa),
196  { (void)ifa; return "Joel Holdsworth, Christian Thaeter, Hermann Vosseler"; }
197  )
198  , LUMIERA_INTERFACE_INLINE (email,
199  const char*, (LumieraInterface ifa),
200  { (void)ifa; return "Lumiera@lists.lumiera.org"; }
201  )
202  , LUMIERA_INTERFACE_INLINE (copyright,
203  const char*, (LumieraInterface ifa),
204  {
205  (void)ifa;
206  return
207  "Copyright (C) Lumiera.org\n"
208  "2007-2008, Joel Holdsworth <joel@airwebreathe.org.uk>\n"
209  "2009, Christian Thaeter <ct@pipapo.org>\n"
210  " Hermann Vosseler <Ichthyostega@web.de>";
211  }
212  )
213  , LUMIERA_INTERFACE_INLINE (license,
214  const char*, (LumieraInterface ifa),
215  {
216  (void)ifa;
217  return
218  "This program is free software; you can redistribute it and/or modify\n"
219  "it under the terms of the GNU General Public License as published by\n"
220  "the Free Software Foundation; either version 2 of the License, or\n"
221  "(at your option) any later version.\n"
222  "\n"
223  "This program is distributed in the hope that it will be useful,\n"
224  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
225  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
226  "GNU General Public License for more details.\n"
227  "\n"
228  "You should have received a copy of the GNU General Public License\n"
229  "along with this program; if not, write to the Free Software\n"
230  "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA";
231  }
232  )
233  , LUMIERA_INTERFACE_INLINE (state,
234  int, (LumieraInterface ifa),
235  {(void)ifa; return LUMIERA_INTERFACE_EXPERIMENTAL; }
236  )
237  , LUMIERA_INTERFACE_INLINE (versioncmp,
238  int, (const char* a, const char* b),
239  {(void)a;(void)b; return 0;}
240  )
241  );
242 
243 
244  LUMIERA_EXPORT( /* ===================== PLUGIN EXPORTS ================================== */
245 
246  LUMIERA_INTERFACE_DEFINE (lumieraorg_Gui, 1
247  ,lumieraorg_GuiStarterPlugin
248  , LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_GuiStarterPlugin_descriptor)
249  , NULL /* on open */
250  , NULL /* on close */
251  , LUMIERA_INTERFACE_INLINE (launchUI,
252  bool, (void* termSig),
253  {
254  return stage::launchUI (*reinterpret_cast<Subsys::SigTerm *> (termSig));
255  }
256  )
257  )
258  );
259 
260 } // extern "C"
void performMainLoop()
start the GTK Main loop and thus activate the UI.
Definition: ui-manager.cpp:138
Dependencies and lifecycle of a partially independent Subsystem of the Application.
Definition: subsys.hpp:70
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:142
void createApplicationWindow()
Set up the first top-level application window.
Definition: ui-manager.cpp:121
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:318
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
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:96
Backbone of the Lumiera GTK GUI.
Definition: ui-bus.hpp:159
Not finished development code.
#define LUMIERA_INTERFACE_INSTANCE(iname, version, name, descriptor, acquire, release,...)
Define an interface instance.
Definition: interface.h:194
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:128
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
lumiera_err lumiera_error(void)
Get and clear current error state.
Definition: error-state.c:124
void launchDetached(ThreadHookable::Launch &&launchBuilder)
Launch an autonomous self-managing thread (and forget about it).
Definition: thread.hpp:750
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:102
A data record to describe interface, interface instances and plug-in instances.
Lumiera public interface.
Definition: advice.cpp:113
The Lumiera UI framework and backbone object.
Definition: ui-manager.hpp:97
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:71
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:80