2008-12-07 08:46:44 +01:00
/*
2008-12-13 21:10:07 +01:00
GuiStart - entry point for the lumiera GUI loaded as shared module
2010-12-17 23:28:49 +01:00
2008-12-07 08:46:44 +01:00
Copyright ( C ) Lumiera . org
2007 - 2008 , Joel Holdsworth < joel @ airwebreathe . org . uk >
2011-02-05 23:53:37 +01:00
2009 , Hermann Vosseler < Ichthyostega @ web . de >
Christian Thaeter < ct @ pipapo . org >
2010-12-17 23:28:49 +01:00
2008-12-07 08:46:44 +01:00
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License as
2010-12-17 23:28:49 +01:00
published by the Free Software Foundation ; either version 2 of
the License , or ( at your option ) any later version .
2008-12-07 08:46:44 +01:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2010-12-17 23:28:49 +01:00
2008-12-07 08:46:44 +01:00
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
2010-12-17 23:28:49 +01:00
2008-12-07 08:46:44 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-01-10 15:29:11 +01:00
2008-12-13 21:10:07 +01:00
/** @file guistart.cpp
2008-12-07 08:46:44 +01:00
* * Start up the Lumiera GTK GUI when loading it as dynamic module .
* * This plugin is linked together with the Lumiera GUI code ; when loaded as
2009-01-10 15:29:11 +01:00
* * Lumiera plugin , it allows to kick off the GTK main event loop and thus to bring
* * up the GUI . The loading and shutdown process is carried out by gui : : GuiFacade and
2008-12-07 08:46:44 +01:00
* * controlled by lumiera : : AppState , which in turn is activated by Lumiera main ( ) .
* *
* * After successfully loading this module , a call to # kickOff is expected to be
* * issued , passing a termination signal ( callback ) to be executed when the GUI
2009-01-10 15:29:11 +01:00
* * terminates . The \ c kickOff ( ) call remains blocked within the main GTK event loop ;
* * thus typically this call should be issued within a separate dedicated GUI thread .
2009-01-03 16:57:51 +01:00
* * Especially , the gui : : GuiRunner will ensure this to happen .
* *
* * Prior to entering the GTK event loop , all primary " business " interface of the GUI
* * will be opened ( currently as of 1 / 09 this is the interface gui : : GuiNotification . )
2008-12-07 08:46:44 +01:00
* *
* * @ see lumiera : : AppState
* * @ see gui : : GuiFacade
* * @ see guifacade . cpp
2009-01-03 16:57:51 +01:00
* * @ see gui : : GtkLumiera # main the GTK GUI main
2008-12-07 08:46:44 +01:00
*/
2014-08-17 08:03:21 +02:00
//--------------------tricky special Include sequence
# include "lib/hash-standard.hpp" // need to be before any inclusion of <string>
2009-01-10 18:01:09 +01:00
# include <locale> // need to include this to prevent errors when libintl.h defines textdomain (because gtk-lumiera removes the def when ENABLE_NLS isn't defined)
2008-12-07 08:46:44 +01:00
2009-01-10 18:01:09 +01:00
# include "gui/gtk-lumiera.hpp" // need to include this before nobugcfg.h, because types.h from GTK tries to shaddow the ERROR macro from windows, which kills nobug's ERROR macro
2014-08-17 08:03:21 +02:00
//--------------------tricky special Include sequence
2009-02-02 05:25:49 +01:00
2009-01-03 16:57:51 +01:00
# include "lib/error.hpp"
2008-12-07 08:46:44 +01:00
# include "gui/guifacade.hpp"
2009-01-10 15:29:11 +01:00
# include "gui/notification-service.hpp"
2009-02-08 02:02:03 +01:00
# include "gui/display-service.hpp"
2008-12-18 08:12:40 +01:00
# include "common/subsys.hpp"
2009-01-16 02:18:58 +01:00
# include "backend/thread-wrapper.hpp"
2013-10-20 03:19:36 +02:00
# include "lib/depend.hpp"
2008-12-07 08:46:44 +01:00
extern " C " {
2008-12-18 08:54:33 +01:00
# include "common/interface.h"
# include "common/interfacedescriptor.h"
2008-12-07 08:46:44 +01:00
}
2014-04-03 22:42:48 +02:00
# include <functional>
2009-01-10 15:29:11 +01:00
# include <string>
2008-12-08 06:50:19 +01:00
2008-12-07 08:46:44 +01:00
2009-01-10 15:29:11 +01:00
using std : : string ;
2009-02-01 01:01:44 +01:00
using backend : : Thread ;
2014-04-03 22:42:48 +02:00
using std : : bind ;
2008-12-07 08:46:44 +01:00
using lumiera : : Subsys ;
2009-01-15 15:16:45 +01:00
using lumiera : : error : : LUMIERA_ERROR_STATE ;
2008-12-07 08:46:44 +01:00
using gui : : LUMIERA_INTERFACE_INAME ( lumieraorg_Gui , 1 ) ;
namespace gui {
namespace { // implementation details
2013-10-24 23:06:36 +02:00
/**************************************************************************/ /**
2009-01-04 15:21:04 +01:00
* Implement the necessary steps for actually making the Lumiera Gui available .
* Open the business interface ( s ) and start up the GTK GUI main event loop .
2008-12-07 08:46:44 +01:00
*/
2009-01-10 15:29:11 +01:00
struct GuiLifecycle
2008-12-07 08:46:44 +01:00
{
2009-01-10 15:29:11 +01:00
string error_ ;
Subsys : : SigTerm & reportOnTermination_ ;
NotificationService activateNotificationService_ ;
2009-02-08 02:02:03 +01:00
DisplayService activateDisplayService_ ;
2009-01-10 15:29:11 +01:00
GuiLifecycle ( Subsys : : SigTerm & terminationHandler )
: reportOnTermination_ ( terminationHandler )
2009-02-08 02:02:03 +01:00
, activateNotificationService_ ( ) // opens the GuiNotification facade interface
, activateDisplayService_ ( ) // opens the gui::Display facade interface
2009-01-10 15:29:11 +01:00
{ }
~ GuiLifecycle ( )
{
2009-01-10 16:15:17 +01:00
reportOnTermination_ ( & error_ ) ; // inform main thread that the GUI has been shut down.
2009-01-10 15:29:11 +01:00
}
2008-12-07 08:46:44 +01:00
2009-01-10 15:29:11 +01:00
void
run ( )
2008-12-07 08:46:44 +01:00
{
2009-01-03 16:57:51 +01:00
try
{
2009-01-10 15:29:11 +01:00
int argc = 0 ;
char * argv [ ] = { } ; // dummy command line for GTK
2009-01-03 16:57:51 +01:00
2011-02-06 21:23:34 +01:00
// execute the GTK Event Loop____________
GtkLumiera : : application ( ) . main ( argc , argv ) ;
2009-01-03 16:57:51 +01:00
if ( ! lumiera_error_peek ( ) )
2009-02-02 05:25:49 +01:00
return ; // all went well, normal shutdown
2009-01-03 16:57:51 +01:00
}
catch ( lumiera : : Error & problem )
{
2009-01-10 15:29:11 +01:00
error_ = problem . what ( ) ;
lumiera_error ( ) ; // clear error flag
2009-01-03 16:57:51 +01:00
return ;
}
catch ( . . . ) { }
2009-01-10 15:29:11 +01:00
error_ = " unexpected error terminated the GUI. " ;
2009-01-03 16:57:51 +01:00
return ;
2008-12-07 08:46:44 +01:00
}
} ;
2009-01-14 12:28:24 +01:00
void
runGUI ( Subsys : : SigTerm & reportTermination )
{
GuiLifecycle ( reportTermination ) . run ( ) ;
}
2008-12-07 08:46:44 +01:00
} // (End) impl details
2009-01-10 15:29:11 +01:00
2009-01-15 15:16:45 +01:00
bool
2009-01-14 12:28:24 +01:00
kickOff ( Subsys : : SigTerm & terminationHandle )
2009-01-10 15:29:11 +01:00
{
2009-01-15 15:16:45 +01:00
try
{
Thread ( " GUI-Main " , bind ( & runGUI , terminationHandle ) ) ;
return true ; // if we reach this line...
}
catch ( . . . )
{
if ( ! lumiera_error_peek ( ) )
LUMIERA_ERROR_SET ( gui , STATE , " unexpected error when starting the GUI thread " ) ;
return false ;
2009-02-02 05:25:49 +01:00
} // note: lumiera_error state remains set
2009-01-10 15:29:11 +01:00
}
2008-12-07 08:46:44 +01:00
} // namespace gui
extern " C " { /* ================== define an lumieraorg_Gui instance ======================= */
LUMIERA_INTERFACE_INSTANCE ( lumieraorg_interfacedescriptor , 0
, lumieraorg_GuiStarterPlugin_descriptor
, NULL , NULL , NULL
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( name ,
2008-12-30 07:28:34 +01:00
const char * , ( LumieraInterface ifa ) ,
{ ( void ) ifa ; return " GuiStarterPlugin " ; }
2008-12-07 08:46:44 +01:00
)
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( brief ,
2008-12-30 07:28:34 +01:00
const char * , ( LumieraInterface ifa ) ,
{ ( void ) ifa ; return " entry point to start up the Lumiera GTK GUI contained in this dynamic module " ; }
2008-12-07 08:46:44 +01:00
)
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( homepage ,
2008-12-30 07:28:34 +01:00
const char * , ( LumieraInterface ifa ) ,
{ ( void ) ifa ; return " http://www.lumiera.org/develompent.html " ; }
2008-12-07 08:46:44 +01:00
)
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( version ,
2008-12-30 07:28:34 +01:00
const char * , ( LumieraInterface ifa ) ,
{ ( void ) ifa ; return " 0.1~pre " ; }
2008-12-07 08:46:44 +01:00
)
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( author ,
2008-12-30 07:28:34 +01:00
const char * , ( LumieraInterface ifa ) ,
{ ( void ) ifa ; return " Joel Holdsworth, Christian Thaeter, Hermann Vosseler " ; }
2008-12-07 08:46:44 +01:00
)
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( email ,
2008-12-30 07:28:34 +01:00
const char * , ( LumieraInterface ifa ) ,
{ ( void ) ifa ; return " Lumiera@lists.lumiera.org " ; }
2008-12-07 08:46:44 +01:00
)
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( copyright ,
2008-12-30 07:28:34 +01:00
const char * , ( LumieraInterface ifa ) ,
2008-12-07 08:46:44 +01:00
{
2008-12-30 07:28:34 +01:00
( void ) ifa ;
2008-12-07 08:46:44 +01:00
return
2008-12-08 06:50:19 +01:00
" Copyright (C) Lumiera.org \n "
2008-12-07 08:46:44 +01:00
" 2007-2008, Joel Holdsworth <joel@airwebreathe.org.uk> \n "
2011-02-05 20:56:51 +01:00
" 2009, Christian Thaeter <ct@pipapo.org> \n "
2008-12-07 08:46:44 +01:00
" Hermann Vosseler <Ichthyostega@web.de> " ;
}
)
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( license ,
2008-12-30 07:28:34 +01:00
const char * , ( LumieraInterface ifa ) ,
2008-12-07 08:46:44 +01:00
{
2008-12-30 07:28:34 +01:00
( void ) ifa ;
2008-12-07 08:46:44 +01:00
return
" This program is free software; you can redistribute it and/or modify \n "
" it under the terms of the GNU General Public License as published by \n "
" the Free Software Foundation; either version 2 of the License, or \n "
" (at your option) any later version. \n "
" \n "
" This program is distributed in the hope that it will be useful, \n "
" but WITHOUT ANY WARRANTY; without even the implied warranty of \n "
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n "
" GNU General Public License for more details. \n "
" \n "
" You should have received a copy of the GNU General Public License \n "
" along with this program; if not, write to the Free Software \n "
" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA " ;
}
)
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( state ,
2008-12-30 07:28:34 +01:00
int , ( LumieraInterface ifa ) ,
{ ( void ) ifa ; return LUMIERA_INTERFACE_EXPERIMENTAL ; }
2008-12-07 08:46:44 +01:00
)
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( versioncmp ,
2008-12-07 08:46:44 +01:00
int , ( const char * a , const char * b ) ,
{ return 0 ; } ////////////////////////////////////////////TODO define version ordering
)
) ;
LUMIERA_EXPORT ( /* ===================== PLUGIN EXPORTS ================================== */
LUMIERA_INTERFACE_DEFINE ( lumieraorg_Gui , 1
, lumieraorg_GuiStarterPlugin
, LUMIERA_INTERFACE_REF ( lumieraorg_interfacedescriptor , 0 , lumieraorg_GuiStarterPlugin_descriptor )
, NULL /* on open */
, NULL /* on close */
2014-03-16 02:21:07 +01:00
, LUMIERA_INTERFACE_INLINE ( kickOff ,
2009-01-15 15:16:45 +01:00
bool , ( void * termSig ) ,
2008-12-07 08:46:44 +01:00
{
2009-01-15 15:16:45 +01:00
return gui : : kickOff ( * reinterpret_cast < Subsys : : SigTerm * > ( termSig ) ) ;
2008-12-07 08:46:44 +01:00
}
)
)
) ;
} // extern "C"