ConfigAdmin.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
19 #include <rtm/ConfigAdmin.h>
20 #include <algorithm>
21 #include <assert.h>
22 #include <string.h>
23 
24 namespace RTC
25 {
33  : m_configsets(configsets), m_activeId("default"),
34  m_active(true), m_changed(false)
35  {
36  }
37 
46  {
47  for (int i(0), len(m_params.size()); i < len; ++i)
48  {
49  if (m_params[i] != NULL) { delete m_params[i]; }
50  }
51  m_params.clear();
52  }
53 
54 
65  {
66  if (m_changed && m_active)
67  {
68  update(m_activeId.c_str());
69  m_changed = false;
70  }
71  return;
72  }
73 
74 
82  void ConfigAdmin::update(const char* config_set)
83  {
84  if (m_configsets.hasKey(config_set) == NULL) { return; }
85 
87 
88  for (int i(0), len(m_params.size()); i < len; ++i)
89  {
90  if (prop.hasKey(m_params[i]->name) != NULL)
91  {
92  m_params[i]->update(prop[m_params[i]->name].c_str());
93  onUpdate(config_set);
94  }
95  }
96  }
97 
98 
106  void ConfigAdmin::update(const char* config_set, const char* config_param)
107  {
108  if ((config_set == 0) || (config_param == 0)) { return; }
109 
110  std::string key(config_set);
111  key += "."; key += config_param;
112 
113  std::vector<ConfigBase*>::iterator it;
114  it = std::find_if(m_params.begin(), m_params.end(),
115  find_conf(config_param));
116  if (it != m_params.end())
117  {
118  (*it)->update(m_configsets[key].c_str());
119  onUpdateParam(config_set, config_param);
120  return;
121  }
122  }
123 
124 
132  bool ConfigAdmin::isExist(const char* param_name)
133  {
134  std::vector<ConfigBase*>::iterator it;
135  it = std::find_if(m_params.begin(), m_params.end(),
136  find_conf(param_name));
137  if (it != m_params.end())
138  {
139  return true;
140  }
141  return false;
142  }
143 
144 
152  const std::vector<coil::Properties*>& ConfigAdmin::getConfigurationSets(void)
153  {
154  return m_configsets.getLeaf();
155  }
156 
164  const coil::Properties&
165  ConfigAdmin::getConfigurationSet(const char* config_id)
166  {
167  coil::Properties* p(m_configsets.findNode(config_id));
168  if (p == 0) { return m_emptyconf; }
169  return *p;
170  }
171 
179  bool
181  {
182  std::string node(config_set.getName());
183  if (node.empty()) { return false; }
184 
185  coil::Properties& p(m_configsets.getNode(config_set.getName()));
186 
187  p << config_set;
188  m_changed = true;
189  m_active = false;
190  onSetConfigurationSet(config_set);
191  return true;
192  }
193 
202  {
204 
205  return p;
206  }
207 
216  {
217  std::string node(config_set.getName());
218  if (node.empty()) { return false; }
219  if (m_configsets.hasKey(node.c_str()) != 0) { return false; }
220 
222  p << config_set;
223  m_newConfig.push_back(node);
224 
225  m_changed = true;
226  m_active = false;
227  onAddConfigurationSet(config_set);
228  return true;
229  }
230 
238  bool ConfigAdmin::removeConfigurationSet(const char* config_id)
239  {
240  if (strcmp(config_id, "default") == 0) return false;
241  if (m_activeId == config_id) return false;
242 
243  // removeable config-set is only config-sets newly added
244  std::vector<std::string>::iterator it;
245  it = std::find(m_newConfig.begin(), m_newConfig.end(), config_id);
246  if (it == m_newConfig.end()) { return false; }
247 
249  if (p != NULL) { delete p; }
250  m_newConfig.erase(it);
251 
252  m_changed = true;
253  m_active = false;
254  onRemoveConfigurationSet(config_id);
255  return true;
256  }
257 
265  bool ConfigAdmin::activateConfigurationSet(const char* config_id)
266  {
267  if (config_id == NULL) { return false; }
268  // '_<conf_name>' is special configuration set name
269  if (config_id[0] == '_') { return false; }
270 
271  if (m_configsets.hasKey(config_id) == 0) { return false; }
272  m_activeId = config_id;
273  m_active = true;
274  m_changed = true;
275  onActivateSet(config_id);
276  return true;
277  }
278 
279  //------------------------------------------------------------
280  // obsolete functions
281  //
283  {
284  std::cerr << "setOnUpdate function is obsolete." << std::endl;
285  std::cerr << "Use addConfigurationSetNameListener instead." << std::endl;
287  }
288 
290  {
291  std::cerr << "setOnUpdateParam function is obsolete." << std::endl;
292  std::cerr << "Use addConfigurationParamListener instead." << std::endl;
294  }
295 
297  {
298  std::cerr << "setOnSetConfigurationSet function is obsolete." << std::endl;
299  std::cerr << "Use addConfigurationSetListener instead." << std::endl;
301  }
302 
304  {
305  std::cerr << "setOnAddConfigurationSet function is obsolete." << std::endl;
306  std::cerr << "Use addConfigurationSetListener instead." << std::endl;
308  }
309 
310  void
312  {
313  std::cerr << "setOnRemoveConfigurationSet function is obsolete."<<std::endl;
314  std::cerr << "Use addConfigurationSetNameListener instead." << std::endl;
316  }
317 
319  {
320  std::cerr << "setOnActivateSet function is obsolete." << std::endl;
321  std::cerr << "Use addConfigurationSetNameListener instead." << std::endl;
323  }
324  //
325  // end of obsolete functions
326  //------------------------------------------------------------
327 
335  void ConfigAdmin::
337  ConfigurationParamListener* listener,
338  bool autoclean)
339  {
340  m_listeners.configparam_[type].addListener(listener, autoclean);
341  }
342 
350  void ConfigAdmin::
352  ConfigurationParamListener* listener)
353  {
354  m_listeners.configparam_[type].removeListener(listener);
355  }
356 
364  void ConfigAdmin::
366  ConfigurationSetListener* listener,
367  bool autoclean)
368  {
369  m_listeners.configset_[type].addListener(listener, autoclean);
370  }
371 
379  void ConfigAdmin::
381  ConfigurationSetListener* listener)
382  {
383  m_listeners.configset_[type].removeListener(listener);
384  }
385 
393  void ConfigAdmin::
396  bool autoclean)
397  {
398  m_listeners.configsetname_[type].addListener(listener, autoclean);
399  }
400 
408  void ConfigAdmin::
411  {
412  m_listeners.configsetname_[type].removeListener(listener);
413  }
414 
415  //------------------------------------------------------------
416  // protected functions
424  void ConfigAdmin::onUpdate(const char* config_set)
425  {
427  }
428 
436  void
437  ConfigAdmin::onUpdateParam(const char* config_set, const char* config_param)
438  {
440  config_param);
441  }
442 
451  {
453  }
454 
463  {
465  }
466 
474  void ConfigAdmin::onRemoveConfigurationSet(const char* config_id)
475  {
477  }
478 
486  void ConfigAdmin::onActivateSet(const char* config_id)
487  {
489  }
490 
491 
492 }; // namespace RTC
void removeConfigurationSetNameListener(ConfigurationSetNameListenerType type, ConfigurationSetNameListener *listener)
Removing ConfigurationSetNameListener.
void onUpdateParam(const char *config_set, const char *config_param)
When the configuration parameter is updated, it is called.
RT-Component.
void onRemoveConfigurationSet(const char *config_id)
Called when the configuration set has been deleted.
void addConfigurationSetNameListener(ConfigurationSetNameListenerType type, ConfigurationSetNameListener *listener, bool autoclean=true)
Adding ConfigurationSetNameListener.
bool activateConfigurationSet(const char *config_id)
Activate the configuration set.
ConfigAdmin(coil::Properties &prop)
Constructor.
Definition: ConfigAdmin.cpp:32
const std::vector< coil::Properties * > & getConfigurationSets(void)
Get all configuration sets.
void notify(const char *config_set_name, const char *config_param_name)
Notify listeners.
ConfigurationSetNameListenerHolder configsetname_[CONFIG_SET_NAME_LISTENER_NUM]
ConfigurationSetNameListenerType listener array The ConfigurationSetNameListenerType listener is stor...
ConfigurationSetListenerHolder configset_[CONFIG_SET_LISTENER_NUM]
ConfigurationSetType listener array The ConfigurationSetType listener is stored.
ConfigurationParamListenerHolder configparam_[CONFIG_PARAM_LISTENER_NUM]
ConfigurationParamType listener array The ConfigurationParamType listener is stored.
void setOnRemoveConfigurationSet(OnRemoveConfigurationSetCallback *cb)
ConfigurationSetListener class.
ConfigurationSetNameListener class.
ConfigurationParamListener class.
Configuration Administration classes.
ConfigurationSetNameListenerType
The types of ConfigurationSetNameListener.
const coil::Properties & getActiveConfigurationSet(void)
Get the active configuration set.
void onActivateSet(const char *config_id)
Called when the configuration set is made active.
void addConfigurationSetListener(ConfigurationSetListenerType type, ConfigurationSetListener *listener, bool autoclean=true)
Adding ConfigurationSetListener.
void setOnActivateSet(OnActivateSetCallback *cb)
void addListener(ConfigurationParamListener *listener, bool autoclean)
Add the listener.
void removeConfigurationSetListener(ConfigurationSetListenerType type, ConfigurationSetListener *listener)
Removing ConfigurationSetListener.
std::vector< std::string > m_newConfig
Definition: ConfigAdmin.h:1431
const coil::Properties & getConfigurationSet(const char *config_id)
Get a configuration set by specified ID.
bool isExist(const char *name)
Check the existence of configuration parameters.
void removeListener(ConfigurationSetNameListener *listener)
Remove the listener.
const char * getName(void) const
Get Names.
Definition: Properties.h:283
Properties * hasKey(const char *key) const
Check whether key exists in the children.
Definition: Properties.cpp:522
const std::vector< Properties * > & getLeaf(void) const
Get elements of leaf.
Definition: Properties.h:340
coil::Properties & m_configsets
Definition: ConfigAdmin.h:1425
void addListener(ConfigurationSetListener *listener, bool autoclean)
Add the listener.
coil::Properties m_emptyconf
Definition: ConfigAdmin.h:1426
void update(void)
Update the values of configuration parameters (Active configuration set)
Definition: ConfigAdmin.cpp:64
void setOnUpdate(OnUpdateCallback *cb)
void setOnSetConfigurationSet(OnSetConfigurationSetCallback *cb)
bool addConfigurationSet(const coil::Properties &configuration_set)
Add the configuration value to configuration set.
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
Properties *const findNode(const std::string &key) const
Get node of properties.
Definition: Properties.cpp:444
void addConfigurationParamListener(ConfigurationParamListenerType type, ConfigurationParamListener *listener, bool autoclean=true)
Adding ConfigurationParamListener.
Properties * removeNode(const char *leaf_name)
Remove node of Properties.
Definition: Properties.cpp:498
void removeListener(ConfigurationParamListener *listener)
Remove the listener.
std::string m_activeId
Definition: ConfigAdmin.h:1428
~ConfigAdmin(void)
Virtual Destructor.
Definition: ConfigAdmin.cpp:45
void removeListener(ConfigurationSetListener *listener)
Remove the listener.
prop
Organization::get_organization_property ();.
void onUpdate(const char *config_set)
When the configuration parameter is updated, it is called.
void notify(const coil::Properties &config_set)
Notify listeners.
Class represents a set of properties.
Definition: Properties.h:101
void notify(const char *config_set_name)
Notify listeners.
void onSetConfigurationSet(const coil::Properties &config_set)
Called when the property is added to the configuration set.
void addListener(ConfigurationSetNameListener *listener, bool autoclean)
Add the listener.
Properties & getNode(const std::string &key)
Get node of properties.
Definition: Properties.cpp:460
void onAddConfigurationSet(const coil::Properties &config_set)
Called when a set value is added to the configuration set.
void setOnAddConfigurationSet(OnAddConfigurationAddCallback *cb)
std::vector< ConfigBase * > m_params
Definition: ConfigAdmin.h:1427
ConfigurationSetListenerType
The types of ConfigurationSetListener.
ConfigurationListeners m_listeners
Definition: ConfigAdmin.h:1432
void removeConfigurationParamListener(ConfigurationParamListenerType type, ConfigurationParamListener *listener)
Removing ConfigurationParamListener.
bool setConfigurationSetValues(const coil::Properties &configuration_set)
Add to configuration set from specified property.
void setOnUpdateParam(OnUpdateParamCallback *cb)
bool removeConfigurationSet(const char *config_id)
Remove the configuration set.
ConfigurationParamListenerType
The types of ConnectorDataListener.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:42