ComponentObserverConsumer.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef RTC_COMPONENTOBSERVERCONSUMER_H
21 #define RTC_COMPONENTOBSERVERCONSUMER_H
22 
23 #include <coil/Mutex.h>
24 #include <coil/Factory.h>
25 #include <coil/stringutil.h>
27 #include <rtm/CorbaConsumer.h>
29 #include <rtm/idl/SDOPackageStub.h>
30 #include "ComponentObserverStub.h"
31 
32 namespace RTC
33 {
34 
41  : public SdoServiceConsumerBase
42  {
43  public:
52 
61 
69  virtual bool init(RTObject_impl& rtobj,
70  const SDOPackage::ServiceProfile& profile);
71 
79  virtual bool reinit(const SDOPackage::ServiceProfile& profile);
80 
88  virtual const SDOPackage::ServiceProfile& getProfile() const;
89 
97  virtual void finalize();
98 
99  protected:
107  inline void updateStatus(OpenRTM::StatusKind statuskind, const char* msg)
108  {
109  try
110  {
111  m_observer->update_status(statuskind, msg);
112  }
113  catch (...)
114  {
116  }
117  }
118 
126  inline const char* toString(OpenRTM::StatusKind kind)
127  {
128  static const char* kinds[] =
129  {
130  "COMPONENT_PROFILE",
131  "RTC_STATUS",
132  "EC_STATUS",
133  "PORT_PROFILE",
134  "CONFIGURATION",
135  "HEARTBEAT"
136  };
137  return (size_t)kind < sizeof(kind)/sizeof(char*) ? kinds[kind] : "";
138  }
139 
148 
156  void switchListeners(bool& next, bool& pre,
157  void (ComponentObserverConsumer::*setfunc)(),
158  void (ComponentObserverConsumer::*unsetfunc)());
159 
160  //============================================================
161  // Heartbeat related functions
169  void heartbeat();
170 
178  void setHeartbeat(coil::Properties& prop);
179 
187  void unsetHeartbeat();
188 
189  //============================================================
190  // Component status related functions
199 
208 
209  //============================================================
210  // Port profile related functions
219 
228 
229 
230  //============================================================
231  // EC profile related functions
240 
249 
250 
251  //============================================================
252  // ComponentProfile related functions
261 
270 
271  //============================================================
272  // Configuration related functions
273 
282 
291 
292 
293  private:
302  {
303  public:
305  : activatedListener(NULL), deactivatedListener(NULL),
306  resetListener(NULL), abortingListener(NULL),
307  finalizeListener(NULL), m_coc(coc) {}
308  void onGeneric(const char* msgprefix, UniqueId ec_id, ReturnCode_t ret)
309  {
310  if (ret == RTC::RTC_OK)
311  {
312  std::string msg(msgprefix);
313  msg += coil::otos(ec_id);
314  m_coc.updateStatus(OpenRTM::RTC_STATUS, msg.c_str());
315  }
316  }
318  {
319  onGeneric("ACTIVE:", ec_id, ret);
320  }
322  {
323  onGeneric("INACTIVE:", ec_id, ret);
324  }
326  {
327  onGeneric("INACTIVE:", ec_id, ret);
328  }
330  {
331  onGeneric("ERROR:", ec_id, ret);
332  }
334  {
335  onGeneric("FINALIZE:", ec_id, ret);
336  }
337 
343  private:
345  };
346 
355  {
356  public:
358  : portAddListener(NULL), portRemoveListener(NULL),
359  portConnectListener(NULL), portDisconnectListener(NULL),
360  m_coc(coc) {}
361  void onGeneric(const char* _msg, const char* portname)
362  {
363  std::string msg(_msg);
364  msg += portname;
365  m_coc.updateStatus(OpenRTM::PORT_PROFILE, msg.c_str());
366  }
367  void onAddPort(const ::RTC::PortProfile& pprof)
368  {
369  onGeneric("ADD:", static_cast<const char*>(pprof.name));
370  }
371  void onRemovePort(const ::RTC::PortProfile& pprof)
372  {
373  onGeneric("REMOVE:", static_cast<const char*>(pprof.name));
374  }
375  void onConnect(const char* portname,
376  ::RTC::ConnectorProfile& pprof, ReturnCode_t ret)
377  {
378  if (ret == RTC::RTC_OK)
379  {
380  onGeneric("CONNECT:", portname);
381  }
382  }
383  void onDisconnect(const char* portname,
384  ::RTC::ConnectorProfile& pprof, ReturnCode_t ret)
385  {
386  if (ret == RTC::RTC_OK)
387  {
388  onGeneric("DISCONNECT:", portname);
389  }
390  }
391 
396 
397  private:
399  };
400 
408  class ECAction
409  {
410  public:
412  : ecAttached(NULL), ecDetached(NULL), ecRatechanged(NULL),
413  ecStartup(NULL), ecShutdown(NULL),
414  m_coc(coc) {}
415  void onGeneric(const char* _msg, UniqueId ec_id)
416  {
417  std::string msg(_msg + coil::otos(ec_id));
418  m_coc.updateStatus(OpenRTM::EC_STATUS, msg.c_str());
419  }
421  {
422  onGeneric("ATTACHED:", ec_id);
423  }
425  {
426  onGeneric("DETACHED:", ec_id);
427  }
429  {
430  if (ret == RTC::RTC_OK)
431  {
432  onGeneric("RATE_CHANGED:", ec_id);
433  }
434  }
436  {
437  if (ret == RTC::RTC_OK)
438  {
439  onGeneric("STARTUP:", ec_id);
440  }
441  }
443  {
444  if (ret == RTC::RTC_OK)
445  {
446  onGeneric("SHUTDOWN:", ec_id);
447  }
448  }
454  private:
456  };
457 
466  {
467  public:
469  : updateConfigParamListener(NULL), setConfigSetListener(NULL),
470  addConfigSetListener(NULL), updateConfigSetListener(NULL),
471  removeConfigSetListener(NULL), activateConfigSetListener(NULL),
472  m_coc(coc) {}
473  void updateConfigParam(const char* configsetname,
474  const char* configparamname)
475  {
476  std::string msg("UPDATE_CONFIG_PARAM: ");
477  msg += configsetname;
478  msg += ".";
479  msg += configparamname;
480  m_coc.updateStatus(OpenRTM::CONFIGURATION, msg.c_str());
481  }
482  void setConfigSet(const coil::Properties& config_set)
483  {
484  std::string msg("SET_CONFIG_SET: ");
485  msg += config_set.getName();
486  m_coc.updateStatus(OpenRTM::CONFIGURATION, msg.c_str());
487  }
488  void addConfigSet(const coil::Properties& config_set)
489  {
490  std::string msg("ADD_CONFIG_SET: ");
491  msg += config_set.getName();
492  m_coc.updateStatus(OpenRTM::CONFIGURATION, msg.c_str());
493  }
494  void updateConfigSet(const char* config_set_name)
495  {
496  std::string msg("UPDATE_CONFIG_SET: ");
497  msg += config_set_name;
498  m_coc.updateStatus(OpenRTM::CONFIGURATION, msg.c_str());
499  }
500  void removeConfigSet(const char* config_set_name)
501  {
502  std::string msg("REMOVE_CONFIG_SET: ");
503  msg += config_set_name;
504  m_coc.updateStatus(OpenRTM::CONFIGURATION, msg.c_str());
505  }
506  void activateConfigSet(const char* config_set_name)
507  {
508  std::string msg("ACTIVATE_CONFIG_SET: ");
509  msg += config_set_name;
510  m_coc.updateStatus(OpenRTM::CONFIGURATION, msg.c_str());
511  }
512  // Listener object's pointer holder
519 
520  private:
522  };
523 
524 
525 
527  SDOPackage::ServiceProfile m_profile;
529 
530  bool m_observed[OpenRTM::STATUS_KIND_NUM];
531 
536 
540 
541  // このタイマーはいずれグローバルなタイマにおきかえる coil::Timer m_timer; }; }; // namespace RTC extern "C" { DLL_EXPORT void ComponentObserverConsumerInit(); }; #endif // RTC_COMPONENTOBSERVERCONSUMER_H
543 
544  };
545 
546 }; // namespace RTC
547 
548 extern "C"
549 {
551 };
552 
553 #endif // RTC_COMPONENTOBSERVERCONSUMER_H
554 
555 
CORBA Consumer class.
PortConnectRetListener class.
RT-Component.
void switchListeners(bool &next, bool &pre, void(ComponentObserverConsumer::*setfunc)(), void(ComponentObserverConsumer::*unsetfunc)())
Switching listeners connecting/disconnecting.
const char * getName(void) const
Get Names.
Definition: Properties.h:283
std::string otos(Printable n)
Convert the given object to std::string.
Definition: stringutil.h:566
void onDisconnect(const char *portname,::RTC::ConnectorProfile &pprof, ReturnCode_t ret)
component action listener class
void unsetComponentProfileListeners()
Unsetting ComponentProfile listener.
void unsetHeartbeat()
Unsetting heartbeat.
ReturnCode_t
Definition: doil.h:53
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
RT-Component class.
Definition: RTObject.h:89
ConfigurationSetListener class.
ConfigurationSetNameListener class.
virtual bool init(RTObject_impl &rtobj, const SDOPackage::ServiceProfile &profile)
Initialization.
ConfigurationParamListener class.
void onRateChanged(UniqueId ec_id, ReturnCode_t ret)
void onReset(UniqueId ec_id, ReturnCode_t ret)
void updateConfigParam(const char *configsetname, const char *configparamname)
SDOPackage::ServiceProfile m_profile
void unsetExecutionContextListeners()
Unsetting EC status listener.
void heartbeat()
Sending a heartbeart signal to observer.
ConfigurationSetNameListener * activateConfigSetListener
virtual const SDOPackage::ServiceProfile & getProfile() const
getting ServiceProfile
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.
void onGeneric(const char *_msg, UniqueId ec_id)
void onGeneric(const char *msgprefix, UniqueId ec_id, ReturnCode_t ret)
void onDeactivated(UniqueId ec_id, ReturnCode_t ret)
void setPortProfileListeners()
Setting port profile listener.
void addConfigSet(const coil::Properties &config_set)
void setListeners(coil::Properties &prop)
Connectiong listeners to RTObject.
ExecutionContextHandle_t UniqueId
void onFinalize(UniqueId ec_id, ReturnCode_t ret)
void onShutdown(UniqueId ec_id, ReturnCode_t ret)
CorbaConsumer< OpenRTM::ComponentObserver > m_observer
bool removeSdoServiceConsumer(const char *id)
[local interface] Remove a SDO service provider
Definition: RTObject.cpp:1962
void setConfigurationListeners()
Setting Configuration listener.
#define DLL_EXPORT
Definition: PluginC.cpp:8
ListenerBase class.
Definition: Listener.h:43
prop
Organization::get_organization_property ();.
void onGeneric(const char *_msg, const char *portname)
void unsetComponentStatusListeners()
Unsetting RTC status listeners.
void onConnect(const char *portname,::RTC::ConnectorProfile &pprof, ReturnCode_t ret)
Timer class.
Definition: Timer.h:53
Class represents a set of properties.
Definition: Properties.h:101
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]
DLL_EXPORT void ComponentObserverConsumerInit()
PortActionListener class.
SDO service consumer base class and its factory.
void unsetConfigurationListeners()
Unsetting Configurationlistener.
void setConfigSet(const coil::Properties &config_set)
void onActivated(UniqueId ec_id, ReturnCode_t ret)
PostComponentActionListener class.
void onAborting(UniqueId ec_id, ReturnCode_t ret)
void setHeartbeat(coil::Properties &prop)
Setting heartbeat.
ComponentObserverConsumer()
ctor of ComponentObserverConsumer
const char * toString(OpenRTM::StatusKind kind)
Converting kind to string.
ExecutionContextActionListener class.


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