00001
00019 #ifndef RTC_CONFIGURATIONLISTENER_H
00020 #define RTC_CONFIGURATIONLISTENER_H
00021
00022 #include <vector>
00023 #include <coil/Properties.h>
00024 #include <coil/Mutex.h>
00025 #include <coil/Guard.h>
00026
00027 namespace RTC
00028 {
00029
00043 enum ConfigurationParamListenerType
00044 {
00045 ON_UPDATE_CONFIG_PARAM,
00046 CONFIG_PARAM_LISTENER_NUM
00047 };
00048
00049
00072 class ConfigurationParamListener
00073 {
00074 public:
00098 static const char* toString(ConfigurationParamListenerType type)
00099 {
00100 static const char* typeString[] =
00101 {
00102 "ON_UPDATE_CONFIG_PARAM",
00103 "CONFIG_PARAM_LISTENER_NUM"
00104 };
00105 if (type < CONFIG_PARAM_LISTENER_NUM)
00106 {
00107 return typeString[type];
00108 }
00109 return "";
00110 }
00111
00119 virtual ~ConfigurationParamListener();
00120
00136 virtual void operator()(const char* config_set_name,
00137 const char* config_param_name) = 0;
00138 };
00139
00140
00141
00158 enum ConfigurationSetListenerType
00159 {
00160 ON_SET_CONFIG_SET,
00161 ON_ADD_CONFIG_SET,
00162 CONFIG_SET_LISTENER_NUM
00163 };
00164
00188 class ConfigurationSetListener
00189 {
00190 public:
00215 static const char* toString(ConfigurationSetListenerType type)
00216 {
00217 static const char* typeString[] =
00218 {
00219 "ON_SET_CONFIG_SET",
00220 "ON_ADD_CONFIG_SET",
00221 "CONFIG_SET_LISTENER_NUM"
00222 };
00223 if (type < CONFIG_SET_LISTENER_NUM) { return typeString[type]; }
00224 return "";
00225 }
00226
00234 virtual ~ConfigurationSetListener();
00235
00251 virtual void operator()(const coil::Properties& config_set) = 0;
00252 };
00253
00254
00255
00266 enum ConfigurationSetNameListenerType
00267 {
00268 ON_UPDATE_CONFIG_SET,
00269 ON_REMOVE_CONFIG_SET,
00270 ON_ACTIVATE_CONFIG_SET,
00271 CONFIG_SET_NAME_LISTENER_NUM
00272 };
00273
00298 class ConfigurationSetNameListener
00299 {
00300 public:
00325 static const char* toString(ConfigurationSetNameListenerType type)
00326 {
00327 static const char* typeString[] =
00328 {
00329 "ON_UPDATE_CONFIG_SET",
00330 "ON_REMOVE_CONFIG_SET",
00331 "ON_ACTIVATE_CONFIG_SET",
00332 "CONFIG_SET_NAME_LISTENER_NUM"
00333 };
00334 if (type < CONFIG_SET_NAME_LISTENER_NUM) { return typeString[type]; }
00335 return "";
00336 }
00337
00345 virtual ~ConfigurationSetNameListener();
00346
00362 virtual void operator()(const char* config_set_name) = 0;
00363 };
00364
00365
00382 class ConfigurationParamListenerHolder
00383 {
00384 typedef std::pair<ConfigurationParamListener*, bool> Entry;
00385 typedef coil::Guard<coil::Mutex> Guard;
00386 public:
00394 ConfigurationParamListenerHolder();
00402 virtual ~ConfigurationParamListenerHolder();
00403
00425 void addListener(ConfigurationParamListener* listener, bool autoclean);
00426
00444 void removeListener(ConfigurationParamListener* listener);
00445
00465 void notify(const char* config_set_name, const char* config_param_name);
00466
00467 private:
00468 std::vector<Entry> m_listeners;
00469 coil::Mutex m_mutex;
00470 };
00471
00472
00473
00490 class ConfigurationSetListenerHolder
00491 {
00492 typedef std::pair<ConfigurationSetListener*, bool> Entry;
00493 typedef coil::Guard<coil::Mutex> Guard;
00494 public:
00502 ConfigurationSetListenerHolder();
00510 virtual ~ConfigurationSetListenerHolder();
00511
00533 void addListener(ConfigurationSetListener* listener, bool autoclean);
00534
00552 void removeListener(ConfigurationSetListener* listener);
00553
00573 void notify(const coil::Properties& config_set);
00574
00575 private:
00576 std::vector<Entry> m_listeners;
00577 coil::Mutex m_mutex;
00578 };
00579
00580
00581
00598 class ConfigurationSetNameListenerHolder
00599 {
00600 typedef std::pair<ConfigurationSetNameListener*, bool> Entry;
00601 typedef coil::Guard<coil::Mutex> Guard;
00602 public:
00610 ConfigurationSetNameListenerHolder();
00611
00619 virtual ~ConfigurationSetNameListenerHolder();
00620
00642 void addListener(ConfigurationSetNameListener* listener, bool autoclean);
00643
00661 void removeListener(ConfigurationSetNameListener* listener);
00662
00680 void notify(const char* config_set_name);
00681
00682 private:
00683 std::vector<Entry> m_listeners;
00684 coil::Mutex m_mutex;
00685 };
00686
00687
00701 class ConfigurationListeners
00702 {
00703 public:
00713 ConfigurationParamListenerHolder
00714 configparam_[CONFIG_PARAM_LISTENER_NUM];
00724 ConfigurationSetListenerHolder
00725 configset_[CONFIG_SET_LISTENER_NUM];
00735 ConfigurationSetNameListenerHolder
00736 configsetname_[CONFIG_SET_NAME_LISTENER_NUM];
00737 };
00738
00739
00740 };
00741
00742 #endif // RTC_CONFIGURATIONLISTENER_H