build a complete simplified mock Session/SessionManager
This commit is contained in:
parent
f1ce05ea9d
commit
2765981db9
7 changed files with 182 additions and 30 deletions
|
|
@ -23,9 +23,22 @@
|
|||
|
||||
/** @file session.hpp
|
||||
** Primary Interface to the current Session.
|
||||
** The session interface can be used to discover session's contents.
|
||||
** Mostly, these objects within the session are MObject subclasses, but they
|
||||
** are attached into the session by a Placement. Usually, you'd want to use
|
||||
** the discovered objects to invoke operations on them; in most cases,
|
||||
** invoking any mutating operation should be wrapped into a Command.
|
||||
**
|
||||
** The Interface Session is abstract and only accessible via the
|
||||
** static field Session::current, which actually refers to a SessManager
|
||||
** singleton instance. The latter acts as smart ptr-to-Impl.
|
||||
** singleton instance. The latter acts as smart ptr-to-Impl for accessing the
|
||||
** current session, but at the same time exposes a lifecycle/management API.
|
||||
**
|
||||
** @note if interested in the interplay of Session, SessManager and the
|
||||
** internal service APIs (SessionServices), you should have a look
|
||||
** at session-service-access-test.cpp, as this test creates a complete
|
||||
** but simplified mock setup of the session and session manager, without
|
||||
** any access and synchronisation and similar concerns, to read top down.
|
||||
**
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef MOBJECT_SESSION_CONTENTS_QUERY_H
|
||||
#define MOBJECT_SESSION_CONTENTS_QUERY_H
|
||||
#ifndef MOBJECT_SESSION_SCOPE_QUERY_H
|
||||
#define MOBJECT_SESSION_SCOPE_QUERY_H
|
||||
|
||||
|
||||
#include "proc/mobject/placement.hpp"
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
**
|
||||
** This file contains the implementation classes, it should never
|
||||
** be included by client code.
|
||||
**
|
||||
** @see session-service-access-test.cpp for a complete simplified mock session manager
|
||||
**
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ PLANNED "SessionManager_test" SessionManager_test <<END
|
|||
END
|
||||
|
||||
|
||||
PLANNED "Accessing implementation level services" SessionServiceAccess_test <<END
|
||||
PLANNED "Accessing session APIs" SessionServiceAccess_test <<END
|
||||
END
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ namespace mobject {
|
|||
namespace session {
|
||||
namespace test {
|
||||
|
||||
using PathQuery;
|
||||
using ContentsQuery;
|
||||
using session::PathQuery;
|
||||
using session::ContentsQuery;
|
||||
using util::isSameObject;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
|
@ -77,6 +77,7 @@ namespace test {
|
|||
void
|
||||
checkQueryOperations()
|
||||
{
|
||||
#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #384 !!!!!!!!!
|
||||
// Prepare an (test)Index (dummy "session")
|
||||
PPIdx index = build_testScopes();
|
||||
PlacementIndexQueryResolver resolver(index);
|
||||
|
|
@ -86,6 +87,7 @@ namespace test {
|
|||
PlacementMO& elm = *ContentsQuery<TestSubMO21>(resolver);
|
||||
|
||||
discover (PathQuery(resolver,elm));
|
||||
#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!!
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
ContentsQuery(Test) - running queries to discover container contents, filtering (sub)types
|
||||
ScopeQuery(Test) - running queries to discover container contents, filtering (sub)types
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2009, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
|
@ -36,7 +36,7 @@ namespace mobject {
|
|||
namespace session {
|
||||
namespace test {
|
||||
|
||||
using ContentsQuery;
|
||||
using session::ContentsQuery;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
|
@ -73,10 +73,10 @@ namespace test {
|
|||
|
||||
ScopeQuery<TestSubMO21> specialEl(resolver,scope, "contents");
|
||||
|
||||
discover (ScopeQuery<MObject> (resolver,*specialEl, "parents"));
|
||||
discover (ScopeQuery<MObject> (resolver,*specialEl, "path"));
|
||||
discover (ScopeQuery<TestSubMO2> (resolver,*specialEl, "path"));
|
||||
discover (specialEl);
|
||||
discover (ScopeQuery<MObject> (resolver,specialEL, "parents"));
|
||||
discover (ScopeQuery<MObject> (resolver,specialEL, "path"));
|
||||
discover (ScopeQuery<TestSubMO2> (resolver,specialEL, "path"));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,13 +25,20 @@
|
|||
#include "proc/mobject/session.hpp"
|
||||
//#include "proc/mobject/session/testsession1.hpp"
|
||||
#include "proc/mobject/session/session-services.hpp"
|
||||
#include "lib/singleton.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
//#include <boost/format.hpp>
|
||||
//#include <iostream>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
//using boost::format;
|
||||
//using std::string;
|
||||
//using std::cout;
|
||||
using lib::Singleton;
|
||||
using boost::lexical_cast;
|
||||
using std::ostream;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
namespace mobject {
|
||||
|
|
@ -39,36 +46,164 @@ namespace session {
|
|||
namespace test {
|
||||
|
||||
|
||||
namespace { // what follows is a simulated (simplified) version
|
||||
// of the complete Session + SessionManager setup.....
|
||||
|
||||
|
||||
/* === Interface level === */
|
||||
|
||||
struct TSessManager;
|
||||
typedef TSessManager& PSess;
|
||||
|
||||
struct TSession
|
||||
{
|
||||
virtual ~TSession () { }
|
||||
static TSessManager& current;
|
||||
|
||||
virtual void externalOperation () =0;
|
||||
};
|
||||
|
||||
struct TSessManager
|
||||
{
|
||||
/** access to the current session */
|
||||
virtual TSession* operator-> () =0;
|
||||
|
||||
virtual void reset () =0;
|
||||
virtual ~TSessManager() { };
|
||||
};
|
||||
|
||||
|
||||
/* === Implementation level === */
|
||||
|
||||
struct TSessionImpl : TSession
|
||||
{
|
||||
static uint magic_;
|
||||
|
||||
/* ==== Session API ==== */
|
||||
void externalOperation() ;
|
||||
|
||||
/* ==== Implementation level API ==== */
|
||||
void implementationService() ;
|
||||
|
||||
/* ==== internals ==== */
|
||||
TSessionImpl()
|
||||
{
|
||||
++magic_;
|
||||
cout << "creating new Session " << magic_ << endl;
|
||||
}
|
||||
|
||||
operator string() const
|
||||
{
|
||||
return string("Session-Impl(")
|
||||
+ lexical_cast<string>(magic_)
|
||||
+ ")";
|
||||
}
|
||||
};
|
||||
|
||||
inline ostream&
|
||||
operator<< (ostream& os, TSessionImpl const& simpl)
|
||||
{
|
||||
return os << string(simpl);
|
||||
}
|
||||
|
||||
void
|
||||
TSessionImpl::externalOperation()
|
||||
{
|
||||
cout << *this << "::externalOperation()" << endl;
|
||||
}
|
||||
|
||||
/* ==== Implementation level API ==== */
|
||||
void
|
||||
TSessionImpl::implementationService()
|
||||
{
|
||||
cout << *this << "::implementationService()" << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct TSessManagerImpl : TSessManager
|
||||
{
|
||||
scoped_ptr<TSessionImpl> pImpl_;
|
||||
|
||||
TSessManagerImpl()
|
||||
: pImpl_(0)
|
||||
{ }
|
||||
|
||||
TSessionImpl*
|
||||
operator-> ()
|
||||
{
|
||||
if (!pImpl_)
|
||||
this->reset();
|
||||
return pImpl_.get();
|
||||
}
|
||||
|
||||
|
||||
/* ==== Manager API ==== */
|
||||
void
|
||||
reset ()
|
||||
{
|
||||
scoped_ptr<TSessionImpl> tmpS (new TSessionImpl);
|
||||
pImpl_.swap (tmpS);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* === storage and basic configuration === */
|
||||
|
||||
uint TSessionImpl::magic_;
|
||||
|
||||
TSessManager& TSession::current = Singleton<TSessManagerImpl>()();
|
||||
//note: comes up already during static initialisation
|
||||
|
||||
|
||||
} // (END) simulated session management
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Verify the access mechanism used by Proc-Layer internals for
|
||||
* accessing implementation level APIs of the session.
|
||||
*
|
||||
* @todo WIP-WIP
|
||||
* Actually, this test uses setup of the real session,
|
||||
* complete with interfaces, implementation and a
|
||||
* session manager frontend.
|
||||
*
|
||||
* @see session-impl.hpp the real thing
|
||||
* @see SessionServices;
|
||||
*/
|
||||
class SessionServiceAccess_test : public Test
|
||||
{
|
||||
virtual void
|
||||
run (Arg arg)
|
||||
run (Arg)
|
||||
{
|
||||
// getCurrentSession ();
|
||||
// clearSession();
|
||||
// loadMockSession();
|
||||
//
|
||||
// clearSession();
|
||||
// buildTestsession1();
|
||||
// string serialized;
|
||||
// saveSession (serialized);
|
||||
// loadSession (serialized);
|
||||
// ASSERT (checkTestsession1());
|
||||
access_defaultSession();
|
||||
make_newSession();
|
||||
invoke_implService();
|
||||
}
|
||||
|
||||
|
||||
/** @test accessing the current (global) session */
|
||||
void
|
||||
getCurrentSession ()
|
||||
access_defaultSession ()
|
||||
{
|
||||
// PSess sess = Session::current;
|
||||
// ASSERT (sess->isValid());
|
||||
cout << "Session not yet used...." << endl;
|
||||
TSession::current->externalOperation();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
make_newSession ()
|
||||
{
|
||||
TSession::current.reset();
|
||||
TSession::current->externalOperation();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
invoke_implService ()
|
||||
{
|
||||
///////////////////////////////TODO
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue