define session lifecycle event IDs

This commit is contained in:
Fischlurch 2009-08-09 19:22:07 +02:00
parent eada1aa745
commit 2e58611e2d
3 changed files with 90 additions and 52 deletions

View file

@ -98,6 +98,11 @@ namespace mobject {
};
extern Symbol ON_SESSION_START; ///< triggered before loading any content into a newly created session
extern Symbol ON_SESSION_INIT; ///< triggered when initialising a new session, after adding content
extern Symbol ON_SESSION_END; ///< triggered before discarding an existing session
namespace session {
/**

View file

@ -35,17 +35,18 @@
#include "proc/mobject/session/defsmanager.hpp"
#include "proc/mobject/session/session-impl.hpp"
#include "include/symbol.hpp"
#include "lib/singleton.hpp"
using lumiera::Symbol;
using lumiera::Singleton;
using mobject::session::SessManager;
using mobject::session::SessManagerImpl;
namespace mobject
{
/** the sole acces point for all client code to the system-wide
namespace mobject {
/** the sole access point for all client code to the system-wide
* "current session". Implemented as smart pointer to singleton
* implementation object, where the smart pointer is actually
* the SessionManager (which is singleton as well...).
@ -55,13 +56,45 @@ namespace mobject
* via arrow notaion (e.g. \code Session::current->getFixture() )
*/
SessManager& Session::current = Singleton<SessManagerImpl>()();
/** \par
* LifecycleHook, to perform all the basic setup for a new session,
* prior to adding any specific data, configuration or content. Any subsystems
* requiring to (re)-initialise for a new session should register here. When this
* hook is activated, the session implementation facilities are available and the
* corresponding interfaces are already opened and accessible, but the session itself
* is completely pristine and empty.
* @note plugins providing additional facilities to be used by content of a (persisted)
* session should register their basic setup functions using this hook, which can be
* done via the C interface functions defined in lifecycle.h
*/
Symbol ON_SESSION_START ("ON_SESSION_START");
/** \par
* LifecycleHook, to perform any initialisation, wiring and registrations necessary
* to get the session into a usable state. When activated, the specific session content
* and configuration has already be loaded. Any subsystems requiring to build some indices
* or wiring to keep track of the session's content should register here.
*/
Symbol ON_SESSION_INIT ("ON_SESSION_INIT");
/** \par
* LifecycleHook, to perform any state saving, deregistration or de-activation necessary
* before bringing down an existing session. When invoked, the session is still fully valid
* and functional, but the GUI/external access has already been closed.
* @todo specify how this is related to "saving". Is there a way for subsystems to add
* specific/internal information into the persisted state, besides actually attaching
* data to objects within the session?
*/
Symbol ON_SESSION_END ("ON_SESSION_END");
Session::~Session ()
{ }
Session::Session (session::DefsManager& def) throw()
: defaults(def)
{ }

View file

@ -30,48 +30,48 @@
namespace lumiera {
namespace test {
uint basicInit (0);
uint customCallback (0);
void basicInitHook () { ++basicInit; }
void myCallback() { ++customCallback; }
Symbol MY_DEADLY_EVENT = "dial M for murder";
namespace // register them to be invoked by lifecycle event id
{
LifecycleHook _schedule1 (ON_BASIC_INIT, &basicInitHook);
LifecycleHook _schedule2 (MY_DEADLY_EVENT, &myCallback);
}
/** @test the global lifecycle hooks got registered,
* the ON_BASIC_INIT hook has been already called,
* while our custom callback can be trigged at our will
*/
class LifeCycle_test : public Test
{
virtual void
run (Arg)
{
ASSERT (basicInit, "the basic-init callback hasn't been invoked automatically");
ASSERT (1 == basicInit, "the basic-init callback has been invoked more than once");
ASSERT (!customCallback);
LifecycleHook::trigger (MY_DEADLY_EVENT);
ASSERT ( 1 == customCallback);
}
};
LAUNCHER (LifeCycle_test, "function common");
namespace lumiera{
namespace test {
uint basicInit (0);
uint customCallback (0);
void basicInitHook () { ++basicInit; }
void myCallback() { ++customCallback; }
Symbol MY_DEADLY_EVENT = "dial M for murder";
namespace // register them to be invoked by lifecycle event id
{
LifecycleHook _schedule1 (ON_BASIC_INIT, &basicInitHook);
LifecycleHook _schedule2 (MY_DEADLY_EVENT, &myCallback);
}
/** @test the global lifecycle hooks got registered,
* the ON_BASIC_INIT hook has been already called,
* while our custom callback can be triggered at our will
*/
class LifeCycle_test : public Test
{
virtual void
run (Arg)
{
ASSERT (basicInit, "the basic-init callback hasn't been invoked automatically");
ASSERT (1 == basicInit, "the basic-init callback has been invoked more than once");
ASSERT (!customCallback);
LifecycleHook::trigger (MY_DEADLY_EVENT);
ASSERT ( 1 == customCallback);
}
} // namespace test
} // namespace util
};
LAUNCHER (LifeCycle_test, "function common");
}} // namespace util::test