OpenWalnut 1.2.5

WModuleInputConnector.h

00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WMODULEINPUTCONNECTOR_H
00026 #define WMODULEINPUTCONNECTOR_H
00027 
00028 #include <string>
00029 
00030 #include <boost/thread/locks.hpp>
00031 
00032 #include "WModule.h"
00033 #include "WModuleConnector.h"
00034 #include "WModuleConnectorSignals.h"
00035 
00036 #include "../common/WCondition.h"
00037 
00038 #include "WExportKernel.h"
00039 
00040 /**
00041  * Class implementing input connection functionality between modules.
00042  */
00043 class OWKERNEL_EXPORT WModuleInputConnector: public WModuleConnector
00044 {
00045 public:
00046 
00047     /**
00048      * Constructor.
00049      *
00050      * \param module the module which is owner of this connector.
00051      * \param name The name of this connector.
00052      * \param description Short description of this connector.
00053      */
00054     WModuleInputConnector( boost::shared_ptr< WModule > module, std::string name="", std::string description="" );
00055 
00056     /**
00057      * Destructor.
00058      */
00059     virtual ~WModuleInputConnector();
00060 
00061     /**
00062      * Checks whether the specified connector is an output connector.
00063      *
00064      * \param con the connector to check against.
00065      *
00066      * \return true if compatible.
00067      */
00068     virtual bool connectable( boost::shared_ptr<WModuleConnector> con );
00069 
00070     /**
00071      * Gets the condition variable that gets fired whenever new data has been sent.
00072      *
00073      * \return the condition
00074      */
00075     boost::shared_ptr< WCondition > getDataChangedCondition();
00076 
00077     /**
00078      * Connects (subscribes) a specified notify function with a signal this module instance is offering.
00079      *
00080      * \exception WModuleSignalSubscriptionFailed thrown if the signal can't be connected.
00081      *
00082      * \param signal the signal to connect to.
00083      * \param notifier the notifier function to bind.
00084      *
00085      * \return the connection. Disconnect it manually if not needed anymore!
00086      */
00087     boost::signals2::connection subscribeSignal( MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier );
00088 
00089     /**
00090      * Returns true if this instance is an WModuleInputConnector.
00091      *
00092      * \return true if castable to WModuleInputConnector.
00093      */
00094     virtual bool isInputConnector() const;
00095 
00096     /**
00097      * Returns true if this instance is an WModuleOutputConnector.
00098      *
00099      * \return true if castable to WModuleOutputConnector.
00100      */
00101     virtual bool isOutputConnector() const;
00102 
00103     /**
00104      * Denotes whether the connected output was updated. This does NOT denote an actual change in the current data!
00105      *
00106      * \return true if there has been an update.
00107      */
00108     virtual bool updated();
00109 
00110     /**
00111      * Resets the updated-flag. Call this from your module to reset the value of updated().
00112      *
00113      * \return the update flag before reset. Useful to get the flag and reset it in one call.
00114      */
00115     virtual bool handledUpdate();
00116 
00117 protected:
00118 
00119     /**
00120      * Connect additional signals.
00121      *
00122      * \param con the connector that requests connection.
00123      *
00124      */
00125     virtual void connectSignals( boost::shared_ptr<WModuleConnector> con );
00126 
00127     /**
00128      * Disconnect all signals subscribed by this connector from "con".
00129      *
00130      * \param con the connector that gets disconnected.
00131      */
00132     virtual void disconnectSignals( boost::shared_ptr<WModuleConnector> con );
00133 
00134     /**
00135      * Gets called when the data on this input connector changed.
00136      *
00137      * \param input the input connector receiving the change.
00138      * \param output the output connector sending the change notification.
00139      */
00140     virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input, boost::shared_ptr<WModuleConnector> output );
00141 
00142     /**
00143      * Gets called whenever a connector gets connected to the specified input.
00144      *
00145      * \param here the connector of THIS module that got connected to "there"
00146      * \param there the connector that has been connected with the connector "here" of this module.
00147      */
00148     virtual void notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> here, boost::shared_ptr<WModuleConnector> there );
00149 
00150     /**
00151      * Sets the update flag (use updated() to query it)to true. This is normally called by the notifyDataChange callback.
00152      */
00153     virtual void setUpdated();
00154 
00155 private:
00156 
00157     /**
00158      * Signal for "DATA_CHANGED" Events. We use a separate signal here (instead of using the signal send by the connected output)
00159      * since the output can not determine the receiver when signalling. So we use an own signal handler and signal to "forward"
00160      * the message and complete the information with a this-pointer.
00161      */
00162     t_GenericSignalType signal_DataChanged;
00163 
00164     /**
00165      * Condition fired whenever data changes.
00166      */
00167     boost::shared_ptr< WCondition > m_dataChangedCondition;
00168 
00169     /**
00170      * Connection for Data Changed signal of the connected output connector.
00171      */
00172     boost::signals2::connection m_DataChangedConnection;
00173 
00174     /**
00175      * This lock protects the m_updated flag.
00176      */
00177     boost::shared_mutex m_updatedLock;
00178 
00179     /**
00180      * A flag denoting that an update was received. It does not denote a real change in the value!
00181      */
00182     bool m_updated;
00183 };
00184 
00185 #endif  // WMODULEINPUTCONNECTOR_H
00186 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends