WModuleInputConnector.h 5.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//---------------------------------------------------------------------------
//
// 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 WMODULEINPUTCONNECTOR_H
#define WMODULEINPUTCONNECTOR_H

28 29
#include <string>

30 31
#include <boost/thread/locks.hpp>

32
#include "WModule.h"
33
#include "WModuleConnector.h"
34
#include "WModuleConnectorSignals.h"
35

36 37
#include "../common/WCondition.h"

38
#include "WExportKernel.h"
39

40 41 42
/**
 * Class implementing input connection functionality between modules.
 */
43
class OWKERNEL_EXPORT WModuleInputConnector: public WModuleConnector
44 45 46 47
{
public:

    /**
48
     * Constructor.
49
     *
50 51 52
     * \param module the module which is owner of this connector.
     * \param name The name of this connector.
     * \param description Short description of this connector.
53
     */
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
54
    WModuleInputConnector( boost::shared_ptr< WModule > module, std::string name="", std::string description="" );
55 56 57 58 59 60

    /**
     * Destructor.
     */
    virtual ~WModuleInputConnector();

61
    /**
62
     * Checks whether the specified connector is an output connector.
63
     *
64
     * \param con the connector to check against.
65
     *
66 67 68 69
     * \return true if compatible.
     */
    virtual bool connectable( boost::shared_ptr<WModuleConnector> con );

70 71 72 73 74 75 76
    /**
     * Gets the condition variable that gets fired whenever new data has been sent.
     *
     * \return the condition
     */
    boost::shared_ptr< WCondition > getDataChangedCondition();

77 78 79 80 81 82 83 84
    /**
     * Connects (subscribes) a specified notify function with a signal this module instance is offering.
     *
     * \exception WModuleSignalSubscriptionFailed thrown if the signal can't be connected.
     *
     * \param signal the signal to connect to.
     * \param notifier the notifier function to bind.
     */
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    boost::signals2::connection subscribeSignal( MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier );

    /**
     * Returns true if this instance is an WModuleInputConnector.
     *
     * \return true if castable to WModuleInputConnector.
     */
    virtual bool isInputConnector() const;

    /**
     * Returns true if this instance is an WModuleOutputConnector.
     *
     * \return true if castable to WModuleOutputConnector.
     */
    virtual bool isOutputConnector() const;
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114
    /**
     * Denotes whether the connected output was updated. This does NOT denote an actual change in the current data!
     *
     * \return true if there has been an update.
     */
    virtual bool updated();

    /**
     * Resets the updated-flag. Call this from your module to reset the value of updated().
     *
     * \return the update flag before reset. Useful to get the flag and reset it in one call.
     */
    virtual bool handledUpdate();

115 116
protected:

117
    /**
118
     * Connect additional signals.
119
     *
120
     * \param con the connector that requests connection.
121
     *
122 123 124
     */
    virtual void connectSignals( boost::shared_ptr<WModuleConnector> con );

125
    /**
126
     * Disconnect all signals subscribed by this connector from "con".
127
     *
128 129 130 131
     * \param con the connector that gets disconnected.
     */
    virtual void disconnectSignals( boost::shared_ptr<WModuleConnector> con );

132
    /**
133
     * Gets called when the data on this input connector changed.
134
     *
135 136 137
     * \param input the input connector receiving the change.
     * \param output the output connector sending the change notification.
     */
138 139 140 141 142 143 144 145 146
    virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input, boost::shared_ptr<WModuleConnector> output );

    /**
     * Gets called whenever a connector gets connected to the specified input.
     *
     * \param here the connector of THIS module that got connected to "there"
     * \param there the connector that has been connected with the connector "here" of this module.
     */
    virtual void notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> here, boost::shared_ptr<WModuleConnector> there );
147

148 149 150 151 152
    /**
     * Sets the update flag (use updated() to query it)to true. This is normally called by the notifyDataChange callback.
     */
    virtual void setUpdated();

153
private:
154

155
    /**
156 157 158 159 160 161
     * Signal for "DATA_CHANGED" Events. We use a separate signal here (instead of using the signal send by the connected output)
     * since the output can not determine the receiver when signalling. So we use an own signal handler and signal to "forward"
     * the message and complete the information with a this-pointer.
     */
    t_GenericSignalType signal_DataChanged;

162 163 164 165 166 167
    /**
     * Condition fired whenever data changes.
     */
    boost::shared_ptr< WCondition > m_dataChangedCondition;

    /**
168
     * Connection for Data Changed signal of the connected output connector.
169 170
     */
    boost::signals2::connection m_DataChangedConnection;
171 172 173 174 175 176 177 178 179 180

    /**
     * This lock protects the m_updated flag.
     */
    boost::shared_mutex m_updatedLock;

    /**
     * A flag denoting that an update was received. It does not denote a real change in the value!
     */
    bool m_updated;
181 182 183 184
};

#endif  // WMODULEINPUTCONNECTOR_H