InPortPullConnector.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #include <rtm/InPortPullConnector.h>
00021 #include <rtm/OutPortConsumer.h>
00022 #include <rtm/ConnectorListener.h>
00023 
00024 namespace RTC
00025 {
00033   InPortPullConnector::InPortPullConnector(ConnectorInfo info,
00034                                            OutPortConsumer* consumer,
00035                                            ConnectorListeners& listeners,
00036                                            CdrBufferBase* buffer)
00037     : InPortConnector(info, buffer), m_consumer(consumer),
00038       m_listeners(listeners)
00039   {
00040     if (buffer == 0)
00041       {
00042         m_buffer = createBuffer(m_profile);
00043       }
00044     if (m_buffer == 0 || m_consumer == 0)
00045       {
00046         throw std::bad_alloc();
00047         return;
00048       }
00049     m_buffer->init(info.properties.getNode("buffer"));
00050     m_consumer->setBuffer(m_buffer);
00051     m_consumer->setListener(info, &m_listeners);
00052 
00053     onConnect();
00054   }
00055   
00063   InPortPullConnector::~InPortPullConnector()
00064   {
00065     onDisconnect();
00066     disconnect();
00067   }
00068   
00076   ConnectorBase::ReturnCode
00077   InPortPullConnector::read(cdrMemoryStream& data)
00078   {
00079     RTC_TRACE(("InPortPullConnector::read()"));
00080     if (m_consumer == 0)
00081       {
00082         return PORT_ERROR;
00083       }
00084     return m_consumer->get(data);
00085   }
00086   
00094   ConnectorBase::ReturnCode InPortPullConnector::disconnect()
00095   {
00096     RTC_TRACE(("disconnect()"));
00097     // delete consumer
00098     if (m_consumer != 0)
00099       {
00100         OutPortConsumerFactory& cfactory(OutPortConsumerFactory::instance());
00101         cfactory.deleteObject(m_consumer);
00102       }
00103     m_consumer = 0;
00104 
00105     return PORT_OK;
00106   }
00107   
00115   CdrBufferBase* InPortPullConnector::createBuffer(ConnectorInfo& info)
00116   {
00117     std::string buf_type;
00118     buf_type = info.properties.getProperty("buffer_type",
00119                                               "ring_buffer");
00120     return CdrBufferFactory::instance().createObject(buf_type);
00121   }
00122 
00130   void InPortPullConnector::onConnect()
00131   {
00132     m_listeners.connector_[ON_CONNECT].notify(m_profile);
00133   }
00134 
00142   void InPortPullConnector::onDisconnect()
00143   {
00144     m_listeners.connector_[ON_DISCONNECT].notify(m_profile);
00145   }
00146 };
00147 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:37