OpenWalnut  1.5.0dev
WModuleOutputConnector.h
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 #ifndef WMODULEOUTPUTCONNECTOR_H
26 #define WMODULEOUTPUTCONNECTOR_H
27 
28 #include <memory>
29 #include <string>
30 
31 #include <boost/signals2/connection.hpp>
32 #include <boost/signals2/signal.hpp>
33 
34 #include "../common/WPrototyped.h"
35 #include "../common/WTransferable.h"
36 #include "WModuleConnector.h"
37 #include "WModuleConnectorSignals.h"
38 
39 class WCondition;
40 
41 /**
42  * Class implementing output connection functionality between modules.
43  */
45 {
46 public:
47  // **************************************************************************************************************************
48  // Methods
49  // **************************************************************************************************************************
50 
51  /**
52  * Constructor.
53  *
54  * \param module the module which is owner of this connector.
55  * \param name The name of this connector.
56  * \param description Short description of this connector.
57  */
58  WModuleOutputConnector( std::shared_ptr< WModule > module, std::string name="", std::string description="" );
59 
60  /**
61  * Destructor.
62  */
63  virtual ~WModuleOutputConnector();
64 
65  /**
66  * Connects (subscribes) a specified notify function with a signal this module instance is offering.
67  *
68  * \exception WModuleSignalSubscriptionFailed thrown if the signal can't be connected.
69  *
70  * \param signal the signal to connect to.
71  * \param notifier the notifier function to bind.
72  *
73  * \return the connection object. Disconnect manually if not needed anymore.
74  */
75  boost::signals2::connection subscribeSignal( MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier );
76 
77  /**
78  * Checks whether the specified connector is an input connector.
79  *
80  * \param con the connector to check against.
81  *
82  * \return true if compatible.
83  */
84  virtual bool connectable( std::shared_ptr<WModuleConnector> con );
85 
86  /**
87  * Checks whether the specified connector is connectable to this one, but ignores compatibility the type to be transferred.
88  *
89  * \param con the connector to check against.
90  *
91  * \return true if compatible.
92  */
93  virtual bool lazyConnectable( std::shared_ptr<WModuleConnector> con );
94 
95  /**
96  * Returns the prototype of the WTransferable used in this connector.
97  *
98  * \return the prototype of the transfered type.
99  */
100  virtual std::shared_ptr< WPrototyped > getTransferPrototype() = 0;
101 
102  /**
103  * Gives back the currently set data as WTransferable.
104  *
105  * \return the data. If no data has been set: a NULL pointer is returned.
106  */
107  virtual const std::shared_ptr< WTransferable > getRawData() const = 0;
108 
109  /**
110  * Returns true if this instance is an WModuleInputConnector.
111  *
112  * \return true if castable to WModuleInputConnector.
113  */
114  virtual bool isInputConnector() const;
115 
116  /**
117  * Returns true if this instance is an WModuleOutputConnector.
118  *
119  * \return true if castable to WModuleOutputConnector.
120  */
121  virtual bool isOutputConnector() const;
122 
123 protected:
124  // If you want to add additional signals an output connector should subscribe FROM an input connector, overwrite
125  // connectSignals
126  // virtual void connectSignals( std::shared_ptr<WModuleConnector> con );
127 
128  /**
129  * Propagates the signal "DATA_CHANGED" to all connected items.
130  */
131  virtual void propagateDataChange();
132 
133 private:
134  /**
135  * Signal fired whenever new data should be propagated. Represented by DATA_CHANGED enum- element.
136  */
137  t_GenericSignalType signal_DataChanged;
138 };
139 
140 #endif // WMODULEOUTPUTCONNECTOR_H
141 
Class to encapsulate boost::condition_variable_any.
Definition: WCondition.h:42
Base class for modelling connections between kernel modules.
Class implementing output 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 std::shared_ptr< WPrototyped > getTransferPrototype()=0
Returns the prototype of the WTransferable used in this connector.
virtual bool isInputConnector() const
Returns true if this instance is an WModuleInputConnector.
virtual const std::shared_ptr< WTransferable > getRawData() const =0
Gives back the currently set data as WTransferable.
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.