From 34b14a226ea9f40afea8c9007a23be32d393e9e6 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 16 Feb 2008 02:47:01 +0100 Subject: [PATCH] defer creation of the empty default sesison, avoids running complex code in static initialisation --- src/proc/mobject/session.hpp | 4 ++ src/proc/mobject/session/sessionimpl.hpp | 2 +- src/proc/mobject/session/sessmanagerimpl.cpp | 49 ++++++++++++++++---- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/proc/mobject/session.hpp b/src/proc/mobject/session.hpp index 149dc6c82..d8b89d16c 100644 --- a/src/proc/mobject/session.hpp +++ b/src/proc/mobject/session.hpp @@ -141,6 +141,10 @@ namespace mobject virtual ~SessManager() {}; }; + + CINELERRA_ERROR_DECLARE (CREATE_SESSION); ///< unable to create basic session. + + } // namespace mobject::session } // namespace mobject diff --git a/src/proc/mobject/session/sessionimpl.hpp b/src/proc/mobject/session/sessionimpl.hpp index d9dc1f078..38448ac41 100644 --- a/src/proc/mobject/session/sessionimpl.hpp +++ b/src/proc/mobject/session/sessionimpl.hpp @@ -98,7 +98,7 @@ namespace mobject virtual void reset () ; virtual void load () ; virtual void save () ; - virtual Session* operator-> () throw() { return pImpl_.get(); } + virtual SessionImpl* operator-> () throw() ; }; diff --git a/src/proc/mobject/session/sessmanagerimpl.cpp b/src/proc/mobject/session/sessmanagerimpl.cpp index ca2797151..ad94c9949 100644 --- a/src/proc/mobject/session/sessmanagerimpl.cpp +++ b/src/proc/mobject/session/sessmanagerimpl.cpp @@ -39,6 +39,7 @@ #include "proc/mobject/session.hpp" #include "proc/mobject/session/sessionimpl.hpp" #include "proc/mobject/session/defsmanager.hpp" +#include "common/error.hpp" using boost::scoped_ptr; @@ -48,17 +49,49 @@ namespace mobject { namespace session { + + CINELERRA_ERROR_DEFINE (CREATE_SESSION, "unable to create basic session"); + + /** Access to the "current session", which actually is + * an SessionImpl instance. This session object is created + * either by loading an existing session, or on demand by + * this accessor function here (when no session was loaded + * or created) + * @note any exceptions arising while building the basic + * session object(s) will halt the system. + */ + SessionImpl* + SessManagerImpl::operator-> () throw() + { + if (!pImpl_) + try + { // create empty default configured session + this->reset(); + } + catch (...) + { + ERROR (oper, "Unrecoverable Failure while creating the empty default session."); + throw cinelerra::error::Fatal ( "Failure while creating the basic session object. Sysstem halted." + , CINELERRA_ERROR_CREATE_SESSION ); + } - /** Besides creating the single system-wide Session manger instance, - * creates an empty default Session as well. - * @note any exceptions arising in the course of this will halt - * the system (and this behaviour is desirable). + + return pImpl_.get(); + } + + + + /** Initially (at static init time), only the single system-wide + * Session manger instance is created. It can be used to load an + * existing session; otherwise an empty default Session an a + * Defaults manager (Config Query system) is created at first + * \link #operator-> access \endlink to the sesion object. */ SessManagerImpl::SessManagerImpl () throw() - : pDefs_ (new DefsManager), - pImpl_ (new SessionImpl (*pDefs_)) - { - } + : pDefs_ (0), + pImpl_ (0) + { } + /** @note no transactional behaviour. * may succeed partial.