Commit 2494e3e7 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - added connectors which are able to forward data to other connectors

parent 6779f219
......@@ -57,6 +57,9 @@ WModuleConnector::WModuleConnector( boost::shared_ptr<WModule> module, std::stri
// closed" message if the connection is closed.
signal_ConnectionEstablished.connect( getSignalHandler( CONNECTION_ESTABLISHED ) );
signal_ConnectionClosed.connect( getSignalHandler( CONNECTION_CLOSED ) );
subscribeSignal( CONNECTION_ESTABLISHED, boost::bind( &WModuleConnector::notifyConnectionEstablished, this, _1, _2 ) );
subscribeSignal( CONNECTION_CLOSED, boost::bind( &WModuleConnector::notifyConnectionClosed, this, _1, _2 ) );
}
WModuleConnector::~WModuleConnector()
......@@ -295,3 +298,13 @@ void WModuleConnector::setName( std::string name )
m_name = name;
}
void WModuleConnector::notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> /*here*/, boost::shared_ptr<WModuleConnector> /*there*/ )
{
// by default: do nothing.
}
void WModuleConnector::notifyConnectionClosed( boost::shared_ptr<WModuleConnector> /*here*/, boost::shared_ptr<WModuleConnector> /*there*/ )
{
// do nothing by default
}
......@@ -198,6 +198,22 @@ protected:
*/
boost::shared_ptr<WModule> m_module;
/**
* Gets called whenever a connector gets connected to the specified input.
*
* \param here the connector of THIS module that got connected to "there"
* \param there the connector that has been connected with the connector "here" of this module.
*/
virtual void notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> here, boost::shared_ptr<WModuleConnector> there );
/**
* Gets called whenever a connection between a remote and local connector gets closed.
*
* \param here the connector of THIS module getting disconnected.
* \param there the connector of the other module getting disconnected.
*/
virtual void notifyConnectionClosed( boost::shared_ptr<WModuleConnector> here, boost::shared_ptr<WModuleConnector> there );
private:
/**
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMODULEFORWARDCONNECTOR_H
#define WMODULEFORWARDCONNECTOR_H
#include <boost/shared_ptr.hpp>
#include "WModuleInputConnector.h"
#include "WModuleOutputConnector.h"
/**
* This is a simple class which forwards input connectors to input connectors, and output connectors to output connectors.
*/
class WModuleForwardConnector
{
public:
/**
* Create a forwarder which forwards all operations on a input connector to another input connector.
*
* \param from the connector whose data should be forwarded
* \param to the connector receiving forwarded data
*/
WModuleForwardConnector( boost::shared_ptr< WModuleInputConnector > from, boost::shared_ptr< WModuleInputConnector > to );
/**
* Create a forwarder which forwards all operations on a output connector to another output connector.
*
* \param from the connector whose data should be forwarded
* \param to the connector that gets the data
*/
WModuleForwardConnector( boost::shared_ptr< WModuleOutputConnector > from, boost::shared_ptr< WModuleOutputConnector > to );
/**
* Destructor.
*/
virtual ~WModuleForwardConnector();
protected:
/**
* The input connector which grabs the data
*/
boost::shared_ptr< WModuleOutputConnector > m_in;
/**
* The output connector which collects data
*/
boost::shared_ptr< WModuleOutputConnector > m_out;
private:
};
#endif // WMODULEFORWARDCONNECTOR_H
......@@ -93,3 +93,14 @@ boost::shared_ptr< WCondition > WModuleInputConnector::getDataChangedCondition()
return m_dataChangedCondition;
}
void WModuleInputConnector::notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> here, boost::shared_ptr<WModuleConnector> there )
{
// since the output connector is not able to fill the parameter "input" we need to forward this message and fill it with the
// proper information
// NOTE: connection established also emits a data changed signal since the data available at the connector has changed.
signal_DataChanged( shared_from_this(), there );
m_dataChangedCondition->notify();
// forward
WModuleConnector::notifyConnectionEstablished( here, there );
}
......@@ -93,8 +93,15 @@ protected:
* \param input the input connector receiving the change.
* \param output the output connector sending the change notification.
*/
virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input,
boost::shared_ptr<WModuleConnector> output );
virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input, boost::shared_ptr<WModuleConnector> output );
/**
* Gets called whenever a connector gets connected to the specified input.
*
* \param here the connector of THIS module that got connected to "there"
* \param there the connector that has been connected with the connector "here" of this module.
*/
virtual void notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> here, boost::shared_ptr<WModuleConnector> there );
private:
......@@ -114,6 +121,7 @@ private:
* Connection for Data Changed signal of the connected output connector.
*/
boost::signals2::connection m_DataChangedConnection;
};
#endif // WMODULEINPUTCONNECTOR_H
......
......@@ -22,20 +22,5 @@
//
//---------------------------------------------------------------------------
#include "WModuleForwardConnector.h"
WModuleForwardConnector::WModuleForwardConnector( boost::shared_ptr< WModuleInputConnector > from, boost::shared_ptr< WModuleInputConnector > to )
{
//m_in = boost::shared_ptr< WModuleInputConnector >( new WModuleInputConnector( from, "forward_in", "forward_out" ) );
}
WModuleForwardConnector::WModuleForwardConnector( boost::shared_ptr< WModuleOutputConnector > from, boost::shared_ptr< WModuleOutputConnector > to )
{
}
WModuleForwardConnector::~WModuleForwardConnector()
{
// cleanup
}
#include "WModuleInputForwardConnector.h"
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMODULEINPUTFORWARDDATA_H
#define WMODULEINPUTFORWARDDATA_H
#include <boost/shared_ptr.hpp>
#include "../common/WLogger.h"
#include "WModuleInputData.h"
#include "WModuleOutputData.h"
/**
* This is a simple class which forwards input data to input data connectors. It itself is a input data connector and can be used
* as one, but also provides the possibility to forward data changes to other input data connectors, using a separate output data
* connector (which is not visible to the outside world).
*/
template< typename T >
class WModuleInputForwardConnector: public WModuleInputData< T >
{
public:
/**
* Constructor. This creates a new input data connector which is able to forward data changes to other input data connectors.
*
* \param module the module which is owner of this connector.
* \param name The name of this connector.
* \param description Short description of this connector.
*/
WModuleInputForwardConnector( boost::shared_ptr<WModule> module, std::string name="", std::string description="" )
:WModuleInputData< T >( module, name, description )
{
// initialize the output data connector
m_out = boost::shared_ptr< WModuleOutputData< T > >( new WModuleOutputData< T >( module, "[FWD]" + name, description ) );
};
/**
* Destructor.
*/
virtual ~WModuleInputForwardConnector()
{
}
/**
* Forward the input to the specified input. The specified input must be compatible with the template parameter of this input.
*
* \param to the input connector to forward data to.
*/
virtual void forward( boost::shared_ptr< WModuleConnector > to )
{
m_out->connect( to );
}
/**
* Remove the specified connector from the forwarding list.
*
* \param to the input connector to be removed from forwarding list.
*/
virtual void unforward( boost::shared_ptr< WModuleConnector > to )
{
m_out->disconnect( to );
}
protected:
/**
* The output connector which collects data and distributes it to all connectors connected using the forwardTo() method.
*/
boost::shared_ptr< WModuleOutputData< T > > m_out;
/**
* Gets called whenever a connected output updates its data. This method uses this callback to update the m_out connector to
* inform all inputs to which the data should be forwarded.
*
* \param input the input connector receiving the change
* \param output the output connector sending the change
*/
void notifyDataChange( boost::shared_ptr<WModuleConnector> input, boost::shared_ptr<WModuleConnector> output )
{
m_out->updateData( WModuleInputData< T >::getData() );
// simply forward the call
WModuleInputData< T >::notifyDataChange( input, output );
}
/**
* Gets called whenever a connector gets connected to the specified input.
*
* \param here the connector of THIS module that got connected to "there"
* \param there the connector that has been connected with the connector "here" of this module.
*/
virtual void notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> here, boost::shared_ptr<WModuleConnector> there )
{
// a connection -> grab the data and forward it to the output connector
m_out->updateData( WModuleInputData< T >::getData() );
// and forward
WModuleInputData< T >::notifyDataChange( here, there );
}
private:
};
#endif // WMODULEINPUTFORWARDDATA_H
......@@ -107,7 +107,7 @@ void WMDistanceMapIsosurface::moduleMain()
// connect the distance map output to the container output to ensure other modules can use the distance map if they want to
//m_distanceMapModule->getOutputConnector( "out" )->forward( m_output );
// we want the container input connector "in" to be connected to the input of WMDistanceMap
//m_input->forward( m_distanceMapModule->getInputConnector( "in" ) );
m_input->forward( m_distanceMapModule->getInputConnector( "in" ) );
//////////////////////////////////////////////////////////////////////////////////
// Done!
......@@ -128,8 +128,8 @@ void WMDistanceMapIsosurface::connectors()
// initialize connectors
// this is the scalar field input
m_input = boost::shared_ptr<WModuleInputData< WDataSetSingle > >(
new WModuleInputData< WDataSetSingle >( shared_from_this(),
m_input = boost::shared_ptr< WModuleInputForwardConnector< WDataSetSingle > >(
new WModuleInputForwardConnector< WDataSetSingle >( shared_from_this(),
"in", "Dataset to compute distance map for." )
);
......@@ -137,7 +137,7 @@ void WMDistanceMapIsosurface::connectors()
addConnector( m_input );
// this output is used to provide the distance map to other modules.
m_output = boost::shared_ptr<WModuleOutputData< WDataSetSingle > >(
m_output = boost::shared_ptr< WModuleOutputData< WDataSetSingle > >(
new WModuleOutputData< WDataSetSingle >( shared_from_this(),
"out", "Distance map for the input data set." )
);
......
......@@ -30,6 +30,7 @@
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleContainer.h"
#include "../../kernel/WModuleInputData.h"
#include "../../kernel/WModuleInputForwardConnector.h"
#include "../../kernel/WModuleOutputData.h"
/**
......@@ -91,7 +92,7 @@ private:
*/
std::string m_description;
boost::shared_ptr< WModuleInputData< WDataSetSingle > > m_input; //!< Input connector required by this module.
boost::shared_ptr< WModuleInputForwardConnector< WDataSetSingle > > m_input; //!< Input connector required by this module.
/**
* Connector to provide the distance map to other modules.
......
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