From 9fc366bd253f89d0e9be507bd5989dda7c0df4b5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 24 Oct 2010 06:50:00 +0200 Subject: [PATCH] session lifecycle implementation.. --- src/proc/mobject/session/defsmanager.cpp | 14 +++--- src/proc/mobject/session/defsmanager.hpp | 10 ++-- .../mobject/session/sess-manager-impl.cpp | 46 ++++++++++++++----- .../mobject/session/sess-manager-impl.hpp | 5 +- wiki/renderengine.html | 13 +++--- 5 files changed, 57 insertions(+), 31 deletions(-) diff --git a/src/proc/mobject/session/defsmanager.cpp b/src/proc/mobject/session/defsmanager.cpp index c31044392..7f660f8c8 100644 --- a/src/proc/mobject/session/defsmanager.cpp +++ b/src/proc/mobject/session/defsmanager.cpp @@ -160,14 +160,14 @@ namespace session { using mobject::session::Track; using mobject::session::PTrack; - template PPipe DefsManager::operator() (const Query&); - template PProcPatt DefsManager::operator() (const Query&); - template PTrack DefsManager::operator() (const Query&); - template PTimeline DefsManager::operator() (const Query&); - template PSequence DefsManager::operator() (const Query&); + template PPipe DefsManager::operator() (Query const&); + template PProcPatt DefsManager::operator() (Query const&); + template PTrack DefsManager::operator() (Query const&); + template PTimeline DefsManager::operator() (Query const&); + template PSequence DefsManager::operator() (Query const&); - template bool DefsManager::define (const PPipe&, const Query&); - template bool DefsManager::forget (const PPipe&); + template bool DefsManager::define (PPipe const&, Query const&); + template bool DefsManager::forget (PPipe const&); }} // namespace mobject::session diff --git a/src/proc/mobject/session/defsmanager.hpp b/src/proc/mobject/session/defsmanager.hpp index 8de9207bd..6d672833f 100644 --- a/src/proc/mobject/session/defsmanager.hpp +++ b/src/proc/mobject/session/defsmanager.hpp @@ -72,14 +72,14 @@ namespace mobject { * is considered \e misconfiguration. */ template - P operator() (const lumiera::Query&); + P operator() (lumiera::Query const&); /** search through the registered defaults, never create anything. * @return object fulfilling the query, \c empty ptr if not found. */ template - P search (const lumiera::Query&); + P search (lumiera::Query const&); /** retrieve an object fulfilling the query and register it as default. * The resolution is delegated to the ConfigQuery system (which may cause @@ -87,7 +87,7 @@ namespace mobject { * @return object fulfilling the query, \c empty ptr if no solution. */ template - P create (const lumiera::Query&); + P create (lumiera::Query const&); /** register the given object as default, after ensuring it fulfils the * query. The latter may cause some properties of the object to be set, @@ -96,13 +96,13 @@ namespace mobject { * @note only a weak ref to the object is stored */ template - bool define (const P&, const lumiera::Query&); + bool define (P const&, lumiera::Query const&); /** remove the defaults registration of the given object, if there was such * @return false if nothing has been changed because the object wasn't registered */ template - bool forget (const P&); + bool forget (P const&); // Q: can we have something along the line of...? diff --git a/src/proc/mobject/session/sess-manager-impl.cpp b/src/proc/mobject/session/sess-manager-impl.cpp index 123f83ac5..f67c83099 100644 --- a/src/proc/mobject/session/sess-manager-impl.cpp +++ b/src/proc/mobject/session/sess-manager-impl.cpp @@ -40,12 +40,15 @@ #include "proc/mobject/session/sess-manager-impl.hpp" #include "proc/mobject/session/defsmanager.hpp" #include "proc/mobject/session/lifecycle-advisor.hpp" +#include "proc/asset/timeline.hpp" #include "lib/error.hpp" +#include "lib/query.hpp" using boost::scoped_ptr; + namespace mobject { namespace session { @@ -92,20 +95,34 @@ namespace session { : public LifecycleAdvisor { SessionPImpl & session_; + bool shall_load_; ////////////TODO a placeholder; later we'll pass in a de-serialiser + /** @note Any session services get up into default configured state. + * After the swap, \c tmpS holds onto the old session, which + * consequently should unwind on leaving this scope. */ void createSessionFacilities() { - UNIMPLEMENTED ("create session implementation objects, pImpl switch"); + SessionPImpl tmpS (new SessionImplAPI); + session_.swap (tmpS); } void injectSessionContent() { - UNIMPLEMENTED ("load default content of de-serialise"); + if (shall_load_) + { + UNIMPLEMENTED ("loading session from persistent storage"); + } + else + { // inject some default session content + asset::PTimeline initialTimeline = session_->defaults (lumiera::Query ()); + /////////////TODO howto "attach a timeline"?? + //session_->attach( timeline ); + } } @@ -147,7 +164,8 @@ namespace session { void deconfigure() { - UNIMPLEMENTED ("anything berfore destroying objects"); + TODO ("reset the assets registered with AssetManager"); + /////////////////////////////////////////////////////////////////// TICKET #154 } @@ -156,6 +174,7 @@ namespace session { public: SessionLifecycleDetails(SessionPImpl& currentSessionAccessPoint) : session_(currentSessionAccessPoint) + , shall_load_(false) { } }; @@ -190,7 +209,7 @@ namespace session { bool SessManagerImpl::isUp () { - return bool(pImpl_); + return bool(pImpl_); ///////////////////// TICKET #702 possible race, because this gets true way before the interface is up } /** @note no transactional behaviour. may succeed partially. @@ -199,6 +218,7 @@ namespace session { void SessManagerImpl::clear () { + Lock sync(this); pImpl_->clear(); } @@ -210,7 +230,9 @@ namespace session { void SessManagerImpl::close () { - UNIMPLEMENTED("clean session shutdown"); + Lock sync(this); + lifecycle_->shutDown(); + pImpl_.reset(); } @@ -223,13 +245,9 @@ namespace session { void SessManagerImpl::reset () { - scoped_ptr tmpS (new SessionImplAPI); - - TODO ("reset the assets registered with AssetManager"); - /////////////////////////////////////////////////////////////////// TICKET #154 - - TODO ("thread lock"); - pImpl_.swap (tmpS); + Lock sync(this); + lifecycle_->shutDown(); + lifecycle_->pullUp(); } @@ -237,6 +255,9 @@ namespace session { SessManagerImpl::load () { UNIMPLEMENTED ("load serialised session"); + Lock sync(this); + lifecycle_->shutDown(); + lifecycle_->pullUp(); } @@ -252,6 +273,7 @@ namespace session { SessManagerImpl::save () { UNIMPLEMENTED ("save session (serialised)"); + /////////////////////////////////////////////////TODO: need lock? } diff --git a/src/proc/mobject/session/sess-manager-impl.hpp b/src/proc/mobject/session/sess-manager-impl.hpp index 602039ce8..dcd671d2f 100644 --- a/src/proc/mobject/session/sess-manager-impl.hpp +++ b/src/proc/mobject/session/sess-manager-impl.hpp @@ -25,6 +25,7 @@ #define MOBJECT_SESSION_SESS_MANAGER_IMPL_H #include "proc/mobject/session/session-impl.hpp" +#include "lib/sync.hpp" namespace mobject { @@ -37,7 +38,9 @@ namespace session { * Session manager implementation class holding the * actual smart pointer to the current Session impl. */ - class SessManagerImpl : public SessManager + class SessManagerImpl + : public SessManager + , public lib::Sync<> { scoped_ptr pImpl_; scoped_ptr lifecycle_; diff --git a/wiki/renderengine.html b/wiki/renderengine.html index f35ae0590..463efe044 100644 --- a/wiki/renderengine.html +++ b/wiki/renderengine.html @@ -2440,7 +2440,7 @@ The general idea is, that each facade interface actually provides access to a sp -
+
An implementation facility used by the session manager implementation to ensure a consistent lifecycle. A template-method-like skeleton of operations can be invoked by the session manager to go through the various lifecycle stages, while the actual implementation functionality is delegated to facilities within the session. The assumption is for the lifecycle advisor to be executed within a controlled environment, a single instance and single threaded.
 
 ---------------------
@@ -2452,15 +2452,16 @@ Reading the source code should convey a complete picture about what is going on
 ;close
 : the shutdown sequence cleanly unwinds any contents and returns into //uninitialised state.//
 ;reset
-: is compriesd of two phases: shutdown and startup of an empty new session
+: is comprised of two phases: shutdown and startup of an empty new session
 : shutdown will be skipped automatically when uninitialised
 : startup has to inject default session content
 ;load
-: similar to the startup sequence of __reset__, but injects serialised content
+: again, first an existing session is brought down cleanly
+: the startup sequence behaves similarly to __reset__, but injects serialised content
 Note that, while causing a short //freeze period,// __saving__ and __(re-)building__ aren't considered lifecycle operations
 
 !!operation sequences
-The ''pull up'' sequence performes basic initialsiation of the session facilities and then, after the pImpl-switch, executes the various loading and startup phases. Any previous session switched away is assumed to unwind automatically, nothing is done especially to disconnnect such an existing session, we simply require the session subsystem to be in a pristine state initially.
+The ''pull up'' sequence performs basic initialisation of the session facilities and then, after the pImpl-switch, executes the various loading and startup phases. Any previous session switched away is assumed to unwind automatically, nothing is done especially to disconnect such an existing session, we simply require the session subsystem to be in a pristine state initially.
 The ''shut down'' sequence does exactly that: halt processing and rendering, disconnect an existing session, if any, get back into initial state. It doesn't care for unwinding session contents, which is assumed to happen automatically when references to previous session contents go out of scope.
 
@@ -4665,7 +4666,7 @@ Currently, I'm planning to modify MObjectRef to return only a const ref to the u <<<
-
+
The current [[Session]] is the root of any state found within Proc-Layer. Thus, events defining the session's lifecycle influence and synchronise the cooperative behaviour of the entities within the model, the ProcDispatcher, [[Fixture]] and any facility below.
 * when ''starting'', on first access an empty session is created, which puts any related facility into a defined initial state.
 * when ''closing'' the session, any dependent facilities are disabled, disconnected, halted or closed
@@ -4700,7 +4701,7 @@ As detailed above, {{{Session::current}}} exposes the management / lifecycle API
 
 !!!closing the session
 # top-level facilities accessing the session (GUI, command processing, scripts) are blocked and the LayerSeparationInterface is closed
-# any render processes are ensured to be terminated (or //disconnected// &mdash; so the can't do any harm)
+# any render processes are ensured to be terminated (or //disconnected// &mdash; so they can't do any harm)
 # the {{{ON_SESSION_END}}} event is emitted
 # the command processing log is tagged
 # the command queue(s) are emptied, discarding any commands not yet executed