PortAdmin.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
19 #include <functional>
20 #include <rtm/RTC.h>
21 #include <rtm/PortAdmin.h>
22 #include <rtm/CORBA_SeqUtil.h>
23 
24 namespace RTC
25 {
34  {
35  find_port_name(const char* name) : m_name(name) {};
36  bool operator()(const PortService_ptr& p)
37  {
38  try
39  {
40 #ifndef ORB_IS_RTORB
41  PortProfile_var prof(p->get_port_profile());
42  std::string name(prof->name);
43 #else // ORB_IS_RTORB
44  PortProfile *pp;
45  pp = p->get_port_profile();
46  std::string name( pp->name);
47  delete pp;
48 #endif // ORB_IS_RTORB
49  return m_name == name;
50  }
51  catch (...)
52  {
53  return false;
54  }
55  return false;
56  }
57  const std::string m_name;
58  };
59 
61  {
62  find_port(const PortService_ptr& p) : m_port(p) {};
63  bool operator()(const PortService_ptr& p)
64  {
65  return m_port->_is_equivalent(p);
66  }
67  const PortService_ptr m_port;
68  };
69 
78  {
80  del_port(PortAdmin* pa) : m_pa(pa) {};
82  {
83  m_pa->removePort(*p);
84  }
85  };
86 
94  PortAdmin::PortAdmin(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
95  : m_pORB(CORBA::ORB::_duplicate(orb)),
96  m_pPOA(PortableServer::POA::_duplicate(poa)),
97  rtclog("portadmin")
98  {
99  }
100 
109  {
110  PortServiceList_var ports;
111  ports = new PortServiceList(m_portRefs);
112  return ports._retn();
113  }
114 
123  {
124 
125 #ifndef ORB_IS_RTORB
126  PortProfileList port_profs;
127  // port_prof_collect p(port_profs);
128  port_prof_collect2 p(port_profs);
129  // m_portServants.for_each(p);
131 #else // ORB_IS_RTORB
132  CORBA::ULong len = m_portRefs.length();
133 
134  PortProfileList port_profs = PortProfileList(len);
135  PortProfile *pp;
136 
137  for (CORBA::ULong i (0); i < len; ++i)
138  {
139  try
140  {
141  pp = m_portRefs[i]->get_port_profile();
142  port_profs[i] = *(pp);
143  delete pp;
144  }
145  catch (...)
146  {
147  ;
148  }
149  }
150 #endif // ORB_IS_RTORB
151  return port_profs;
152  }
153 
161  PortService_ptr PortAdmin::getPortRef(const char* port_name) const
162  {
163  CORBA::Long index;
164  index = CORBA_SeqUtil::find(m_portRefs, find_port_name(port_name));
165  if (index >= 0)
166  {//throw NotFound(port_name);
167  return m_portRefs[index];
168  }
169  return RTC::PortService::_nil();
170  }
171 
179  PortBase* PortAdmin::getPort(const char* port_name) const
180  {
181  return m_portServants.find(port_name);
182  }
183 
192  {
193  // Check for duplicate
195  {
196  return false;
197  }
198 
199  // Store Port's ref to PortServiceList
201  RTC::PortService::_duplicate(port.getPortRef()));
202 
203  // Store Port servant
204  return m_portServants.registerObject(&port);
205  }
206 
214  bool PortAdmin::addPort(PortService_ptr port)
215  {
216  // Check for duplicate
217  try
218  {
219  PortProfile_var prof(port->get_port_profile());
220  std::string name(prof->name);
221 
222 // Why RtORB delete _var object explicitly?
223 #ifdef ORB_IS_RTORB
224  delete prof._retn();
225 #endif
226  if (CORBA_SeqUtil::find(m_portRefs, find_port_name(name.c_str())) != -1)
227  {
228  return false;
229  }
230  }
231  catch (...)
232  {
233  return false;
234  }
235  CORBA_SeqUtil::push_back(m_portRefs, RTC::PortService::_duplicate(port));
236  return true;
237  }
238 
240  {
241  if (!addPort(port))
242  {
243  RTC_ERROR(("registerPort(PortBase&) failed."));
244  }
245  }
246 
247  void PortAdmin::registerPort(PortService_ptr port)
248  {
249  if (!addPort(port))
250  {
251  RTC_ERROR(("registerPort(PortService_ptr) failed."));
252  }
253  }
254 
263  {
264  try
265  {
266  port.disconnect_all();
267  // port.shutdown();
268 
269  const char* tmp(port.getProfile().name);
271 
272  PortableServer::ObjectId_var oid = m_pPOA->servant_to_id(&port);
273  m_pPOA->deactivate_object(oid);
274  port.setPortRef(RTC::PortService::_nil());
275 
276  return m_portServants.unregisterObject(tmp) == NULL ? false : true;
277  }
278  catch (...)
279  {
280  return false;
281  }
282  }
283 
284  bool PortAdmin::removePort(PortService_ptr port)
285  {
286  try
287  {
289  return true;
290  }
291  catch (...)
292  {
293  return false;
294  }
295  }
296 
298  {
299  if (!removePort(port))
300  {
301  RTC_ERROR(("deletePort(PortBase&) failed."));
302  }
303  }
304  void PortAdmin::deletePort(PortService_ptr port)
305  {
306  if (!removePort(port))
307  {
308  RTC_ERROR(("deletePort(PortService_ptr) failed."));
309  }
310  }
311 
312 
320  void PortAdmin::deletePortByName(const char* port_name)
321  {
322  if (!port_name) return;
323  PortBase& p(*m_portServants.find(port_name));
324  removePort(p);
325  }
326 
335  {
336  std::vector<PortBase*> ports;
337  ports = m_portServants.getObjects();
338  for (int i(0), len(ports.size()); i < len; ++i)
339  {
340  ports[i]->activateInterfaces();
341  }
342  }
343 
352  {
353  std::vector<PortBase*> ports;
354  ports = m_portServants.getObjects();
355  for (int i(0), len(ports.size()); i < len; ++i)
356  {
357  ports[i]->deactivateInterfaces();
358  }
359  }
360 
369  {
370  deactivatePorts();
371  std::vector<PortBase*> ports;
372  ports = m_portServants.getObjects();
373  for_each(ports.begin(), ports.end(), del_port(this));
374  }
375 };
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
RT-Component.
void finalizePorts()
Deactivate all Ports and unregister them.
Definition: PortAdmin.cpp:368
Logger rtclog
Logger stream.
Definition: PortAdmin.h:523
CORBA::ORB_var m_pORB
Reference to ORB.
Definition: PortAdmin.h:496
PortableServer::POA_var m_pPOA
Reference to POA.
Definition: PortAdmin.h:505
PortService_ptr getPortRef()
Get the object reference of this Port.
Definition: PortBase.cpp:545
PortServiceList * getPortServiceList() const
Get PortServiceList.
Definition: PortAdmin.cpp:108
const char * getName() const
Get the name of this Port.
Definition: PortBase.cpp:504
void operator()(PortBase *p)
Definition: PortAdmin.cpp:81
PortService_ptr getPortRef(const char *port_name) const
Get the reference to Port object.
Definition: PortAdmin.cpp:161
PortBase * getPort(const char *port_name) const
Get pointer to the Port&#39;s servant.
Definition: PortAdmin.cpp:179
void activatePorts()
Activate all Port interfaces.
Definition: PortAdmin.cpp:334
void setPortRef(PortService_ptr port_ref)
Set the object reference of this Port.
Definition: PortBase.cpp:531
Functor to fing a Port.
Definition: PortAdmin.cpp:33
PortProfileList corerection functor.
Definition: PortAdmin.h:579
Functor to delete the Port.
Definition: PortAdmin.cpp:77
void registerPort(PortBase &port)
Regsiter the Port.
Definition: PortAdmin.cpp:239
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
list index
Definition: rtimages.py:10
PortProfileList getPortProfileList() const
Get PorProfileList.
Definition: PortAdmin.cpp:122
CORBA sequence utility template functions.
void erase_if(CorbaSequence &seq, Functor f)
Remove an element of a sequence according to a predicate.
const PortProfile & getProfile() const
Get the PortProfile of the Port.
Definition: PortBase.cpp:517
ObjectManager< const char *, PortBase, comp_op< PortBase > > m_portServants
Definition: PortAdmin.h:595
void deactivatePorts()
Deactivate all Port interfaces.
Definition: PortAdmin.cpp:351
find_port(const PortService_ptr &p)
Definition: PortAdmin.cpp:62
bool removePort(PortBase &port)
Unregister the Port registration.
Definition: PortAdmin.cpp:262
const std::string m_name
Definition: PortAdmin.cpp:57
std::vector< IPortService * > PortServiceList
Definition: IPortService.h:39
del_port(PortAdmin *pa)
Definition: PortAdmin.cpp:80
void deletePortByName(const char *port_name)
Unregister the Port&#39;s registration by its name.
Definition: PortAdmin.cpp:320
bool addPort(PortBase &port)
Regsiter the Port.
Definition: PortAdmin.cpp:191
const PortService_ptr m_port
Definition: PortAdmin.cpp:67
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
RTComponent header.
bool operator()(const PortService_ptr &p)
Definition: PortAdmin.cpp:36
PortServiceList m_portRefs
List of Port&#39;s object references.
Definition: PortAdmin.h:514
void deletePort(PortBase &port)
Unregister the Port registration.
Definition: PortAdmin.cpp:297
virtual ReturnCode_t disconnect_all()
[CORBA interface] Disconnect the All Ports
Definition: PortBase.cpp:454
bool operator()(const PortService_ptr &p)
Definition: PortAdmin.cpp:63
std::vector< PortProfile * > PortProfileList
Definition: IPortService.h:63
Functor for_each(CorbaSequence &seq, Functor f)
Apply the functor to all CORBA sequence elements.
Definition: CORBA_SeqUtil.h:98
RTC&#39;s Port administration class.
PortAdmin(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
Constructor.
Definition: PortAdmin.cpp:94
find_port_name(const char *name)
Definition: PortAdmin.cpp:35


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