1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
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.
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.
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/>.
23
//---------------------------------------------------------------------------
25
#ifndef WMODULEINPUTCONNECTOR_H
26
#define WMODULEINPUTCONNECTOR_H
30
#include <boost/thread/locks.hpp>
33
#include "WModuleConnector.h"
34
#include "WModuleConnectorSignals.h"
36
#include "../common/WCondition.h"
38
#include "WExportKernel.h"
41
* Class implementing input connection functionality between modules.
43
class OWKERNEL_EXPORT WModuleInputConnector: public WModuleConnector
50
* \param module the module which is owner of this connector.
51
* \param name The name of this connector.
52
* \param description Short description of this connector.
54
WModuleInputConnector( boost::shared_ptr< WModule > module, std::string name="", std::string description="" );
59
virtual ~WModuleInputConnector();
62
* Checks whether the specified connector is an output connector.
64
* \param con the connector to check against.
66
* \return true if compatible.
68
virtual bool connectable( boost::shared_ptr<WModuleConnector> con );
71
* Gets the condition variable that gets fired whenever new data has been sent.
73
* \return the condition
75
boost::shared_ptr< WCondition > getDataChangedCondition();
78
* Connects (subscribes) a specified notify function with a signal this module instance is offering.
80
* \exception WModuleSignalSubscriptionFailed thrown if the signal can't be connected.
82
* \param signal the signal to connect to.
83
* \param notifier the notifier function to bind.
85
* \return the connection. Disconnect it manually if not needed anymore!
87
boost::signals2::connection subscribeSignal( MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier );
90
* Returns true if this instance is an WModuleInputConnector.
92
* \return true if castable to WModuleInputConnector.
94
virtual bool isInputConnector() const;
97
* Returns true if this instance is an WModuleOutputConnector.
99
* \return true if castable to WModuleOutputConnector.
101
virtual bool isOutputConnector() const;
104
* Denotes whether the connected output was updated. This does NOT denote an actual change in the current data!
106
* \return true if there has been an update.
108
virtual bool updated();
111
* Resets the updated-flag. Call this from your module to reset the value of updated().
113
* \return the update flag before reset. Useful to get the flag and reset it in one call.
115
virtual bool handledUpdate();
120
* Connect additional signals.
122
* \param con the connector that requests connection.
125
virtual void connectSignals( boost::shared_ptr<WModuleConnector> con );
128
* Disconnect all signals subscribed by this connector from "con".
130
* \param con the connector that gets disconnected.
132
virtual void disconnectSignals( boost::shared_ptr<WModuleConnector> con );
135
* Gets called when the data on this input connector changed.
137
* \param input the input connector receiving the change.
138
* \param output the output connector sending the change notification.
140
virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input, boost::shared_ptr<WModuleConnector> output );
143
* Gets called whenever a connector gets connected to the specified input.
145
* \param here the connector of THIS module that got connected to "there"
146
* \param there the connector that has been connected with the connector "here" of this module.
148
virtual void notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> here, boost::shared_ptr<WModuleConnector> there );
151
* Sets the update flag (use updated() to query it)to true. This is normally called by the notifyDataChange callback.
153
virtual void setUpdated();
158
* Signal for "DATA_CHANGED" Events. We use a separate signal here (instead of using the signal send by the connected output)
159
* since the output can not determine the receiver when signalling. So we use an own signal handler and signal to "forward"
160
* the message and complete the information with a this-pointer.
162
t_GenericSignalType signal_DataChanged;
165
* Condition fired whenever data changes.
167
boost::shared_ptr< WCondition > m_dataChangedCondition;
170
* Connection for Data Changed signal of the connected output connector.
172
boost::signals2::connection m_DataChangedConnection;
175
* This lock protects the m_updated flag.
177
boost::shared_mutex m_updatedLock;
180
* A flag denoting that an update was received. It does not denote a real change in the value!
185
#endif // WMODULEINPUTCONNECTOR_H