OpenWalnut  1.5.0dev
WModuleOutputConnector.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 #include <string>
27 
28 #include <boost/signals2/connection.hpp>
29 #include <boost/signals2/signal.hpp>
30 
31 #include "../common/WCondition.h"
32 #include "WModuleConnectorSignals.h"
33 #include "WModuleInputConnector.h"
34 #include "WModuleOutputConnector.h"
35 
36 WModuleOutputConnector::WModuleOutputConnector( std::shared_ptr< WModule > module, std::string name, std::string description )
37  : WModuleConnector( module, name, description )
38 {
39 }
40 
42 {
43  // cleanup
44 }
45 
46 bool WModuleOutputConnector::connectable( std::shared_ptr<WModuleConnector> con )
47 {
48  // output connectors are just allowed to get connected with input connectors
49  if( dynamic_cast<WModuleInputConnector*>( con.get() ) ) // NOLINT - since we really need them here
50  {
51  return true;
52  }
53 
54  return false;
55 }
56 
57 bool WModuleOutputConnector::lazyConnectable( std::shared_ptr<WModuleConnector> con )
58 {
59  // output connectors are just allowed to get connected with input connectors
60  if( dynamic_cast<WModuleInputConnector*>( con.get() ) ) // NOLINT - since we really need them here
61  {
62  return true;
63  }
64 
65  return false;
66 }
67 
68 boost::signals2::connection WModuleOutputConnector::subscribeSignal( MODULE_CONNECTOR_SIGNAL signal,
69  t_GenericSignalHandlerType notifier )
70 {
71  // connect DataChanged signal
72  switch( signal )
73  {
74  case DATA_CHANGED:
75  return signal_DataChanged.connect( notifier );
76  default: // we do not know this signal: maybe the base class knows it
77  return WModuleConnector::subscribeSignal( signal, notifier );
78  }
79 }
80 
82 {
83  signal_DataChanged( std::shared_ptr<WModuleConnector>(), shared_from_this() );
84  m_dataChangedCondition->notify();
85 }
86 
88 {
89  return false;
90 }
91 
93 {
94  return true;
95 }
Base class for modelling connections between kernel modules.
virtual boost::signals2::connection subscribeSignal(MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier)
Connects a specified notify function with a signal this module instance is offering.
std::shared_ptr< WCondition > m_dataChangedCondition
Condition fired whenever data changes.
Class implementing input connection functionality between modules.
virtual bool lazyConnectable(std::shared_ptr< WModuleConnector > con)
Checks whether the specified connector is connectable to this one, but ignores compatibility the type...
virtual bool isInputConnector() const
Returns true if this instance is an WModuleInputConnector.
virtual bool connectable(std::shared_ptr< WModuleConnector > con)
Checks whether the specified connector is an input connector.
WModuleOutputConnector(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Constructor.
virtual void propagateDataChange()
Propagates the signal "DATA_CHANGED" to all connected items.
boost::signals2::connection subscribeSignal(MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier)
Connects (subscribes) a specified notify function with a signal this module instance is offering.
virtual bool isOutputConnector() const
Returns true if this instance is an WModuleOutputConnector.
t_GenericSignalType signal_DataChanged
Signal fired whenever new data should be propagated.
virtual ~WModuleOutputConnector()
Destructor.