OutPortPullConnector.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #include <rtm/OutPortPullConnector.h>
00021 #include <rtm/OutPortProvider.h>
00022 
00023 namespace RTC
00024 {
00032   OutPortPullConnector::OutPortPullConnector(ConnectorInfo info,
00033                                              OutPortProvider* provider,
00034                                              ConnectorListeners& listeners,
00035                                              CdrBufferBase* buffer)
00036     : OutPortConnector(info),
00037       m_provider(provider),
00038       m_listeners(listeners),
00039       m_buffer(buffer)
00040   {
00041     // create buffer
00042     if (m_buffer == 0)
00043       {
00044         m_buffer = createBuffer(info);
00045       }
00046 
00047     if (m_provider == 0 || m_buffer == 0) { throw std::bad_alloc(); }
00048 
00049     m_buffer->init(info.properties.getNode("buffer"));
00050     m_provider->setBuffer(m_buffer);
00051     m_provider->setConnector(this);
00052     //    m_provider->init(m_profile /* , m_listeners */);
00053     m_provider->setListener(info, &m_listeners);
00054 
00055     onConnect();
00056   }
00057 
00065   OutPortPullConnector::~OutPortPullConnector()
00066   {
00067     onDisconnect();
00068     disconnect();
00069   }
00070 
00078   ConnectorBase::ReturnCode
00079   OutPortPullConnector::write(const cdrMemoryStream& data)
00080   {
00081     m_buffer->write(data);
00082     return PORT_OK;
00083   }
00084 
00092   ConnectorBase::ReturnCode OutPortPullConnector::disconnect()
00093   {
00094     RTC_TRACE(("disconnect()"));
00095     // delete provider
00096     if (m_provider != 0)
00097       {
00098         OutPortProviderFactory& cfactory(OutPortProviderFactory::instance());
00099         cfactory.deleteObject(m_provider);
00100       }
00101     m_provider = 0;
00102 
00103     // delete buffer
00104     if (m_buffer != 0)
00105       {
00106         CdrBufferFactory& bfactory(CdrBufferFactory::instance());
00107         bfactory.deleteObject(m_buffer);
00108       }
00109     m_buffer = 0;
00110 
00111     return PORT_OK;
00112   }
00113 
00127   CdrBufferBase* OutPortPullConnector::getBuffer()
00128   {
00129     return m_buffer;
00130   }
00131   
00139   CdrBufferBase* OutPortPullConnector::createBuffer(ConnectorInfo& info)
00140   {
00141     std::string buf_type;
00142     buf_type = info.properties.getProperty("buffer_type",
00143                                               "ring_buffer");
00144     return CdrBufferFactory::instance().createObject(buf_type);
00145   }
00146 
00154   void OutPortPullConnector::onConnect()
00155   {
00156     m_listeners.connector_[ON_CONNECT].notify(m_profile);
00157   }
00158 
00166   void OutPortPullConnector::onDisconnect()
00167   {
00168     m_listeners.connector_[ON_DISCONNECT].notify(m_profile);
00169   }
00170 };
00171 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:05