Commit 564bd605 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - prepared connectors to use weak pointers to manage the module

parent 6794f199
...@@ -48,6 +48,7 @@ WModuleConnector::WModuleConnector( boost::shared_ptr< WModule > module, std::st ...@@ -48,6 +48,7 @@ WModuleConnector::WModuleConnector( boost::shared_ptr< WModule > module, std::st
{ {
// initialize members // initialize members
m_module = module; m_module = module;
m_moduleName = module->getName();
m_name = name; m_name = name;
m_description = description; m_description = description;
...@@ -103,10 +104,11 @@ unsigned int WModuleConnector::isConnected() ...@@ -103,10 +104,11 @@ unsigned int WModuleConnector::isConnected()
void WModuleConnector::connect( boost::shared_ptr<WModuleConnector> con ) void WModuleConnector::connect( boost::shared_ptr<WModuleConnector> con )
{ {
boost::shared_ptr< WModuleContainer > container = m_module->getAssociatedContainer(); boost::shared_ptr< WModule > module = m_module;//.lock(); // it is "unlocked" at the end of this function as "module" looses its scope
boost::shared_ptr< WModuleContainer > container = module->getAssociatedContainer();
std::string containerName = container.get() ? container->getName() : "Unknown"; std::string containerName = container.get() ? container->getName() : "Unknown";
WLogger::getLogger()->addLogMessage( "Connecting " + con->getCanonicalName() + " with " + getCanonicalName() WLogger::getLogger()->addLogMessage( "Connecting " + con->getCanonicalName() + " with " + getCanonicalName(),
, "ModuleContainer (" + containerName + ")", LL_INFO ); "ModuleContainer (" + containerName + ")", LL_INFO );
// are both partners compatible to each other? // are both partners compatible to each other?
if ( !( con->connectable( shared_from_this() ) && connectable( con ) ) ) if ( !( con->connectable( shared_from_this() ) && connectable( con ) ) )
...@@ -203,7 +205,8 @@ boost::signals2::connection WModuleConnector::subscribeSignal( MODULE_CONNECTOR_ ...@@ -203,7 +205,8 @@ boost::signals2::connection WModuleConnector::subscribeSignal( MODULE_CONNECTOR_
const t_GenericSignalHandlerType WModuleConnector::getSignalHandler( MODULE_CONNECTOR_SIGNAL signal ) const t_GenericSignalHandlerType WModuleConnector::getSignalHandler( MODULE_CONNECTOR_SIGNAL signal )
{ {
// the module instance knows that // the module instance knows that
return m_module->getSignalHandler( signal ); boost::shared_ptr< WModule > module = m_module;//.lock(); // it is "unlocked" at the end of this function as "module" looses its scope
return module->getSignalHandler( signal );
} }
void WModuleConnector::disconnect( boost::shared_ptr<WModuleConnector> con, bool removeFromOwnList ) void WModuleConnector::disconnect( boost::shared_ptr<WModuleConnector> con, bool removeFromOwnList )
...@@ -291,7 +294,7 @@ const std::string WModuleConnector::getName() const ...@@ -291,7 +294,7 @@ const std::string WModuleConnector::getName() const
const std::string WModuleConnector::getCanonicalName() const const std::string WModuleConnector::getCanonicalName() const
{ {
std::ostringstream s; std::ostringstream s;
s << m_module->getName() << ":" << getName(); s << m_moduleName << ":" << getName();
return s.str(); return s.str();
} }
......
...@@ -207,6 +207,11 @@ protected: ...@@ -207,6 +207,11 @@ protected:
*/ */
boost::shared_ptr< WModule > m_module; boost::shared_ptr< WModule > m_module;
/**
* The name of the module owning this connector.
*/
std::string m_moduleName;
/** /**
* Gets called whenever a connector gets connected to the specified input. * Gets called whenever a connector gets connected to the specified input.
* *
......
...@@ -399,8 +399,10 @@ void WModuleProjectFileCombiner::save( std::ostream& output ) // NOLINT ...@@ -399,8 +399,10 @@ void WModuleProjectFileCombiner::save( std::ostream& output ) // NOLINT
for ( std::set<boost::shared_ptr<WModuleConnector> >::const_iterator iciter = ( *citer )->m_connected.begin(); for ( std::set<boost::shared_ptr<WModuleConnector> >::const_iterator iciter = ( *citer )->m_connected.begin();
iciter != ( *citer )->m_connected.end(); ++iciter ) iciter != ( *citer )->m_connected.end(); ++iciter )
{ {
// as the module is a weak_ptr -> lock and get access to it
boost::shared_ptr< WModule > theOtherModule = ( *iciter )->m_module;//.lock();
output << "CONNECTION:(" << moduleToIDMap[ ( *iter ) ] << "," << ( *citer )->getName() << ")->(" << output << "CONNECTION:(" << moduleToIDMap[ ( *iter ) ] << "," << ( *citer )->getName() << ")->(" <<
moduleToIDMap[ ( *iciter )->m_module ] << "," << ( *iciter )->getName() << ")" << std::endl; moduleToIDMap[ theOtherModule ] << "," << ( *iciter )->getName() << ")" << std::endl;
} }
lock.unlock(); lock.unlock();
} }
......
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