OutPortCorbaCdrConsumer.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 #include <rtm/Manager.h>
22 #include <rtm/NVUtil.h>
23 
24 namespace RTC
25 {
34  {
35  rtclog.setName("OutPortCorbaCdrConsumer");
36  }
37 
46  {
47  }
48 
57  {
58  RTC_TRACE(("OutPortCorbaCdrConsumer::init()"));
59  }
60 
69  {
70  RTC_TRACE(("OutPortCorbaCdrConsumer::setBuffer()"));
71  m_buffer = buffer;
72  }
73 
82  ConnectorListeners* listeners)
83  {
84  RTC_TRACE(("OutPortCorbaCdrConsumer::setListener()"));
85  m_listeners = listeners;
86  m_profile = info;
87  }
88 
98  {
99  RTC_TRACE(("OutPortCorbaCdrConsumer::get()"));
100  ::OpenRTM::CdrData_var cdr_data;
101 
102  try
103  {
104  ::OpenRTM::PortStatus ret(_ptr()->get(cdr_data.out()));
105 
106  if (ret == ::OpenRTM::PORT_OK)
107  {
108  RTC_DEBUG(("get() successful"));
109  data.put_octet_array(&(cdr_data[0]), (int)cdr_data->length());
110  RTC_PARANOID(("CDR data length: %d", cdr_data->length()));
111 
112  onReceived(data);
113  onBufferWrite(data);
114 
115  if (m_buffer->full())
116  {
117  RTC_INFO(("InPort buffer is full."));
118  onBufferFull(data);
119  onReceiverFull(data);
120  }
121  m_buffer->put(data);
124 
125  return PORT_OK;
126  }
127  return convertReturn(ret, data);
128  }
129  catch (...)
130  {
131  RTC_WARN(("Exception caought from OutPort::get()."));
132  return CONNECTION_LOST;
133  }
134  RTC_ERROR(("OutPortCorbaCdrConsumer::get(): Never comes here."));
135  return UNKNOWN_ERROR;
136  }
137 
147  {
148  RTC_TRACE(("OutPortCorbaCdrConsumer::subscribeInterface()"));
149  CORBA::Long index;
150  index = NVUtil::find_index(properties,
151  "dataport.corba_cdr.outport_ior");
152  if (index < 0)
153  {
154  RTC_DEBUG(("dataport.corba_cdr.outport_ior not found."));
155  return false;
156  }
157 
158  if (NVUtil::isString(properties,
159  "dataport.corba_cdr.outport_ior"))
160  {
161  RTC_DEBUG(("dataport.corba_cdr.outport_ior found."));
162  const char* ior;
163  properties[index].value >>= ior;
164 
165  CORBA::ORB_ptr orb = ::RTC::Manager::instance().getORB();
166  CORBA::Object_var var = orb->string_to_object(ior);
167  bool ret(setObject(var.in()));
168  if (ret)
169  {
170  RTC_DEBUG(("CorbaConsumer was set successfully."));
171  }
172  else
173  {
174  RTC_ERROR(("Invalid object reference."))
175  }
176  return ret;
177  }
178 
179  return false;
180  }
181 
191  {
192  RTC_TRACE(("OutPortCorbaCdrConsumer::unsubscribeInterface()"));
193  CORBA::Long index;
194  index = NVUtil::find_index(properties,
195  "dataport.corba_cdr.outport_ior");
196  if (index < 0)
197  {
198  RTC_DEBUG(("dataport.corba_cdr.outport_ior not found."));
199  return;
200  }
201 
202  const char* ior;
203  if (properties[index].value >>= ior)
204  {
205  RTC_DEBUG(("dataport.corba_cdr.outport_ior found."));
206  CORBA::ORB_ptr orb = RTC::Manager::instance().getORB();
207  CORBA::Object_var var = orb->string_to_object(ior);
208  if (_ptr()->_is_equivalent(var))
209  {
210  releaseObject();
211  RTC_DEBUG(("CorbaConsumer's reference was released."));
212  return;
213  }
214  RTC_ERROR(("hmm. Inconsistent object reference."));
215  }
216  }
217 
226  OutPortCorbaCdrConsumer::convertReturn(::OpenRTM::PortStatus status,
227  const cdrMemoryStream& data)
228  {
229  switch(status)
230  {
231  case ::OpenRTM::PORT_OK:
232  // never comes here
233  return PORT_OK;
234  break;
235 
236  case ::OpenRTM::PORT_ERROR:
237  onSenderError();
238  return PORT_ERROR;
239  break;
240 
241  case ::OpenRTM::BUFFER_FULL:
242  // never comes here
243  return BUFFER_FULL;
244  break;
245 
246  case ::OpenRTM::BUFFER_EMPTY:
247  onSenderEmpty();
248  return BUFFER_EMPTY;
249  break;
250 
251  case ::OpenRTM::BUFFER_TIMEOUT:
252  onSenderTimeout();
253  return BUFFER_TIMEOUT;
254  break;
255 
256  case ::OpenRTM::UNKNOWN_ERROR:
257  onSenderError();
258  return UNKNOWN_ERROR;
259  break;
260 
261  default:
262  onSenderError();
263  return UNKNOWN_ERROR;
264  }
265 
266  onSenderError();
267  return UNKNOWN_ERROR;
268  }
269 
270 
271 }; // namespace RTC
272 
273 extern "C"
274 {
283  {
286  factory.addFactory("corba_cdr",
291  }
292 };
ConnectorListeners class.
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
virtual void releaseObject()
Clear CORBA object setting.
virtual ReturnCode advanceWptr(long int n=1)=0
Forward n writing pointers.
RT-Component.
bool isString(const SDOPackage::NVList &nv, const char *name)
Validate whether value type specified by name is string type.
Definition: NVUtil.cpp:239
OutPortConsumer::ReturnCode convertReturn(::OpenRTM::PortStatus status, const cdrMemoryStream &data)
Return codes conversion.
virtual ReturnCode get(cdrMemoryStream &data)
Read data.
void onSenderEmpty()
Notify an ON_SENDER_EMPTY event to listeners.
AbstractClass * Creator()
Creator template.
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
void onBufferFull(const cdrMemoryStream &data)
Notify an ON_BUFFER_FULL event to listeners.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
virtual ReturnCode put(const DataType &value)=0
Write data into the buffer.
ReturnCode addFactory(const Identifier &id, Creator creator, Destructor destructor)
Add factory.
void setName(const char *name)
Set suffix of date/time string of header.
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 void unsubscribeInterface(const SDOPackage::NVList &properties)
Unsubscribe the data receive notification.
OutPortCorbaCdrConsumer class.
#define RTC_WARN(fmt)
Warning log output macro.
Definition: SystemLogger.h:444
RTComponent manager class.
#define RTC_PARANOID(fmt)
Paranoid level log output macro.
Definition: SystemLogger.h:555
const CORBA::Long find_index(const SDOPackage::NVList &nv, const char *name)
Return the index of element specified by name from NVList.
Definition: NVUtil.cpp:227
virtual bool setObject(CORBA::Object_ptr obj)
Set Object.
DATAPORTSTATUS_ENUM OutPortCorbaCdrConsumer()
Constructor.
#define RTC_DEBUG(fmt)
Debug level log output macro.
Definition: SystemLogger.h:488
void OutPortCorbaCdrConsumerInit(void)
Module initialization.
#define RTC_TRACE(fmt)
void onReceived(const cdrMemoryStream &data)
Notify an ON_RECEIVED event to listeners.
list index
Definition: rtimages.py:10
virtual bool full(void) const =0
Check on whether the buffer is full.
NameValue and NVList utility functions.
virtual ~OutPortCorbaCdrConsumer(void)
Destructor.
Logger rtclog
Logger stream.
typename::OpenRTM::OutPortCdr::_ptr_type _ptr()
Get Object reference narrowed as ObjectType.
OutPortCorbaCdrConsumer class.
::RTC::BufferStatus::Enum ReturnCode
prop
Organization::get_organization_property ();.
void onBufferWrite(const cdrMemoryStream &data)
Notify an ON_BUFFER_WRITE event to listeners.
void onReceiverFull(const cdrMemoryStream &data)
Notify an ON_RECEIVER_FULL event to listeners.
virtual bool subscribeInterface(const SDOPackage::NVList &properties)
Subscribe the data receive notification.
void Destructor(AbstractClass *&obj)
Destructor template.
Class represents a set of properties.
Definition: Properties.h:101
virtual ReturnCode advanceRptr(long int n=1)=0
Forward n reading pointers.
void onSenderTimeout()
Notify an ON_SENDER_TIMEOUT event to listeners.
#define RTC_INFO(fmt)
Information level log output macro.
Definition: SystemLogger.h:466
OutPortConsumer abstract class.
virtual void setListener(ConnectorInfo &info, ConnectorListeners *listeners)
Set the listener.
virtual void setBuffer(CdrBufferBase *buffer)
Setting outside buffer&#39;s pointer.
BufferBase abstract class.
Definition: BufferBase.h:104
virtual void init(coil::Properties &prop)
Initializing configuration.


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