32 #include "../common/WLogger.h"
33 #include "combiner/WApplyCombiner.h"
34 #include "exceptions/WPrototypeNotUnique.h"
35 #include "exceptions/WPrototypeUnknown.h"
37 #include "WModuleCombiner.h"
38 #include "WModuleFactory.h"
72 std::set< std::string > names;
74 while( listIter != l->get().end() )
79 if( names.count( ( *listIter )->getName() ) )
82 "\" is not unique. Modules have to have a unique name. Ignoring this module." ),
83 "ModuleFactory", LL_ERROR );
85 l->get().erase( listIter++ );
90 names.insert( ( *listIter )->getName() );
107 return ( ticket->get().count( module ) != 0 );
112 wlog::debug(
"ModuleFactory" ) <<
"Creating new instance of prototype \"" << prototype->getName() <<
"\".";
120 throw WPrototypeUnknown( std::string(
"Could not clone module \"" + prototype->getName() +
"\" since it is no prototype." ) );
127 boost::shared_ptr< WModule > clone = boost::shared_ptr< WModule >( prototype->factory() );
129 clone->setUUID( uuid );
133 clone->setLocalPath( prototype->getLocalPath() );
141 module->initialize();
161 boost::shared_ptr< WModule > ret = boost::shared_ptr< WModule >();
162 for( std::set< boost::shared_ptr< WModule > >::const_iterator listIter = l->get().begin(); listIter != l->get().end();
165 if( ( *listIter )->getName() == name )
180 if( ret == boost::shared_ptr< WModule >() )
182 throw WPrototypeUnknown( std::string(
"Could not find prototype \"" + name +
"\"." ) );
195 std::vector< WModule::ConstSPtr > ret;
201 for( std::set< boost::shared_ptr< WModule > >::const_iterator listIter = l->get().begin(); listIter != l->get().end();
204 if( ( *listIter )->getType() == type )
206 ret.push_back( *listIter );
220 WCombinerTypes::WCompatiblesList compatibles;
226 bool addModulesWithoutInput = !module;
228 if( addModulesWithoutInput )
236 if( pcons.size() == 0 )
239 WCombinerTypes::WOneToOneCombiners lComp;
242 lComp.push_back( boost::shared_ptr< WApplyCombiner >(
new WApplyCombiner( module,
"", *listIter,
"" ) ) );
245 compatibles.push_back( WCombinerTypes::WCompatiblesGroup( ( *listIter ), lComp ) );
257 WCombinerTypes::WOneToOneCombiners lComp = WApplyCombiner::createCombinerList< WApplyCombiner >( module, ( *listIter ) );
260 if( lComp.size() != 0 )
262 compatibles.push_back( WCombinerTypes::WCompatiblesGroup( ( *listIter ), lComp ) );
271 std::sort( compatibles.begin(), compatibles.end(), WCombinerTypes::compatiblesSort );
278 WCombinerTypes::WCompatiblesList compatibles;
288 WCombinerTypes::WOneToOneCombiners lComp;
291 lComp.push_back( boost::shared_ptr< WApplyCombiner >(
new WApplyCombiner( *listIter ) ) );
294 compatibles.push_back( WCombinerTypes::WCompatiblesGroup( ( *listIter ), lComp ) );
301 std::sort( compatibles.begin(), compatibles.end(), WCombinerTypes::compatiblesSort );
313 UuidModuleMap::const_iterator it = r->get().find( uuid );
314 if( it != r->get().end() )
317 boost::weak_ptr< WModule > m = ( *it ).second;
boost::shared_ptr< WSharedObjectTicketWrite< PrototypeContainerType > > WriteTicket
Type for write tickets.
const boost::shared_ptr< WModule > getPrototypeByInstance(boost::shared_ptr< WModule > instance)
Finds a prototype using an instance of a module.
const boost::shared_ptr< WModule > getPrototypeByName(std::string name)
Finds a prototype using the specified name.
WCombinerTypes::WCompatiblesList getAllPrototypes()
Creates a list of WApplyCombiner for all modules known by the factory.
std::set< boost::shared_ptr< WModule > >::iterator PrototypeContainerIteratorType
Iterator for the prototype set.
static boost::shared_ptr< WModuleFactory > m_instance
Singleton instance of WModuleFactory.
boost::shared_ptr< WModule > create(boost::shared_ptr< WModule > prototype, std::string uuid="")
Create a new and initialized module using the specified prototype.
std::pair< Iterator, bool > insert(const value_type &x)
Inserts the specified element.
Loads module prototypes from shared objects in a given directory and injects it into the module facto...
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
static bool isPrototype(boost::shared_ptr< WModule > module)
Checks whether the specified module is a prototype or an instantiated module.
WModuleLoader::SPtr m_moduleLoader
Loader class managing dynamically loaded modules in OpenWalnut.
static boost::shared_ptr< WModuleLoader > getModuleLoader()
Returns instance of the module loader.
static WModule::SPtr findByUUID(std::string uuid)
Find a module instance by UUID.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
boost::shared_ptr< WModuleFactory > SPtr
Shared pointer to a WModule.
PrototypeSharedContainerType::ReadTicket getPrototypes() const
This method gives read access to the list of all prototypes.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
virtual ~WModuleFactory()
Destructor.
WModuleFactory()
Constructors are protected because this is a Singleton.
boost::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
static SPtr getModuleFactory()
Returns instance of the module factory to use to create modules.
static void initializeModule(boost::shared_ptr< WModule > module)
This method uses a newly created instance of WModule and initializes it properly. ...
std::vector< WModule::ConstSPtr > getPrototypesByType(MODULE_TYPE type)
Finds a prototype using an type.
std::vector< boost::shared_ptr< WModuleInputConnector > > InputConnectorList
The type for the list of input connectors.
This class provides a common interface for thread-safe access to associative containers (set...
std::set< boost::shared_ptr< WModule > >::const_iterator PrototypeContainerConstIteratorType
Const iterator for the prototype set.
Base class for all combiners which apply one connection between two connectors of two modules...
Thrown whenever an unknown prototype is specified.
WSharedAssociativeContainer< UuidModuleMap > m_uuidModuleMap
Keep track of uuids of each created module.
void load()
Loads the modules and creates prototypes.
PrototypeSharedContainerType m_prototypes
The module prototypes available.
const boost::shared_ptr< WModule > isPrototypeAvailable(std::string name)
Searches a prototype by name.
bool checkPrototype(boost::shared_ptr< WModule > module, PrototypeSharedContainerType::ReadTicket ticket)
Checks whether the specified module is a prototype or an instantiated module.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
boost::shared_ptr< WSharedObjectTicketRead< PrototypeContainerType > > ReadTicket
Type for read tickets.
WCombinerTypes::WCompatiblesList getCompatiblePrototypes(boost::shared_ptr< WModule > module=boost::shared_ptr< WModule >())
Returns a set of module combiners with module combinations compatible with the specified one...