Commit 829dbbfd authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - implemented basic deletion combiner functionality.

parent ed078576
......@@ -37,7 +37,8 @@
#include "WQtCombinerActionList.h"
WQtCombinerActionList::WQtCombinerActionList( QWidget* parent, WIconManager* icons, WCombinerTypes::WCompatiblesList compatibles ):
WQtCombinerActionList::WQtCombinerActionList( QWidget* parent, WIconManager* icons, WCombinerTypes::WCompatiblesList compatibles,
bool ignoreWhiteList ):
QList< QAction* >()
{
// These modules will be allowed to be shown.
......@@ -49,8 +50,9 @@ WQtCombinerActionList::WQtCombinerActionList( QWidget* parent, WIconManager* ico
for ( WCombinerTypes::WCompatiblesList::iterator groups = compatibles.begin(); groups != compatibles.end(); ++groups )
{
// check current prototype against whitelist
if( moduleWhiteList.size()
&& std::find( moduleWhiteList.begin(), moduleWhiteList.end(), groups->first->getName() ) == moduleWhiteList.end() )
if( !ignoreWhiteList && // ignore the whitelist?
moduleWhiteList.size() && // whitelist empty?
std::find( moduleWhiteList.begin(), moduleWhiteList.end(), groups->first->getName() ) == moduleWhiteList.end() )
{
continue;
}
......
......@@ -46,8 +46,9 @@ public:
* \param parent the parent widget of this widget, i.e. the widget that manages it.
* \param icons the icon manager holding the right icons for all the prototypes
* \param compatibles the list of combiners
* \param ignoreWhiteList if true, the list won't be filtered using the whitelist
*/
WQtCombinerActionList( QWidget* parent, WIconManager* icons, WCombinerTypes::WCompatiblesList compatibles );
WQtCombinerActionList( QWidget* parent, WIconManager* icons, WCombinerTypes::WCompatiblesList compatibles, bool ignoreWhiteList = false );
/**
* Destructor.
......
......@@ -733,20 +733,27 @@ WQtCombinerToolbar* WQtDatasetBrowser::createCompatibleButtons( boost::shared_pt
// build the prototype menu
QMenu* m = new QMenu( m_moduleTreeWidget );
m->addActions( WQtCombinerActionList( m, m_mainWindow->getIconManager(), comps ) );
m_connectWithPrototypeAction->setDisabled( !comps.size() ); // disable if no entry inside
delete( m_connectWithPrototypeAction->menu() ); // ensure that combiners get free'd
m_connectWithPrototypeAction->setMenu( m );
// build the module menu
WCombinerTypes::WCompatiblesList containerComps = WKernel::getRunningKernel()->getRootContainer()->getPossibleConnections( module );
m = new QMenu( m_moduleTreeWidget );
m->addActions( WQtCombinerActionList( m, m_mainWindow->getIconManager(), containerComps ) );
delete( m_connectWithModuleAction->menu() ); // ensure that combiners get free'd
m->addActions( WQtCombinerActionList( m, m_mainWindow->getIconManager(), containerComps, true ) );
m_connectWithModuleAction->setDisabled( !containerComps.size() ); // disable if no entry inside
delete m_connectWithModuleAction->menu();
m_connectWithModuleAction->setMenu( m );
// build the disconnect menu
// TODO(ebaum): do
WCombinerTypes::WDisconnectList disconnects;
if ( module )
{
disconnects = module->getPossibleDisconnections();
}
m = new QMenu( m_moduleTreeWidget );
m->addAction( new QAction( "Not Yet Implemented.", m_moduleTreeWidget ) );
//m->addActions( WQtCombinerActionList( m, m_mainWindow->getIconManager(), disconnects ) );
m_disconnectAction->setDisabled( !disconnects.size() ); // disable if no entry inside
delete( m_disconnectAction->menu() ); // ensure that combiners get free'd
m_disconnectAction->setMenu( m );
......
......@@ -129,6 +129,39 @@ void WModule::disconnect()
}
}
WCombinerTypes::WDisconnectList WModule::getPossibleDisconnections()
{
WCombinerTypes::WDisconnectList discons;
// iterate inputs
for( InputConnectorList::iterator listIter = m_inputConnectors.begin(); listIter != m_inputConnectors.end(); ++listIter )
{
// get all connections of the current connector:
WCombinerTypes::WDisconnectGroup g = WCombinerTypes::WDisconnectGroup( ( *listIter )->getName(),
( *listIter )->getPossibleDisconnections() );
if ( g.second.size() )
{
discons.push_back( g );
}
}
// iterate outputs
for( OutputConnectorList::iterator listIter = m_outputConnectors.begin(); listIter != m_outputConnectors.end(); ++listIter )
{
// get all connections of the current connector:
WCombinerTypes::WDisconnectGroup g = WCombinerTypes::WDisconnectGroup( ( *listIter )->getName(),
( *listIter )->getPossibleDisconnections() );
if ( g.second.size() )
{
discons.push_back( g );
}
}
return discons;
}
void WModule::removeConnectors()
{
m_initialized( false );
......
......@@ -35,6 +35,7 @@
#include <boost/function.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "WModuleCombinerTypes.h"
#include "WModuleConnectorSignals.h"
#include "WModuleSignals.h"
#include "WModuleTypes.h"
......@@ -255,6 +256,13 @@ public:
*/
void disconnect();
/**
* Gives a list of all WDisconnectCombiners possible. Please note that while the list exists, connections might change.
*
* \return the list of possible disconnect operations
*/
WCombinerTypes::WDisconnectList getPossibleDisconnections();
protected:
/**
......
......@@ -25,10 +25,13 @@
#ifndef WMODULECOMBINERTYPES_H
#define WMODULECOMBINERTYPES_H
#include <string>
#include <boost/shared_ptr.hpp>
class WModule;
class WApplyCombiner;
class WDisconnectCombiner;
namespace WCombinerTypes
{
......@@ -48,6 +51,21 @@ namespace WCombinerTypes
*/
typedef std::vector< WCompatiblesGroup > WCompatiblesList;
/**
* A list of all combiners which are each able to disconnect one connection for a fixed source connector
*/
typedef std::vector< boost::shared_ptr< WDisconnectCombiner > > WDisconnectCombiners;
/**
* A pair of a connector and DisconnectCombiners for each connection from/to the connector specified in the first element of the pair.
*/
typedef std::pair< std::string, WDisconnectCombiners > WDisconnectGroup;
/**
* A list of all connectors and their possible disconnect- combiner.
*/
typedef std::vector< WDisconnectGroup > WDisconnectList;
/**
* Sorting function for sorting the compatibles list. It uses the alphabetical order of the names.
*
......
......@@ -39,13 +39,14 @@
#include <boost/signals2/connection.hpp>
#include "WModule.h"
#include "WModuleConnectorSignals.h"
#include "WModuleContainer.h"
#include "combiner/WDisconnectCombiner.h"
#include "exceptions/WModuleConnectionFailed.h"
#include "exceptions/WModuleConnectionInvalid.h"
#include "exceptions/WModuleConnectorsIncompatible.h"
#include "exceptions/WModuleDisconnectFailed.h"
#include "exceptions/WModuleSignalSubscriptionFailed.h"
#include "exceptions/WModuleConnectorsIncompatible.h"
#include "WModuleConnectorSignals.h"
#include "WModuleConnector.h"
......@@ -217,6 +218,11 @@ const t_GenericSignalHandlerType WModuleConnector::getSignalHandler( MODULE_CONN
return module->getSignalHandler( signal );
}
boost::shared_ptr< WModule > WModuleConnector::getModule() const
{
return m_module.lock(); // it is "unlocked" at the end of this function as "module" looses its scope
}
void WModuleConnector::disconnect( boost::shared_ptr<WModuleConnector> con, bool removeFromOwnList )
{
if ( !isConnectedTo( con ) )
......@@ -317,6 +323,24 @@ void WModuleConnector::setName( std::string name )
m_name = name;
}
WCombinerTypes::WDisconnectCombiners WModuleConnector::getPossibleDisconnections()
{
WCombinerTypes::WDisconnectCombiners l;
// acquire read lock
boost::shared_lock<boost::shared_mutex> rlock( m_connectionListLock );
// for each connector
for( std::set<boost::shared_ptr<WModuleConnector> >::iterator listIter = m_connected.begin(); listIter != m_connected.end(); ++listIter )
{
// simply create the combiner
l.push_back( boost::shared_ptr< WDisconnectCombiner >( new WDisconnectCombiner( shared_from_this(), ( *listIter ) ) ) );
}
rlock.unlock();
return l;
}
void WModuleConnector::notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> /*here*/, boost::shared_ptr<WModuleConnector> /*there*/ )
{
// by default: do nothing.
......
......@@ -35,6 +35,7 @@
#include <boost/bind.hpp>
#include "WModule.h"
#include "WModuleCombinerTypes.h"
#include "WModuleConnectorSignals.h"
/**
......@@ -62,6 +63,13 @@ public:
*/
virtual ~WModuleConnector();
/**
* Returns the module which owns this connector.
*
* \return the module owning the connector.
*/
boost::shared_ptr< WModule > getModule() const;
/**
* Disconnects this connector if connected. If it is not connected: nothing happens.
*
......@@ -163,6 +171,14 @@ public:
*/
virtual bool connectable( 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.
*
* \return the possible disconnections.
*/
WCombinerTypes::WDisconnectCombiners getPossibleDisconnections();
protected:
/**
......
......@@ -28,22 +28,14 @@
WApplyCombiner::WApplyCombiner( boost::shared_ptr< WModuleContainer > target,
boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > prototype, std::string targetConnector ):
WModuleCombiner( target ),
m_srcModule( srcModule ),
m_srcConnector( srcConnector ),
m_targetModule( prototype ),
m_targetConnector( targetConnector )
boost::shared_ptr< WModule > targetModule, std::string targetConnector ):
WModuleOneToOneCombiner( target, srcModule, srcConnector, targetModule, targetConnector )
{
}
WApplyCombiner::WApplyCombiner( boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > prototype, std::string targetConnector ):
WModuleCombiner(),
m_srcModule( srcModule ),
m_srcConnector( srcConnector ),
m_targetModule( prototype ),
m_targetConnector( targetConnector )
boost::shared_ptr< WModule > targetModule, std::string targetConnector ):
WModuleOneToOneCombiner( srcModule, srcConnector, targetModule, targetConnector )
{
}
......@@ -52,27 +44,6 @@ WApplyCombiner::~WApplyCombiner()
// cleanup
}
boost::shared_ptr< WModule > WApplyCombiner::getSrcModule() const
{
return m_srcModule;
}
std::string WApplyCombiner::getSrcConnector() const
{
return m_srcConnector;
}
boost::shared_ptr< WModule > WApplyCombiner::getTargetModule() const
{
return m_targetModule;
}
std::string WApplyCombiner::getTargetConnector() const
{
return m_targetConnector;
}
void WApplyCombiner::apply()
{
// create the modules from the prototypes if needed
......
......@@ -33,8 +33,8 @@
#include <boost/shared_ptr.hpp>
#include "../WModule.h"
#include "../WModuleCombiner.h"
#include "../WModuleCombinerTypes.h"
#include "WModuleOneToOneCombiner.h"
#include "../WModuleInputConnector.h"
#include "../WModuleOutputConnector.h"
......@@ -42,7 +42,7 @@
/**
* Base class for all combiners which apply one connection between two connectors of two modules.
*/
class WApplyCombiner: public WModuleCombiner
class WApplyCombiner: public WModuleOneToOneCombiner
{
public:
......@@ -87,34 +87,6 @@ public:
*/
virtual void apply();
/**
* Gets the source module. This module's output connector is connected with the target.
*
* \return the source module.
*/
boost::shared_ptr< WModule > getSrcModule() const;
/**
* The output connector of m_srcModule to connect with m_targetConnector.
*
* \return the source module's output connector.
*/
std::string getSrcConnector() const;
/**
* The module/prototype to connect with m_srcModule.
*
* \return the target module prototype.
*/
boost::shared_ptr< WModule > getTargetModule() const;
/**
* The input connector the target module to connect with m_srcConnector.
*
* \return the target module's input connector.
*/
std::string getTargetConnector() const;
/**
* This method creates a list of possible combiners for connections between the specified modules. Both modules can be prototypes.
*
......@@ -163,26 +135,6 @@ public:
protected:
/**
* The source module to connect with the target
*/
boost::shared_ptr< WModule > m_srcModule;
/**
* The output connector of m_srcModule to connect with m_targetConnector.
*/
std::string m_srcConnector;
/**
* The module/prototype to connect with m_srcMdodule.
*/
boost::shared_ptr< WModule > m_targetModule;
/**
* The input connector the target module to connect with m_srcConnector.
*/
std::string m_targetConnector;
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/>.
//
//---------------------------------------------------------------------------
#include <iostream>
#include <map>
#include <list>
#include <string>
#include <utility>
#include <boost/regex.hpp>
#include <boost/lexical_cast.hpp>
#include "../WKernel.h"
#include "../WModuleCombiner.h"
#include "../WModuleFactory.h"
#include "../WModuleConnector.h"
#include "../WModule.h"
#include "../WModuleInputConnector.h"
#include "../WModuleOutputConnector.h"
#include "../exceptions/WModuleConnectorNotFound.h"
#include "../../common/WLogger.h"
#include "WApplyModuleCombiner.h"
WApplyModuleCombiner::WApplyModuleCombiner( boost::shared_ptr< WModuleContainer > target,
boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > targetModule, std::string targetConnector ):
WApplyCombiner( target, srcModule, srcConnector, targetModule, targetConnector )
{
// initialize
}
WApplyModuleCombiner::WApplyModuleCombiner( boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > targetModule, std::string targetConnector ):
WApplyCombiner( srcModule, srcConnector, targetModule, targetConnector )
{
// initialize
}
WApplyModuleCombiner::~WApplyModuleCombiner()
{
// cleanup
}
void WApplyModuleCombiner::apply()
{
/*// add the target module to the container
m_container->add( targetModule );
// NOTE: here, we assume the src module already to be in the container. If not, connect will fail with an exception -> so no need for a
// separate exception here
// wait for the source module if there is any
if ( m_srcModule ) // specifying a NULL source module causes the combiner to only add the target
{
m_srcModule->isReadyOrCrashed().wait();
if ( m_srcModule->isCrashed()() )
{
wlog::error( "Prototype Combiner" ) << "The source module \"" << m_srcModule->getName() << "\" has crashed. Abort.";
return;
}
}
targetModule->isReadyOrCrashed().wait();
if ( targetModule->isCrashed()() )
{
wlog::error( "Prototype Combiner" ) << "The target module \"" << targetModule->getName() << "\" has crashed. Abort.";
return;
}
// if the target connector is an empty string -> do not connect, just add
if ( m_targetConnector.empty() )
{
return;
}
// and connect them finally:
if ( m_srcModule )
{
targetModule->getInputConnector( m_targetConnector )->connect( m_srcModule->getOutputConnector( m_srcConnector ) );
}*/
}
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#include "WDisconnectCombiner.h"
WDisconnectCombiner::WDisconnectCombiner( boost::shared_ptr< WModuleContainer > target,
boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > targetModule, std::string targetConnector ):
WModuleOneToOneCombiner( target, srcModule, srcConnector, targetModule, targetConnector )
{
}
WDisconnectCombiner::WDisconnectCombiner( boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > targetModule, std::string targetConnector ):
WModuleOneToOneCombiner( srcModule, srcConnector, targetModule, targetConnector )
{
}
WDisconnectCombiner::WDisconnectCombiner( boost::shared_ptr< WModuleConnector > srcConnector,
boost::shared_ptr< WModuleConnector > targetConnector ):
WModuleOneToOneCombiner( srcConnector->getModule(), srcConnector->getName(), targetConnector->getModule(), targetConnector->getName() )
{
}
WDisconnectCombiner::~WDisconnectCombiner()
{
// cleanup
}
void WDisconnectCombiner::apply()
{
}
......@@ -22,8 +22,8 @@
//
//---------------------------------------------------------------------------
#ifndef WAPPLYMODULECOMBINER_H
#define WAPPLYMODULECOMBINER_H
#ifndef WDISCONNECTCOMBINER_H
#define WDISCONNECTCOMBINER_H
#include <list>
#include <map>
......@@ -33,53 +33,59 @@
#include <boost/shared_ptr.hpp>
#include "../WModule.h"
#include "WApplyCombiner.h"
#include "../WModuleCombinerTypes.h"
#include "WModuleOneToOneCombiner.h"
#include "../WModuleConnector.h"
/**
* This class combines an existing module with an specified module. The connections to use must be explicitly known.
* Combiner which disconnects the specified connection.
*/
class WApplyModuleCombiner: public WApplyCombiner
class WDisconnectCombiner: public WModuleOneToOneCombiner
{
public:
/**
* Creates a combiner which sets up the specified module-to-module connection. Specifying a NULL pointer to the srcModule parameter
* causes the combiner to only add the target module without any connections. This is especially useful for modules which do not provide any
* input which must be connected.
* Creates a combiner which disconnects the specified connection. If the specified connection does not exist (anymore), nothing will happen.
*
* \param target the target container
* \param srcModule the module whose connector should be disconnected
* \param srcConnector the srcModule connector to disconnect
* \param targetModule the module whose connector should be disconnected from srcConnector
* \param targetConnector the targetModule connector to disconnect.
*/
WDisconnectCombiner( boost::shared_ptr< WModuleContainer > target,
boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > targetModule, std::string targetConnector );
/**
* Creates a combiner which disconnects the specified connection. If the specified connection does not exist (anymore), nothing will happen.
*
* \param target the target container
* \param srcModule the module whose output should be connected with the target module input
* \param srcConnector the output connector of the module
* \param targetModule the module to use for connecting the module with
* \param targetConnector the input connector of the targetModule to connect with srcConnector.
* \param srcModule the module whose connector should be disconnected
* \param srcConnector the srcModule connector to disconnect
* \param targetModule the module whose connector should be disconnected from srcConnector
* \param targetConnector the targetModule connector to disconnect.
*/
WApplyModuleCombiner( boost::shared_ptr< WModuleContainer > target,
boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > targetModule, std::string targetConnector );
WDisconnectCombiner( boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > targetModule, std::string targetConnector );