OutPortPushConnector.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 #include <coil/stringutil.h>
21 
23 #include <rtm/ConnectorListener.h>
24 
25 namespace RTC
26 {
35  InPortConsumer* consumer,
36  ConnectorListeners& listeners,
37  CdrBufferBase* buffer)
38  : OutPortConnector(info),
39  m_consumer(consumer), m_publisher(0),
40  m_listeners(listeners), m_buffer(buffer)
41  {
42  // publisher/buffer creation. This may throw std::bad_alloc;
44  if (m_buffer == 0)
45  {
46  m_buffer = createBuffer(info);
47  }
48  if (m_publisher == 0 || m_buffer == 0 || m_consumer == 0)
49  { throw std::bad_alloc(); }
50 
51  if (m_publisher->init(info.properties) != PORT_OK)
52  {
53  throw std::bad_alloc();
54  }
55  m_buffer->init(info.properties.getNode("buffer"));
56  m_consumer->init(info.properties);
57 
61 
62  onConnect();
63  }
64 
73  {
74  onDisconnect();
75  disconnect();
76  }
77 
86  OutPortPushConnector::write(const cdrMemoryStream& data)
87  {
88  RTC_TRACE(("write()"));
89  RTC_PARANOID(("data size = %d bytes", data.bufSize()));
90 
91  return m_publisher->write(data, 0, 0);
92  }
93 
102  {
103  RTC_TRACE(("disconnect()"));
104  // delete publisher
105  if (m_publisher != 0)
106  {
107  RTC_DEBUG(("delete publisher"));
109  pfactory.deleteObject(m_publisher);
110  }
111  m_publisher = 0;
112 
113  // delete consumer
114  if (m_consumer != 0)
115  {
116  RTC_DEBUG(("delete consumer"));
118  cfactory.deleteObject(m_consumer);
119  }
120  m_consumer = 0;
121 
122  // delete buffer
123  if (m_buffer != 0)
124  {
125  RTC_DEBUG(("delete buffer"));
127  bfactory.deleteObject(m_buffer);
128  }
129  m_buffer = 0;
130  RTC_TRACE(("disconnect() done"));
131  return PORT_OK;
132  }
133 
144  {
146  }
147 
158  {
160  }
161 
176  {
177  return m_buffer;
178  }
179 
188  {
189  std::string pub_type;
190  pub_type = info.properties.getProperty("subscription_type",
191  "flush");
192  coil::normalize(pub_type);
193  return PublisherFactory::instance().createObject(pub_type);
194  }
195 
204  {
205  std::string buf_type;
206  buf_type = info.properties.getProperty("buffer_type",
207  "ring_buffer");
208  return CdrBufferFactory::instance().createObject(buf_type);
209  }
210 
219  {
221  }
222 
231  {
233  }
234 };
235 
virtual ReturnCode write(const cdrMemoryStream &data)
Writing data.
void onDisconnect()
Invoke callback when connection is destroied.
ConnectorListeners class.
InPortConsumer abstract class.
std::string normalize(std::string &str)
Erase the head/tail blank and replace upper case to lower case.
Definition: stringutil.cpp:303
virtual void activate()
Connector activation.
virtual void init(coil::Properties &prop)=0
Initializing configuration.
coil::Properties properties
Connection properties.
RT-Component.
void onConnect()
Invoke callback when connection is established.
virtual CdrBufferBase * getBuffer()
Getting Buffer.
virtual void deactivate()
Connector deactivation.
virtual ReturnCode setBuffer(BufferBase< cdrMemoryStream > *buffer)=0
Setting buffer pointer.
ConnectorListenerHolder connector_[CONNECTOR_LISTENER_NUM]
ConnectorListenerType listener array The ConnectorListenerType listener is stored.
virtual CdrBufferBase * createBuffer(ConnectorInfo &info)
create buffer
virtual ReturnCode disconnect()
disconnect
ConnectorListeners & m_listeners
A reference to a ConnectorListener.
ConnectorInfo m_profile
PortProfile of the Port.
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
GlobalFactory template class.
virtual ReturnCode deactivate()=0
deactivation
CdrBufferBase * m_buffer
A pointer to a buffer.
#define RTC_PARANOID(fmt)
Paranoid level log output macro.
Definition: SystemLogger.h:555
virtual ReturnCode init(coil::Properties &prop)=0
Initializing configuration.
InPortConsumer * m_consumer
A pointer to an InPortConsumer.
#define RTC_DEBUG(fmt)
Debug level log output macro.
Definition: SystemLogger.h:488
#define RTC_TRACE(fmt)
Push type connector class.
PublisherBase * m_publisher
A pointer to a publisher.
void deleteObject(const Identifier &id, AbstractClass *&obj)
Delete factory object.
virtual PublisherBase * createPublisher(ConnectorInfo &info)
create buffer
virtual ReturnCode write(const cdrMemoryStream &data, unsigned long sec, unsigned long usec)=0
Write data.
DATAPORTSTATUS_ENUM OutPortPushConnector(ConnectorInfo info, InPortConsumer *consumer, ConnectorListeners &listeners, CdrBufferBase *buffer=0)
Constructor.
::RTC::BufferStatus::Enum ReturnCode
Base class of Publisher.
Definition: PublisherBase.h:63
virtual ReturnCode setListener(ConnectorInfo &info, ConnectorListeners *listeners)=0
Set the listener.
virtual ~OutPortPushConnector()
Destructor.
Properties & getNode(const std::string &key)
Get node of properties.
Definition: Properties.cpp:455
virtual ReturnCode setConsumer(InPortConsumer *consumer)=0
Store InPort consumer.
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 ReturnCode activate()=0
activation


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