Commit 8c426a9e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[FIX #387] connections can now be forced if the connector output was not set.

parent 0a1e4614
......@@ -112,7 +112,7 @@ unsigned int WModuleConnector::isConnected()
return count;
}
void WModuleConnector::connect( boost::shared_ptr<WModuleConnector> con )
void WModuleConnector::connect( boost::shared_ptr<WModuleConnector> con, bool force )
{
boost::shared_ptr< WModule > module = m_module.lock(); // it is "unlocked" at the end of this function as "module" looses its scope
std::string containerName = "Unknown";
......@@ -126,11 +126,25 @@ void WModuleConnector::connect( boost::shared_ptr<WModuleConnector> con )
"ModuleContainer (" + containerName + ")", LL_INFO );
// are both partners compatible to each other?
if( !( con->connectable( shared_from_this() ) && connectable( con ) ) )
if( force )
{
std::ostringstream s;
s << "Connection between " << getCanonicalName() << " and " << con->getCanonicalName() << " failed.";
throw WModuleConnectorsIncompatible( s.str() );
// if not forced, use a complete compatibility check
if( !( con->lazyConnectable( shared_from_this() ) && lazyConnectable( con ) ) )
{
std::ostringstream s;
s << "Connection between " << getCanonicalName() << " and " << con->getCanonicalName() << " failed.";
throw WModuleConnectorsIncompatible( s.str() );
}
}
else
{
// if not forced, use a complete compatibility check
if( !( con->connectable( shared_from_this() ) && connectable( con ) ) )
{
std::ostringstream s;
s << "Connection between " << getCanonicalName() << " and " << con->getCanonicalName() << " failed.";
throw WModuleConnectorsIncompatible( s.str() );
}
}
// check whether they are already connected
......
......@@ -102,12 +102,13 @@ public:
* WModuleConnector::connectable is used to determine whether the connection is possible or not.
*
* \param con the connector to connect.
* \param force force connection even if incompatible. Used primarily for project file loader. If true, only a \ref lazyConnectable is used.
*
* \exception WModuleConnectionFailed if connection can not be established.
*
* \return true if successful
*/
virtual void connect( boost::shared_ptr<WModuleConnector> con );
virtual void connect( boost::shared_ptr<WModuleConnector> con, bool force = false );
/**
* Checks whether this connector is connected to the given one. If there is the strange case where one connector is connected
......@@ -185,6 +186,16 @@ public:
*/
virtual bool connectable( boost::shared_ptr<WModuleConnector> con ) = 0;
/**
* Checks whether the specified connector is connectable to this one, but ignores compatibility the type to be transferred. If you implement your
* own connectors, please override and check for compatibility with your matching connectors, but ignore the transfer type.
*
* \param con the connector to check against.
*
* \return true if compatible.
*/
virtual bool lazyConnectable( boost::shared_ptr<WModuleConnector> con ) = 0;
/**
* Returns a list of possible disconnections for this connector. Please be aware that the connections might change during the life-time of
* the returned DisconnectCombiner instances.
......
......@@ -66,6 +66,16 @@ bool WModuleInputConnector::connectable( boost::shared_ptr<WModuleConnector> con
return false;
}
bool WModuleInputConnector::lazyConnectable( boost::shared_ptr<WModuleConnector> con )
{
// output connectors are just allowed to get connected with input connectors
if( dynamic_cast<WModuleOutputConnector*>( con.get() ) ) // NOLINT - since we really need them here
{
return true;
}
return false;
}
void WModuleInputConnector::connectSignals( boost::shared_ptr<WModuleConnector> con )
{
WModuleConnector::connectSignals( con );
......
......@@ -65,6 +65,15 @@ public:
*/
virtual bool connectable( boost::shared_ptr<WModuleConnector> con );
/**
* Checks whether the specified connector is connectable to this one, but ignores compatibility the type to be transferred.
*
* \param con the connector to check against.
*
* \return true if compatible.
*/
virtual bool lazyConnectable( boost::shared_ptr<WModuleConnector> con );
/**
* Gets the condition variable that gets fired whenever new data has been sent.
*
......
......@@ -54,6 +54,17 @@ bool WModuleOutputConnector::connectable( boost::shared_ptr<WModuleConnector> co
return false;
}
bool WModuleOutputConnector::lazyConnectable( boost::shared_ptr<WModuleConnector> con )
{
// output connectors are just allowed to get connected with input connectors
if( dynamic_cast<WModuleInputConnector*>( con.get() ) ) // NOLINT - since we really need them here
{
return true;
}
return false;
}
boost::signals2::connection WModuleOutputConnector::subscribeSignal( MODULE_CONNECTOR_SIGNAL signal,
t_GenericSignalHandlerType notifier )
{
......
......@@ -83,6 +83,15 @@ public:
*/
virtual bool connectable( boost::shared_ptr<WModuleConnector> con );
/**
* Checks whether the specified connector is connectable to this one, but ignores compatibility the type to be transferred.
*
* \param con the connector to check against.
*
* \return true if compatible.
*/
virtual bool lazyConnectable( boost::shared_ptr<WModuleConnector> con );
/**
* Returns the prototype of the WTransferable used in this connector.
*
......
......@@ -343,7 +343,8 @@ void WModuleProjectFileCombiner::apply()
// finally, connect them
try
{
con1->connect( con2 );
// force connection since data modules might not yet have set an output -> makes them incompatible -> con fails.
con1->connect( con2, true);
}
catch( const WException& e )
{
......
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