From 933e486cf9d6fe5b205e5716b78fc8e218de2d48 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 27 Dec 2012 02:31:58 +0100 Subject: [PATCH] clarify some aspects of Session lifecycle - consider especially where the reset of internal indices happens - actively purge the Assets, the ConfigRules and Defaults --- src/common/config-rules.hpp | 4 +++ src/proc/asset/struct-factory-impl.hpp | 12 ++++----- .../mobject/session/lifecycle-advisor.hpp | 26 ++++++++++++++----- .../session/query/fake-configrules.cpp | 15 +++++++++++ .../session/query/fake-configrules.hpp | 1 + .../mobject/session/sess-manager-impl.cpp | 3 +++ 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/common/config-rules.hpp b/src/common/config-rules.hpp index 84262a253..6f83aae76 100644 --- a/src/common/config-rules.hpp +++ b/src/common/config-rules.hpp @@ -199,6 +199,10 @@ namespace lumiera { virtual ~ConfigRules() {} public: + /** roll back to a pristine yet operational state. + * Discards all information collected through use */ + virtual void reset() =0; + // TODO: find out what operations we need to support here for the »real solution« (using Prolog) }; diff --git a/src/proc/asset/struct-factory-impl.hpp b/src/proc/asset/struct-factory-impl.hpp index 441c1be37..0a80b6833 100644 --- a/src/proc/asset/struct-factory-impl.hpp +++ b/src/proc/asset/struct-factory-impl.hpp @@ -51,12 +51,12 @@ #include "proc/asset/struct-scheme.hpp" +#include "lib/format-string.hpp" #include "lib/query-util.hpp" #include "lib/symbol.hpp" #include "lib/error.hpp" #include "lib/util.hpp" -#include #include @@ -64,9 +64,8 @@ namespace proc { namespace asset { - using boost::format; - using lib::Symbol; + using util::_Fmt; using util::uNum; using util::isnil; using util::contains; @@ -119,8 +118,9 @@ namespace asset { // no name-ID contained in the query... // so we'll create a new one static int i=0; - static format namePattern ("%s.%d"); - nameID = str(namePattern % StructTraits::namePrefix() % (++i) ); + nameID = _Fmt("%s.%d") + % StructTraits::namePrefix() + % (++i); } ENSURE (!isnil (nameID)); @@ -176,7 +176,7 @@ namespace asset { template STRU* fabricate (Query const& caps) { - throw error::Config ( str(format("The following Query could not be resolved: %s.") % caps.asKey()) + throw error::Config ("The following Query could not be resolved: " + caps.asKey() , LUMIERA_ERROR_CAPABILITY_QUERY ); } diff --git a/src/proc/mobject/session/lifecycle-advisor.hpp b/src/proc/mobject/session/lifecycle-advisor.hpp index 7955ada11..d2297a51e 100644 --- a/src/proc/mobject/session/lifecycle-advisor.hpp +++ b/src/proc/mobject/session/lifecycle-advisor.hpp @@ -25,7 +25,7 @@ ** Implementation facility providing an operation skeleton of session lifecycle. ** This header is intended to be included into the session manager implementation; ** it should not be used by client code otherwise. The purpose of the LifecycleAdvisor - ** is to to get a consolidated view on the whole lifecycle. Reading this source file + ** is to get a consolidated view on the whole lifecycle. Reading this source file ** should convey a complete picture about what is going on with respect to the ** session lifecycle. Besides that, no actual implementation code is to be found ** here; any implementation is delegated to the relevant session facilities. @@ -33,7 +33,7 @@ ** The idea of a LifecycleAdvisor is inspired by GUI frameworks, especially ** Spring RichClient. Typically, such frameworks provide a means for flexible ** configuration of the application lifecycle. Configurability isn't the primary - ** goal here, as there is only one Lumiera application and the session lifecycle + ** goal here, as there is only one Lumiera application and the session lifecycle ** can be considered fixed, with the exception of some extension points, which are ** implemented as "lifecycle events". ** @@ -89,7 +89,7 @@ namespace session { void pullUp() { - createSessionFacilities(); + createSessionFacilities(); // includes switch of the "current" Session emitEvent (ON_SESSION_START); injectSessionContent(); emitEvent (ON_SESSION_INIT); @@ -106,7 +106,8 @@ namespace session { * cleanup and consolidation routines, the command framework is * disconnected from the log, discarding any pending commands. * This brings the session subsystem back into \em de-configured - * state, all asset and content objects pending eviction. + * state, all asset and content objects pending eviction, + * and the internal knowledge-base rolled back to zero. */ void shutDown() @@ -132,7 +133,11 @@ namespace session { /** - * + * Build and wire all the sub components together forming the session implementation. + * All these components are created to be operational in principle, but not initialised + * or outfitted with actual boilerplate state. After leaving this function, all of the + * technical / implementation level invariants are fulfilled. As a final step, + * the "current" session pointer is switched. */ virtual void createSessionFacilities() =0; @@ -174,7 +179,16 @@ namespace session { /** - * + * This final stage of the session lifecycle terminates the operational state of + * all parts of the current session. When entering this phase, it can be assumed + * that no entity from outside the session will access any of these parts anymore. + * Now, all the internal indices and knowledge registries are advised to purge, + * thereby rendering any session content officially non-existent. + * @note even after leaving this phase, all session components remain valid + * and basically operational. Already disconnected render processes + * might still access implementation facilities or session content. + * The actual unwinding and destruction is controlled by memory + * management and thus by reference count. */ virtual void deconfigure() =0; }; diff --git a/src/proc/mobject/session/query/fake-configrules.cpp b/src/proc/mobject/session/query/fake-configrules.cpp index 0b0bff6a8..fd6b64c2f 100644 --- a/src/proc/mobject/session/query/fake-configrules.cpp +++ b/src/proc/mobject/session/query/fake-configrules.cpp @@ -108,6 +108,19 @@ namespace session { } + /** clear the contents of the mock solution table. + * Used by Session lifecycle to restore pristine state + */ + void + MockTable::reset() + { + answer_.clear(); + isInit_ = false; + INFO (config, "discarded all config query mock answers."); + } + + + /* under some circumstances we need to emulate the behaviour * @@ -183,6 +196,7 @@ namespace session { if (!newTimeline) newTimeline = Struct::retrieve.made4fake (normalisedQuery); // no suitable Timeline found: create and attach new one answer_.insert (entry (normalisedQuery, newTimeline)); // "learn" the found/created Timeline as new solution + answer_.insert (entry (query, newTimeline)); return true; } @@ -218,6 +232,7 @@ namespace session { if (!newSequence) newSequence = Struct::retrieve.made4fake (normalisedQuery); // no suitable found: create and attach new Sequence answer_.insert (entry (normalisedQuery, newSequence)); // "learn" the found/created new solution + answer_.insert (entry (query, newSequence)); return true; } diff --git a/src/proc/mobject/session/query/fake-configrules.hpp b/src/proc/mobject/session/query/fake-configrules.hpp index c706910bf..c790fa12b 100644 --- a/src/proc/mobject/session/query/fake-configrules.hpp +++ b/src/proc/mobject/session/query/fake-configrules.hpp @@ -129,6 +129,7 @@ namespace session { protected: MockTable (); + virtual void reset(); any const& fetch_from_table_for (QueryKey const& query); // special cases.... diff --git a/src/proc/mobject/session/sess-manager-impl.cpp b/src/proc/mobject/session/sess-manager-impl.cpp index 496244c57..533e5e567 100644 --- a/src/proc/mobject/session/sess-manager-impl.cpp +++ b/src/proc/mobject/session/sess-manager-impl.cpp @@ -42,6 +42,7 @@ #include "proc/mobject/session.hpp" #include "proc/mobject/session/sess-manager-impl.hpp" #include "proc/mobject/session/lifecycle-advisor.hpp" +#include "proc/config-resolver.hpp" #include "proc/asset/timeline.hpp" #include "common/query/defs-manager.hpp" #include "common/query.hpp" @@ -175,6 +176,8 @@ namespace session { void deconfigure() { + session_->defaults.clear(); + ConfigResolver::instance().reset(); // forget any configuration rules AssetManager::instance().clear(); /////////////////////////////////////////////////////////////////// TICKET #154 }