[openrtm-commit:01059] r560 - in branches/RELENG_1_1/OpenRTM-aist-Python: . OpenRTM_aist OpenRTM_aist/examples/ConfigSample OpenRTM_aist/test

openrtm @ openrtm.org openrtm @ openrtm.org
2013年 4月 27日 (土) 01:09:39 JST


Author: n-ando
Date: 2013-04-27 01:09:39 +0900 (Sat, 27 Apr 2013)
New Revision: 560

Modified:
   branches/RELENG_1_1/OpenRTM-aist-Python/
   branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ConfigAdmin.py
   branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ConfigurationListener.py
   branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
   branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/examples/ConfigSample/ConfigSample.py
   branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/test/test_ConfigAdmin.py
Log:
r498-r500, r502, r511, r543-r544 merged from trunk


Property changes on: branches/RELENG_1_1/OpenRTM-aist-Python
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/RELENG_1_0/OpenRTM-aist-Python:345-404
/branches/RELENG_1_1/OpenRTM-aist-Python:396-478
   + /branches/RELENG_1_0/OpenRTM-aist-Python:345-404
/branches/RELENG_1_1/OpenRTM-aist-Python:396-478
/trunk/OpenRTM-aist-Python:498-500,502,511,543-544

Modified: branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ConfigAdmin.py
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ConfigAdmin.py	2013-04-26 15:15:33 UTC (rev 559)
+++ branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ConfigAdmin.py	2013-04-26 16:09:39 UTC (rev 560)
@@ -131,16 +131,63 @@
   def __init__(self, name, var, def_val, trans=None):
     self.name = name
     self._default_value = def_val
+    self.string_value = ""
+    self.callback = None
     self._var = var
     if trans:
       self._trans = trans
     else:
       self._trans = OpenRTM_aist.stringTo
+    return
 
 
   ##
   # @if jp
+  #
+  # @brief コールバックのセット
   # 
+  # 変数変更時にコールされるコールバック関数をセットする.
+  #
+  # @else
+  #
+  # @brief Setting callback
+  #
+  # This member function sets callback function which is called
+  # when variable is changed.
+  #
+  # @endif
+  #
+  # void setCallback(CallbackFunc cbf);
+  def setCallback(self, cbf):
+    self.callback = cbf
+    
+    return
+
+
+  ##
+  # @if jp
+  #
+  # @brief 変数変更を知らせるオブザーバ関数
+  # 
+  # 変数変更を知らせるオブザーバ関数.
+  #
+  # @else
+  #
+  # @brief Observer function to notify variable changed
+  #
+  # This function notifies variable has been changed.
+  #
+  # @endif
+  #
+  # void notifyUpdate(const char* key, const char* val);
+  def notifyUpdate(self, key, val):
+    self.callback(key, val)
+    return
+
+
+  ##
+  # @if jp
+  # 
   # @brief バインドパラメータ値を更新
   # 
   # コンフィギュレーション設定値でコンフィギュレーションパラメータを更新する
@@ -164,13 +211,18 @@
   # @endif
   # virtual bool update(const char* val)
   def update(self, val):
+    if self.string_value == val:
+      return True
+    self.string_value = val
+    # value changed
     if self._trans(self._var, val):
+      self.notifyUpdate(self.name, val)
       return True
-    self._trans(self._var, self._default_value)
+    self._trans(self._var, self.default_value)
+    self.notifyUpdate(self.name, val)
     return False
 
 
-
 ##
 # @if jp
 # @class ConfigAdmin
@@ -347,6 +399,7 @@
     self._emptyconf  = OpenRTM_aist.Properties()
     self._newConfig  = []
     self._listeners  = OpenRTM_aist.ConfigurationListeners()
+    self._changedParam = []
 
   ##
   # @if jp
@@ -414,17 +467,68 @@
     if trans is None:
       trans = OpenRTM_aist.stringTo
     
+    if not param_name or not def_val:
+      return False
+
     if self.isExist(param_name):
       return False
 
     if not trans(var, def_val):
       return False
+    conf_ = Config(param_name, var, def_val, trans)
+    self._params.append(conf_)
+    conf_.setCallback(self.onUpdateParam)
+    self.update(self.getActiveId(), param_name)
     
-    self._params.append(Config(param_name, var, def_val, trans))
     return True
 
 
   ##
+  # @if jp
+  #
+  # @brief コンフィギュレーションパラメータの解除
+  # 
+  # コンフィギュレーションパラメータと変数のバインドを解除する。
+  # 指定した名称のコンフィギュレーションパラメータが存在しない場合は
+  # falseを返す。
+  #
+  # @param param_name コンフィギュレーションパラメータ名
+  # @return 設定結果(設定成功:true,設定失敗:false)
+  # 
+  # @else
+  #
+  # @brief Unbinding configuration parameters
+  # 
+  # Unbind configuration parameter from its variable. It returns
+  # false, if configuration parameter of specified name has already
+  # existed.
+  #
+  # @param param_name Configuration parameter name
+  # @return Setup result (Successful:true, Failed:false)
+  #
+  # @endif
+  #
+  # bool unbindParameter(const char* param_name);
+  def unbindParameter(self, param_name):
+    find_idx = -1
+    for (find_idx,param) in enumerate(self._params):
+      if param.name == param_name:
+        break
+    if find_idx == -1:
+      return False
+
+    del self._params[find_idx]
+
+    # configsets
+    leaf = self._configsets.getLeaf()
+    for i in range(len(leaf)):
+      if leaf[i].hasKey(param_name):
+        leaf[i].removeNode(param_name)
+
+    return True
+
+
+  ##
   # void update(void);
   #
   # @if jp
@@ -530,24 +634,28 @@
     if config_set and config_param is None:
       if self._configsets.hasKey(config_set) is None:
         return
+      self._changedParam = []
       prop = self._configsets.getNode(config_set)
       for i in range(len(self._params)):
         if prop.hasKey(self._params[i].name):
+          # self._changedParam is updated here
           self._params[i].update(prop.getProperty(self._params[i].name))
-          self.onUpdate(config_set)
+      self.onUpdate(config_set)
 
     # update(const char* config_set, const char* config_param)
     if config_set and config_param:
+      self._changedParam = []
       key = config_set
       key = key+"."+config_param
       for conf in self._params:
         if conf.name == config_param:
           conf.update(self._configsets.getProperty(key))
-          self.onUpdateParam(config_set, config_param)
+          #self.onUpdateParam(config_set, config_param)
           return
 
     # update()
     if config_set is None and config_param is None:
+      self._changedParam = []
       if self._changed and self._active:
         self.update(self._activeId)
         self._changed = False
@@ -621,7 +729,30 @@
 
   ##
   # @if jp
+  #
+  # @brief 変更されたパラメータのリスト
   # 
+  # コンフィギュレーションパラメータのうち変更されたもののリストを返す。
+  #
+  # @return 変更されたパラメータ名リスト
+  #
+  # @else
+  #
+  # @brief Changed parameters list
+  # 
+  # This operation returns parameter list which are changed.
+  #
+  # @return Changed parameters list
+  #
+  # @endif
+  #
+  # coil::vstring& changedParameters() { return m_changedParam; }
+  def changedParameters(self):
+    return self._changedParam
+
+  ##
+  # @if jp
+  # 
   # @brief アクティブ・コンフィギュレーションセットIDの取得
   # 
   # 現在アクティブなコンフィギュレーションセットのIDを取得する。
@@ -794,13 +925,14 @@
   # @endif
   # bool setConfigurationSetValues(const coil::Properties& config_set)
   def setConfigurationSetValues(self, config_set):
-    if config_set.getName() == "" or config_set.getName() is None:
+    node_ = config_set.getName()
+    if node_ == "" or node_ is None:
       return False
 
-    if not self._configsets.hasKey(config_set.getName()):
+    if not self._configsets.hasKey(node_):
       return False
 
-    p = self._configsets.getNode(config_set.getName())
+    p = self._configsets.getNode(node_)
     if p is None:
       return False
 
@@ -1441,8 +1573,8 @@
   # 設定されてるコールバックオブジェクトを呼び出す。
   #
   # @param self 
-  # @param config_set コンフィギュレーションID
   # @param config_param コンフィギュレーションパラメータ名
+  # @param config_value コンフィギュレーション値
   #
   # @else
   #
@@ -1451,15 +1583,16 @@
   # Call the set callback object.
   # 
   # @param self 
-  # @param config_set configuration-set ID.
   # @param config_param configuration parameter name.
+  # @param config_value configuration value.
   #
   # @endif
   #
-  # void onUpdateParam(const char* config_set, const char* config_param);
-  def onUpdateParam(self, config_set, config_param):
-    self._listeners.configparam_[OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM].notify(config_set,
-                                                                                                            config_param)
+  # void onUpdateParam(const char* config_param, const char* config_value);
+  def onUpdateParam(self, config_param, config_value):
+    self._changedParam.append(config_param)
+    self._listeners.configparam_[OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM].notify(config_param,
+                                                                                                            config_value)
     return
 
 

Modified: branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ConfigurationListener.py
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ConfigurationListener.py	2013-04-26 15:15:33 UTC (rev 559)
+++ branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ConfigurationListener.py	2013-04-26 16:09:39 UTC (rev 560)
@@ -48,7 +48,7 @@
 # Configuration パラメータの変更に関するリスナクラス。
 # 以下のイベントに対してコールバックされる。
 #
-# - ON_UPDATE_CONFIG_PARAM
+# - ON_UPDATE_CONFIG_PARAM: パラメータが変更された
 #
 # @else
 # @class ConfigurationParamListener class

Modified: branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2013-04-26 15:15:33 UTC (rev 559)
+++ branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2013-04-26 16:09:39 UTC (rev 560)
@@ -227,7 +227,7 @@
         manager.initExecContext()
         manager.initComposite()
         manager.initTimer()
-        #manager.initManagerServant()
+        manager.initManagerServant()
 
     return manager
 

Modified: branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/examples/ConfigSample/ConfigSample.py
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/examples/ConfigSample/ConfigSample.py	2013-04-26 15:15:33 UTC (rev 559)
+++ branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/examples/ConfigSample/ConfigSample.py	2013-04-26 16:09:39 UTC (rev 560)
@@ -37,7 +37,15 @@
   i = (i+1) % 4
   return str_[i]
 
+class MyConfigurationParamListner(OpenRTM_aist.ConfigurationParamListener):
+  def __init__(self):
+    pass
 
+  def __call__(self, config_set_name, config_param_name):
+    print "Changed config_set_name: ", config_set_name, " config_param_name: ", config_param_name
+    return
+    
+
 class ConfigSample(OpenRTM_aist.DataFlowComponentBase):
   # class constructor
   def __init__(self, manager):
@@ -60,7 +68,8 @@
     self.bindParameter("str_param0", self._str_param0, "hoge")
     self.bindParameter("str_param1", self._str_param1, "dara")
     self.bindParameter("vector_param0", self._vector_param0, "0.0,1.0,2.0,3.0,4.0")
-  
+    self.addConfigurationParamListener(OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM,
+                                       MyConfigurationParamListner())
 
     print "\n Please change configuration values from RtcLink"
     

Modified: branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/test/test_ConfigAdmin.py
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/test/test_ConfigAdmin.py	2013-04-26 15:15:33 UTC (rev 559)
+++ branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/test/test_ConfigAdmin.py	2013-04-26 16:09:39 UTC (rev 560)
@@ -89,6 +89,14 @@
     self._ca.bindParameter("str_param0", self.str_param0, "hoge")
     self._ca.bindParameter("str_param1", self.str_param1, "dara")
     self._ca.bindParameter("vector_param0", self.vector_param0, "0.0,1.0,2.0,3.0,4.0")
+    print "Changed Parameters: ", self._ca.changedParameters()
+    self.assertEqual(True,self._ca.unbindParameter("int_param0"))
+    self.assertEqual(True,self._ca.unbindParameter("int_param1"))
+    self.assertEqual(True,self._ca.unbindParameter("double_param0"))
+    self.assertEqual(True,self._ca.unbindParameter("double_param1"))
+    self.assertEqual(True,self._ca.unbindParameter("str_param0"))
+    self.assertEqual(True,self._ca.unbindParameter("str_param1"))
+    self.assertEqual(True,self._ca.unbindParameter("vector_param0"))
     return
 
   def test_update(self):
@@ -180,29 +188,29 @@
     return
 
   def test_setOnUpdate(self):
-    self._ca.setOnUpdate(None)
+    self._ca.setOnUpdate(self.CallBack)
     return
 
   def test_setOnUpdateParam(self):
-    self._ca.setOnUpdateParam(None)
+    self._ca.setOnUpdateParam(self.CallBack)
     return
 
   def test_setOnSetConfigurationSet(self):
-    self._ca.setOnSetConfigurationSet(None)
+    self._ca.setOnSetConfigurationSet(self.CallBack)
     return
 
   def test_setOnAddConfigurationSet(self):
-    self._ca.setOnAddConfigurationSet(None)
+    self._ca.setOnAddConfigurationSet(self.CallBack)
     return 
 
 
   def test_setOnRemoveConfigurationSet(self):
-    self._ca.setOnRemoveConfigurationSet(None)
+    self._ca.setOnRemoveConfigurationSet(self.CallBack)
     return 
 
 
   def test_setOnActivateSet(self):
-    self._ca.setOnActivateSet(None)
+    self._ca.setOnActivateSet(self.CallBack)
     return 
 
   



More information about the openrtm-commit mailing list