From fa9b23115cc4587bf7232b2d21dd68f903729581 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 2 Dec 2008 04:53:30 +0100 Subject: [PATCH] move init plugin/interface system and global init to AppState::init() --- src/lumiera/appstate.cpp | 56 ++++++++++++++++++++++++++--- src/lumiera/appstate.hpp | 10 ++++-- src/lumiera/interfaceregistry.h | 2 +- src/lumiera/lumiera.c | 6 ---- src/lumiera/lumiera_init.c | 3 -- src/lumiera/main.cpp | 9 ++--- src/lumiera/plugin.h | 4 +-- src/lumiera/subsys.cpp | 64 +++++++++++++++++++++++++++++++++ src/lumiera/subsys.hpp | 22 +----------- 9 files changed, 130 insertions(+), 46 deletions(-) create mode 100644 src/lumiera/subsys.cpp diff --git a/src/lumiera/appstate.cpp b/src/lumiera/appstate.cpp index 149be2773..05b28ee2e 100644 --- a/src/lumiera/appstate.cpp +++ b/src/lumiera/appstate.cpp @@ -21,17 +21,26 @@ * *****************************************************/ +#include "include/error.hpp" #include "include/lifecycle.h" #include "lumiera/appstate.hpp" #include "lib/lifecycleregistry.hpp" -#include "include/error.hpp" +extern "C" { +#include "lumiera/config_interface.h" + +#include "lumiera/interface.h" +#include "lumiera/interfaceregistry.h" +#include "lumiera/plugin.h" +} + #include "common/util.hpp" using util::isnil; using util::cStr; + namespace lumiera { @@ -52,7 +61,8 @@ namespace lumiera { * client codes POV it just behaves like intended). */ AppState::AppState() - : lifecycleHooks_(new LifecycleRegistry) + : lifecycleHooks_(new LifecycleRegistry), + parts_(0) { lifecycleHooks_->execute (ON_BASIC_INIT); // note in most cases a NOP } @@ -80,10 +90,48 @@ namespace lumiera { + + + // ==== implementation startup sequence for main() ======= + + struct SubsystemRunner + { + Option& opts_; + + SubsystemRunner (Option& opts) + : opts_(opts) + { } + + }; + + +#define _THROW_IF \ + if (lumiera_error_peek()) \ + throw error::Fatal (lumiera_error()); + + + void - AppState::evaluate (lumiera::Option& options) + AppState::init (Option& options) { - UNIMPLEMENTED ("evaluate the options and set global application state"); + TRACE (lumiera, "initialising application core..."); + + lumiera_interfaceregistry_init (); + _THROW_IF + + TODO ("use a plugindb instead of loading all plugins at once"); + lumiera_plugin_discover (lumiera_plugin_load, lumiera_plugin_register); + _THROW_IF + + lumiera_config_interface_init (); + _THROW_IF + + AppState::lifecycle (ON_GLOBAL_INIT); + _THROW_IF + + + parts_.reset (new SubsystemRunner (options)); + TRACE (lumiera, "Lumiera core started successfully."); } diff --git a/src/lumiera/appstate.hpp b/src/lumiera/appstate.hpp index 0d8138729..017f896c8 100644 --- a/src/lumiera/appstate.hpp +++ b/src/lumiera/appstate.hpp @@ -53,6 +53,7 @@ namespace lumiera { using boost::noncopyable; class LifecycleRegistry; + class SubsystemRunner; /** @@ -82,10 +83,11 @@ namespace lumiera { static void lifecycle (Symbol eventLabel); - /** evaluate the command line options and maybe additional configuration + /** evaluate the result of option parsing and maybe additional configuration * such as to be able to determine the further behaviour of the application. - * Set the internal state within this object accordingly */ - void evaluate (lumiera::Option& options); + * Set the internal state within this object accordingly. + * @return the AppState singleton instance */ + void init (lumiera::Option& options); /** building on the state determined by #evaluate, decide if the given Subsys @@ -123,8 +125,10 @@ namespace lumiera { private: typedef scoped_ptr PLife; + typedef scoped_ptr PSub; PLife lifecycleHooks_; + PSub parts_; friend class LifecycleHook; diff --git a/src/lumiera/interfaceregistry.h b/src/lumiera/interfaceregistry.h index 98e0df83e..425961fd4 100644 --- a/src/lumiera/interfaceregistry.h +++ b/src/lumiera/interfaceregistry.h @@ -33,7 +33,7 @@ /** * @file * Interface instances are published and activated by registering them - * into a gloabl registry, which is defined here. This instances are identified + * into a global registry, which is defined here. This instances are identified * by their name and major version. */ diff --git a/src/lumiera/lumiera.c b/src/lumiera/lumiera.c index 289646180..db4a260b0 100644 --- a/src/lumiera/lumiera.c +++ b/src/lumiera/lumiera.c @@ -58,12 +58,6 @@ start (int argc, char** argv) TODO ("commandline parser"); lumiera_config_init (LUMIERA_CONFIG_PATH); - lumiera_interfaceregistry_init (); - TODO ("plugindb support instead loading all plugins at once"); - lumiera_plugin_discover (lumiera_plugin_load, lumiera_plugin_register); - - lumiera_init (); - TRACE (lumiera, "Lumiera is alive"); TODO ("video editing"); diff --git a/src/lumiera/lumiera_init.c b/src/lumiera/lumiera_init.c index 479fb5622..78e1a13ed 100644 --- a/src/lumiera/lumiera_init.c +++ b/src/lumiera/lumiera_init.c @@ -63,9 +63,6 @@ lumiera_preinit (void) void lumiera_init (void) { - TRACE (lumiera, "initializing"); - - lumiera_config_interface_init (); } diff --git a/src/lumiera/main.cpp b/src/lumiera/main.cpp index fc7946166..4004a6119 100644 --- a/src/lumiera/main.cpp +++ b/src/lumiera/main.cpp @@ -26,7 +26,6 @@ #include "include/nobugcfg.h" #include "include/error.hpp" -#include "include/lifecycle.h" #include "lumiera/appstate.hpp" #include "lumiera/option.hpp" @@ -57,14 +56,12 @@ main (int argc, const char* argv[]) { NOTICE (lumiera, "*** Lumiera NLE for Linux ***"); - Cmdline args (argc,argv); AppState& application = AppState::instance(); - lumiera::Option options (args); - application.evaluate (options); - try { - AppState::lifecycle (ON_GLOBAL_INIT); + Cmdline args (argc,argv); + lumiera::Option options (args); + application.init (options); session.depends (builder); netNode.depends (session); diff --git a/src/lumiera/plugin.h b/src/lumiera/plugin.h index 21d32c3a1..f5a5ffc21 100644 --- a/src/lumiera/plugin.h +++ b/src/lumiera/plugin.h @@ -72,7 +72,7 @@ NOBUG_DECLARE_FLAG (plugin); struct lumiera_plugin_struct; typedef struct lumiera_plugin_struct lumiera_plugin; typedef lumiera_plugin* LumieraPlugin; -enum lumiera_plugin_type; + /** * Allocates an preinitializes a plugin structure @@ -89,7 +89,7 @@ lumiera_plugin_new (const char* name); * Stores any pending error (from loading) in self which clears out the LUMIERA_ERROR_PLUGIN_INIT error state * which was initialized by lumiera_plugin_new(), stores the handle and plugin pointers in the plugin struct. * @param self pointer to the plugin struct - * @param handle opaque handle refering to some plugin type specific data + * @param handle opaque handle referring to some plugin type specific data * @param plugin a lumieraorg__plugin interface which will be used to initialize this plugin */ LumieraPlugin diff --git a/src/lumiera/subsys.cpp b/src/lumiera/subsys.cpp new file mode 100644 index 000000000..c8a87aa2c --- /dev/null +++ b/src/lumiera/subsys.cpp @@ -0,0 +1,64 @@ +/* + Subsys - interface for describing an application part to be handled by main() + + Copyright (C) Lumiera.org + 2008, Hermann Vosseler + + 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 "lumiera/subsys.hpp" + +#include "include/error.hpp" +//#include "common/util.hpp" + + +//using util::isnil; +//using util::cStr; + +namespace lumiera { + + + + + + Subsys::~Subsys() { } + + + + Subsys& + Subsys::depends (Subsys& prereq) + { + TODO ("anything else to care when defining a dependency on the prerequisite subsystem??");/////////////////////TODO + prereq_.push_back(&prereq); + return *this; + } + + + + bool + Subsys::isRunning() + { + UNIMPLEMENTED ("maintain isRunning flag in a threadsafe manner"); + return false; + } + + + + + +} // namespace lumiera diff --git a/src/lumiera/subsys.hpp b/src/lumiera/subsys.hpp index f618fe187..df7db5255 100644 --- a/src/lumiera/subsys.hpp +++ b/src/lumiera/subsys.hpp @@ -73,8 +73,7 @@ namespace lumiera { public: typedef void (SigTerm)(Error*); ///////////////////TODO better use Glib-- Signal type? - - virtual ~Subsys () {}; + virtual ~Subsys(); /** define a dependency to another Subsys @@ -112,25 +111,6 @@ namespace lumiera { - //------ implementation skeleton ---------- - inline Subsys& - Subsys::depends (Subsys& prereq) - { - TODO ("anything else to care when defining a dependency on the prerequisite subsystem??");/////////////////////TODO - prereq_.push_back(&prereq); - return *this; - } - - - - inline bool - Subsys::isRunning() - { - UNIMPLEMENTED ("maintain isRunning flag in a threadsafe manner"); - return false; - } - - } // namespace lumiera #endif