InPortPushConnector.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
21 #include <rtm/InPortProvider.h>
22 #include <rtm/ConnectorListener.h>
23 
24 namespace RTC
25 {
35  ConnectorListeners& listeners,
36  CdrBufferBase* buffer)
37  : InPortConnector(info, buffer),
38  m_provider(provider),
39  m_listeners(listeners),
40  m_deleteBuffer(buffer == 0 ? true : false)
41  {
42  // publisher/buffer creation. This may throw std::bad_alloc;
43  if (m_buffer == 0)
44  {
45  m_buffer = createBuffer(info);
46  }
47  if (m_buffer == 0 || m_provider==0) throw std::bad_alloc();
48 
49  m_buffer->init(info.properties.getNode("buffer"));
50  m_provider->init(info.properties);
53 
54  onConnect();
55  }
56 
65  {
66  onDisconnect();
67  disconnect();
68  }
69 
78  InPortPushConnector::read(cdrMemoryStream& data)
79  {
80  RTC_TRACE(("read()"));
81  /*
82  * buffer returns
83  * BUFFER_OK
84  * BUFFER_EMPTY
85  * TIMEOUT
86  * PRECONDITION_NOT_MET
87  */
88  if (m_buffer == 0)
89  {
90  return PRECONDITION_NOT_MET;
91  }
93  switch (ret)
94  {
96  return PORT_OK;
97  break;
99  return BUFFER_EMPTY;
100  break;
102  return BUFFER_TIMEOUT;
103  break;
105  return PRECONDITION_NOT_MET;
106  break;
107  default:
108  return PORT_ERROR;
109  }
110  }
111 
120  {
121  RTC_TRACE(("disconnect()"));
122  // delete provider
123  if (m_provider != 0)
124  {
126  cfactory.deleteObject(m_provider);
127  }
128  m_provider = 0;
129 
130  // delete buffer
131  if (m_buffer != 0 && m_deleteBuffer == true)
132  {
134  bfactory.deleteObject(m_buffer);
135  }
136  m_buffer = 0;
137 
138  return PORT_OK;
139  }
140 
149  {
150  std::string buf_type;
151  buf_type = info.properties.getProperty("buffer_type",
152  "ring_buffer");
153  return CdrBufferFactory::instance().createObject(buf_type);
154  }
155 
164  {
166  }
167 
176  {
178  }
179 
180 };
181 
ConnectorListeners class.
ConnectorListeners & m_listeners
A reference to a ConnectorListener.
ConnectorInfo m_profile
ConnectorInfo.
virtual void setBuffer(BufferBase< cdrMemoryStream > *buffer)=0
Setting outside buffer&#39;s pointer.
coil::Properties properties
Connection properties.
InPortProvider class.
RT-Component.
ConnectorListenerHolder connector_[CONNECTOR_LISTENER_NUM]
ConnectorListenerType listener array The ConnectorListenerType listener is stored.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
GlobalFactory template class.
void onConnect()
Invoke callback when connection is established.
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
virtual ReturnCode read(cdrMemoryStream &data)
Reading data.
CdrBufferBase * m_buffer
Connector&#39;s buffer.
virtual CdrBufferBase * createBuffer(ConnectorInfo &info)
create buffer
DATAPORTSTATUS_ENUM InPortPushConnector(ConnectorInfo info, InPortProvider *provider, ConnectorListeners &listeners, CdrBufferBase *buffer=0)
Constructor.
#define RTC_TRACE(fmt)
InPortProvider * m_provider
the pointer to the InPortConsumer
virtual ReturnCode disconnect()
disconnect
void deleteObject(const Identifier &id, AbstractClass *&obj)
Delete factory object.
Push type connector class.
virtual void init(coil::Properties &prop)=0
Initializing configuration.
::RTC::BufferStatus::Enum ReturnCode
virtual ReturnCode read(DataType &value, long int sec=-1, long int nsec=-1)=0
Read data from the buffer.
virtual ~InPortPushConnector()
Destructor.
Properties & getNode(const std::string &key)
Get node of properties.
Definition: Properties.cpp:455
void notify(const ConnectorInfo &info)
Notify listeners.
virtual void init(const coil::Properties &prop)=0
Set the buffer.
BufferBase abstract class.
Definition: BufferBase.h:104
connector listener class
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
Definition: Properties.cpp:156
virtual void setListener(ConnectorInfo &info, ConnectorListeners *listeners)=0
Set the listener.
void onDisconnect()
Invoke callback when connection is destroied.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:58