00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <string>
00026
00027 #include "WModule.h"
00028 #include "WModuleOutputConnector.h"
00029 #include "WModuleConnectorSignals.h"
00030
00031 #include "WModuleInputConnector.h"
00032
00033 WModuleInputConnector::WModuleInputConnector( boost::shared_ptr< WModule > module, std::string name, std::string description ):
00034 WModuleConnector( module, name, description ),
00035 m_updated( false )
00036 {
00037
00038
00039
00040
00041 signal_DataChanged.connect( getSignalHandler( DATA_CHANGED ) );
00042
00043
00044 m_dataChangedCondition = boost::shared_ptr< WCondition >( new WCondition() );
00045
00046
00047 signal_ConnectionClosed.connect( boost::bind( &WModuleInputConnector::setUpdated, this ) );
00048 signal_ConnectionClosed.connect( boost::bind( &WCondition::notify, m_dataChangedCondition ) );
00049 }
00050
00051 WModuleInputConnector::~WModuleInputConnector()
00052 {
00053
00054 m_DataChangedConnection.disconnect();
00055 signal_ConnectionClosed.disconnect_all_slots();
00056 }
00057
00058 bool WModuleInputConnector::connectable( boost::shared_ptr<WModuleConnector> con )
00059 {
00060
00061 if( dynamic_cast<WModuleOutputConnector*>( con.get() ) )
00062 {
00063 return true;
00064 }
00065 return false;
00066 }
00067
00068 void WModuleInputConnector::connectSignals( boost::shared_ptr<WModuleConnector> con )
00069 {
00070 WModuleConnector::connectSignals( con );
00071
00072
00073
00074
00075 m_DataChangedConnection = con->subscribeSignal( DATA_CHANGED,
00076 boost::bind( &WModuleInputConnector::notifyDataChange, this, _1, _2 )
00077 );
00078 }
00079
00080 void WModuleInputConnector::disconnectSignals( boost::shared_ptr<WModuleConnector> con )
00081 {
00082 m_DataChangedConnection.disconnect();
00083
00084 WModuleConnector::disconnectSignals( con );
00085 }
00086
00087 boost::signals2::connection WModuleInputConnector::subscribeSignal( MODULE_CONNECTOR_SIGNAL signal,
00088 t_GenericSignalHandlerType notifier )
00089 {
00090
00091 switch ( signal )
00092 {
00093 case DATA_CHANGED:
00094 return signal_DataChanged.connect( notifier );
00095 default:
00096 return WModuleConnector::subscribeSignal( signal, notifier );
00097 }
00098 }
00099
00100 void WModuleInputConnector::notifyDataChange( boost::shared_ptr<WModuleConnector> ,
00101 boost::shared_ptr<WModuleConnector> output )
00102 {
00103 setUpdated();
00104
00105
00106
00107 signal_DataChanged( shared_from_this(), output );
00108 m_dataChangedCondition->notify();
00109 }
00110
00111 boost::shared_ptr< WCondition > WModuleInputConnector::getDataChangedCondition()
00112 {
00113 return m_dataChangedCondition;
00114 }
00115
00116 void WModuleInputConnector::notifyConnectionEstablished( boost::shared_ptr<WModuleConnector> here, boost::shared_ptr<WModuleConnector> there )
00117 {
00118
00119
00120
00121 notifyDataChange( here, there );
00122
00123
00124 WModuleConnector::notifyConnectionEstablished( here, there );
00125 }
00126
00127 bool WModuleInputConnector::isInputConnector() const
00128 {
00129 return true;
00130 }
00131
00132 bool WModuleInputConnector::isOutputConnector() const
00133 {
00134 return false;
00135 }
00136
00137 bool WModuleInputConnector::updated()
00138 {
00139 boost::lock_guard<boost::shared_mutex> lock( m_updatedLock );
00140 return m_updated;
00141 }
00142
00143 void WModuleInputConnector::setUpdated()
00144 {
00145 boost::lock_guard<boost::shared_mutex> lock( m_updatedLock );
00146 m_updated = true;
00147 }
00148
00149 bool WModuleInputConnector::handledUpdate()
00150 {
00151 boost::lock_guard<boost::shared_mutex> lock( m_updatedLock );
00152 bool old = m_updated;
00153 m_updated = false;
00154 return old;
00155 }
00156