OpenRTM-aist  2.0.1
ConfigurationListener.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef RTC_CONFIGURATIONLISTENER_H
20 #define RTC_CONFIGURATIONLISTENER_H
21 
22 #include <coil/Properties.h>
23 #include <mutex>
24 
25 #include <utility>
26 #include <vector>
27 #include <array>
28 
29 namespace RTC
30 {
31  //============================================================
45  enum class ConfigurationParamListenerType : uint8_t
46  {
49  };
50 
51 
75  {
76  public:
100  static const char* toString(ConfigurationParamListenerType type)
101  {
103  {
104  static const char* const typeString[] =
105  {
106  "ON_UPDATE_CONFIG_PARAM",
107  "CONFIG_PARAM_LISTENER_NUM"
108  };
109  return typeString[static_cast<uint8_t>(type)];
110  }
111  return "";
112  }
113 
121  virtual ~ConfigurationParamListener();
122 
138  virtual void operator()(const char* config_set_name,
139  const char* config_param_name) = 0;
140  };
141 
142 
143  //============================================================
160  enum class ConfigurationSetListenerType : uint8_t
161  {
165  };
166 
191  {
192  public:
217  static const char* toString(ConfigurationSetListenerType type)
218  {
220  {
221  static const char* const typeString[] =
222  {
223  "ON_SET_CONFIG_SET",
224  "ON_ADD_CONFIG_SET",
225  "CONFIG_SET_LISTENER_NUM"
226  };
227  return typeString[static_cast<uint8_t>(type)];
228  }
229  return "";
230  }
231 
239  virtual ~ConfigurationSetListener();
240 
256  virtual void operator()(const coil::Properties& config_set) = 0;
257  };
258 
259 
260  //============================================================
271  enum class ConfigurationSetNameListenerType : uint8_t
272  {
277  };
278 
304  {
305  public:
331  {
333  {
334  static const char* const typeString[] =
335  {
336  "ON_UPDATE_CONFIG_SET",
337  "ON_REMOVE_CONFIG_SET",
338  "ON_ACTIVATE_CONFIG_SET",
339  "CONFIG_SET_NAME_LISTENER_NUM"
340  };
341  return typeString[static_cast<uint8_t>(type)];
342  }
343  return "";
344  }
345 
354 
370  virtual void operator()(const char* config_set_name) = 0;
371  };
372 
373 
391  {
392  using Entry = std::pair<ConfigurationParamListener*, bool>;
393  public:
410 
432  void addListener(ConfigurationParamListener* listener, bool autoclean);
433 
452 
472  void notify(const char* config_set_name, const char* config_param_name);
473 
474  private:
475  std::vector<Entry> m_listeners;
476  std::mutex m_mutex;
477  };
478 
479 
480  //============================================================
498  {
499  using Entry = std::pair<ConfigurationSetListener*, bool>;
500  public:
517 
539  void addListener(ConfigurationSetListener* listener, bool autoclean);
540 
559 
579  void notify(const coil::Properties& config_set);
580 
581  private:
582  std::vector<Entry> m_listeners;
583  std::mutex m_mutex;
584  };
585 
586 
587  //============================================================
605  {
606  using Entry = std::pair<ConfigurationSetNameListener*, bool>;
607  public:
616 
625 
647  void addListener(ConfigurationSetNameListener* listener, bool autoclean);
648 
667 
685  void notify(const char* config_set_name);
686 
687  private:
688  std::vector<Entry> m_listeners;
689  std::mutex m_mutex;
690  };
691 
692  //------------------------------------------------------------
707  {
708  public:
742  bool addListener(ConfigurationParamListenerType type, ConfigurationParamListener* listener, bool autoclean=true);
791  bool addListener(ConfigurationSetListenerType type, ConfigurationSetListener* listener, bool autoclean=true);
840  bool addListener(ConfigurationSetNameListenerType type, ConfigurationSetNameListener* listener, bool autoclean=true);
884  inline bool notify(ConfigurationParamListenerType type, const char* config_set_name, const char* config_param_name)
885  {
886  if (static_cast<uint8_t>(type) < configparam_.size())
887  {
888  configparam_[static_cast<uint8_t>(type)].notify(config_set_name, config_param_name);
889  return true;
890  }
891  return false;
892  }
913  inline bool notify(ConfigurationSetListenerType type, const coil::Properties& config_set)
914  {
915  if (static_cast<uint8_t>(type) < configset_.size())
916  {
917  configset_[static_cast<uint8_t>(type)].notify(config_set);
918  return true;
919  }
920  return false;
921  }
942  inline bool notify(ConfigurationSetNameListenerType type, const char* config_set_name)
943  {
944  if (static_cast<uint8_t>(type) < configsetname_.size())
945  {
946  configsetname_[static_cast<uint8_t>(type)].notify(config_set_name);
947  return true;
948  }
949  return false;
950  }
951  private:
961  std::array<ConfigurationParamListenerHolder, static_cast<uint8_t>(ConfigurationParamListenerType::CONFIG_PARAM_LISTENER_NUM)> configparam_;
971  std::array<ConfigurationSetListenerHolder, static_cast<uint8_t>(ConfigurationSetListenerType::CONFIG_SET_LISTENER_NUM)> configset_;
981  std::array<ConfigurationSetNameListenerHolder, static_cast<uint8_t>(ConfigurationSetNameListenerType::CONFIG_SET_NAME_LISTENER_NUM)> configsetname_;
982  };
983 
984 
985 } // namespace RTC
986 
987 #endif // RTC_CONFIGURATIONLISTENER_H
RTC::ConfigurationParamListener::toString
static const char * toString(ConfigurationParamListenerType type)
Convert ConfigurationParamListenerType into the string.
Definition: ConfigurationListener.h:100
RTC::ConfigurationSetNameListenerType::ON_REMOVE_CONFIG_SET
@ ON_REMOVE_CONFIG_SET
RTC::ConfigurationListeners::removeListener
bool removeListener(ConfigurationParamListenerType type, ConfigurationParamListener *listener)
Remove the listener.
RTC::ConfigurationSetNameListenerHolder
ConfigurationSetNameListener holder class.
Definition: ConfigurationListener.h:604
RTC::ConfigurationParamListenerType::ON_UPDATE_CONFIG_PARAM
@ ON_UPDATE_CONFIG_PARAM
RTC::ConfigurationSetListenerType
ConfigurationSetListenerType
The types of ConfigurationSetListener.
Definition: ConfigurationListener.h:160
RTC::ConfigurationParamListenerHolder::ConfigurationParamListenerHolder
ConfigurationParamListenerHolder()
Constructor.
RTC::ConfigurationListeners::notify
bool notify(ConfigurationParamListenerType type, const char *config_set_name, const char *config_param_name)
Definition: ConfigurationListener.h:884
RTC::ConfigurationParamListenerHolder::~ConfigurationParamListenerHolder
virtual ~ConfigurationParamListenerHolder()
Destructor.
RTC::ConfigurationParamListenerHolder::notify
void notify(const char *config_set_name, const char *config_param_name)
Notify listeners.
RTC::ConfigurationParamListenerHolder::addListener
void addListener(ConfigurationParamListener *listener, bool autoclean)
Add the listener.
RTC::ConfigurationListeners::addListener
bool addListener(ConfigurationParamListenerType type, ConfigurationParamListener *listener, bool autoclean=true)
Add the listener.
RTC::ConfigurationSetNameListenerHolder::removeListener
void removeListener(ConfigurationSetNameListener *listener)
Remove the listener.
RTC::ConfigurationSetNameListener
ConfigurationSetNameListener class.
Definition: ConfigurationListener.h:303
RTC::ConfigurationSetListenerType::CONFIG_SET_LISTENER_NUM
@ CONFIG_SET_LISTENER_NUM
RTC::ConfigurationSetListenerType::ON_SET_CONFIG_SET
@ ON_SET_CONFIG_SET
RTC::ConfigurationSetNameListener::~ConfigurationSetNameListener
virtual ~ConfigurationSetNameListener()
Destructor.
RTC::ConfigurationSetListenerHolder::addListener
void addListener(ConfigurationSetListener *listener, bool autoclean)
Add the listener.
RTC::ConfigurationSetListenerHolder::notify
void notify(const coil::Properties &config_set)
Notify listeners.
RTC::ConfigurationSetNameListenerHolder::ConfigurationSetNameListenerHolder
ConfigurationSetNameListenerHolder()
Constructor.
RTC::ConfigurationParamListenerType
ConfigurationParamListenerType
The types of ConnectorDataListener.
Definition: ConfigurationListener.h:45
RTC::ConfigurationSetListenerHolder::ConfigurationSetListenerHolder
ConfigurationSetListenerHolder()
Constructor.
RTC::ConfigurationParamListener
ConfigurationParamListener class.
Definition: ConfigurationListener.h:74
RTC::ConfigurationSetNameListenerType
ConfigurationSetNameListenerType
The types of ConfigurationSetNameListener.
Definition: ConfigurationListener.h:271
RTC::ConfigurationSetListenerHolder
ConfigurationSetListener holder class.
Definition: ConfigurationListener.h:497
RTC::ConfigurationSetListenerHolder::removeListener
void removeListener(ConfigurationSetListener *listener)
Remove the listener.
RTC::ConfigurationListeners::notify
bool notify(ConfigurationSetListenerType type, const coil::Properties &config_set)
Definition: ConfigurationListener.h:913
RTC::ConfigurationSetNameListenerType::ON_UPDATE_CONFIG_SET
@ ON_UPDATE_CONFIG_SET
RTC::ConfigurationSetNameListener::toString
static const char * toString(ConfigurationSetNameListenerType type)
Convert ConfigurationSetNameListenerType into the string.
Definition: ConfigurationListener.h:330
RTC::ConfigurationListeners
Definition: ConfigurationListener.h:706
RTC::ConfigurationSetNameListener::operator()
virtual void operator()(const char *config_set_name)=0
Virtual Callback function.
RTC::ConfigurationParamListener::operator()
virtual void operator()(const char *config_set_name, const char *config_param_name)=0
Virtual Callback function.
RTC::ConfigurationParamListenerHolder
ConfigurationParamListener holder class.
Definition: ConfigurationListener.h:390
RTC::ConfigurationParamListenerType::CONFIG_PARAM_LISTENER_NUM
@ CONFIG_PARAM_LISTENER_NUM
RTC::ConfigurationListeners::notify
bool notify(ConfigurationSetNameListenerType type, const char *config_set_name)
Definition: ConfigurationListener.h:942
RTC::ConfigurationSetListener::~ConfigurationSetListener
virtual ~ConfigurationSetListener()
Destructor.
RTC::ConfigurationParamListener::~ConfigurationParamListener
virtual ~ConfigurationParamListener()
Destructor.
RTC::ConfigurationSetListener::operator()
virtual void operator()(const coil::Properties &config_set)=0
Virtual Callback function.
RTC::ConfigurationSetNameListenerHolder::notify
void notify(const char *config_set_name)
Notify listeners.
RTC::ConfigurationSetNameListenerHolder::addListener
void addListener(ConfigurationSetNameListener *listener, bool autoclean)
Add the listener.
RTC
RT-Component.
RTC::Properties
coil::Properties Properties
Definition: RTC.h:72
RTC::ConfigurationSetNameListenerHolder::~ConfigurationSetNameListenerHolder
virtual ~ConfigurationSetNameListenerHolder()
Destructor.
RTC::ConfigurationSetNameListenerType::CONFIG_SET_NAME_LISTENER_NUM
@ CONFIG_SET_NAME_LISTENER_NUM
RTC::ConfigurationSetListenerType::ON_ADD_CONFIG_SET
@ ON_ADD_CONFIG_SET
RTC::ConfigurationSetNameListenerType::ON_ACTIVATE_CONFIG_SET
@ ON_ACTIVATE_CONFIG_SET
RTC::ConfigurationSetListener
ConfigurationSetListener class.
Definition: ConfigurationListener.h:190
RTC::ConfigurationListeners::~ConfigurationListeners
~ConfigurationListeners()
Destructor.
RTC::ConfigurationParamListenerHolder::removeListener
void removeListener(ConfigurationParamListener *listener)
Remove the listener.
RTC::ConfigurationSetListenerHolder::~ConfigurationSetListenerHolder
virtual ~ConfigurationSetListenerHolder()
Destructor.
RTC::ConfigurationSetListener::toString
static const char * toString(ConfigurationSetListenerType type)
Convert ConfigurationSetNameListenerType into the string.
Definition: ConfigurationListener.h:217