ConfigAdmin.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
16 
17 
18 
19 import copy
20 import OpenRTM_aist
21 
22 
24  def __init__(self):
25  pass
26 
27 
28  def __call__(self, config_set):
29  pass
30 
31 
32 
34  def __init__(self):
35  pass
36 
37 
38  def __call__(self, config_set, config_param):
39  pass
40 
41 
42 
44  def __init__(self):
45  pass
46 
47 
48  def __call__(self, config_set):
49  pass
50 
51 
52 
54  def __init__(self):
55  pass
56 
57 
58  def __call__(self, config_set):
59  pass
60 
61 
62 
64  def __init__(self):
65  pass
66 
67 
68  def __call__(self, config_set):
69  pass
70 
71 
72 
74  def __init__(self):
75  pass
76 
77 
78  def __call__(self, config_id):
79  pass
80 
81 
82 
83 
101 class Config:
102  """
103  """
104 
105 
131  def __init__(self, name, var, def_val, trans=None):
132  self.name = name
133  self.default_value = def_val
134  self._var = var
135  if trans:
136  self._trans = trans
137  else:
138  self._trans = OpenRTM_aist.stringTo
139 
140 
141 
166  def update(self, val):
167  if self._trans(self._var, val):
168  return True
169  self._trans(self._var, self._default_value)
170  return False
171 
172 
173 
174 
319  """
320  """
321 
322 
341  def __init__(self, configsets):
342  self._configsets = configsets
343  self._activeId = "default"
344  self._active = True
345  self._changed = False
346  self._params = []
348  self._newConfig = []
350 
351 
368  def __del__(self):
369  del self._params
370 
371 
372 
413  def bindParameter(self, param_name, var, def_val, trans=None):
414  if trans is None:
415  trans = OpenRTM_aist.stringTo
416 
417  if self.isExist(param_name):
418  return False
419 
420  if not trans(var, def_val):
421  return False
422 
423  self._params.append(Config(param_name, var, def_val, trans))
424  return True
425 
426 
427 
528  def update(self, config_set=None, config_param=None):
529  # update(const char* config_set)
530  if config_set and config_param is None:
531  if self._configsets.hasKey(config_set) is None:
532  return
533  prop = self._configsets.getNode(config_set)
534  for i in range(len(self._params)):
535  if prop.hasKey(self._params[i].name):
536  self._params[i].update(prop.getProperty(self._params[i].name))
537  self.onUpdate(config_set)
538 
539  # update(const char* config_set, const char* config_param)
540  if config_set and config_param:
541  key = config_set
542  key = key+"."+config_param
543  for conf in self._params:
544  if conf.name == config_param:
545  conf.update(self._configsets.getProperty(key))
546  self.onUpdateParam(config_set, config_param)
547  return
548 
549  # update()
550  if config_set is None and config_param is None:
551  if self._changed and self._active:
552  self.update(self._activeId)
553  self._changed = False
554  return
555 
556 
557 
583  def isExist(self, param_name):
584  if not self._params:
585  return False
586 
587  for conf in self._params:
588  if conf.name == param_name:
589  return True
590 
591  return False
592 
593 
594 
618  def isChanged(self):
619  return self._changed
620 
621 
622 
645  def getActiveId(self):
646  return self._activeId
647 
648 
649 
673  def haveConfig(self, config_id):
674  if self._configsets.hasKey(config_id) is None:
675  return False
676  else:
677  return True
678 
679 
680 
704  def isActive(self):
705  return self._active
706 
707 
708 
732  return self._configsets.getLeaf()
733 
734 
735 
764  def getConfigurationSet(self, config_id):
765  prop = self._configsets.getNode(config_id)
766  if prop is None:
767  return self._emptyconf
768  return prop
769 
770 
771 
796  def setConfigurationSetValues(self, config_set):
797  if config_set.getName() == "" or config_set.getName() is None:
798  return False
799 
800  if not self._configsets.hasKey(config_set.getName()):
801  return False
802 
803  p = self._configsets.getNode(config_set.getName())
804  if p is None:
805  return False
806 
807  p.mergeProperties(config_set)
808  self._changed = True
809  self._active = False
810  self.onSetConfigurationSet(config_set)
811  return True
812 
813 
814 
841  p = self._configsets.getNode(self._activeId)
842  if p is None:
843  return self._emptyconf
844 
845  return p
846 
847 
848 
873  def addConfigurationSet(self, configset):
874  if self._configsets.hasKey(configset.getName()):
875  return False
876  node = configset.getName()
877 
878  # Create node
879  self._configsets.createNode(node)
880 
881  p = self._configsets.getNode(node)
882  if p is None:
883  return False
884 
885  p.mergeProperties(configset)
886  self._newConfig.append(node)
887 
888  self._changed = True
889  self._active = False
890  self.onAddConfigurationSet(configset)
891  return True
892 
893 
894 
951  def removeConfigurationSet(self, config_id):
952  if config_id == "default":
953  return False
954  if self._activeId == config_id:
955  return False
956 
957  find_flg = False
958  # removeable config-set is only config-sets newly added
959  for (idx,conf) in enumerate(self._newConfig):
960  if conf == config_id:
961  find_flg = True
962  break
963 
964 
965  if not find_flg:
966  return False
967 
968  p = self._configsets.getNode(config_id)
969  if p:
970  p.getRoot().removeNode(config_id)
971  del p
972 
973  del self._newConfig[idx]
974 
975  self._changed = True
976  self._active = False
977  self.onRemoveConfigurationSet(config_id)
978  return True
979 
980 
981 
1010  def activateConfigurationSet(self, config_id):
1011  if config_id is None:
1012  return False
1013 
1014  # '_<conf_name>' is special configuration set name
1015  if config_id[0] == '_':
1016  return False
1017 
1018  if not self._configsets.hasKey(config_id):
1019  return False
1020  self._activeId = config_id
1021  self._active = True
1022  self._changed = True
1023  self.onActivateSet(config_id)
1024  return True
1025 
1026 
1027  #------------------------------------------------------------
1028  # obsolete functions
1029  #
1030 
1031 
1051  def setOnUpdate(self, cb):
1052  print "setOnUpdate function is obsolete."
1053  print "Use addConfigurationSetNameListener instead."
1054  self._listeners.configsetname_[OpenRTM_aist.ConfigurationSetNameListenerType.ON_UPDATE_CONFIG_SET].addListener(cb, False)
1055  return
1056 
1057 
1058 
1078  def setOnUpdateParam(self, cb):
1079  print "setOnUpdateParam function is obsolete."
1080  print "Use addConfigurationParamListener instead."
1081  self._listeners.configparam_[OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM].addListener(cb, False)
1082  return
1083 
1084 
1085 
1106  print "setOnSetConfigurationSet function is obsolete."
1107  print "Use addConfigurationSetListener instead."
1108  self._listeners.configset_[OpenRTM_aist.ConfigurationSetListenerType.ON_SET_CONFIG_SET].addListener(cb, False)
1109  return
1110 
1111 
1112 
1133  print "setOnAddConfigurationSet function is obsolete."
1134  print "Use addConfigurationSetListener instead."
1135  self._listeners.configset_[OpenRTM_aist.ConfigurationSetListenerType.ON_ADD_CONFIG_SET].addListener(cb, False)
1136  return
1137 
1138 
1139 
1160  print "setOnRemoveConfigurationSet function is obsolete."
1161  print "Use addConfigurationSetNameListener instead."
1162  self._listeners.configsetname_[OpenRTM_aist.ConfigurationSetNameListenerType.ON_REMOVE_CONFIG_SET].addListener(cb, False)
1163  return
1164 
1165 
1166 
1186  def setOnActivateSet(self, cb):
1187  print "setOnActivateSet function is obsolete."
1188  print "Use addConfigurationSetNameListener instead."
1189  self._listeners.configsetname_[OpenRTM_aist.ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET].addListener(cb, False)
1190  return
1191 
1192  #
1193  # end of obsolete functions
1194  #------------------------------------------------------------
1195 
1196 
1231  def addConfigurationParamListener(self, type, listener, autoclean = True):
1232  self._listeners.configparam_[type].addListener(listener, autoclean)
1233  return
1234 
1235 
1236 
1262  def removeConfigurationParamListener(self, type, listener):
1263  self._listeners.configparam_[type].removeListener(listener)
1264  return
1265 
1266 
1267 
1301  def addConfigurationSetListener(self, type, listener, autoclean = True):
1302  self._listeners.configset_[type].addListener(listener, autoclean)
1303  return
1304 
1305 
1306 
1329  def removeConfigurationSetListener(self, type, listener):
1330  self._listeners.configset_[type].removeListener(listener)
1331  return
1332 
1333 
1334 
1371  def addConfigurationSetNameListener(self, type, listener, autoclean = True):
1372  self._listeners.configsetname_[type].addListener(listener, autoclean)
1373  return
1374 
1375 
1376 
1404  def removeConfigurationSetNameListener(self, type, listener):
1405  self._listeners.configsetname_[type].removeListener(listener)
1406  return
1407 
1408 
1409 
1431  def onUpdate(self, config_set):
1432  self._listeners.configsetname_[OpenRTM_aist.ConfigurationSetNameListenerType.ON_UPDATE_CONFIG_SET].notify(config_set)
1433  return
1434 
1435 
1436 
1460  def onUpdateParam(self, config_set, config_param):
1461  self._listeners.configparam_[OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM].notify(config_set,
1462  config_param)
1463  return
1464 
1465 
1466 
1488  def onSetConfigurationSet(self, config_set):
1489  self._listeners.configset_[OpenRTM_aist.ConfigurationSetListenerType.ON_SET_CONFIG_SET].notify(config_set)
1490  return
1491 
1492 
1493 
1515  def onAddConfigurationSet(self, config_set):
1516  self._listeners.configset_[OpenRTM_aist.ConfigurationSetListenerType.ON_ADD_CONFIG_SET].notify(config_set)
1517  return
1518 
1519 
1520 
1542  def onRemoveConfigurationSet(self, config_id):
1543  self._listeners.configsetname_[OpenRTM_aist.ConfigurationSetNameListenerType.ON_REMOVE_CONFIG_SET].notify(config_id)
1544  return
1545 
1546 
1547 
1569  def onActivateSet(self, config_id):
1570  self._listeners.configsetname_[OpenRTM_aist.ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET].notify(config_id)
1571  return
1572 
1573 
1574  class find_conf:
1575  def __init__(self, name):
1576  self._name = name
1577  return
1578 
1579  def __call__(self, conf):
1580  if conf is None or conf is 0:
1581  return False
1582 
1583  return self._name == conf.name
def removeConfigurationSet(self, config_id)
Remove the configuration set.
Definition: ConfigAdmin.py:951
def setOnActivateSet(self, cb)
Set callback that is called by OnActivateSet.
def isChanged(self)
Confirm to change configuration parameters.
Definition: ConfigAdmin.py:618
def __init__(self, name, var, def_val, trans=None)
Constructor.
Definition: ConfigAdmin.py:131
def onActivateSet(self, config_id)
Called when the configuration set is made active.
def setOnRemoveConfigurationSet(self, cb)
Set callback that is called by OnRemoveConfigurationSet.
def isExist(self, param_name)
Check the existence of configuration parameters.
Definition: ConfigAdmin.py:583
def onAddConfigurationSet(self, config_set)
Called when a set value is added to the configuration set.
def onUpdate(self, config_set)
When the configuration parameter is updated, it is called.
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
def update(self, config_set=None, config_param=None)
void update(void);
Definition: ConfigAdmin.py:528
def bindParameter(self, param_name, var, def_val, trans=None)
Setup for configuration parameters.
Definition: ConfigAdmin.py:413
def setOnAddConfigurationSet(self, cb)
Set callback that is called by OnSetConfiguration.
def setOnSetConfigurationSet(self, cb)
Set callback that is called by OnSetConfiguration.
def onRemoveConfigurationSet(self, config_id)
Called when the configuration set has been deleted.
def setOnUpdateParam(self, cb)
Set callback that is called by OnUpdateParam.
def getActiveConfigurationSet(self)
Get the active configuration set.
Definition: ConfigAdmin.py:840
def onUpdateParam(self, config_set, config_param)
When the configuration parameter is updated, it is called.
def activateConfigurationSet(self, config_id)
Activate the configuration set.
def addConfigurationSetNameListener(self, type, listener, autoclean=True)
Adding ConfigurationSetNameListener.
def update(self, val)
Update a bind parameter value.
Definition: ConfigAdmin.py:166
def getConfigurationSets(self)
Get all configuration sets.
Definition: ConfigAdmin.py:731
def isActive(self)
Confirm to activate configuration set.
Definition: ConfigAdmin.py:704
def haveConfig(self, config_id)
Check the existence of configuration set.
Definition: ConfigAdmin.py:673
def addConfigurationSetListener(self, type, listener, autoclean=True)
Adding ConfigurationSetListener.
def addConfigurationSet(self, configset)
Add the configuration value to configuration set.
Definition: ConfigAdmin.py:873
def setOnUpdate(self, cb)
Set callback that is called by OnUpdate.
def getConfigurationSet(self, config_id)
Get a configuration set by specified ID.
Definition: ConfigAdmin.py:764
def removeConfigurationSetNameListener(self, type, listener)
Removing ConfigurationSetNameListener.
def __init__(self, configsets)
Constructor.
Definition: ConfigAdmin.py:341
def __call__(self, config_set, config_param)
Definition: ConfigAdmin.py:38
def removeConfigurationParamListener(self, type, listener)
Removing ConfigurationParamListener.
def getActiveId(self)
Get ID of active configuration set.
Definition: ConfigAdmin.py:645
def setConfigurationSetValues(self, config_set)
Add to configuration set from specified property.
Definition: ConfigAdmin.py:796
def addConfigurationParamListener(self, type, listener, autoclean=True)
Adding ConfigurationParamListener.
def removeConfigurationSetListener(self, type, listener)
Removing ConfigurationSetListener.
def onSetConfigurationSet(self, config_set)
Called when the property is added to the configuration set.


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34