PublisherFlush.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #include <coil/Properties.h>
00021 #include <rtm/RTC.h>
00022 #include <rtm/PublisherBase.h>
00023 #include <rtm/PublisherFlush.h>
00024 #include <rtm/InPortConsumer.h>
00025 #include <rtm/ConnectorListener.h>
00026 
00027 namespace RTC
00028 {
00036   PublisherFlush::PublisherFlush()
00037     : rtclog("PublisherFlush"),
00038       m_consumer(0), m_listeners(0), m_active(false),
00039       m_retcode(PORT_OK)
00040   {
00041   }
00042 
00050   PublisherFlush::~PublisherFlush()
00051   {
00052     RTC_TRACE(("~PublisherFlush()"));
00053     // "consumer" should be deleted in the Connector
00054     m_consumer = 0;
00055   }
00056   
00064   PublisherBase::ReturnCode PublisherFlush::init(coil::Properties& prop)
00065   {
00066     RTC_TRACE(("init()"));
00067     return PORT_OK;
00068   }
00069 
00077   PublisherBase::ReturnCode
00078   PublisherFlush::setConsumer(InPortConsumer* consumer)
00079   {
00080     RTC_TRACE(("setConsumer()"));
00081     
00082     if (consumer == 0)
00083       {
00084         return INVALID_ARGS;
00085       }
00086     m_consumer = consumer;
00087     return PORT_OK;
00088   }
00089 
00097   PublisherBase::ReturnCode PublisherFlush::setBuffer(CdrBufferBase* buffer)
00098   {
00099     RTC_TRACE(("setBuffer()"));
00100 
00101     return PORT_OK;
00102   }
00103 
00111   ::RTC::DataPortStatus::Enum
00112   PublisherFlush::setListener(ConnectorInfo& info,
00113                               RTC::ConnectorListeners* listeners)
00114   {
00115     RTC_TRACE(("setListeners()"));
00116 
00117     if (listeners == 0)
00118       {
00119         RTC_ERROR(("setListeners(listeners == 0): invalid argument"));
00120         return INVALID_ARGS;
00121       }
00122 
00123     m_profile = info;
00124     m_listeners = listeners;
00125 
00126     return PORT_OK;
00127   }
00128 
00136   PublisherBase::ReturnCode PublisherFlush::write(const cdrMemoryStream& data,
00137                                                   unsigned long sec,
00138                                                   unsigned long usec)
00139   {
00140     RTC_PARANOID(("write()"));
00141 
00142     if (m_consumer == 0) { return PRECONDITION_NOT_MET; }
00143     if (m_listeners == 0) { return PRECONDITION_NOT_MET; }
00144 
00145     if (m_retcode == CONNECTION_LOST)
00146       {
00147         RTC_DEBUG(("write(): connection lost."));
00148         return m_retcode;
00149       }
00150 
00151     onSend(data);
00152     ReturnCode ret(m_consumer->put(data));
00153     // consumer::put() returns
00154     //  {PORT_OK, PORT_ERROR, SEND_FULL, SEND_TIMEOUT, UNKNOWN_ERROR}
00155 
00156     switch (ret)
00157       {
00158       case PORT_OK:
00159         onReceived(data);
00160         return ret;
00161       case PORT_ERROR:
00162         onReceiverError(data);
00163         return ret;
00164       case SEND_FULL:
00165         onReceiverFull(data);
00166         return ret;
00167       case SEND_TIMEOUT:
00168         onReceiverTimeout(data);
00169         return ret;
00170       case CONNECTION_LOST:
00171         onReceiverTimeout(data);
00172         return ret;
00173       case UNKNOWN_ERROR:
00174         onReceiverError(data);
00175         return ret;
00176       default:
00177         onReceiverError(data);
00178         return ret;
00179       }
00180     return ret;
00181   }
00182 
00190   bool PublisherFlush::isActive()
00191   {
00192     return m_active;
00193   }
00194 
00202   PublisherBase::ReturnCode PublisherFlush::activate()
00203   {
00204     m_active = true;
00205     return PORT_OK;
00206   }
00207 
00215   PublisherBase::ReturnCode PublisherFlush::deactivate()
00216   {
00217     m_active = false;
00218     return PORT_OK;
00219   }
00220 
00221 }; // namespace RTC
00222 
00223 
00224 extern "C"
00225 {
00226   void PublisherFlushInit()
00227   {
00228     ::RTC::PublisherFactory::
00229       instance().addFactory("flush",
00230                             ::coil::Creator< ::RTC::PublisherBase,
00231                                              ::RTC::PublisherFlush>,
00232                             ::coil::Destructor< ::RTC::PublisherBase,
00233                                                 ::RTC::PublisherFlush>);
00234   }
00235 };
00236 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17