OpenWalnut  1.4.0
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 <string>
29 
30 #include <boost/signals2/signal.hpp>
31 #include <boost/signals2/connection.hpp>
32 
33 class WModule;
34 #include "WModuleConnector.h"
35 #include "WModuleConnectorSignals.h"
36 #include "../common/WPrototyped.h"
37 #include "../common/WTransferable.h"
38 
39 
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( boost::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( boost::shared_ptr<WModuleConnector> con );
85 
86  /**
87  * Returns the prototype of the WTransferable used in this connector.
88  *
89  * \return the prototype of the transfered type.
90  */
91  virtual boost::shared_ptr< WPrototyped > getTransferPrototype() = 0;
92 
93  /**
94  * Gives back the currently set data as WTransferable.
95  *
96  * \return the data. If no data has been set: a NULL pointer is returned.
97  */
98  virtual const boost::shared_ptr< WTransferable > getRawData() const = 0;
99 
100  /**
101  * Returns true if this instance is an WModuleInputConnector.
102  *
103  * \return true if castable to WModuleInputConnector.
104  */
105  virtual bool isInputConnector() const;
106 
107  /**
108  * Returns true if this instance is an WModuleOutputConnector.
109  *
110  * \return true if castable to WModuleOutputConnector.
111  */
112  virtual bool isOutputConnector() const;
113 
114 protected:
115  // If you want to add additional signals an output connector should subscribe FROM an input connector, overwrite
116  // connectSignals
117  // virtual void connectSignals( boost::shared_ptr<WModuleConnector> con );
118 
119  /**
120  * Propagates the signal "DATA_CHANGED" to all connected items.
121  */
122  virtual void propagateDataChange();
123 
124 private:
125  /**
126  * Signal fired whenever new data should be propagated. Represented by DATA_CHANGED enum- element.
127  */
128  t_GenericSignalType signal_DataChanged;
129 };
130 
131 #endif // WMODULEOUTPUTCONNECTOR_H
132