2007-09-02 18:48:22 +02:00
|
|
|
/*
|
|
|
|
|
Struct(Asset) - key abstraction: structural asset
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-03-10 04:25:03 +01:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2007-09-02 18:48:22 +02:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "proc/asset/struct.hpp"
|
2010-03-21 05:25:52 +01:00
|
|
|
#include "proc/assetmanager.hpp"
|
2012-12-01 08:44:07 +01:00
|
|
|
#include "proc/config-resolver.hpp"
|
2008-02-10 17:23:16 +01:00
|
|
|
|
2010-02-28 07:17:12 +01:00
|
|
|
#include "proc/asset/struct-factory-impl.hpp"
|
2008-01-07 18:16:03 +01:00
|
|
|
|
2008-12-17 17:53:32 +01:00
|
|
|
#include "lib/util.hpp"
|
2010-03-06 04:30:12 +01:00
|
|
|
#include "lib/symbol.hpp"
|
2012-12-03 00:18:18 +01:00
|
|
|
#include "lib/query-util.hpp"
|
2009-01-25 00:24:42 +01:00
|
|
|
#include "include/logging.h"
|
2012-12-01 08:44:07 +01:00
|
|
|
#include "common/query.hpp"
|
2007-09-02 18:48:22 +02:00
|
|
|
|
2008-02-18 04:16:53 +01:00
|
|
|
#include <boost/format.hpp>
|
2008-02-15 02:56:25 +01:00
|
|
|
|
2008-02-18 04:16:53 +01:00
|
|
|
using boost::format;
|
2008-02-15 02:56:25 +01:00
|
|
|
|
2009-09-24 23:02:40 +02:00
|
|
|
using lib::Symbol;
|
2012-12-03 00:18:18 +01:00
|
|
|
using lib::query::normaliseID;
|
2008-03-10 08:38:59 +01:00
|
|
|
using lumiera::query::QueryHandler;
|
2012-12-01 08:44:07 +01:00
|
|
|
using proc::ConfigResolver;
|
2008-02-10 17:23:16 +01:00
|
|
|
|
2008-02-18 04:16:53 +01:00
|
|
|
using util::contains;
|
2008-02-10 17:23:16 +01:00
|
|
|
|
|
|
|
|
|
2011-12-02 16:10:03 +01:00
|
|
|
namespace proc {
|
2010-02-28 07:17:12 +01:00
|
|
|
namespace asset {
|
2007-09-16 03:02:05 +02:00
|
|
|
|
2010-12-30 04:30:33 +01:00
|
|
|
/****** NOTE: not fully implemented yet. What follows is partially a hack to build simple tests *******/
|
2010-02-28 07:17:12 +01:00
|
|
|
|
2008-02-15 02:56:25 +01:00
|
|
|
|
|
|
|
|
|
2007-09-16 03:02:05 +02:00
|
|
|
|
|
|
|
|
|
2008-02-10 17:23:16 +01:00
|
|
|
/** storage for the static StructFactory instance */
|
2010-10-29 04:28:46 +02:00
|
|
|
StructFactory Struct::retrieve;
|
2008-02-10 17:23:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/** using private implementation detail class */
|
|
|
|
|
StructFactory::StructFactory ()
|
|
|
|
|
: impl_(new StructFactoryImpl(*this))
|
|
|
|
|
{ }
|
2007-09-16 03:02:05 +02:00
|
|
|
|
|
|
|
|
|
2010-10-29 04:28:46 +02:00
|
|
|
/** invoke the factory to create new Structural Asset.
|
|
|
|
|
* This function skips the query and retrieval of existing
|
|
|
|
|
* instances and immediately creates a new one.
|
|
|
|
|
* @param nameID (optional) an ID to use; if omitted an ID
|
|
|
|
|
* will be default created, based on the kind of Asset.
|
2010-10-29 05:24:19 +02:00
|
|
|
* @throw error::Invalid in case of ID clash with an existing Asset
|
2010-10-29 04:28:46 +02:00
|
|
|
* @return an Struct smart ptr linked to the internally registered smart ptr
|
|
|
|
|
* created as a side effect of calling the concrete Struct subclass ctor.
|
2012-12-09 02:42:36 +01:00
|
|
|
* @todo using the AssetManager this way for picking up the previously stored
|
|
|
|
|
* asset is a code smell ////////////////////////////TICKET #691
|
2010-10-29 04:28:46 +02:00
|
|
|
*/
|
|
|
|
|
template<class STRU>
|
2015-07-02 19:16:46 +02:00
|
|
|
lib::P<STRU>
|
2010-10-29 04:28:46 +02:00
|
|
|
StructFactory::newInstance (Symbol nameID)
|
|
|
|
|
{
|
|
|
|
|
Query<STRU> desired_name (isnil(nameID)? "" : "id("+nameID+")");
|
|
|
|
|
STRU* pS = impl_->fabricate (desired_name);
|
|
|
|
|
return AssetManager::instance().wrap (*pS);
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-10 17:23:16 +01:00
|
|
|
|
2010-10-29 04:28:46 +02:00
|
|
|
|
2012-12-09 02:42:36 +01:00
|
|
|
/** Retrieve a suitable Structural Asset instance, possibly create one.
|
2009-01-05 16:17:17 +01:00
|
|
|
* First tries to resolve the asset by issuing an capability query.
|
2008-12-28 05:36:37 +01:00
|
|
|
* If unsuccessful, use some internally specialised ctor call.
|
2010-03-06 04:30:12 +01:00
|
|
|
* @todo work out the struct asset naming scheme! /////////////////////////////////TICKET #565
|
2010-02-28 07:17:12 +01:00
|
|
|
* @todo for now we're using a faked config query, just pulling preconfigured
|
|
|
|
|
* hardwired answers from a table. Should be replaced by a real resolution engine.
|
2010-10-28 03:57:12 +02:00
|
|
|
* @note the exact calling sequence implemented here can be considered a compromise,
|
2012-12-09 02:42:36 +01:00
|
|
|
* due to having neither a working resolution, nor a generic interface for
|
2010-10-28 03:57:12 +02:00
|
|
|
* issuing queries. Thus, directly calling this factory acts as a replacement
|
2012-12-09 02:42:36 +01:00
|
|
|
* for both. The intended solution would be to have a dedicated QueryResolver,
|
|
|
|
|
* which is fully integrated into a generic rules driven query subsystem, but
|
|
|
|
|
* has the additional ability to "translate" capabilities directly into the
|
|
|
|
|
* respective properties of of asset::Struct subclasses.
|
2015-01-17 16:08:56 +01:00
|
|
|
* @return a Struct smart ptr linked to the internally registered smart ptr
|
2010-10-29 04:28:46 +02:00
|
|
|
* created as a side effect of calling the concrete Struct subclass ctor.
|
2007-09-16 03:02:05 +02:00
|
|
|
*/
|
2008-02-10 17:23:16 +01:00
|
|
|
template<class STRU>
|
2015-07-02 19:16:46 +02:00
|
|
|
lib::P<STRU>
|
2010-10-29 04:28:46 +02:00
|
|
|
StructFactory::operator() (Query<STRU> const& capabilities)
|
2007-09-16 03:02:05 +02:00
|
|
|
{
|
2015-07-02 19:16:46 +02:00
|
|
|
lib::P<STRU> res;
|
2012-12-01 08:44:07 +01:00
|
|
|
QueryHandler<STRU>& typeHandler = ConfigResolver::instance();
|
2008-03-10 08:38:59 +01:00
|
|
|
typeHandler.resolve (res, capabilities);
|
2008-02-10 17:23:16 +01:00
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
|
|
// create new one, since the
|
|
|
|
|
// ConfigQuery didn't yield any result
|
|
|
|
|
STRU* pS = impl_->fabricate(capabilities);
|
|
|
|
|
return AssetManager::instance().wrap (*pS);
|
2008-01-14 01:01:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-11-02 04:09:06 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////TICKET #710 : backdoor for fake-configrules
|
|
|
|
|
/** special backdoor for fake-configrules.hpp
|
|
|
|
|
* This allows to simulate creation of objects triggered by rules.
|
|
|
|
|
* Actually we use just a fake implementation based on a table lookup
|
|
|
|
|
* plus some hard wired special cases, which need to call in here to
|
|
|
|
|
* fabricate new objects, which can then be used as "solutions".
|
|
|
|
|
* @param query a prolog like query string
|
|
|
|
|
* @note works quite similar like the #operator(), but without
|
|
|
|
|
* re-invoking the ConfigRules....
|
|
|
|
|
*/
|
|
|
|
|
template<class STRU>
|
2015-07-02 19:16:46 +02:00
|
|
|
lib::P<STRU>
|
2010-11-02 04:09:06 +01:00
|
|
|
StructFactory::made4fake (Query<STRU> const& query)
|
|
|
|
|
{
|
|
|
|
|
STRU* pS = impl_->fabricate(query);
|
|
|
|
|
return AssetManager::instance().wrap (*pS);
|
|
|
|
|
}
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////TICKET #710 : backdoor for fake-configrules
|
2008-01-27 23:40:45 +01:00
|
|
|
|
|
|
|
|
|
2008-02-14 04:12:30 +01:00
|
|
|
/** Factory method for creating Pipes explicitly.
|
2008-12-28 05:36:37 +01:00
|
|
|
* Normalises pipe- and streamID, then retrieves the
|
2008-01-14 01:01:11 +01:00
|
|
|
* default processing pattern (ProcPatt) for this streamID.
|
2008-02-14 04:12:30 +01:00
|
|
|
* The Pipe ctor will fill out the shortDesc and longDesc
|
|
|
|
|
* automatically, based on pipeID and streamID (and they
|
2008-01-14 01:01:11 +01:00
|
|
|
* are editable anyways)
|
|
|
|
|
* @see ProcPatt
|
|
|
|
|
* @see DefaultsManager
|
|
|
|
|
*/
|
2015-07-02 19:16:46 +02:00
|
|
|
lib::P<Pipe>
|
2010-10-29 06:09:06 +02:00
|
|
|
StructFactory::newPipe (string pipeID, string streamID)
|
2008-01-14 01:01:11 +01:00
|
|
|
{
|
2009-07-13 01:16:40 +02:00
|
|
|
normaliseID (pipeID);
|
|
|
|
|
normaliseID (streamID);
|
2008-02-18 04:16:53 +01:00
|
|
|
static format descriptor("pipe(%s), stream(%s).");
|
2010-12-10 17:39:39 +01:00
|
|
|
Pipe* pP = impl_->fabricate (Query<Pipe> (str(descriptor % pipeID % streamID)));
|
2008-01-14 01:01:11 +01:00
|
|
|
return AssetManager::instance().wrap (*pP);
|
2007-09-16 03:02:05 +02:00
|
|
|
}
|
2010-02-28 07:17:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 16:10:03 +01:00
|
|
|
}} // namespace asset
|
2008-02-10 17:23:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
|
/* explicit instantiations of the factory methods */
|
|
|
|
|
/**************************************************/
|
|
|
|
|
|
2008-02-14 04:12:30 +01:00
|
|
|
#include "proc/asset/pipe.hpp"
|
2010-12-30 04:30:33 +01:00
|
|
|
#include "proc/asset/procpatt.hpp"
|
2010-03-12 01:49:30 +01:00
|
|
|
#include "proc/asset/timeline.hpp"
|
|
|
|
|
#include "proc/asset/sequence.hpp"
|
2008-02-10 17:23:16 +01:00
|
|
|
|
|
|
|
|
|
2011-12-02 16:10:03 +01:00
|
|
|
namespace proc {
|
2009-01-05 16:17:17 +01:00
|
|
|
namespace asset {
|
2015-07-02 19:16:46 +02:00
|
|
|
using PPipe = lib::P<Pipe>;
|
2008-02-10 17:23:16 +01:00
|
|
|
|
2015-07-02 19:16:46 +02:00
|
|
|
template PPipe StructFactory::operator() (Query<Pipe> const&);
|
2010-11-02 04:09:06 +01:00
|
|
|
template PProcPatt StructFactory::operator() (Query<const ProcPatt> const&);
|
|
|
|
|
template PTimeline StructFactory::operator() (Query<Timeline> const&);
|
|
|
|
|
template PSequence StructFactory::operator() (Query<Sequence>const&);
|
2010-02-28 07:17:12 +01:00
|
|
|
|
2015-07-02 19:16:46 +02:00
|
|
|
template PPipe StructFactory::newInstance (Symbol);
|
2010-10-29 04:28:46 +02:00
|
|
|
template PProcPatt StructFactory::newInstance (Symbol);
|
|
|
|
|
template PTimeline StructFactory::newInstance (Symbol);
|
|
|
|
|
template PSequence StructFactory::newInstance (Symbol);
|
|
|
|
|
|
2015-07-02 19:16:46 +02:00
|
|
|
template PPipe StructFactory::made4fake (Query<Pipe> const&);
|
2010-11-02 04:09:06 +01:00
|
|
|
template PProcPatt StructFactory::made4fake (Query<const ProcPatt> const&);
|
|
|
|
|
template PTimeline StructFactory::made4fake (Query<Timeline> const&);
|
|
|
|
|
template PSequence StructFactory::made4fake (Query<Sequence>const&);
|
2008-02-10 17:23:16 +01:00
|
|
|
|
2011-12-02 16:10:03 +01:00
|
|
|
}} // namespace asset
|