ComponentObserverConsumer.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
19 #include <coil/stringutil.h>
20 #include <rtm/Typename.h>
21 #include "ComponentObserverSkel.h"
23 #include <iostream>
24 
25 namespace RTC
26 {
35  : m_rtobj(NULL),
36  m_compstat(*this), m_portaction(*this),
37  m_ecaction(*this), m_configMsg(*this),
38  m_interval(0, 100000), m_heartbeat(false),
39  m_hblistenerid(NULL),
40  m_timer(m_interval)
41  {
42  for (size_t i(0); i < OpenRTM::STATUS_KIND_NUM; ++i)
43  {
44  m_observed[i] = false;
45  }
46  }
47 
56  {
63  }
64 
72  bool
74  const SDOPackage::ServiceProfile& profile)
75  {
76  if (!m_observer.setObject(profile.service))
77  {
78  // narrowing failed
79  return false;
80  }
81 
82  m_rtobj = &rtobj;
83  m_profile = profile;
85  NVUtil::copyToProperties(prop, profile.properties);
86  setHeartbeat(prop);
87  setListeners(prop);
88  return true;
89  }
90 
98  bool
99  ComponentObserverConsumer::reinit(const SDOPackage::ServiceProfile& profile)
100  {
101  if (!m_observer._ptr()->_is_equivalent(profile.service))
102  {
104  if (!tmp.setObject(profile.service))
105  {
106  return false;
107  }
109  m_observer.setObject(profile.service);
110  }
111  m_profile= profile;
113  NVUtil::copyToProperties(prop, profile.properties);
114  setHeartbeat(prop);
115  setListeners(prop);
116  return true;
117  }
118 
126  const SDOPackage::ServiceProfile&
128  {
129  return m_profile;
130  }
131 
140  {
146  unsetHeartbeat();
147  }
148 
149  //============================================================
150  // protected functions
151 
160  {
161  if (prop["observed_status"].empty())
162  {
163  prop["observed_status"] = "ALL";
164  }
165 
166  coil::vstring observed(coil::split(prop["observed_status"], ","));
167  bool flags[OpenRTM::STATUS_KIND_NUM];
168  for (int i(0); i < OpenRTM::STATUS_KIND_NUM; ++i)
169  {
170  flags[i] = false;
171  }
172  for (size_t i(0); i < observed.size(); ++i)
173  {
174  coil::toUpper(observed[i]);
175  if (observed[i] == "COMPONENT_PROFILE")
176  {
177  flags[OpenRTM::COMPONENT_PROFILE] = 1;
178  }
179  else if (observed[i] == "RTC_STATUS")
180  {
181  flags[OpenRTM::RTC_STATUS] = 1;
182  }
183  else if (observed[i] == "EC_STATUS")
184  {
185  flags[OpenRTM::EC_STATUS] = 1;
186  }
187  else if (observed[i] == "PORT_PROFILE")
188  {
189  flags[OpenRTM::PORT_PROFILE] = 1;
190  }
191  else if (observed[i] == "CONFIGURATION")
192  {
193  flags[OpenRTM::CONFIGURATION] = 1;
194  }
195  else if (observed[i] == "ALL")
196  {
197  for (int j(0); j < OpenRTM::STATUS_KIND_NUM; ++j)
198  {
199  flags[j] = true;
200  }
201  break;
202  }
203  }
204 
205  switchListeners(flags[OpenRTM::COMPONENT_PROFILE],
206  m_observed[OpenRTM::COMPONENT_PROFILE],
209  switchListeners(flags[OpenRTM::RTC_STATUS],
210  m_observed[OpenRTM::RTC_STATUS],
213  switchListeners(flags[OpenRTM::EC_STATUS],
214  m_observed[OpenRTM::EC_STATUS],
217  switchListeners(flags[OpenRTM::PORT_PROFILE],
218  m_observed[OpenRTM::PORT_PROFILE],
221  switchListeners(flags[OpenRTM::CONFIGURATION],
222  m_observed[OpenRTM::CONFIGURATION],
225 
226  }
227 
236  switchListeners(bool& next, bool& pre,
237  void (ComponentObserverConsumer::*setfunc)(),
238  void (ComponentObserverConsumer::*unsetfunc)())
239  {
240  if (!pre && next)
241  {
242  (this->*setfunc)();
243  pre = true;
244  }
245  else if (pre && !next)
246  {
247  (this->*unsetfunc)();
248  pre = false;
249  }
250  }
251 
252  //============================================================
253  // Heartbeat related functions
254 
263  {
264  updateStatus(OpenRTM::HEARTBEAT, "");
265  }
266 
275  {
276  if (coil::toBool(prop["heartbeat.enable"], "YES", "NO", false))
277  {
278  std::string interval(prop["heartbeat.interval"]);
279  if (interval.empty())
280  {
281  m_interval = 1.0;
282  }
283  else
284  {
285  double tmp;
286  coil::stringTo(tmp, interval.c_str());
287  m_interval = tmp;
288  }
289  coil::TimeValue tm;
290  tm = m_interval;
292  registerListenerObj(this, &ComponentObserverConsumer::heartbeat, tm);
293  m_timer.start();
294  }
295  else
296  {
297  if (m_heartbeat == true && m_hblistenerid != 0)
298  {
299  unsetHeartbeat();
300  m_timer.stop();
301  }
302  }
303  }
304 
313  {
315  m_heartbeat = false;
316  m_hblistenerid = 0;
317  m_timer.stop();
318  }
319 
320 
321  //============================================================
322  // Component status
323 
332  {
333  if (m_compstat.activatedListener == NULL)
334  {
337  m_compstat,
339  }
340  if (m_compstat.deactivatedListener == NULL)
341  {
344  m_compstat,
346  }
347  if (m_compstat.resetListener == NULL)
348  {
351  m_compstat,
353  }
354  if (m_compstat.abortingListener == NULL)
355  {
358  m_compstat,
360  }
361  if (m_compstat.finalizeListener == NULL)
362  {
365  m_compstat,
367  }
368  }
369 
378  {
379  if (m_compstat.activatedListener != NULL)
380  {
384  }
385  if (m_compstat.deactivatedListener != NULL)
386  {
390  }
391  if (m_compstat.resetListener != NULL)
392  {
395  m_compstat.resetListener = NULL;
396  }
397  if (m_compstat.abortingListener != NULL)
398  {
402  }
403  if (m_compstat.finalizeListener != NULL)
404  {
408  }
409  }
410 
411  //============================================================
412  // Port profile
422  {
423  if (m_portaction.portAddListener == NULL)
424  {
427  m_portaction,
429  }
430  if (m_portaction.portRemoveListener == NULL)
431  {
434  m_portaction,
436  }
437  if (m_portaction.portConnectListener == NULL)
438  {
441  m_portaction,
443  }
445  {
448  m_portaction,
450  }
451  }
452 
461  {
462  if (m_portaction.portAddListener != NULL)
463  {
467  }
468  if (m_portaction.portRemoveListener != NULL)
469  {
473  }
474  if (m_portaction.portConnectListener != NULL)
475  {
479  }
481  {
485  }
486  }
487 
488  //============================================================
489  // ExecutionContext profile
490 
499  {
500  if (m_ecaction.ecAttached == NULL)
501  {
504  m_ecaction,
506  }
507  if (m_ecaction.ecDetached == NULL)
508  {
511  m_ecaction,
513  }
514  if (m_ecaction.ecRatechanged == NULL)
515  {
518  m_ecaction,
520  }
521  if (m_ecaction.ecStartup == NULL)
522  {
525  m_ecaction,
527  }
528  if (m_ecaction.ecShutdown == NULL)
529  {
532  m_ecaction,
534  }
535  }
536 
545  {
546  if (m_ecaction.ecAttached != NULL)
547  {
550  }
551  if (m_ecaction.ecDetached != NULL)
552  {
555  }
556  if (m_ecaction.ecRatechanged != NULL)
557  {
560  }
561  if (m_ecaction.ecStartup != NULL)
562  {
565  }
566  if (m_ecaction.ecShutdown != NULL)
567  {
570  }
571  }
572 
573  //============================================================
574  // ComponentProfile related functions
583  {
584  }
585 
594  {
595  }
596 
597 
598  //============================================================
599  // Configuration
600 
602  {
605  m_configMsg,
609  m_configMsg,
613  m_configMsg,
617  m_configMsg,
621  m_configMsg,
625  m_configMsg,
627  }
628 
637  {
638 
640  {
641  m_rtobj->
642  removeConfigurationParamListener(ON_UPDATE_CONFIG_PARAM,
645  }
646  if (m_configMsg.setConfigSetListener != NULL)
647  {
651  }
652  if (m_configMsg.addConfigSetListener != NULL)
653  {
657  }
659  {
663  }
665  {
669  }
671  {
675  }
676  }
677 
678 
679 }; // namespace RTC
680 
681 extern "C"
682 {
684  {
687  factory.addFactory(CORBA_Util::toRepositoryId<OpenRTM::ComponentObserver>(),
692  }
693 };
virtual void releaseObject()
Clear CORBA object setting.
RT-Component.
void toUpper(std::string &str)
Uppercase String Transformation.
Definition: stringutil.cpp:68
void switchListeners(bool &next, bool &pre, void(ComponentObserverConsumer::*setfunc)(), void(ComponentObserverConsumer::*unsetfunc)())
Switching listeners connecting/disconnecting.
void onDisconnect(const char *portname,::RTC::ConnectorProfile &pprof, ReturnCode_t ret)
bool stringTo(To &val, const char *str)
Convert the given std::string to object.
Definition: stringutil.h:597
void unsetComponentProfileListeners()
Unsetting ComponentProfile listener.
AbstractClass * Creator()
Creator template.
void unsetHeartbeat()
Unsetting heartbeat.
void addPortConnectRetListener(PortConnectRetListenerType listener_type, PortConnectRetListener *listener, bool autoclean=true)
Adding PortConnectRet type listener.
Definition: RTObject.cpp:2326
void removeConfigurationSetListener(ConfigurationSetListenerType type, ConfigurationSetListener *listener)
Removing ConfigurationSetListener.
Definition: RTObject.cpp:2401
void addConfigurationSetListener(ConfigurationSetListenerType type, ConfigurationSetListener *listener, bool autoclean=true)
Adding ConfigurationSetListener.
Definition: RTObject.cpp:2386
void removePortConnectRetListener(PortConnectRetListenerType listener_type, PortConnectRetListener *listener)
Removing PortConnectRet type listener.
Definition: RTObject.cpp:2342
RT-Component class.
Definition: RTObject.h:89
ReturnCode addFactory(const Identifier &id, Creator creator, Destructor destructor)
Add factory.
virtual bool init(RTObject_impl &rtobj, const SDOPackage::ServiceProfile &profile)
Initialization.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:341
void onRateChanged(UniqueId ec_id, ReturnCode_t ret)
void onReset(UniqueId ec_id, ReturnCode_t ret)
void addExecutionContextActionListener(ECActionListenerType listener_type, ECActionListener *listener, bool autoclean=true)
Adding ExecutionContextAction type listener.
Definition: RTObject.cpp:2261
void updateConfigParam(const char *configsetname, const char *configparamname)
SDOPackage::ServiceProfile m_profile
void unsetExecutionContextListeners()
Unsetting EC status listener.
Typename function.
void heartbeat()
Sending a heartbeart signal to observer.
ConfigurationSetNameListener * activateConfigSetListener
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
void ComponentObserverConsumerInit()
GlobalFactory template class.
virtual const SDOPackage::ServiceProfile & getProfile() const
getting ServiceProfile
void addConfigurationSetNameListener(ConfigurationSetNameListenerType type, ConfigurationSetNameListener *listener, bool autoclean=true)
Adding ConfigurationSetNameListener.
Definition: RTObject.cpp:2415
void onRemovePort(const ::RTC::PortProfile &pprof)
TimeValue class.
Definition: TimeValue.h:40
void setComponentProfileListeners()
Setting ComponentProfile listener.
void onAddPort(const ::RTC::PortProfile &pprof)
virtual bool reinit(const SDOPackage::ServiceProfile &profile)
Re-initialization.
Component observer SDO service consumer implementation.
std::vector< std::string > vstring
Definition: stringutil.h:37
void onDeactivated(UniqueId ec_id, ReturnCode_t ret)
void setPortProfileListeners()
Setting port profile listener.
void addConfigSet(const coil::Properties &config_set)
void stop()
Stop Timer task.
Definition: Timer.cpp:107
virtual bool setObject(CORBA::Object_ptr obj)
Set Object.
void setListeners(coil::Properties &prop)
Connectiong listeners to RTObject.
void onFinalize(UniqueId ec_id, ReturnCode_t ret)
void onShutdown(UniqueId ec_id, ReturnCode_t ret)
void copyToProperties(coil::Properties &prop, const SDOPackage::NVList &nv)
Copy NVList to the Proeprties.
Definition: NVUtil.cpp:137
CorbaConsumer< OpenRTM::ComponentObserver > m_observer
def j(str, encoding="cp932")
Definition: RunAtFirst.py:198
void setConfigurationListeners()
Setting Configuration listener.
void removePortActionListener(PortActionListenerType listener_type, PortActionListener *listener)
Removing PortAction type listener.
Definition: RTObject.cpp:2243
void addConfigurationParamListener(ConfigurationParamListenerType type, ConfigurationParamListener *listener, bool autoclean=true)
Adding ConfigurationParamListener.
Definition: RTObject.cpp:2357
ObjectTypePtr _ptr()
Get Object reference narrowed as ObjectType.
void removePostComponentActionListener(PostComponentActionListenerType listener_type, PostComponentActionListener *listener)
Removing PostComponentAction type listener.
Definition: RTObject.cpp:2206
void removeConfigurationSetNameListener(ConfigurationSetNameListenerType type, ConfigurationSetNameListener *listener)
Removing ConfigurationSetNameListener.
Definition: RTObject.cpp:2430
prop
Organization::get_organization_property ();.
void unsetComponentStatusListeners()
Unsetting RTC status listeners.
void removeExecutionContextActionListener(ECActionListenerType listener_type, ECActionListener *listener)
Removing ExecutionContextAction type listener.
Definition: RTObject.cpp:2280
void Destructor(AbstractClass *&obj)
Destructor template.
void onConnect(const char *portname,::RTC::ConnectorProfile &pprof, ReturnCode_t ret)
Class represents a set of properties.
Definition: Properties.h:101
bool toBool(std::string str, std::string yes, std::string no, bool default_value)
Convert given string into bool value.
Definition: stringutil.cpp:410
void start()
Start Timer task.
Definition: Timer.cpp:90
void onStartup(UniqueId ec_id, ReturnCode_t ret)
void setExecutionContextListeners()
Setting EC status listener.
void setComponentStatusListeners()
Setting RTC status listeners.
void activateConfigSet(const char *config_set_name)
void unsetPortProfileListeners()
Unsetting port profile listener.
virtual void finalize()
Finalization.
void updateStatus(OpenRTM::StatusKind statuskind, const char *msg)
Calling remote object.
bool m_observed[OpenRTM::STATUS_KIND_NUM]
bool unregisterListener(ListenerId id)
Unregister listener.
Definition: Timer.cpp:165
void addPostComponentActionListener(PostComponentActionListenerType listener_type, PostComponentActionListener *listener, bool autoclean=true)
Adding PostComponentAction type listener.
Definition: RTObject.cpp:2186
void unsetConfigurationListeners()
Unsetting Configurationlistener.
void setConfigSet(const coil::Properties &config_set)
void onActivated(UniqueId ec_id, ReturnCode_t ret)
void onAborting(UniqueId ec_id, ReturnCode_t ret)
void setHeartbeat(coil::Properties &prop)
Setting heartbeat.
ComponentObserverConsumer()
ctor of ComponentObserverConsumer
void addPortActionListener(PortActionListenerType listener_type, PortActionListener *listener, bool autoclean=true)
Adding PortAction type listener.
Definition: RTObject.cpp:2224


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