InPortCorbaCdrProvider.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #include <rtm/InPortCorbaCdrProvider.h>
00021 
00022 #ifdef WIN32
00023 #pragma warning( disable : 4290 )
00024 #endif
00025 
00026 namespace RTC
00027 {
00035   InPortCorbaCdrProvider::InPortCorbaCdrProvider(void)
00036    : m_buffer(0) 
00037   {
00038     // PortProfile setting
00039     setInterfaceType("corba_cdr");
00040     
00041     // ConnectorProfile setting
00042     m_objref = this->_this();
00043     
00044     // set InPort's reference
00045     CORBA::ORB_ptr orb = ::RTC::Manager::instance().getORB();
00046     CORBA::String_var ior = orb->object_to_string(m_objref.in());
00047     CORBA_SeqUtil::
00048       push_back(m_properties,
00049                 NVUtil::newNV("dataport.corba_cdr.inport_ior", ior.in()));
00050     CORBA_SeqUtil::
00051       push_back(m_properties,
00052                 NVUtil::newNV("dataport.corba_cdr.inport_ref", m_objref));
00053   }
00054   
00062   InPortCorbaCdrProvider::~InPortCorbaCdrProvider(void)
00063   {
00064     try
00065       {
00066         PortableServer::ObjectId_var oid;
00067         oid = _default_POA()->servant_to_id(this);
00068         _default_POA()->deactivate_object(oid);
00069       }
00070     catch (PortableServer::POA::ServantNotActive &e)
00071       {
00072         RTC_ERROR(("%s", e._name()));
00073       }
00074     catch (PortableServer::POA::WrongPolicy &e)
00075       {
00076         RTC_ERROR(("%s", e._name()));
00077       }
00078     catch (...)
00079       {
00080         // never throws exception
00081         RTC_ERROR(("Unknown exception caught."));
00082       }
00083   }
00084 
00085   void InPortCorbaCdrProvider::init(coil::Properties& prop)
00086   {
00087   }
00088 
00096   void InPortCorbaCdrProvider::
00097   setBuffer(BufferBase<cdrMemoryStream>* buffer)
00098   {
00099     m_buffer = buffer;
00100   }
00101 
00109   void InPortCorbaCdrProvider::setListener(ConnectorInfo& info,
00110                                            ConnectorListeners* listeners)
00111   {
00112     m_profile = info;
00113     m_listeners = listeners;
00114   }
00115 
00123   void InPortCorbaCdrProvider::setConnector(InPortConnector* connector)
00124   {
00125     m_connector = connector;
00126   }
00127 
00135   ::OpenRTM::PortStatus
00136   InPortCorbaCdrProvider::put(const ::OpenRTM::CdrData& data)
00137     throw (CORBA::SystemException)
00138   {
00139     RTC_PARANOID(("InPortCorbaCdrProvider::put()"));
00140 
00141     if (m_buffer == 0)
00142       {
00143         cdrMemoryStream cdr;
00144         cdr.put_octet_array(&(data[0]), data.length());
00145         onReceiverError(cdr);
00146         return ::OpenRTM::PORT_ERROR;
00147       }
00148 
00149     RTC_PARANOID(("received data size: %d", data.length()))
00150     cdrMemoryStream cdr;
00151     // set endian type
00152     bool endian_type = m_connector->isLittleEndian();
00153     RTC_TRACE(("connector endian: %s", endian_type ? "little":"big"));
00154     cdr.setByteSwapFlag(endian_type);
00155     cdr.put_octet_array(&(data[0]), data.length());
00156 
00157     RTC_PARANOID(("converted CDR data size: %d", cdr.bufSize()));
00158     onReceived(cdr);
00159     BufferStatus::Enum ret = m_buffer->write(cdr);
00160 
00161     return convertReturn(ret, cdr);
00162   }
00163 
00171   ::OpenRTM::PortStatus
00172   InPortCorbaCdrProvider::convertReturn(BufferStatus::Enum status,
00173                                         const cdrMemoryStream& data)
00174   {
00175     switch(status)
00176       {
00177       case BufferStatus::BUFFER_OK:
00178         onBufferWrite(data);
00179         return ::OpenRTM::PORT_OK;
00180         break;
00181 
00182       case BufferStatus::BUFFER_ERROR:
00183         onReceiverError(data);
00184         return ::OpenRTM::PORT_ERROR;
00185         break;
00186 
00187       case BufferStatus::BUFFER_FULL:
00188         onBufferFull(data);
00189         onReceiverFull(data);
00190         return ::OpenRTM::BUFFER_FULL;
00191         break;
00192 
00193       case BufferStatus::BUFFER_EMPTY:
00194         // never come here
00195         return ::OpenRTM::BUFFER_EMPTY;
00196         break;
00197 
00198       case BufferStatus::PRECONDITION_NOT_MET:
00199         onReceiverError(data);
00200         return ::OpenRTM::PORT_ERROR;
00201         break;
00202 
00203       case BufferStatus::TIMEOUT:
00204         onBufferWriteTimeout(data);
00205         onReceiverTimeout(data);
00206         return ::OpenRTM::BUFFER_TIMEOUT;
00207         break;
00208 
00209       default:
00210         return ::OpenRTM::UNKNOWN_ERROR;
00211       }
00212 
00213     onReceiverError(data);
00214     return ::OpenRTM::UNKNOWN_ERROR;
00215   }
00216 
00217 };     // namespace RTC
00218 
00219 
00220 extern "C"
00221 {
00229   void InPortCorbaCdrProviderInit(void)
00230   {
00231     RTC::InPortProviderFactory& factory(RTC::InPortProviderFactory::instance());
00232     factory.addFactory("corba_cdr",
00233                        ::coil::Creator< ::RTC::InPortProvider,
00234                                         ::RTC::InPortCorbaCdrProvider>,
00235                        ::coil::Destructor< ::RTC::InPortProvider,
00236                                            ::RTC::InPortCorbaCdrProvider>);
00237   }
00238 };


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