ConfigAdmin.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef RTC_CONFIGADMIN_H
20 #define RTC_CONFIGADMIN_H
21 
22 #include <string>
23 #include <vector>
24 #include <iostream>
25 #include <coil/Properties.h>
26 #include <coil/stringutil.h>
28 
43 namespace RTC
44 {
57 
70 
83 
96 
109 
122 
123 
124  //============================================================
125  // ConfigBase class
126  //============================================================
157  struct ConfigBase
158  {
180  ConfigBase(const char* name_, const char* def_val)
181  : name(name_), default_value(def_val) {}
182 
198  virtual ~ConfigBase(void){};
199 
225  virtual bool update(const char* val) = 0;
226 
234  const char* name;
235 
243  const char* default_value;
244  };
245 
246  //============================================================
247  // Config template class
248  //============================================================
281  template <typename VarType,
282  typename TransFunc = bool (*)(VarType&, const char*)>
283  class Config
284  : public ConfigBase
285  {
286  public:
312  Config(const char* name, VarType& var, const char* def_val,
313  TransFunc trans = coil::stringTo)
314  : ConfigBase(name, def_val), m_var(var), m_trans(trans)
315  {
316  }
317 
333  virtual ~Config(void){}
334 
358  virtual bool update(const char* val)
359  {
360  if ((*m_trans)(m_var, val)) { return true; }
361  (*m_trans)(m_var, default_value);
362  return false;
363  }
364 
365  protected:
373  VarType& m_var;
374 
383  TransFunc m_trans;
384  };
385 
386  //============================================================
387  // ConfigAdmin class
388  //============================================================
535  {
536  public:
557 
573  ~ConfigAdmin(void);
574 
611  template <typename VarType>
612  bool bindParameter(const char* param_name, VarType& var,
613  const char* def_val,
614  bool (*trans)(VarType&, const char*) = coil::stringTo)
615  {
616  if (param_name == 0) { return false; }
617  if (def_val == 0) { return false; }
618  if (isExist(param_name)) { return false; }
619  if (!trans(var, def_val)) { return false; }
620  m_params.push_back(new Config<VarType>(param_name, var, def_val, trans));
621  return true;
622  }
623 
650  void update(void);
651 
686  void update(const char* config_set);
687 
725  void update(const char* config_set, const char* config_param);
726 
753  bool isExist(const char* name);
754 
775  bool isChanged(void) {return m_changed;}
776 
796  const char* getActiveId(void) {return m_activeId.c_str();}
797 
822  bool haveConfig(const char* config_id)
823  {
824  return (m_configsets.hasKey(config_id) == NULL) ? false : true;
825  }
826 
847  bool isActive(void)
848  {
849  return m_active;
850  }
851  // const std::vector<Properties*>* getConfigurationParameterValues();
852  // const Properties* getConfigurationParameterValue(const char* name);
853  // bool setConfigurationParameter(const char* name, const char* value);
854 
874  const std::vector<coil::Properties*>& getConfigurationSets(void);
875 
903  const coil::Properties& getConfigurationSet(const char* config_id);
904 
934  bool setConfigurationSetValues(const coil::Properties& configuration_set);
935 
959  const coil::Properties& getActiveConfigurationSet(void);
960 
984  bool addConfigurationSet(const coil::Properties& configuration_set);
985 
1040  bool removeConfigurationSet(const char* config_id);
1041 
1069  bool activateConfigurationSet(const char* config_id);
1070 
1071  //------------------------------------------------------------
1072  // obsolete functions
1073  //
1074  void setOnUpdate(OnUpdateCallback* cb);
1075 
1076  void setOnUpdateParam(OnUpdateParamCallback* cb);
1077 
1078  void setOnSetConfigurationSet(OnSetConfigurationSetCallback* cb);
1079 
1080  void setOnAddConfigurationSet(OnAddConfigurationAddCallback* cb);
1081 
1082  void setOnRemoveConfigurationSet(OnRemoveConfigurationSetCallback* cb);
1083 
1084  void setOnActivateSet(OnActivateSetCallback* cb);
1085  //
1086  // end of obsolete functions
1087  //------------------------------------------------------------
1088 
1121  void addConfigurationParamListener(ConfigurationParamListenerType type,
1122  ConfigurationParamListener* listener,
1123  bool autoclean = true);
1124 
1149  void removeConfigurationParamListener(ConfigurationParamListenerType type,
1150  ConfigurationParamListener* listener);
1151 
1183  void addConfigurationSetListener(ConfigurationSetListenerType type,
1184  ConfigurationSetListener* listener,
1185  bool autoclean = true);
1186 
1209  void removeConfigurationSetListener(ConfigurationSetListenerType type,
1210  ConfigurationSetListener* listener);
1211 
1246  void
1247  addConfigurationSetNameListener(ConfigurationSetNameListenerType type,
1248  ConfigurationSetNameListener* listener,
1249  bool autoclean = true);
1250 
1277  void
1278  removeConfigurationSetNameListener(ConfigurationSetNameListenerType type,
1279  ConfigurationSetNameListener* listener);
1280 
1281  protected:
1301  void onUpdate(const char* config_set);
1302 
1324  void onUpdateParam(const char* config_set, const char* config_param);
1325 
1345  void onSetConfigurationSet(const coil::Properties& config_set);
1346 
1366  void onAddConfigurationSet(const coil::Properties& config_set);
1367 
1387  void onRemoveConfigurationSet(const char* config_id);
1388 
1408  void onActivateSet(const char* config_id);
1409 
1410  private:
1411  ConfigAdmin(const ConfigAdmin& ca);
1412  ConfigAdmin& operator=(const ConfigAdmin& ca);
1413 
1414  struct find_conf
1415  {
1416  std::string m_name;
1417  find_conf(const char* name) : m_name(name) {};
1419  {
1420  if (conf == 0) { return false; }
1421  return (m_name == conf->name);
1422  }
1423  };
1424 
1427  std::vector<ConfigBase*> m_params;
1428  std::string m_activeId;
1429  bool m_active;
1431  std::vector<std::string> m_newConfig;
1433 
1434  };
1435 }; // namespace RTC
1436 #endif // RTC_CONFIGADMIN_H
ConfigBase abstract class.
Definition: ConfigAdmin.h:157
ConfigurationSetNameListener OnActivateSetCallback
Definition: ConfigAdmin.h:121
ConfigurationParamListener OnUpdateParamCallback
Definition: ConfigAdmin.h:69
RT-Component.
bool stringTo(To &val, const char *str)
Convert the given std::string to object.
Definition: stringutil.h:597
ConfigBase(const char *name_, const char *def_val)
Constructer.
Definition: ConfigAdmin.h:180
ConfigurationSetNameListener OnRemoveConfigurationSetCallback
Definition: ConfigAdmin.h:108
bool isActive(void)
Confirm to activate configuration set.
Definition: ConfigAdmin.h:847
ConfigurationSetListener class.
ConfigurationSetNameListener class.
ConfigurationParamListener class.
ConfigurationSetNameListenerType
The types of ConfigurationSetNameListener.
std::vector< std::string > m_newConfig
Definition: ConfigAdmin.h:1431
VarType & m_var
Configuration parameter variable.
Definition: ConfigAdmin.h:373
coil::Properties & m_configsets
Definition: ConfigAdmin.h:1425
coil::Properties m_emptyconf
Definition: ConfigAdmin.h:1426
ConfigurationSetListener OnAddConfigurationAddCallback
Definition: ConfigAdmin.h:95
find_conf(const char *name)
Definition: ConfigAdmin.h:1417
bool isChanged(void)
Confirm to change configuration parameters.
Definition: ConfigAdmin.h:775
virtual bool update(const char *val)=0
Pure virtual function to update configuration parameter values.
TransFunc m_trans
Transformation function to convert configuration parameter type into string format.
Definition: ConfigAdmin.h:383
const char * name
Configuration name.
Definition: ConfigAdmin.h:234
std::string m_activeId
Definition: ConfigAdmin.h:1428
prop
Organization::get_organization_property ();.
virtual ~ConfigBase(void)
Virtual Destructor.
Definition: ConfigAdmin.h:198
Class represents a set of properties.
Definition: Properties.h:101
bool operator()(ConfigBase *conf)
Definition: ConfigAdmin.h:1418
virtual bool update(const char *val)
Update a bind parameter value.
Definition: ConfigAdmin.h:358
const char * getActiveId(void)
Get ID of active configuration set.
Definition: ConfigAdmin.h:796
ConfigurationSetNameListener OnUpdateCallback
Definition: ConfigAdmin.h:56
std::vector< ConfigBase * > m_params
Definition: ConfigAdmin.h:1427
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
Setup for configuration parameters.
Definition: ConfigAdmin.h:612
virtual ~Config(void)
Virtual Destructor.
Definition: ConfigAdmin.h:333
Config class.
Definition: ConfigAdmin.h:283
ConfigurationSetListenerType
The types of ConfigurationSetListener.
Config(const char *name, VarType &var, const char *def_val, TransFunc trans=coil::stringTo)
Constructor.
Definition: ConfigAdmin.h:312
ConfigurationListeners m_listeners
Definition: ConfigAdmin.h:1432
bool haveConfig(const char *config_id)
Check the existence of configuration set.
Definition: ConfigAdmin.h:822
const char * default_value
Default value in string format.
Definition: ConfigAdmin.h:243
ConfigurationParamListenerType
The types of ConnectorDataListener.
ConfigurationSetListener OnSetConfigurationSetCallback
Definition: ConfigAdmin.h:82
Configuration related event listener classes.


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