Commit 1ea8e12f authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - basic skeleton added for applying modules on others

parent b1f1c802
...@@ -29,9 +29,11 @@ ...@@ -29,9 +29,11 @@
#include "WModule.h" #include "WModule.h"
#include "exceptions/WModuleUninitialized.h" #include "exceptions/WModuleUninitialized.h"
#include "exceptions/WModuleAlreadyAssociated.h"
#include "exceptions/WModuleSignalSubscriptionFailed.h" #include "exceptions/WModuleSignalSubscriptionFailed.h"
#include "../common/WLogger.h" #include "../common/WLogger.h"
#include "WKernel.h" #include "WKernel.h"
#include "WModuleFactory.h"
#include "WModuleContainer.h" #include "WModuleContainer.h"
...@@ -198,3 +200,29 @@ void WModuleContainer::addDefaultNotifier( MODULE_SIGNAL signal, t_ModuleErrorSi ...@@ -198,3 +200,29 @@ void WModuleContainer::addDefaultNotifier( MODULE_SIGNAL signal, t_ModuleErrorSi
} }
} }
boost::shared_ptr< WModule > WModuleContainer::applyModule( boost::shared_ptr< WModule > applyOn, std::string what )
{
return applyModule( applyOn, WModuleFactory::getModuleFactory()->getPrototypeByName( what ) );
}
boost::shared_ptr< WModule > WModuleContainer::applyModule( boost::shared_ptr< WModule > applyOn, boost::shared_ptr< WModule > prototype )
{
// is this module already associated with another container?
if ( applyOn->isAssociated()() && ( applyOn->getAssociatedContainer() != shared_from_this() ) )
{
throw WModuleAlreadyAssociated( "The specified module \"" + applyOn->getName() + "\" is associated with another container." );
}
// create a new initialized instance of the module
boost::shared_ptr< WModule > m = WModuleFactory::getModuleFactory()->create( prototype );
// add it
add( m, true );
// TODO(ebaum): do actual connection stuff
WLogger::getLogger()->addLogMessage( "Combining modules \"" + applyOn->getName() + "\" and \"" + m->getName() + "\" not yet implemented.",
"ModuleContainer (" + m_name + ")", LL_WARNING );
return m;
}
...@@ -108,6 +108,26 @@ public: ...@@ -108,6 +108,26 @@ public:
*/ */
virtual void addDefaultNotifier( MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier ); virtual void addDefaultNotifier( MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier );
/**
* Function combines to modules.
*
* \param applyOn the module which already has to be in the container and to apply the other one on.
* \param what the prototype name of the module to apply on the other one specified.
*
* \return the newly created module connected with the one specified in applyOn.
*/
virtual boost::shared_ptr< WModule > applyModule( boost::shared_ptr< WModule > applyOn, std::string what );
/**
* Function combines to modules.
*
* \param applyOn the module which already has to be in the container and to apply the other one on.
* \param prototype the prototype of the module to apply on the other one specified.
*
* \return the newly created module connected with the one specified in applyOn.
*/
virtual boost::shared_ptr< WModule > applyModule( boost::shared_ptr< WModule > applyOn, boost::shared_ptr< WModule > prototype );
protected: protected:
/** /**
......
//---------------------------------------------------------------------------
//
// 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 <string>
#include "WModuleAlreadyAssociated.h"
WModuleAlreadyAssociated::WModuleAlreadyAssociated( const std::string& msg ): WModuleException( msg )
{
// initialize members
}
WModuleAlreadyAssociated::~WModuleAlreadyAssociated() throw()
{
// cleanup
}
//---------------------------------------------------------------------------
//
// 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 WMODULEALREADYASSOCIATED_H
#define WMODULEALREADYASSOCIATED_H
#include <string>
#include "WModuleException.h"
/**
* General purpose exception and therefore base class for all kernel related exceptions.
* \ingroup kernel
*/
class WModuleAlreadyAssociated: public WModuleException
{
public:
/**
* Default constructor.
* \param msg the exception message.
*/
explicit WModuleAlreadyAssociated( const std::string& msg = "Module already associated with another container." );
/**
* Destructor.
*/
virtual ~WModuleAlreadyAssociated() throw();
protected:
private:
};
#endif // WMODULEALREADYASSOCIATED_H
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