Commit 18d0e510 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - Basic infrastructure for transferring arbitrary data using templates

parent 60575f73
FILE( GLOB KERNEL_SRC "*.cpp" )
FILE( GLOB KERNEL_SRC "*.cpp" "*.hpp" )
FILE( GLOB MODULES_SRC "../modules/navigationSlices/*.cpp" )
ADD_SUBDIRECTORY( exceptions )
......@@ -16,6 +16,12 @@ IF( CXXTEST_FOUND )
${testLibs}
"WKernel.cpp"
"WModule.cpp"
"WModuleInputConnector.cpp"
"WModuleOutputConnector.cpp"
"WModuleInputData.hpp"
"WModuleOutputData.hpp"
"WModuleInputData.cpp"
"WModuleOutputData.cpp"
"../modules/navigationSlices/WNavigationSliceModule.cpp"
)
ENDIF( CXXTEST_FOUND )
......@@ -104,7 +104,7 @@ protected:
// Connector Management
//
// **************************************************************************************************************************
/**
* Initialize connectors in this function. This function must not be called multiple times for one module instance.
* The module container manages calling those functions -> so just implement it.
......@@ -153,7 +153,6 @@ protected:
*/
void removeConnectors();
// **************************************************************************************************************************
//
// Signal handlers that HAVE to be in every module. By default they do nothing. You should overwrite them to get notified
......@@ -172,7 +171,6 @@ protected:
*/
virtual const t_GenericSignalHandlerType getSignalHandler( MODULE_CONNECTOR_SIGNAL signal );
/**
* Gets called whenever a connector gets connected to the specified input.
*
......@@ -198,14 +196,13 @@ protected:
virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input,
boost::shared_ptr<WModuleConnector> output );
private:
/**
* True if everything is initialized and ready to be used.
*/
bool m_Initialized;
/**
* Lock for m_InputConnectors.
*/
......
......@@ -34,13 +34,13 @@ class WModuleConnector;
* Enum of all possible signals between WModuleConnector instances.
* TODO(ebaum): Replace this by an automatic mapping class also able to allow varying function signatures.
*/
typedef enum {
typedef enum
{
CONNECTION_ESTABLISHED, // a connection has been established
CONNECTION_CLOSED, // a connection has been closed
DATA_CHANGED // data on an output connector has been changed
} MODULE_CONNECTOR_SIGNAL;
}
MODULE_CONNECTOR_SIGNAL;
// **************************************************************************************************************************
// Types
......
......@@ -30,8 +30,6 @@
#include "WModule.h"
#include "WModuleConnector.h"
class WModuleOutputConnector;
/**
* Class implementing input connection functionality between modules.
*/
......
//---------------------------------------------------------------------------
//
// 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 WMODULEINPUTDATA_H
#define WMODULEINPUTDATA_H
#include <string>
// this seems to be necessary
template < typename T > class WModuleInputData;
#include "WModuleOutputData.hpp"
#include "WModuleInputConnector.h"
/**
* Class offering an instantiate-able data connection between modules.
* Due to is template style it is possible to bind nearly arbitrary data.
*/
template < typename T >
class WModuleInputData: public WModuleInputConnector
{
public:
/**
* Constructor.
*
* \param module the module which is owner of this connector.
* \param name The name of this connector.
* \param description Short description of this connector.
*/
WModuleInputData( boost::shared_ptr<WModule> module, std::string name="", std::string description="" ):
WModuleInputConnector( module, name, description )
{
};
/**
* Destructor.
*/
virtual ~WModuleInputData()
{
};
/**
* Gives the currently set data.
*
* \return the data currently set.
*/
const boost::shared_ptr<T> getData() const
{
//return m_data;
};
protected:
/**
* Checks whether the specified connector is an input connector and compatible with T.
*
* \param con the connector to check against.
*
* \return true if compatible.
*/
virtual bool connectable( boost::shared_ptr<WModuleConnector> con )
{
if ( dynamic_cast<WModuleOutputData<T>* >( con.get() ) ) // NOLINT - since we really need them here
{
// NOTE: the upper cast already checked the compatibility completely. WModuleInputConnector::connectable does the
// same check again. But since we do not know what checks will be added to WModuleInputConnector::connectable in the
// future we forward the call.
return WModuleInputConnector::connectable( con );
}
return false;
};
private:
};
#endif // WMODULEINPUTDATA_H
......@@ -52,6 +52,7 @@ bool WModuleOutputConnector::connectable( boost::shared_ptr<WModuleConnector> co
{
return true;
}
return false;
}
......@@ -68,3 +69,7 @@ boost::signals2::connection WModuleOutputConnector::subscribeSignal( MODULE_CONN
}
}
void WModuleOutputConnector::propagateDataChange()
{
//signal_DataChanged();
}
......@@ -34,8 +34,6 @@
#include "WModuleConnector.h"
#include "WModuleConnectorSignals.h"
class WModuleInputConnector;
/**
* Class implementing output connection functionality between modules.
*/
......@@ -88,9 +86,14 @@ protected:
* \param con the connector that requests connection.
*
*/
// If you want to add additional signals an output connector should subscrie FROM an input connector overwrite connectSignals
// If you want to add additional signals an output connector should subscribe FROM an input connector, overwrite connectSignals
// virtual void connectSignals( boost::shared_ptr<WModuleConnector> con );
/**
* Propagates the signal "DATA_CHANGED" to all connected items.
*/
virtual void propagateDataChange();
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 WMODULEOUTPUTDATA_H
#define WMODULEOUTPUTDATA_H
#include <string>
#include <boost/shared_ptr.hpp>
// this seems to be necessary
template < typename T > class WModuleOutputData;
#include "WModuleInputData.hpp"
#include "WModuleOutputConnector.h"
/**
* Class offering an instantiate-able data connection between modules.
* Due to is template style it is possible to bind nearly arbitrary data.
*/
template < typename T >
class WModuleOutputData: public WModuleOutputConnector
{
public:
/**
* Constructor.
*
* \param module the module which is owner of this connector.
* \param name The name of this connector.
* \param description Short description of this connector.
*/
WModuleOutputData( boost::shared_ptr<WModule> module, std::string name="", std::string description="" ):
WModuleOutputConnector( module, name, description )
{
};
/**
* Destructor.
*/
virtual ~WModuleOutputData()
{
};
/**
* Update the data associated
*
* \param data
*/
virtual void updateData( boost::shared_ptr<T> data )
{
m_data=data;
// broadcast this event
propagateDataChange();
};
/**
* Gives the currently set data.
*
* \return the data currently set.
*/
const boost::shared_ptr<T> getData() const
{
return m_data;
};
protected:
/**
* Checks whether the specified connector is an input connector and compatible with T.
*
* \param con the connector to check against.
*
* \return true if compatible.
*/
virtual bool connectable( boost::shared_ptr<WModuleConnector> con )
{
if ( dynamic_cast<WModuleInputData<T>* >( con.get() ) ) // NOLINT - since we really need them here
{
// NOTE: the upper cast already checked the compatibility completely. WModuleOutputConnector::connectable does the
// same check again. But since we do not know what checks will be added to WModuleOutputConnector::connectable in the
// future we forward the call.
return WModuleOutputConnector::connectable( con );
}
return false;
};
private:
/**
* The data associated with this connector.
*/
boost::shared_ptr<T> m_data;
};
#endif // WMODULEOUTPUTDATA_H
......@@ -26,14 +26,17 @@
#define WMODULECONNECTOR_TEST_H
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
#include <cxxtest/TestSuite.h>
#include "../WModuleConnector.h"
#include "../WModuleOutputConnector.h"
#include "../WModuleInputData.hpp"
#include "../WModuleOutputData.hpp"
#include "../WModuleInputConnector.h"
#include "../WModuleOutputConnector.h"
#include "../WModule.h"
#include "../../common/WSegmentationFault.h"
#include "../exceptions/WModuleConnectorInitFailed.h"
......@@ -72,19 +75,32 @@ public:
virtual void connectors()
{
m_Input= boost::shared_ptr<WModuleInputConnector>(
new WModuleInputConnector( shared_from_this(), "in1", "desc1" )
m_Input= boost::shared_ptr<WModuleInputData<int> >(
new WModuleInputData<int> ( shared_from_this(), "in1", "desc1" )
);
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
addConnector( m_Input );
m_Output= boost::shared_ptr<WModuleOutputConnector>(
new WModuleOutputConnector( shared_from_this(), "out1", "desc2" )
m_Output= boost::shared_ptr<WModuleOutputData<int> >(
new WModuleOutputData<int> ( shared_from_this(), "out1", "desc2" )
);
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
addConnector( m_Output );
/*
m_Input= boost::shared_ptr<WModuleInputConnector >(
new WModuleInputConnector ( shared_from_this(), "in1", "desc1" )
);
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
addConnector( m_Input );
m_Output= boost::shared_ptr<WModuleOutputConnector >(
new WModuleOutputConnector ( shared_from_this(), "out1", "desc2" )
);
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
addConnector( m_Output );
WModule::connectors();
*/
}
protected:
......@@ -125,8 +141,11 @@ protected:
private:
boost::shared_ptr<WModuleInputData<int> > m_Input;
boost::shared_ptr<WModuleOutputData<int> > m_Output;
/*
boost::shared_ptr<WModuleInputConnector> m_Input;
boost::shared_ptr<WModuleOutputConnector> m_Output;
boost::shared_ptr<WModuleOutputConnector> m_Output;*/
};
......@@ -213,7 +232,7 @@ public:
TS_ASSERT( m3->m_InputConnectors.size() == 1 );
TS_ASSERT( m3->m_OutputConnectors.size() == 1 );
// now we have 2 properly initialized modules?
// now we have 3 properly initialized modules?
TS_ASSERT( m1->isInitialized() );
TS_ASSERT( m2->isInitialized() );
TS_ASSERT( m3->isInitialized() );
......@@ -263,7 +282,7 @@ public:
{
createModules();
initModules();
TS_ASSERT_THROWS_NOTHING( initConnections() );
// check that every connector has an connection count of 1
......@@ -271,7 +290,6 @@ public:
TS_ASSERT( m1->m_Input->m_Connected.size() == 1 );
TS_ASSERT( m2->m_Output->m_Connected.size() == 1 );
TS_ASSERT( m2->m_Input->m_Connected.size() == 1 );
}
/**
......@@ -282,7 +300,7 @@ public:
createModules();
initModules();
initConnections();
// try to connect twice
TS_ASSERT_THROWS_NOTHING( m1->m_Output->connect( m2->m_Input ) );
TS_ASSERT_THROWS_NOTHING( m1->m_Input->connect( m2->m_Output ) );
......@@ -290,7 +308,6 @@ public:
TS_ASSERT( m1->m_Input->m_Connected.size() == 1 );
TS_ASSERT( m2->m_Output->m_Connected.size() == 1 );
TS_ASSERT( m2->m_Input->m_Connected.size() == 1 );
}
/**
......@@ -301,7 +318,7 @@ public:
createModules();
initModules();
initConnections();
// Disconnect something not connected
TS_ASSERT_THROWS_NOTHING( m1->m_Output->disconnect( m1->m_Input ) );
TS_ASSERT( m1->m_Output->m_Connected.size() == 1 );
......@@ -351,7 +368,7 @@ public:
TS_ASSERT( m1->m_InputConnectors.size() == 0 );
TS_ASSERT( m1->m_OutputConnectors.size() == 0 );
}
/**
* Tests the signal handler management.
*/
......@@ -360,12 +377,9 @@ public:
createModules();
initModules();
initConnections();
// propagate change
}
};
#endif // WMODULECONNECTOR_TEST_H
......@@ -203,7 +203,7 @@ _CPP_HEADERS = frozenset([
# Other heders which are include like system headers, starting with a '<'
_OTHER_HEADERS = frozenset([
'QtGui', 'QtCore', 'QtOpenGL', 'GL', 'cxxtest', 'boost', 'osg', 'osgViewer', 'osgDB', 'osgUtil', 'osgGA'
'QtGui', 'QtCore', 'QtOpenGL', 'GL', 'cxxtest', 'boost', 'osg','osgText', 'osgViewer', 'osgDB', 'osgUtil', 'osgGA'
])
# Assertion macros. These are defined in base/logging.h and
......@@ -1661,9 +1661,9 @@ def CheckSpacing(filename, clean_lines, linenum, error):
# We allow no-spaces around << and >> when used like this: 10<<20, but
# not otherwise (particularly, not when used as streams)
match = Search(r'[^0-9\s](<<|>>)[^0-9\s]', line)
if match:
if match and not Search(r'operator(<<|>>)', line):
error(filename, linenum, 'whitespace/operators', 3,
'Missing spaces around %s' % match.group(2))
'Missing spaces around %s' % match.group(1))
# There shouldn't be space around unary operators
match = Search(r'(!\s|~\s|[\s]--[\s;]|[\s]\+\+[\s;])', line)
......@@ -1777,7 +1777,10 @@ def CheckBraces(filename, clean_lines, linenum, error):
if Search(r'}', line):
# the second term is for detecting that the closing brace is part of an array
# initalizer list. Attention ';' must occur at the end of class definitions
if not Match(r'^\s*};?$', line) and not Search(r'\[.*\]\s+=\s+{.*};', line):
# but we will ignore comments when there is a closing brace ( third term )
if( not Match(r'^\s*};?$', line) and
not Search(r'\[.*\]\s+=\s+{.*};', line) and
not Search(r'}\s+//', clean_lines.raw_lines[linenum]) ):
error(filename, linenum, 'readability/braces', 5, 'Closing braces have a line for themselfs.')
# Likewise, an else should never have the else clause on the same line
......@@ -1867,7 +1870,7 @@ def CheckCheck(filename, clean_lines, linenum, error):
# Encourage replacing plain CHECKs with CHECK_EQ/CHECK_NE/etc.
for operator in ['==', '!=', '>=', '>', '<=', '<']:
if ReplaceableCheck(operator, current_macro, line):
if ReplaceableCheck(operator, current_macro, line) and not Search(r'^TS_ASSERT', current_macro):
error(filename, linenum, 'readability/check', 2,
'Consider using %s instead of %s(a %s b)' % (
_CHECK_REPLACEMENT[current_macro][operator],
......
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