2008-12-01 08:04:43 +01:00
|
|
|
/*
|
|
|
|
|
GuiFacade - access point for communicating with the Lumiera GTK GUI
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
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 02139, USA.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "gui/guifacade.hpp"
|
2009-02-01 00:02:50 +01:00
|
|
|
#include "include/guinotification-facade.h"
|
2008-12-28 05:20:35 +01:00
|
|
|
#include "lib/sync.hpp"
|
2008-12-27 00:53:35 +01:00
|
|
|
#include "lib/error.hpp"
|
2008-12-17 17:53:32 +01:00
|
|
|
#include "lib/singleton.hpp"
|
2009-07-20 04:21:24 +02:00
|
|
|
#include "lib/functor-util.hpp"
|
2008-12-18 08:12:40 +01:00
|
|
|
#include "common/instancehandle.hpp"
|
2008-12-01 08:04:43 +01:00
|
|
|
|
2008-12-06 22:01:44 +01:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
2008-12-08 03:01:02 +01:00
|
|
|
#include <tr1/functional>
|
2008-12-04 04:21:02 +01:00
|
|
|
#include <string>
|
2008-12-01 08:04:43 +01:00
|
|
|
|
|
|
|
|
|
2008-12-04 04:21:02 +01:00
|
|
|
namespace gui {
|
|
|
|
|
|
|
|
|
|
using std::string;
|
2008-12-06 22:01:44 +01:00
|
|
|
using boost::scoped_ptr;
|
2008-12-08 03:01:02 +01:00
|
|
|
using std::tr1::bind;
|
|
|
|
|
using std::tr1::placeholders::_1;
|
2008-12-06 22:01:44 +01:00
|
|
|
using lumiera::Subsys;
|
2008-12-07 05:36:02 +01:00
|
|
|
using lumiera::InstanceHandle;
|
2008-12-08 03:01:02 +01:00
|
|
|
using util::dispatchSequenced;
|
2008-12-28 05:20:35 +01:00
|
|
|
using lib::Sync;
|
2008-12-29 06:07:28 +01:00
|
|
|
using lib::RecursiveLock_NoWait;
|
2008-12-08 05:20:14 +01:00
|
|
|
|
2008-12-01 08:04:43 +01:00
|
|
|
|
2008-12-06 22:01:44 +01:00
|
|
|
|
2010-02-13 17:41:16 +01:00
|
|
|
/** load and start the GUI as a plugin */
|
2008-12-06 22:01:44 +01:00
|
|
|
struct GuiRunner
|
|
|
|
|
: public GuiFacade
|
2008-12-01 08:04:43 +01:00
|
|
|
{
|
2008-12-07 05:36:02 +01:00
|
|
|
typedef InstanceHandle<LUMIERA_INTERFACE_INAME(lumieraorg_Gui, 1)> GuiHandle;
|
2008-12-06 22:01:44 +01:00
|
|
|
|
|
|
|
|
GuiHandle theGUI_;
|
2008-12-01 08:04:43 +01:00
|
|
|
|
|
|
|
|
|
2008-12-07 08:46:44 +01:00
|
|
|
GuiRunner (Subsys::SigTerm terminationHandle)
|
|
|
|
|
: theGUI_("lumieraorg_Gui", 1, 1, "lumieraorg_GuiStarterPlugin") // load GuiStarterPlugin
|
2008-12-01 08:04:43 +01:00
|
|
|
{
|
2008-12-07 05:36:02 +01:00
|
|
|
ASSERT (theGUI_);
|
2009-01-15 15:16:45 +01:00
|
|
|
bool res = this->kickOff (terminationHandle);
|
2009-01-03 16:05:04 +01:00
|
|
|
|
2009-01-15 15:16:45 +01:00
|
|
|
if (!res || lumiera_error_peek())
|
2008-12-07 08:46:44 +01:00
|
|
|
throw lumiera::error::Fatal("failed to bring up GUI",lumiera_error());
|
2008-12-01 08:04:43 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-07 08:46:44 +01:00
|
|
|
~GuiRunner () { }
|
|
|
|
|
|
|
|
|
|
|
2009-01-15 15:16:45 +01:00
|
|
|
bool kickOff (Subsys::SigTerm& terminationHandle)
|
2008-12-07 08:46:44 +01:00
|
|
|
{
|
2009-01-15 15:16:45 +01:00
|
|
|
return theGUI_->kickOff (reinterpret_cast<void*> (&terminationHandle));
|
2008-12-01 08:04:43 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-12-06 22:01:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-13 17:41:16 +01:00
|
|
|
namespace { // implementation of GUI-"Subsystem" : start GUI through GuiStarterPlugin
|
2008-12-06 22:01:44 +01:00
|
|
|
|
2008-12-07 08:46:44 +01:00
|
|
|
scoped_ptr<GuiRunner> facade (0);
|
2008-12-06 22:01:44 +01:00
|
|
|
|
2009-01-03 16:05:04 +01:00
|
|
|
|
2008-12-06 22:01:44 +01:00
|
|
|
class GuiSubsysDescriptor
|
2008-12-28 05:20:35 +01:00
|
|
|
: public lumiera::Subsys,
|
2008-12-29 06:07:28 +01:00
|
|
|
public Sync<RecursiveLock_NoWait>
|
2008-12-06 22:01:44 +01:00
|
|
|
{
|
|
|
|
|
operator string () const { return "Lumiera GTK GUI"; }
|
|
|
|
|
|
|
|
|
|
bool
|
2008-12-08 03:01:02 +01:00
|
|
|
shouldStart (lumiera::Option& opts)
|
2008-12-06 22:01:44 +01:00
|
|
|
{
|
2008-12-08 03:01:02 +01:00
|
|
|
if (opts.isHeadless() || 0 < opts.getPort())
|
|
|
|
|
{
|
2009-01-24 03:13:08 +01:00
|
|
|
INFO (guifacade, "*not* starting the GUI...");
|
2008-12-08 03:01:02 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return true;
|
2008-12-06 22:01:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
start (lumiera::Option&, Subsys::SigTerm termination)
|
|
|
|
|
{
|
2008-12-28 05:20:35 +01:00
|
|
|
Lock guard (this);
|
2008-12-08 03:01:02 +01:00
|
|
|
if (facade) return false; // already started
|
|
|
|
|
|
|
|
|
|
facade.reset (
|
|
|
|
|
new GuiRunner ( // trigger loading load the GuiStarterPlugin...
|
|
|
|
|
dispatchSequenced( closeOnTermination_ // on termination call this->closeGuiModule(*) first
|
|
|
|
|
, termination))); //...followed by invoking the given termSignal
|
2008-12-07 08:46:44 +01:00
|
|
|
return true;
|
2008-12-06 22:01:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
triggerShutdown () throw()
|
|
|
|
|
{
|
2008-12-07 08:46:44 +01:00
|
|
|
try { GuiNotification::facade().triggerGuiShutdown ("Application shutdown"); }
|
|
|
|
|
|
|
|
|
|
catch (...){}
|
2008-12-06 22:01:44 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-08 03:01:02 +01:00
|
|
|
bool
|
|
|
|
|
checkRunningState () throw()
|
|
|
|
|
{
|
|
|
|
|
return (facade);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-03 16:05:04 +01:00
|
|
|
|
2008-12-08 03:01:02 +01:00
|
|
|
void
|
2009-01-10 16:15:17 +01:00
|
|
|
closeGuiModule (std::string *)
|
2008-12-08 03:01:02 +01:00
|
|
|
{
|
2008-12-28 05:20:35 +01:00
|
|
|
Lock guard (this);
|
2008-12-08 03:01:02 +01:00
|
|
|
if (!facade)
|
|
|
|
|
{
|
2009-01-24 03:13:08 +01:00
|
|
|
WARN (guifacade, "Termination signal invoked, but GUI is currently closed. "
|
|
|
|
|
"Probably this is due to some broken startup logic and should be fixed.");
|
2008-12-08 03:01:02 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
facade.reset (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Subsys::SigTerm closeOnTermination_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
GuiSubsysDescriptor()
|
|
|
|
|
: closeOnTermination_ (bind (&GuiSubsysDescriptor::closeGuiModule, this, _1))
|
|
|
|
|
{ }
|
|
|
|
|
|
2008-12-13 21:10:23 +01:00
|
|
|
~GuiSubsysDescriptor()
|
|
|
|
|
{
|
|
|
|
|
if (facade)
|
|
|
|
|
{
|
2009-01-24 03:13:08 +01:00
|
|
|
WARN (guifacade, "GUI subsystem terminates, but GuiFacade isn't properly closed. "
|
2008-12-13 21:10:23 +01:00
|
|
|
"Closing it forcedly; this indicates broken startup logic and should be fixed.");
|
|
|
|
|
try { facade.reset (0); }
|
2009-01-24 03:13:08 +01:00
|
|
|
catch(...) { WARN_IF (lumiera_error_peek(), guifacade, "Ignoring error: %s", lumiera_error()); }
|
2009-02-08 04:10:37 +01:00
|
|
|
lumiera_error(); // clear any remaining error state...
|
2008-12-13 21:10:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
2008-12-06 22:01:44 +01:00
|
|
|
};
|
|
|
|
|
|
2009-09-30 00:27:14 +02:00
|
|
|
lib::Singleton<GuiSubsysDescriptor> theDescriptor;
|
2008-12-06 22:01:44 +01:00
|
|
|
|
|
|
|
|
} // (End) impl details
|
2008-12-01 08:04:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-07 08:46:44 +01:00
|
|
|
|
|
|
|
|
|
2008-12-01 08:04:43 +01:00
|
|
|
/** @internal intended for use by main(). */
|
2008-12-05 11:07:01 +01:00
|
|
|
lumiera::Subsys&
|
2008-12-01 08:04:43 +01:00
|
|
|
GuiFacade::getDescriptor()
|
|
|
|
|
{
|
|
|
|
|
return theDescriptor();
|
|
|
|
|
}
|
2008-12-06 22:01:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
GuiFacade::isUp ()
|
|
|
|
|
{
|
|
|
|
|
return (facade);
|
|
|
|
|
}
|
2008-12-01 08:04:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace gui
|
2009-01-24 03:13:08 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Local Variables:
|
|
|
|
|
// mode: C++
|
|
|
|
|
// c-file-style: "gnu"
|
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
|
// End:
|
|
|
|
|
*/
|