Commit 700b8807 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - adopted datamodule skeleton to templates

parent 6b72a7b7
//---------------------------------------------------------------------------
//
// 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 <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../../kernel/WKernel.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleConnector.h"
#include "../../kernel/WModuleOutputData.hpp"
#include "../../dataHandler/WDataSet.h"
#include "WDataModule.h"
WDataModule::WDataModule():
WModule()
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// Implement WModule::initializeConnectors instead.
// initialize members
}
WDataModule::~WDataModule()
{
// cleanup
removeConnectors();
}
const std::string WDataModule::getName() const
{
return "Data Module";
}
const std::string WDataModule::getDescription() const
{
return "This module can encapsulate WDataSet instances.";
}
void WDataModule::connectors()
{
// initialize connectors
// call WModules initialization
WModule::connectors();
}
void WDataModule::notifyDataChange( boost::shared_ptr<WModuleConnector> input,
boost::shared_ptr<WModuleConnector> output )
{
WModule::notifyDataChange( input, output );
}
void WDataModule::threadMain()
{
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
{
// do fancy stuff
sleep( 1 );
}
// clean up stuff
}
......@@ -27,6 +27,8 @@
#include <string>
#include <boost/shared_ptr.hpp>
#include "../../kernel/WKernel.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleConnector.h"
......@@ -35,9 +37,10 @@
#include "../../dataHandler/WDataSet.h"
/**
* Module for encapsulating WDataSets.
* TODO(ebaum): write more
* Module for encapsulating WDataSets. It can encapsulate almost everything, but is intended to be used with WDataSets and its
* inherited classes. This class builds a "source".
*/
template < typename T >
class WDataModule: public WModule
{
public:
......@@ -91,7 +94,77 @@ protected:
boost::shared_ptr<WModuleConnector> output );
private:
/**
* The only output of this data module.
*/
boost::shared_ptr<WModuleOutputData<T> > m_output;
};
template < typename T >
WDataModule<T>::WDataModule():
WModule()
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// Implement WModule::initializeConnectors instead.
// initialize members
}
template < typename T >
WDataModule<T>::~WDataModule()
{
// cleanup
}
template < typename T >
const std::string WDataModule<T>::getName() const
{
return "Data Module";
}
template < typename T >
const std::string WDataModule<T>::getDescription() const
{
return "This module can encapsulate data.";
}
template < typename T >
void WDataModule<T>::connectors()
{
// initialize connectors
m_output= boost::shared_ptr<WModuleOutputData<T> >(
new WModuleOutputData<T>( shared_from_this(),
"out1", "A loaded dataset." )
);
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
addConnector( m_output );
// call WModules initialization
WModule::connectors();
}
template < typename T >
void WDataModule<T>::notifyDataChange( boost::shared_ptr<WModuleConnector> input,
boost::shared_ptr<WModuleConnector> output )
{
WModule::notifyDataChange( input, output );
}
template < typename T >
void WDataModule<T>::threadMain()
{
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
{
// do fancy stuff
sleep( 1 );
}
// clean up stuff
}
#endif // WDATAMODULE_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