00001 #!/usr/bin/env python 00002 # -*- coding: euc-jp -*- 00003 00004 ## 00005 # @file ConfigurationListener.py 00006 # @brief Configuration related event listener classes 00007 # @date $Date$ 00008 # @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara 00009 # 00010 # Copyright (C) 2011 00011 # Intelligent Systems Research Institute, 00012 # National Institute of 00013 # Advanced Industrial Science and Technology (AIST), Japan 00014 # All rights reserved. 00015 00016 import OpenRTM_aist 00017 00018 ## 00019 # @if jp 00020 # @brief ConfigurationParamListener のタイプ 00021 # 00022 # - ON_UPDATE_CONFIG_PARAM, 00023 # 00024 # @else 00025 # @brief The types of ConnectorDataListener 00026 # 00027 # - ON_UPDATE_CONFIG_PARAM, 00028 # 00029 # @endif 00030 # 00031 class ConfigurationParamListenerType: 00032 """ 00033 """ 00034 00035 def __init__(self): 00036 pass 00037 00038 ON_UPDATE_CONFIG_PARAM = 0 00039 CONFIG_PARAM_LISTENER_NUM = 1 00040 00041 00042 00043 ## 00044 # @if jp 00045 # @class ConfigurationParamListener クラス 00046 # @brief ConfigurationParamListener クラス 00047 # 00048 # Configuration パラメータの変更に関するリスナクラス。 00049 # 以下のイベントに対してコールバックされる。 00050 # 00051 # - ON_UPDATE_CONFIG_PARAM 00052 # 00053 # @else 00054 # @class ConfigurationParamListener class 00055 # @brief ConfigurationParamListener class 00056 # 00057 # This class is abstract base class for listener classes that 00058 # provides callbacks for various events for Configuration parameter. 00059 # The listener will be called on the following event. 00060 # 00061 # - ON_UPDATE_CONFIG_PARAM 00062 # 00063 # @endif 00064 class ConfigurationParamListener: 00065 """ 00066 """ 00067 00068 def __init__(self): 00069 pass 00070 00071 ## 00072 # @if jp 00073 # 00074 # @brief ConfigurationParamListenerType を文字列に変換 00075 # 00076 # ConfigurationParamListenerType を文字列に変換する 00077 # 00078 # @param type 変換対象 ConfigurationParamListenerType 00079 # 00080 # @return 文字列変換結果 00081 # 00082 # @else 00083 # 00084 # @brief Convert ConfigurationParamListenerType into the string. 00085 # 00086 # Convert ConfigurationParamListenerType into the string. 00087 # 00088 # @param type The target ConfigurationParamListenerType for transformation 00089 # 00090 # @return Trnasformation result of string representation 00091 # 00092 # @endif 00093 # static const char* toString(ConfigurationParamListenerType type) 00094 def toString(type): 00095 typeString = ["ON_UPDATE_CONFIG_PARAM", 00096 "CONFIG_PARAM_LISTENER_NUM"] 00097 00098 if type < ConfigurationParamListenerType.CONFIG_PARAM_LISTENER_NUM: 00099 return typeString[type] 00100 00101 return ""; 00102 00103 toString = staticmethod(toString) 00104 00105 00106 ## 00107 # @if jp 00108 # @brief デストラクタ 00109 # @else 00110 # @brief Destructor 00111 # @endif 00112 def __del__(self): 00113 pass 00114 00115 00116 ## 00117 # @if jp 00118 # 00119 # @brief 仮想コールバック関数 00120 # 00121 # ConfigurationParamListener のコールバック関数 00122 # 00123 # @else 00124 # 00125 # @brief Virtual Callback function 00126 # 00127 # This is a the Callback function for ConfigurationParamListener. 00128 # 00129 # @endif 00130 # virtual void operator()(const char* config_set_name, 00131 # const char* config_param_name) = 0; 00132 def __call__(self, config_set_name, config_param_name): 00133 pass 00134 00135 00136 00137 #============================================================ 00138 ## 00139 # @if jp 00140 # @brief ConfigurationSetListener のタイプ 00141 # 00142 # - ON_SET_CONFIG_SET: ConfigurationSet 単位で値がセットされた 00143 # - ON_ADD_CONFIG_SET: ConfigurationSet が追加された 00144 # 00145 # @else 00146 # @brief The types of ConfigurationSetListener 00147 # 00148 # - ON_SET_CONFIG_SET: Value list has been set as a configuration set 00149 # - ON_ADD_CONFIG_SET: A new configuration set has been added 00150 # 00151 # @endif 00152 class ConfigurationSetListenerType: 00153 """ 00154 """ 00155 00156 def __init__(self): 00157 pass 00158 00159 ON_SET_CONFIG_SET = 0 00160 ON_ADD_CONFIG_SET = 1 00161 CONFIG_SET_LISTENER_NUM = 2 00162 00163 00164 00165 ## 00166 # @if jp 00167 # @class ConfigurationSetListener クラス 00168 # @brief ConfigurationSetListener クラス 00169 # 00170 # Configurationセットが変更されたり追加された場合に呼び出されるリスナクラス。 00171 # 以下のConfigurationセットに関連するイベントに対するリスナ。 00172 # 00173 # - ON_SET_CONFIG_SET: ConfigurationSet 単位で値がセットされた 00174 # - ON_ADD_CONFIG_SET: ConfigurationSet が追加された 00175 # 00176 # @else 00177 # @class ConfigurationSetListener class 00178 # @brief ConfigurationSetListener class 00179 # 00180 # This class is abstract base class for listener classes that 00181 # provides callbacks for configuration set's related events. 00182 # 00183 # - ON_SET_CONFIG_SET: Value list has been set as a configuration set 00184 # - ON_ADD_CONFIG_SET: A new configuration set has been added 00185 # 00186 # @endif 00187 class ConfigurationSetListener: 00188 """ 00189 """ 00190 00191 def __init__(self): 00192 pass 00193 00194 00195 ## 00196 # @if jp 00197 # 00198 # @brief ConfigurationSetListenerType を文字列に変換 00199 # 00200 # ConfigurationSetListenerType を文字列に変換する 00201 # 00202 # @param type 変換対象 ConfigurationSetListenerType 00203 # 00204 # @return 文字列変換結果 00205 # 00206 # @else 00207 # 00208 # @brief Convert ConfigurationSetListenerType into the string. 00209 # 00210 # Convert ConfigurationSetListenerType into the string. 00211 # 00212 # @param type The target ConfigurationSetListenerType for 00213 # transformation 00214 # 00215 # @return Trnasformation result of string representation 00216 # 00217 # @endif 00218 # static const char* toString(ConfigurationSetListenerType type) 00219 def toString(type): 00220 typeString = ["ON_SET_CONFIG_SET", 00221 "ON_ADD_CONFIG_SET", 00222 "CONFIG_SET_LISTENER_NUM"] 00223 if type < ConfigurationSetListenerType.CONFIG_SET_LISTENER_NUM: 00224 return typeString[type] 00225 00226 return ""; 00227 00228 toString = staticmethod(toString) 00229 00230 00231 ## 00232 # @if jp 00233 # @brief デストラクタ 00234 # @else 00235 # @brief Destructor 00236 # @endif 00237 def __del__(self): 00238 pass 00239 00240 00241 ## 00242 # @if jp 00243 # 00244 # @brief 仮想コールバック関数 00245 # 00246 # ConfigurationSetListener のコールバック関数 00247 # 00248 # @else 00249 # 00250 # @brief Virtual Callback function 00251 # 00252 # This is a the Callback function for ConfigurationSetListener 00253 # 00254 # @endif 00255 # virtual void operator()(const coil::Properties& config_set) = 0; 00256 def __call__(self, config_set): 00257 pass 00258 00259 00260 00261 #============================================================ 00262 ## 00263 # @if jp 00264 # @brief ConfigurationSetNameListenerType 00265 # 00266 # @else 00267 # @brief The types of ConfigurationSetNameListener 00268 # 00269 # @endif 00270 class ConfigurationSetNameListenerType: 00271 """ 00272 """ 00273 00274 def __init__(self): 00275 pass 00276 00277 ON_UPDATE_CONFIG_SET = 0 00278 ON_REMOVE_CONFIG_SET = 1 00279 ON_ACTIVATE_CONFIG_SET = 2 00280 CONFIG_SET_NAME_LISTENER_NUM = 3 00281 00282 00283 00284 ## 00285 # @if jp 00286 # @class ConfigurationSetNameListener クラス 00287 # @brief ConfigurationSetNameListener クラス 00288 # 00289 # ConfigurationSetに関するイベントに関するリスナークラス。 00290 # 00291 # - ON_UPDATE_CONFIG_SET: 00292 # - ON_REMOVE_CONFIG_SET: 00293 # - ON_ACTIVATE_CONFIG_SET: 00294 # 00295 # @else 00296 # @class ConfigurationSetNameListener class 00297 # @brief ConfigurationSetNameListener class 00298 # 00299 # This class is abstract base class for listener classes that 00300 # provides callbacks for various events for ConfigurationSet. 00301 # 00302 # - ON_UPDATE_CONFIG_SET: 00303 # - ON_REMOVE_CONFIG_SET: 00304 # - ON_ACTIVATE_CONFIG_SET: 00305 # 00306 # @endif 00307 class ConfigurationSetNameListener: 00308 """ 00309 """ 00310 00311 def __init__(self): 00312 pass 00313 00314 00315 ## 00316 # @if jp 00317 # 00318 # @brief ConfigurationSetNameListenerType を文字列に変換 00319 # 00320 # ConfigurationSetNameListenerType を文字列に変換する 00321 # 00322 # @param type 変換対象 ConfigurationSetNameListenerType 00323 # 00324 # @return 文字列変換結果 00325 # 00326 # @else 00327 # 00328 # @brief Convert ConfigurationSetNameListenerType into the string. 00329 # 00330 # Convert ConfigurationSetNameListenerType into the string. 00331 # 00332 # @param type The target ConfigurationSetNameListenerType for 00333 # transformation 00334 # 00335 # @return Trnasformation result of string representation 00336 # 00337 # @endif 00338 # static const char* toString(ConfigurationSetNameListenerType type) 00339 def toString(type): 00340 typeString = ["ON_UPDATE_CONFIG_SET", 00341 "ON_REMOVE_CONFIG_SET", 00342 "ON_ACTIVATE_CONFIG_SET", 00343 "CONFIG_SET_NAME_LISTENER_NUM"] 00344 if type < ConfigurationSetNameListenerType.CONFIG_SET_NAME_LISTENER_NUM: 00345 return typeString[type] 00346 00347 return ""; 00348 00349 toString = staticmethod(toString) 00350 00351 00352 ## 00353 # @if jp 00354 # @brief デストラクタ 00355 # @else 00356 # @brief Destructor 00357 # @endif 00358 def __del__(self): 00359 pass 00360 00361 00362 ## 00363 # @if jp 00364 # 00365 # @brief 仮想コールバック関数 00366 # 00367 # ConfigurationSetNameListener のコールバック関数 00368 # 00369 # @else 00370 # 00371 # @brief Virtual Callback function 00372 # 00373 # This is a the Callback function for ConfigurationSetNameListener. 00374 # 00375 # @endif 00376 # virtual void operator()(const char* config_set_name) = 0; 00377 def __call__(self, config_set_name): 00378 pass 00379 00380 00381 00382 ## 00383 # @if jp 00384 # 00385 # @class Entry 00386 # @brief リスナーと自動削除フラグ格納用の汎用クラス 00387 # 00388 # リスナーオブジェクトと自動削除のためのフラグを格納するための汎用クラス 00389 # 00390 # @else 00391 # 00392 # @class Entry 00393 # @brief Listner and autoclean-flag holder class 00394 # 00395 # A general-purpose class to store away a listener object and 00396 # a flag for automatic deletion 00397 # 00398 # @endif 00399 class Entry: 00400 def __init__(self,listener,autoclean): 00401 self.listener = listener 00402 self.autoclean = autoclean 00403 return 00404 00405 00406 00407 ## 00408 # @if jp 00409 # @class ConfigurationParamListenerHolder 00410 # @brief ConfigurationParamListener ホルダクラス 00411 # 00412 # 複数の ConfigurationParamListener を保持し管理するクラス。 00413 # 00414 # @else 00415 # @class ConfigurationParamListenerHolder 00416 # @brief ConfigurationParamListener holder class 00417 # 00418 # This class manages one ore more instances of 00419 # ConfigurationParamListener class. 00420 # 00421 # @endif 00422 class ConfigurationParamListenerHolder: 00423 """ 00424 """ 00425 00426 ## 00427 # @if jp 00428 # @brief コンストラクタ 00429 # @else 00430 # @brief Constructor 00431 # @endif 00432 # ConfigurationParamListenerHolder(); 00433 def __init__(self): 00434 self._listeners = [] 00435 pass 00436 00437 00438 ## 00439 # @if jp 00440 # @brief デストラクタ 00441 # @else 00442 # @brief Destructor 00443 # @endif 00444 def __del__(self): 00445 for (idx, listener) in enumerate(self._listeners): 00446 if listener.autoclean: 00447 self._listeners[idx] = None 00448 return 00449 00450 00451 ## 00452 # @if jp 00453 # 00454 # @brief リスナーの追加 00455 # 00456 # リスナーを追加する。 00457 # 00458 # @param listener 追加するリスナ 00459 # @param autoclean true:デストラクタで削除する, 00460 # false:デストラクタで削除しない 00461 # @else 00462 # 00463 # @brief Add the listener. 00464 # 00465 # This method adds the listener. 00466 # 00467 # @param listener Added listener 00468 # @param autoclean true:The listener is deleted at the destructor., 00469 # false:The listener is not deleted at the destructor. 00470 # @endif 00471 # void addListener(ConfigurationParamListener* listener, bool autoclean); 00472 def addListener(self, listener, autoclean): 00473 self._listeners.append(Entry(listener, autoclean)) 00474 return 00475 00476 00477 ## 00478 # @if jp 00479 # 00480 # @brief リスナーの削除 00481 # 00482 # リスナを削除する。 00483 # 00484 # @param listener 削除するリスナ 00485 # @else 00486 # 00487 # @brief Remove the listener. 00488 # 00489 # This method removes the listener. 00490 # 00491 # @param listener Removed listener 00492 # @endif 00493 # void removeListener(ConfigurationParamListener* listener); 00494 def removeListener(self, listener): 00495 len_ = len(self._listeners) 00496 for i in range(len_): 00497 idx = (len_ - 1) - i 00498 if self._listeners[idx].listener == listener: 00499 if self._listeners[idx].autoclean: 00500 self._listeners[idx].listener = None 00501 del self._listeners[idx] 00502 return 00503 return 00504 00505 00506 ## 00507 # @if jp 00508 # 00509 # @brief リスナーへ通知する 00510 # 00511 # 登録されているリスナのコールバックメソッドを呼び出す。 00512 # 00513 # @param info ConnectorInfo 00514 # @param cdrdata データ 00515 # @else 00516 # 00517 # @brief Notify listeners. 00518 # 00519 # This calls the Callback method of the registered listener. 00520 # 00521 # @param info ConnectorInfo 00522 # @param cdrdata Data 00523 # @endif 00524 # void notify(const char* config_set_name, const char* config_param_name); 00525 def notify(self, config_set_name, config_param_name): 00526 for listener in self._listeners: 00527 listener.listener(config_set_name, config_param_name) 00528 return 00529 00530 00531 00532 #============================================================ 00533 ## 00534 # @if jp 00535 # @class ConfigurationSetListenerHolder 00536 # @brief ConfigurationSetListener ホルダクラス 00537 # 00538 # 複数の ConfigurationSetListener を保持し管理するクラス。 00539 # 00540 # @else 00541 # @class ConfigurationSetListenerHolder 00542 # @brief ConfigurationSetListener holder class 00543 # 00544 # This class manages one ore more instances of 00545 # ConfigurationSetListener class. 00546 # 00547 # @endif 00548 class ConfigurationSetListenerHolder: 00549 """ 00550 """ 00551 00552 ## 00553 # @if jp 00554 # @brief コンストラクタ 00555 # @else 00556 # @brief Constructor 00557 # @endif 00558 # ConfigurationSetListenerHolder(); 00559 def __init__(self): 00560 self._listeners = [] 00561 pass 00562 00563 00564 ## 00565 # @if jp 00566 # @brief デストラクタ 00567 # @else 00568 # @brief Destructor 00569 # @endif 00570 def __del__(self): 00571 for (idx, listener) in enumerate(self._listeners): 00572 if listener.autoclean: 00573 self._listeners[idx] = None 00574 return 00575 00576 00577 ## 00578 # @if jp 00579 # 00580 # @brief リスナーの追加 00581 # 00582 # リスナーを追加する。 00583 # 00584 # @param listener 追加するリスナ 00585 # @param autoclean true:デストラクタで削除する, 00586 # false:デストラクタで削除しない 00587 # @else 00588 # 00589 # @brief Add the listener. 00590 # 00591 # This method adds the listener. 00592 # 00593 # @param listener Added listener 00594 # @param autoclean true:The listener is deleted at the destructor., 00595 # false:The listener is not deleted at the destructor. 00596 # @endif 00597 # void addListener(ConfigurationSetListener* listener, bool autoclean); 00598 def addListener(self, listener, autoclean): 00599 self._listeners.append(Entry(listener, autoclean)) 00600 return 00601 00602 00603 ## 00604 # @if jp 00605 # 00606 # @brief リスナーの削除 00607 # 00608 # リスナを削除する。 00609 # 00610 # @param listener 削除するリスナ 00611 # @else 00612 # 00613 # @brief Remove the listener. 00614 # 00615 # This method removes the listener. 00616 # 00617 # @param listener Removed listener 00618 # @endif 00619 # void removeListener(ConfigurationSetListener* listener); 00620 def removeListener(self, listener): 00621 len_ = len(self._listeners) 00622 for i in range(len_): 00623 idx = (len_ - 1) - i 00624 if self._listeners[idx].listener == listener: 00625 if self._listeners[idx].autoclean: 00626 self._listeners[idx].listener = None 00627 del self._listeners[idx] 00628 return 00629 return 00630 00631 00632 ## 00633 # @if jp 00634 # 00635 # @brief リスナーへ通知する 00636 # 00637 # 登録されているリスナのコールバックメソッドを呼び出す。 00638 # 00639 # @param info ConnectorInfo 00640 # @param cdrdata データ 00641 # @else 00642 # 00643 # @brief Notify listeners. 00644 # 00645 # This calls the Callback method of the registered listener. 00646 # 00647 # @param info ConnectorInfo 00648 # @param cdrdata Data 00649 # @endif 00650 # void notify(const coil::Properties& config_set); 00651 def notify(self, config_set): 00652 for listener in self._listeners: 00653 listener.listener(config_set) 00654 return 00655 00656 00657 00658 #============================================================ 00659 ## 00660 # @if jp 00661 # @class ConfigurationSetNameListenerHolder 00662 # @brief ConfigurationSetNameListener ホルダクラス 00663 # 00664 # 複数の ConfigurationSetNameListener を保持し管理するクラス。 00665 # 00666 # @else 00667 # @class ConfigurationSetNameListenerHolder 00668 # @brief ConfigurationSetNameListener holder class 00669 # 00670 # This class manages one ore more instances of 00671 # ConfigurationSetNameListener class. 00672 # 00673 # @endif 00674 class ConfigurationSetNameListenerHolder: 00675 """ 00676 """ 00677 00678 ## 00679 # @if jp 00680 # @brief コンストラクタ 00681 # @else 00682 # @brief Constructor 00683 # @endif 00684 # ConfigurationSetNameListenerHolder(); 00685 def __init__(self): 00686 self._listeners = [] 00687 pass 00688 00689 00690 ## 00691 # @if jp 00692 # @brief デストラクタ 00693 # @else 00694 # @brief Destructor 00695 # @endif 00696 def __del__(self): 00697 for (idx, listener) in enumerate(self._listeners): 00698 if listener.autoclean: 00699 self._listeners[idx] = None 00700 return 00701 00702 00703 ## 00704 # @if jp 00705 # 00706 # @brief リスナーの追加 00707 # 00708 # リスナーを追加する。 00709 # 00710 # @param listener 追加するリスナ 00711 # @param autoclean true:デストラクタで削除する, 00712 # false:デストラクタで削除しない 00713 # @else 00714 # 00715 # @brief Add the listener. 00716 # 00717 # This method adds the listener. 00718 # 00719 # @param listener Added listener 00720 # @param autoclean true:The listener is deleted at the destructor., 00721 # false:The listener is not deleted at the destructor. 00722 # @endif 00723 # void addListener(ConfigurationSetNameListener* listener, bool autoclean); 00724 def addListener(self, listener, autoclean): 00725 self._listeners.append(Entry(listener, autoclean)) 00726 return 00727 00728 00729 ## 00730 # @if jp 00731 # 00732 # @brief リスナーの削除 00733 # 00734 # リスナを削除する。 00735 # 00736 # @param listener 削除するリスナ 00737 # @else 00738 # 00739 # @brief Remove the listener. 00740 # 00741 # This method removes the listener. 00742 # 00743 # @param listener Removed listener 00744 # @endif 00745 # void removeListener(ConfigurationSetNameListener* listener); 00746 def removeListener(self, listener): 00747 len_ = len(self._listeners) 00748 for i in range(len_): 00749 idx = (len_ - 1) - i 00750 if self._listeners[idx].listener == listener: 00751 if self._listeners[idx].autoclean: 00752 self._listeners[idx].listener = None 00753 del self._listeners[idx] 00754 return 00755 return 00756 00757 00758 ## 00759 # @if jp 00760 # 00761 # @brief リスナーへ通知する 00762 # 00763 # 登録されているリスナのコールバックメソッドを呼び出す。 00764 # 00765 # @param info ConnectorInfo 00766 # @else 00767 # 00768 # @brief Notify listeners. 00769 # 00770 # This calls the Callback method of the registered listener. 00771 # 00772 # @param info ConnectorInfo 00773 # @endif 00774 # void notify(const char* config_set_name); 00775 def notify(self, config_set_name): 00776 for listener in self._listeners: 00777 listener.listener(config_set_name) 00778 return 00779 00780 00781 00782 #------------------------------------------------------------ 00783 ## 00784 # @if jp 00785 # @class ConfigurationActionListeners 00786 # @brief ConfigurationActionListeners クラス 00787 # 00788 # 00789 # @else 00790 # @class ConfigurationActionListeners 00791 # @brief ConfigurationActionListeners class 00792 # 00793 # 00794 # @endif 00795 class ConfigurationListeners: 00796 """ 00797 """ 00798 00799 def __init__(self): 00800 pass 00801 00802 00803 ## 00804 # @if jp 00805 # @brief ConfigurationParamListenerTypeリスナ配列 00806 # ConfigurationParamTypeリスナを格納 00807 # @else 00808 # @brief ConfigurationParamListenerType listener array 00809 # The ConfigurationParamListenerType listener is stored. 00810 # @endif 00811 configparam_num = ConfigurationParamListenerType.CONFIG_PARAM_LISTENER_NUM 00812 configparam_ = [ConfigurationParamListenerHolder() 00813 for i in range(configparam_num)] 00814 00815 ## 00816 # @if jp 00817 # @brief ConfigurationSetListenerTypeリスナ配列 00818 # ConfigurationSetListenerTypeリスナを格納 00819 # @else 00820 # @brief ConfigurationSetListenerType listener array 00821 # The ConfigurationSetListenerType listener is stored. 00822 # @endif 00823 configset_num = ConfigurationSetListenerType.CONFIG_SET_LISTENER_NUM 00824 configset_ = [ConfigurationSetListenerHolder() 00825 for i in range(configset_num)] 00826 00827 ## 00828 # @if jp 00829 # @brief ConfigurationSetNameListenerTypeリスナ配列 00830 # ConfigurationSetNameListenerTypeリスナを格納 00831 # @else 00832 # @brief ConfigurationSetNameListenerType listener array 00833 # The ConfigurationSetNameListenerType listener is stored. 00834 # @endif 00835 configsetname_num = ConfigurationSetNameListenerType.CONFIG_SET_NAME_LISTENER_NUM 00836 configsetname_ = [ConfigurationSetNameListenerHolder() 00837 for i in range(configsetname_num)]