OutPortCorbaCdrProvider.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
21 
22 #ifdef WIN32
23 #pragma warning( disable : 4290 )
24 #endif
25 
26 namespace RTC
27 {
36  : m_buffer(0)
37  {
38  // PortProfile setting
39  setInterfaceType("corba_cdr");
40 
41  // ConnectorProfile setting
42  m_objref = this->_this();
43 
44  // set outPort's reference
45  CORBA::ORB_ptr orb = ::RTC::Manager::instance().getORB();
46  CORBA::String_var ior = orb->object_to_string(m_objref.in());
47 #ifndef ORB_IS_RTORB
50  NVUtil::newNV("dataport.corba_cdr.outport_ior", ior));
51 #else // ORB_IS_RTORB
54  NVUtil::newNV("dataport.corba_cdr.outport_ior", ior.in()));
55 #endif // ORB_IS_RTORB
58  NVUtil::newNV("dataport.corba_cdr.outport_ref", m_objref));
59  }
60 
69  {
70  try
71  {
72  PortableServer::ObjectId_var oid;
73  oid = _default_POA()->servant_to_id(this);
74  _default_POA()->deactivate_object(oid);
75  }
76  catch (PortableServer::POA::ServantNotActive &e)
77  {
78  RTC_ERROR(("%s", e._name()));
79  }
80  catch (PortableServer::POA::WrongPolicy &e)
81  {
82  RTC_ERROR(("%s", e._name()));
83  }
84  catch (...)
85  {
86  // never throws exception
87  RTC_ERROR(("Unknown exception caught."));
88  }
89  }
90 
99  {
100  }
101 
110  {
111  m_buffer = buffer;
112  }
113 
122  ConnectorListeners* listeners)
123  {
124  m_profile = info;
125  m_listeners = listeners;
126  }
127 
136  {
137  m_connector = connector;
138  }
139 
147  ::OpenRTM::PortStatus
148  OutPortCorbaCdrProvider::get(::OpenRTM::CdrData_out data)
149  throw (CORBA::SystemException)
150  {
151  RTC_PARANOID(("OutPortCorbaCdrProvider::get()"));
152  // at least the output "data" area should be allocated
153  data = new ::OpenRTM::CdrData();
154 
155  if (m_buffer == 0)
156  {
157  onSenderError();
158  return ::OpenRTM::UNKNOWN_ERROR;
159  }
160 
161  cdrMemoryStream cdr;
163 
165  {
166  CORBA::ULong len((CORBA::ULong)cdr.bufSize());
167  RTC_PARANOID(("converted CDR data size: %d", len));
168 
169  if (len == (CORBA::ULong)0) {
170  RTC_ERROR(("buffer is empty."));
171  return ::OpenRTM::BUFFER_EMPTY;
172  }
173 #ifndef ORB_IS_RTORB
174  data->length(len);
175  cdr.get_octet_array(&((*data)[0]), len);
176 #else
177  data->length(len);
178  cdr.get_octet_array((char *)&((*data)[0]), (int)len);
179 #endif // ORB_IS_RTORB
180  }
181 
182  return convertReturn(ret, cdr);
183  }
184 
192  ::OpenRTM::PortStatus
194  const cdrMemoryStream& data)
195  {
196  switch(status)
197  {
199  onBufferRead(data);
200  onSend(data);
201  return ::OpenRTM::PORT_OK;
202  break;
203 
205  onSenderError();
206  return ::OpenRTM::PORT_ERROR;
207  break;
208 
210  // never come here
211  return ::OpenRTM::BUFFER_FULL;
212  break;
213 
215  onBufferEmpty();
216  onSenderEmpty();
217  return ::OpenRTM::BUFFER_EMPTY;
218  break;
219 
221  onSenderError();
222  return ::OpenRTM::PORT_ERROR;
223  break;
224 
227  onSenderTimeout();
228  return ::OpenRTM::BUFFER_TIMEOUT;
229  break;
230 
231  default:
232  return ::OpenRTM::UNKNOWN_ERROR;
233  }
234 
235  onSenderError();
236  return ::OpenRTM::UNKNOWN_ERROR;
237  }
238 
239 }; // namespace RTC
240 
241 extern "C"
242 {
251  {
254  factory.addFactory("corba_cdr",
259  }
260 };
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
Definition: NVUtil.h:79
ConnectorListeners class.
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
virtual void setConnector(OutPortConnector *connector)
set Connector
RT-Component.
void onSenderEmpty()
Notify an ON_SENDER_EMPTY event to listeners.
void setInterfaceType(const char *interface_type)
Set the interface type.
void onBufferRead(const cdrMemoryStream &data)
Notify an ON_BUFFER_READ event to listeners.
AbstractClass * Creator()
Creator template.
::OpenRTM::OutPortCdr_var m_objref
virtual ~OutPortCorbaCdrProvider(void)
Destructor.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void onSenderTimeout()
Notify an ON_SENDER_TIMEOUT event to listeners.
ReturnCode addFactory(const Identifier &id, Creator creator, Destructor destructor)
Add factory.
CORBA::ORB_ptr getORB()
Get the pointer to ORB.
Definition: Manager.cpp:832
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
GlobalFactory template class.
virtual ::OpenRTM::PortStatus get(::OpenRTM::CdrData_out data)
[CORBA interface] Get data from the buffer
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
::OpenRTM::PortStatus convertReturn(BufferStatus::Enum status, const cdrMemoryStream &data)
Return codes conversion.
void onSend(const cdrMemoryStream &data)
Notify an ON_SEND event to listeners.
#define RTC_PARANOID(fmt)
Paranoid level log output macro.
Definition: SystemLogger.h:555
virtual void init(coil::Properties &prop)
Initializing configuration.
void onSenderError()
Notify an ON_SENDER_ERROR event to listeners.
void onBufferReadTimeout()
Notify an ON_BUFFER_READ_TIMEOUT event to listeners.
OutPortProvider.
::RTC::BufferStatus::Enum ReturnCode
virtual void setListener(ConnectorInfo &info, ConnectorListeners *listeners)
Set the listener.
prop
Organization::get_organization_property ();.
virtual void setBuffer(CdrBufferBase *buffer)
Setting outside buffer&#39;s pointer.
virtual ReturnCode read(DataType &value, long int sec=-1, long int nsec=-1)=0
Read data from the buffer.
void Destructor(AbstractClass *&obj)
Destructor template.
Class represents a set of properties.
Definition: Properties.h:101
SDOPackage::NVList m_properties
Properties to hold the port profiles.
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
OutPortCorbaCdrProvider class.
void OutPortCorbaCdrProviderInit(void)
Module initialization.
BufferBase abstract class.
Definition: BufferBase.h:104
void onBufferEmpty()
Notify an ON_BUFFER_EMPTY event to listeners.
OutPortCorbaCdrProvider class.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:53