2008-06-24 05:19:11 +02:00
|
|
|
/*
|
|
|
|
|
NodeWiring - Implementation of the node network and operation control
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "proc/engine/procnode.hpp"
|
|
|
|
|
#include "proc/engine/nodewiring.hpp"
|
|
|
|
|
#include "proc/engine/nodeoperation.hpp"
|
2009-08-29 16:13:42 +02:00
|
|
|
#include "proc/engine/nodewiring-config.hpp"
|
2008-07-05 18:50:54 +02:00
|
|
|
|
2009-06-30 04:54:50 +02:00
|
|
|
#include "lib/meta/typelist-util.hpp"
|
2008-08-03 16:47:38 +02:00
|
|
|
|
2008-06-24 05:19:11 +02:00
|
|
|
|
|
|
|
|
namespace engine {
|
2008-08-04 05:42:55 +02:00
|
|
|
|
|
|
|
|
namespace config {
|
2008-08-03 16:47:38 +02:00
|
|
|
|
|
|
|
|
using lumiera::typelist::Flags;
|
|
|
|
|
using lumiera::typelist::CombineFlags;
|
|
|
|
|
using lumiera::typelist::DefineConfigByFlags;
|
|
|
|
|
using lumiera::typelist::Instantiation;
|
|
|
|
|
using lumiera::typelist::Apply;
|
|
|
|
|
using lumiera::typelist::Filter;
|
|
|
|
|
|
2009-08-29 18:33:46 +02:00
|
|
|
using lib::AllocationCluster;
|
|
|
|
|
|
2008-08-03 16:47:38 +02:00
|
|
|
|
|
|
|
|
typedef Flags<CACHING,PROCESS,INPLACE>::Tuple AllFlags;
|
2008-08-04 05:42:55 +02:00
|
|
|
|
2008-08-03 16:47:38 +02:00
|
|
|
/** build the list of all possible flag combinations */
|
|
|
|
|
typedef CombineFlags<AllFlags> AllFlagCombinations;
|
2008-08-04 05:42:55 +02:00
|
|
|
|
2008-08-03 16:47:38 +02:00
|
|
|
/** build a configuration type for each of those flag combinations */
|
|
|
|
|
typedef Apply<AllFlagCombinations::List, DefineConfigByFlags> AllConfigs;
|
|
|
|
|
|
|
|
|
|
/** filter those configurations which actually define a wiring strategy */
|
|
|
|
|
typedef Filter<AllConfigs::List, Instantiation<Strategy>::Test> PossibleConfigs;
|
|
|
|
|
|
2008-08-04 05:42:55 +02:00
|
|
|
|
2009-08-30 14:50:40 +02:00
|
|
|
#define PICK_FLAG(_FLAG_) config::FlagInfo<CONF>::CODE & (_FLAG_)
|
|
|
|
|
|
|
|
|
|
template<class CONF>
|
|
|
|
|
struct UseBufferProvider
|
|
|
|
|
: config::SelectBuffProvider< PICK_FLAG (CACHING), PICK_FLAG (INPLACE) >
|
|
|
|
|
{ };
|
2008-10-13 04:33:10 +02:00
|
|
|
|
|
|
|
|
// internal details: setting up a factory for each required configuration
|
2008-08-03 16:47:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-30 14:11:14 +02:00
|
|
|
/**
|
|
|
|
|
* Fabricating a WiringDescriptor
|
|
|
|
|
* tailored for a specific node wiring situation.
|
|
|
|
|
*/
|
2008-08-03 16:47:38 +02:00
|
|
|
template<class CONF>
|
|
|
|
|
class WiringDescriptorFactory
|
|
|
|
|
{
|
2009-08-29 18:33:46 +02:00
|
|
|
AllocationCluster& alloc_;
|
2008-08-04 05:42:55 +02:00
|
|
|
|
2009-08-30 14:50:40 +02:00
|
|
|
/* ==== pick actual wiring code ==== */
|
|
|
|
|
typedef Strategy<CONF> Strategy;
|
|
|
|
|
typedef typename UseBufferProvider<CONF>::Type BuffProvider;
|
|
|
|
|
typedef ActualInvocationProcess<Strategy, BuffProvider> InvocationStateType;
|
|
|
|
|
|
|
|
|
|
// the concrete implementation of the glue code...
|
|
|
|
|
typedef NodeWiring<InvocationStateType> ActualWiring;
|
|
|
|
|
|
|
|
|
|
|
2008-08-03 16:47:38 +02:00
|
|
|
public:
|
2009-08-29 18:33:46 +02:00
|
|
|
WiringDescriptorFactory(AllocationCluster& a)
|
2008-08-03 16:47:38 +02:00
|
|
|
: alloc_(a) {}
|
|
|
|
|
|
|
|
|
|
WiringDescriptor&
|
2009-08-30 14:50:40 +02:00
|
|
|
operator() (WiringSituation const& intendedWiring)
|
2008-08-03 16:47:38 +02:00
|
|
|
{
|
2009-08-30 14:50:40 +02:00
|
|
|
return alloc_.create<ActualWiring> (intendedWiring);
|
2008-08-03 16:47:38 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2009-08-30 14:50:40 +02:00
|
|
|
/** invocation signature of the factories */
|
|
|
|
|
typedef WiringDescriptor& (FunctionType)(WiringSituation const&);
|
2008-08-03 16:47:38 +02:00
|
|
|
|
2009-08-30 14:50:40 +02:00
|
|
|
/** preconfigured table of all possible factories */
|
2008-10-13 04:33:10 +02:00
|
|
|
typedef ConfigSelector< WiringDescriptorFactory ///< Factory template to instantiate
|
2009-08-30 14:50:40 +02:00
|
|
|
, FunctionType ///< function signature of the Factories
|
2009-08-29 18:33:46 +02:00
|
|
|
, AllocationCluster& ///< allocator fed to all factories
|
2008-08-04 05:42:55 +02:00
|
|
|
> WiringSelector;
|
|
|
|
|
|
|
|
|
|
|
2008-08-03 16:47:38 +02:00
|
|
|
struct WiringFactoryImpl
|
|
|
|
|
{
|
2008-08-04 05:42:55 +02:00
|
|
|
WiringSelector selector;
|
2008-08-03 16:47:38 +02:00
|
|
|
|
2009-09-05 04:10:51 +02:00
|
|
|
WiringFactoryImpl (AllocationCluster& alloc)
|
2008-08-04 05:42:55 +02:00
|
|
|
: selector(config::PossibleConfigs::List(), alloc)
|
2008-08-03 16:47:38 +02:00
|
|
|
{ }
|
|
|
|
|
};
|
|
|
|
|
|
2008-10-13 04:33:10 +02:00
|
|
|
} // (END) internals (namespace config)
|
2008-08-03 16:47:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-06-24 05:19:11 +02:00
|
|
|
|
2009-09-05 04:10:51 +02:00
|
|
|
/** As the WiringFactory (and all the embedded factories
|
2009-08-30 14:50:40 +02:00
|
|
|
* for the specific wiring situations) use the AllocationCluster
|
|
|
|
|
* of the current build process, we need to create a new instance
|
|
|
|
|
* for each newly built segment of the low-level model.
|
2009-09-05 04:10:51 +02:00
|
|
|
* @note As this ctor creates a WiringFactoryImpl instance,
|
|
|
|
|
* compiling this invocation actually drives the necessary
|
|
|
|
|
* template instantiations for all cases encountered while
|
|
|
|
|
* building the node network.
|
2009-08-30 14:50:40 +02:00
|
|
|
*/
|
|
|
|
|
WiringFactory::WiringFactory (lib::AllocationCluster& a)
|
|
|
|
|
: alloc_(a),
|
|
|
|
|
pImpl_(new config::WiringFactoryImpl (alloc_))
|
|
|
|
|
{ }
|
2009-09-05 04:10:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
WiringFactory::~WiringFactory () {}
|
|
|
|
|
|
2009-08-30 14:50:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-06-24 05:19:11 +02:00
|
|
|
/** create and configure a concrete wiring descriptor to tie
|
|
|
|
|
* a ProcNode to its predecessor nodes. This includes selecting
|
2009-09-05 04:10:51 +02:00
|
|
|
* the actual StateAdapter type, configuring it based on operation
|
|
|
|
|
* control templates (policy classes).
|
2008-06-29 15:32:19 +02:00
|
|
|
* The created WiringDescriptor object is bulk allocated similar to the ProcNode
|
2008-07-05 18:50:54 +02:00
|
|
|
* objects for a given segment of the Timeline. It should be further configured
|
2008-06-24 05:19:11 +02:00
|
|
|
* with the actual predecessor nodes pointers and can then be used to create
|
|
|
|
|
* the new processing node to be wired up.
|
|
|
|
|
*/
|
|
|
|
|
WiringDescriptor&
|
2009-09-05 04:10:51 +02:00
|
|
|
WiringFactory::operator() (WiringSituation const& setup)
|
2008-06-24 05:19:11 +02:00
|
|
|
{
|
2009-09-05 04:10:51 +02:00
|
|
|
long config = setup.getFlags();
|
|
|
|
|
return pImpl_->selector[config] (setup);
|
2008-06-24 05:19:11 +02:00
|
|
|
}
|
2008-08-04 05:42:55 +02:00
|
|
|
|
2008-06-24 05:19:11 +02:00
|
|
|
|
|
|
|
|
} // namespace engine
|