Commit 1488673b authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - 1-1 connector compatibility test

parent 08cc85d3
......@@ -95,7 +95,7 @@ WGEViewer::WGEViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, i
WGEViewer::~WGEViewer()
{
// cleanup
wait( true );
close();
}
osg::ref_ptr<osgViewer::CompositeViewer> WGEViewer::getViewer()
......
......@@ -141,8 +141,8 @@ int WKernel::run()
m_gui->getLoadButtonSignal()->connect( boost::bind( &WKernel::doLoadDataSets, this, _1 ) );
// default modules
m_moduleContainer->add( m_moduleFactory->create( m_moduleFactory->getPrototypeByName( "Navigation Slice Module" ) ) );
m_moduleContainer->add( m_moduleFactory->create( m_moduleFactory->getPrototypeByName( "Coordinate System Module" ) ) );
//m_moduleContainer->add( m_moduleFactory->create( m_moduleFactory->getPrototypeByName( "Navigation Slice Module" ) ) );
//m_moduleContainer->add( m_moduleFactory->create( m_moduleFactory->getPrototypeByName( "Coordinate System Module" ) ) );
m_gui->wait( false );
m_FinishRequested = true;
......
......@@ -32,6 +32,7 @@
#include "WModuleOutputConnector.h"
#include "WModuleConnectorSignals.h"
#include "WModuleContainer.h"
#include "WModuleFactory.h"
#include "exceptions/WModuleSignalUnknown.h"
#include "exceptions/WModuleSignalSubscriptionFailed.h"
#include "exceptions/WModuleConnectorInitFailed.h"
......@@ -190,6 +191,11 @@ const t_GenericSignalHandlerType WModule::getSignalHandler( MODULE_CONNECTOR_SIG
}
}
std::set< boost::shared_ptr< WModule > > WModule::getCompatibles()
{
return WModuleFactory::getModuleFactory()->getCompatiblePrototypes( shared_from_this() );
}
bool WModule::isInitialized() const
{
return m_initialized;
......
......@@ -160,6 +160,13 @@ public:
virtual boost::signals2::connection subscribeSignal( MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier );
virtual boost::signals2::connection subscribeSignal( MODULE_SIGNAL signal, t_ModuleErrorSignalHandlerType notifier );
/**
* Returns a set of prototypes compatible with this module's connectors.
*
* \return set of prototypes.
*/
virtual std::set< boost::shared_ptr< WModule > > getCompatibles();
protected:
/**
......
......@@ -144,8 +144,6 @@ public:
*/
void setName( std::string name );
protected:
/**
* Checks whether the specified connector is connectable to this one.
*
......@@ -155,6 +153,8 @@ protected:
*/
virtual bool connectable( boost::shared_ptr<WModuleConnector> con )=0;
protected:
/**
* List of connectors connected to this connector.
*/
......
......@@ -158,11 +158,60 @@ const boost::shared_ptr< WModule > WModuleFactory::getPrototypeByName( std::stri
return ret;
}
const boost::shared_ptr< WModule > WModuleFactory::getPrototypeByInstance( boost::shared_ptr< WModule > /*instance*/ )
const boost::shared_ptr< WModule > WModuleFactory::getPrototypeByInstance( boost::shared_ptr< WModule > instance )
{
// TODO(ebaum): implement
WLogger::getLogger()->addLogMessage( "Searching prototype by instance, NOT YET IMPLEMENTED", "ModuleFactory", LL_WARNING );
return getPrototypeByName( instance->getName() );
}
std::set< boost::shared_ptr< WModule > > WModuleFactory::getCompatiblePrototypes( boost::shared_ptr< WModule > module )
{
std::set< boost::shared_ptr < WModule > > compatibles;
// for this a read lock is sufficient
boost::shared_lock< boost::shared_mutex > slock = boost::shared_lock< boost::shared_mutex >( m_prototypesLock );
// get offered outputs
std::set<boost::shared_ptr<WModuleOutputConnector> > cons = module->getOutputConnectors();
if ( cons.size() == 0 )
{
// in this case return the empty list
return compatibles;
}
// TODO(ebaum): see ticket #178 for this
if ( cons.size() > 1 )
{
WLogger::getLogger()->addLogMessage( "Can not find compatibles for modules with more than 1 output connector. Using "
+ ( *cons.begin() )->getCanonicalName() + " for compatibility check.", "ModuleFactory", LL_WARNING );
}
// go through every prototype
for( std::set< boost::shared_ptr< WModule > >::iterator listIter = m_prototypes.begin(); listIter != m_prototypes.end();
++listIter )
{
// get connectors of this prototype
std::set<boost::shared_ptr<WModuleInputConnector> > pcons = ( *listIter )->getInputConnectors();
// ensure we have 1 connector
if ( pcons.size() == 0 )
{
continue;
}
if ( pcons.size() > 1 )
{
WLogger::getLogger()->addLogMessage( "Can not find compatibles for modules with more than 1 input connector. Using "
+ ( *pcons.begin() )->getCanonicalName() + " for compatibility check.", "ModuleFactory", LL_WARNING );
}
// check whether the outputs are compatible with the inputs of the prototypes
if ( ( *cons.begin() )->connectable( *pcons.begin() ) )
{
// it is compatible -> add to list
compatibles.insert( *listIter );
}
}
slock.unlock();
return boost::shared_ptr< WModule >();
return compatibles;
}
......@@ -94,14 +94,19 @@ public:
/**
* Checks whether the first instance can be casted to the second one.
*
* \param module1 the module to check.
* \param module2 the module to check against.
* \param module the module to check.
*
* \return
* \return true if the dynamic_cast is successful
*/
template <typename T>
static bool isA( boost::shared_ptr< WModule > module );
/**
* Returns a set of modules compatible with the specified one.
*
* \return set of compatible prototypes.
*/
std::set< boost::shared_ptr< WModule > > getCompatiblePrototypes( boost::shared_ptr< WModule > module );
protected:
/**
......
......@@ -52,8 +52,6 @@ public:
*/
virtual ~WModuleInputConnector();
protected:
/**
* Checks whether the specified connector is an output connector.
*
......@@ -63,6 +61,8 @@ protected:
*/
virtual bool connectable( boost::shared_ptr<WModuleConnector> con );
protected:
/**
* Connect additional signals.
*
......
......@@ -99,8 +99,6 @@ public:
return dat;
};
protected:
/**
* Checks whether the specified connector is an input connector and compatible with T.
*
......@@ -120,6 +118,8 @@ protected:
return false;
};
protected:
private:
};
......
......@@ -69,8 +69,6 @@ public:
*/
boost::signals2::connection subscribeSignal( MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier );
protected:
/**
* Checks whether the specified connector is an input connector.
*
......@@ -80,6 +78,8 @@ protected:
*/
virtual bool connectable( boost::shared_ptr<WModuleConnector> con );
protected:
// If you want to add additional signals an output connector should subscribe FROM an input connector, overwrite
// connectSignals
// virtual void connectSignals( boost::shared_ptr<WModuleConnector> con );
......
......@@ -87,8 +87,6 @@ public:
return m_data;
};
protected:
/**
* Checks whether the specified connector is an input connector and compatible with T.
*
......@@ -109,6 +107,8 @@ protected:
return false;
};
protected:
private:
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment