OutPort.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef RTC_OUTPORT_H
21 #define RTC_OUTPORT_H
22 
23 #include <functional>
24 #include <string>
25 
26 #include <coil/TimeValue.h>
27 #include <coil/Time.h>
28 #include <coil/TimeMeasure.h>
29 #include <coil/OS.h>
30 
31 #include <rtm/RTC.h>
32 #include <rtm/Typename.h>
33 #include <rtm/OutPortBase.h>
34 #include <rtm/CdrBufferBase.h>
35 #include <rtm/PortCallback.h>
36 #include <rtm/OutPortConnector.h>
37 
59 template <class DataType>
60 void setTimestamp(DataType& data)
61 {
62  // set timestamp
64  data.tm.sec = tm.sec();
65  data.tm.nsec = tm.usec() * 1000;
66 }
67 
68 namespace RTC
69 {
105  template <class DataType>
106  class OutPort
107  : public OutPortBase
108  {
109  public:
133  OutPort(const char* name, DataType& value)
134 #if defined(__GNUC__) && (__GNUC__ <= 3 && __GNUC_MINOR__ <= 3)
135  : OutPortBase(name, ::CORBA_Util::toRepositoryIdOfStruct<DataType>()),
136 #else
137  : OutPortBase(name, ::CORBA_Util::toRepositoryId<DataType>()),
138 #endif
139  m_value(value), m_onWrite(0), m_onWriteConvert(0)
140  {
141  addProperty("dataport.data_value", CORBA::Short(0));
142  {
143  Guard guard(m_profile_mutex);
145  "dataport.data_value");
146  }
147  }
148 
164  virtual ~OutPort(void)
165  {
166  }
167 
209  virtual bool write(DataType& value)
210  {
211  RTC_TRACE(("DataType write()"));
212 
213  if (m_onWrite != NULL)
214  {
215  (*m_onWrite)(value);
216  RTC_TRACE(("OnWrite called"));
217  }
218  {
219  Guard guard(m_profile_mutex);
220  m_profile.properties[m_propValueIndex].value <<= value;
221  }
222 
223  bool result(true);
224  std::vector<const char *> disconnect_ids;
225  {
226  Guard guard(m_connectorsMutex);
227  // check number of connectors
228  size_t conn_size(m_connectors.size());
229  if (!(conn_size > 0)) { return false; }
230 
231  m_status.resize(conn_size);
232 
233  for (size_t i(0), len(conn_size); i < len; ++i)
234  {
235  ReturnCode ret;
236  if (m_onWriteConvert != NULL)
237  {
238  RTC_DEBUG(("m_connectors.OnWriteConvert called"));
239  ret = m_connectors[i]->write(((*m_onWriteConvert)(value)));
240  }
241  else
242  {
243  RTC_DEBUG(("m_connectors.write called"));
244  ret = m_connectors[i]->write(value);
245  }
246  m_status[i] = ret;
247  if (ret == PORT_OK) { continue; }
248 
249  result = false;
250  const char* id(m_connectors[i]->profile().id.c_str());
251 
252  if (ret == CONNECTION_LOST)
253  {
254  RTC_WARN(("connection_lost id: %s", id));
255  if (m_onConnectionLost != 0)
256  {
257  RTC::ConnectorProfile prof(findConnProfile(id));
258  (*m_onConnectionLost)(prof);
259  }
260  disconnect_ids.push_back(id);
261  }
262  }
263  }
264  std::for_each(disconnect_ids.begin(),disconnect_ids.end(),
265  std::bind1st(std::mem_fun(&PortBase::disconnect),this));
266  return result;
267  }
268 
290  bool write()
291  {
292  return write(m_value);
293  }
294 
320  bool operator<<(DataType& value)
321  {
322  return write(value);
323  }
324 
358  {
359  return m_status[index];
360  }
392  {
393  return m_status;
394  }
395 
425  inline void setOnWrite(OnWrite<DataType>* on_write)
426  {
427  m_onWrite = on_write;
428  }
429 
466  inline void setOnWriteConvert(OnWriteConvert<DataType>* on_wconvert)
467  {
468  m_onWriteConvert = on_wconvert;
469  }
470 
471  private:
472  std::string m_typename;
480  DataType& m_value;
481 
490 
499 
501 
503 
504  CORBA::Long m_propValueIndex;
505  };
506 }; // namespace RTC
507 
508 #endif // RTC_OUTPORT_H
RT-Component.
std::vector< OutPortConnector * > m_connectors
Connection list.
Definition: OutPortBase.h:1032
OnWrite< DataType > * m_onWrite
Pointer to OnWrite callback functor.
Definition: OutPort.h:489
void setOnWriteConvert(OnWriteConvert< DataType > *on_wconvert)
Set OnWriteConvert callback.
Definition: OutPort.h:466
Data convert callback abstract class on write()
Definition: PortCallback.h:258
coil::Mutex m_connectorsMutex
Definition: PortBase.h:2088
coil::Mutex m_profile_mutex
Mutex of PortProfile.
Definition: PortBase.h:2087
virtual ~OutPort(void)
Destructor.
Definition: OutPort.h:164
OutPortConnector class.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
bool write()
Write data.
Definition: OutPort.h:290
DataPortStatusList getStatusList()
Getting specified connector&#39;s writing status list.
Definition: OutPort.h:391
PortCallback class.
Typename function.
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
TimeValue class.
Definition: TimeValue.h:40
#define RTC_WARN(fmt)
Warning log output macro.
Definition: SystemLogger.h:444
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
std::vector< DataPortStatus::Enum > DataPortStatusList
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
Definition: ace/coil/Time.h:57
virtual ReturnCode_t disconnect(const char *connector_id)
[CORBA interface] Disconnect the Port
Definition: PortBase.cpp:339
#define RTC_DEBUG(fmt)
Debug level log output macro.
Definition: SystemLogger.h:488
bool operator<<(DataType &value)
Write data.
Definition: OutPort.h:320
#define RTC_TRACE(fmt)
list index
Definition: rtimages.py:10
coil::TimeMeasure m_cdrtime
Definition: OutPort.h:500
Callback abstract class on write()
Definition: PortCallback.h:192
OutPortBase(const char *name, const char *data_type)
Constructor.
Definition: OutPortBase.cpp:81
void setTimestamp(DataType &data)
Setting timestamp to data.
Definition: OutPort.h:60
DataPortStatusList m_status
Definition: OutPort.h:502
InPortBase base class.
PortProfile m_profile
PortProfile of the Port.
Definition: PortBase.h:2070
OnWriteConvert< DataType > * m_onWriteConvert
Pointer to OnWriteConvert callback functor.
Definition: OutPort.h:498
DataPortStatus::Enum getStatus(int index)
Getting specified connector&#39;s writing status.
Definition: OutPort.h:357
std::string m_typename
Definition: OutPort.h:472
long int sec() const
Get value of second time scale.
Definition: TimeValue.h:110
OutPort(const char *name, DataType &value)
Constructor.
Definition: OutPort.h:133
long int usec() const
Get value of micro second time scale.
Definition: TimeValue.h:131
virtual bool write(DataType &value)
Write data.
Definition: OutPort.h:209
void setOnWrite(OnWrite< DataType > *on_write)
Set OnWrite callback.
Definition: OutPort.h:425
TimeMeasure class.
Definition: TimeMeasure.h:49
RTComponent header.
ConnectionCallback * m_onConnectionLost
Callback functor objects.
Definition: PortBase.h:2196
CORBA::Long m_propValueIndex
Definition: OutPort.h:504
void addProperty(const char *key, ValueType value)
Add NameValue data to PortProfile&#39;s properties.
Definition: PortBase.h:1876
Enum
DataPortStatus return codes.
ConnectorProfile findConnProfile(const char *id)
Find ConnectorProfile with id.
Definition: PortBase.cpp:770
Functor for_each(CorbaSequence &seq, Functor f)
Apply the functor to all CORBA sequence elements.
Definition: CORBA_SeqUtil.h:98
DataType & m_value
The reference to type-T variable that is bound.
Definition: OutPort.h:480


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:43