00001 #!/usr/bin/env python 00002 # -*- coding: euc-jp -*- 00003 00004 ## 00005 # @file ComponentActionListener.py 00006 # @brief component action listener class 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 00017 #============================================================ 00018 00019 ## 00020 # @if jp 00021 # @brief PreComponentActionListener のタイプ 00022 # 00023 # - PRE_ON_INITIALIZE: onInitialize 直前 00024 # - PRE_ON_FINALIZE: onFinalize 直前 00025 # - PRE_ON_STARTUP: onStartup 直前 00026 # - PRE_ON_SHUTDOWN: onShutdown 直前 00027 # - PRE_ON_ACTIVATED: onActivated 直前 00028 # - PRE_ON_DEACTIVATED: onDeactivated 直前 00029 # - PRE_ON_ABORTING: onAborted 直前 00030 # - PRE_ON_ERROR: onError 直前 00031 # - PRE_ON_RESET: onReset 直前 00032 # - PRE_ON_EXECUTE: onExecute 直前 00033 # - PRE_ON_STATE_UPDATE: onStateUpdate 直前 00034 # - PRE_ON_RATE_CHANGED: onRateChanged 直前 00035 # 00036 # @else 00037 # @brief The types of ConnectorDataListener 00038 # 00039 # @endif 00040 class PreComponentActionListenerType: 00041 """ 00042 """ 00043 00044 def __init__(self): 00045 pass 00046 00047 PRE_ON_INITIALIZE = 0 00048 PRE_ON_FINALIZE = 1 00049 PRE_ON_STARTUP = 2 00050 PRE_ON_SHUTDOWN = 3 00051 PRE_ON_ACTIVATED = 4 00052 PRE_ON_DEACTIVATED = 5 00053 PRE_ON_ABORTING = 6 00054 PRE_ON_ERROR = 7 00055 PRE_ON_RESET = 8 00056 PRE_ON_EXECUTE = 9 00057 PRE_ON_STATE_UPDATE = 10 00058 PRE_ON_RATE_CHANGED = 11 00059 PRE_COMPONENT_ACTION_LISTENER_NUM = 12 00060 00061 00062 ## 00063 # @if jp 00064 # @class PreComponentActionListener クラス 00065 # @brief PreComponentActionListener クラス 00066 # 00067 # OMG RTC仕様で定義されている以下のコンポーネントアクショントについ 00068 # て、 00069 # 00070 # - on_initialize() 00071 # - on_finalize() 00072 # - on_startup() 00073 # - on_shutdown() 00074 # - on_activated 00075 # - on_deactivated() 00076 # - on_aborted() 00077 # - on_error() 00078 # - on_reset() 00079 # - on_execute() 00080 # - on_state_update() 00081 # - on_rate_changed() 00082 # 00083 # 各アクションに対応するユーザーコードが呼ばれる直前のタイミング 00084 # でコールされるリスナクラスの基底クラス。 00085 # 00086 # - PRE_ON_INITIALIZE: 00087 # - PRE_ON_FINALIZE: 00088 # - PRE_ON_STARTUP: 00089 # - PRE_ON_SHUTDOWN: 00090 # - PRE_ON_ACTIVATED: 00091 # - PRE_ON_DEACTIVATED: 00092 # - PRE_ON_ABORTING: 00093 # - PRE_ON_ERROR: 00094 # - PRE_ON_RESET: 00095 # - PRE_IN_EXECUTE: 00096 # - PRE_ON_STATE_UPDATE: 00097 # - PRE_ON_RATE_CHANGED: 00098 # 00099 # @else 00100 # @class PreComponentActionListener class 00101 # @brief PreComponentActionListener class 00102 # 00103 # This class is abstract base class for listener classes that 00104 # provides callbacks for various events in rtobject. 00105 # 00106 # @endif 00107 class PreComponentActionListener: 00108 """ 00109 """ 00110 00111 def __init__(self): 00112 pass 00113 00114 ## 00115 # @if jp 00116 # 00117 # @brief PreComponentActionListenerType を文字列に変換 00118 # 00119 # PreComponentActionListenerType を文字列に変換する 00120 # 00121 # @param type 変換対象 PreComponentActionListenerType 00122 # 00123 # @return 文字列変換結果 00124 # 00125 # @else 00126 # 00127 # @brief Convert PreComponentActionListenerType into the string. 00128 # 00129 # Convert PreComponentActionListenerType into the string. 00130 # 00131 # @param type The target PreComponentActionListenerType for transformation 00132 # 00133 # @return Trnasformation result of string representation 00134 # 00135 # @endif 00136 # static const char* toString(PreComponentActionListenerType type) 00137 def toString(type): 00138 typeString = ["PRE_ON_INITIALIZE", 00139 "PRE_ON_FINALIZE", 00140 "PRE_ON_STARTUP", 00141 "PRE_ON_SHUTDOWN", 00142 "PRE_ON_ACTIVATED", 00143 "PRE_ON_DEACTIVATED", 00144 "PRE_ON_ABORTING", 00145 "PRE_ON_ERROR", 00146 "PRE_ON_RESET", 00147 "PRE_ON_EXECUTE", 00148 "PRE_ON_STATE_UPDATE", 00149 "PRE_ON_RATE_CHANGED", 00150 "PRE_COMPONENT_ACTION_LISTENER_NUM"] 00151 if type < PreComponentActionListenerType.PRE_COMPONENT_ACTION_LISTENER_NUM: 00152 return typeString[type] 00153 00154 return "" 00155 toString = staticmethod(toString) 00156 00157 ## 00158 # @if jp 00159 # @brief デストラクタ 00160 # @else 00161 # @brief Destructor 00162 # @endif 00163 def __del__(self): 00164 pass 00165 00166 ## 00167 # @if jp 00168 # 00169 # @brief 仮想コールバック関数 00170 # 00171 # PreComponentActionListener のコールバック関数 00172 # 00173 # @else 00174 # 00175 # @brief Virtual Callback function 00176 # 00177 # This is a the Callback function for PreComponentActionListener. 00178 # 00179 # @endif 00180 # virtual void operator()(UniqueId ec_id) = 0; 00181 def __call__(self, ec_id): 00182 pass 00183 00184 00185 #============================================================ 00186 00187 ## 00188 # @if jp 00189 # @brief PostCompoenntActionListener のタイプ 00190 # 00191 # - POST_ON_INITIALIZE: 00192 # - POST_ON_FINALIZE: 00193 # - POST_ON_STARTUP: 00194 # - POST_ON_SHUTDOWN: 00195 # - POST_ON_ACTIVATED: 00196 # - POST_ON_DEACTIVATED: 00197 # - POST_ON_ABORTING: 00198 # - POST_ON_ERROR: 00199 # - POST_ON_RESET: 00200 # - POST_ON_EXECUTE: 00201 # - POST_ON_STATE_UPDATE: 00202 # - POST_ON_RATE_CHANGED: 00203 # 00204 # @else 00205 # @brief The types of ConnectorDataListener 00206 # 00207 # @endif 00208 class PostComponentActionListenerType: 00209 """ 00210 """ 00211 def __init__(self): 00212 pass 00213 00214 POST_ON_INITIALIZE = 0 00215 POST_ON_FINALIZE = 1 00216 POST_ON_STARTUP = 2 00217 POST_ON_SHUTDOWN = 3 00218 POST_ON_ACTIVATED = 4 00219 POST_ON_DEACTIVATED = 5 00220 POST_ON_ABORTING = 6 00221 POST_ON_ERROR = 7 00222 POST_ON_RESET = 8 00223 POST_ON_EXECUTE = 9 00224 POST_ON_STATE_UPDATE = 10 00225 POST_ON_RATE_CHANGED = 11 00226 POST_COMPONENT_ACTION_LISTENER_NUM = 12 00227 00228 00229 00230 ## 00231 # @if jp 00232 # @class PostComponentActionListener クラス 00233 # @brief PostComponentActionListener クラス 00234 # 00235 # OMG RTC仕様で定義されている以下のコンポーネントアクショントについ 00236 # て、 00237 # 00238 # - on_initialize() 00239 # - on_finalize() 00240 # - on_startup() 00241 # - on_shutdown() 00242 # - on_activated 00243 # - on_deactivated() 00244 # - on_aborted() 00245 # - on_error() 00246 # - on_reset() 00247 # - on_execute() 00248 # - on_state_update() 00249 # - on_rate_changed() 00250 # 00251 # 各アクションに対応するユーザーコードが呼ばれる直前のタイミング 00252 # でコールされるリスなクラスの基底クラス。 00253 # 00254 # - POST_ON_INITIALIZE: 00255 # - POST_ON_FINALIZE: 00256 # - POST_ON_STARTUP: 00257 # - POST_ON_SHUTDOWN: 00258 # - POST_ON_ACTIVATED: 00259 # - POST_ON_DEACTIVATED: 00260 # - POST_ON_ABORTING: 00261 # - POST_ON_ERROR: 00262 # - POST_ON_RESET: 00263 # - POST_ON_EXECUTE: 00264 # - POST_ON_STATE_UPDATE: 00265 # - POST_ON_RATE_CHANGED: 00266 # 00267 # @else 00268 # @class PostComponentActionListener class 00269 # @brief PostComponentActionListener class 00270 # 00271 # This class is abstract base class for listener classes that 00272 # provides callbacks for various events in rtobject. 00273 # 00274 # @endif 00275 class PostComponentActionListener: 00276 """ 00277 """ 00278 00279 def __init__(self): 00280 pass 00281 00282 ## 00283 # @if jp 00284 # 00285 # @brief PostComponentActionListenerType を文字列に変換 00286 # 00287 # PostComponentActionListenerType を文字列に変換する 00288 # 00289 # @param type 変換対象 PostComponentActionListenerType 00290 # 00291 # @return 文字列変換結果 00292 # 00293 # @else 00294 # 00295 # @brief Convert PostComponentActionListenerType into the string. 00296 # 00297 # Convert PostComponentActionListenerType into the string. 00298 # 00299 # @param type The target PostComponentActionListenerType for transformation 00300 # 00301 # @return Trnasformation result of string representation 00302 # 00303 # @endif 00304 # static const char* toString(PostComponentActionListenerType type) 00305 def toString(type): 00306 typeString = ["POST_ON_INITIALIZE", 00307 "POST_ON_FINALIZE", 00308 "POST_ON_STARTUP", 00309 "POST_ON_SHUTDOWN", 00310 "POST_ON_ACTIVATED", 00311 "POST_ON_DEACTIVATED", 00312 "POST_ON_ABORTING", 00313 "POST_ON_ERROR", 00314 "POST_ON_RESET", 00315 "POST_ON_EXECUTE", 00316 "POST_ON_STATE_UPDATE", 00317 "POST_ON_RATE_CHANGED", 00318 "POST_COMPONENT_ACTION_LISTENER_NUM"] 00319 if type < PostComponentActionListenerType.POST_COMPONENT_ACTION_LISTENER_NUM: 00320 return typeString[type] 00321 return ""; 00322 00323 toString = staticmethod(toString) 00324 00325 ## 00326 # @if jp 00327 # @brief デストラクタ 00328 # @else 00329 # @brief Destructor 00330 # @endif 00331 def __del__(self): 00332 pass 00333 00334 ## 00335 # @if jp 00336 # 00337 # @brief 仮想コールバック関数 00338 # 00339 # PostComponentActionListener のコールバック関数 00340 # 00341 # @else 00342 # 00343 # @brief Virtual Callback function 00344 # 00345 # This is a the Callback function for PostComponentActionListener. 00346 # 00347 # @endif 00348 #virtual void operator()(UniqueId ec_id, 00349 # ReturnCode_t ret) = 0; 00350 def __call__(self, ec_id, ret): 00351 pass 00352 00353 00354 00355 #============================================================ 00356 ## 00357 # @if jp 00358 # @brief PortActionListener のタイプ 00359 # 00360 # - ADD_PORT: Port 追加時 00361 # - REMOVE_PORT: Port 削除時 00362 # 00363 # @else 00364 # @brief The types of PortActionListener 00365 # 00366 # @endif 00367 class PortActionListenerType: 00368 """ 00369 """ 00370 00371 def __init__(self): 00372 pass 00373 00374 ADD_PORT = 0 00375 REMOVE_PORT = 1 00376 PORT_ACTION_LISTENER_NUM = 2 00377 00378 00379 00380 ## 00381 # @if jp 00382 # @class PortActionListener クラス 00383 # @brief PortActionListener クラス 00384 # 00385 # 各アクションに対応するユーザーコードが呼ばれる直前のタイミング 00386 # でコールされるリスなクラスの基底クラス。 00387 # 00388 # - ADD_PORT: 00389 # - REMOVE_PORT: 00390 # 00391 # @else 00392 # @class PortActionListener class 00393 # @brief PortActionListener class 00394 # 00395 # This class is abstract base class for listener classes that 00396 # provides callbacks for various events in rtobject. 00397 # 00398 # @endif 00399 class PortActionListener: 00400 """ 00401 """ 00402 00403 def __init__(self): 00404 pass 00405 00406 ## 00407 # @if jp 00408 # 00409 # @brief PortActionListenerType を文字列に変換 00410 # 00411 # PortActionListenerType を文字列に変換する 00412 # 00413 # @param type 変換対象 PortActionListenerType 00414 # 00415 # @return 文字列変換結果 00416 # 00417 # @else 00418 # 00419 # @brief Convert PortActionListenerType into the string. 00420 # 00421 # Convert PortActionListenerType into the string. 00422 # 00423 # @param type The target PortActionListenerType for transformation 00424 # 00425 # @return Trnasformation result of string representation 00426 # 00427 # @endif 00428 #static const char* toString(PortActionListenerType type) 00429 def toString(type): 00430 typeString = ["ADD_PORT", 00431 "REMOVE_PORT", 00432 "PORT_ACTION_LISTENER_NUM"] 00433 if type < PortActionListenerType.PORT_ACTION_LISTENER_NUM: 00434 return typeString[type] 00435 return "" 00436 00437 toString = staticmethod(toString) 00438 00439 ## 00440 # @if jp 00441 # @brief デストラクタ 00442 # @else 00443 # @brief Destructor 00444 # @endif 00445 #virtual ~PortActionListener(); 00446 def __del__(self): 00447 pass 00448 00449 ## 00450 # @if jp 00451 # 00452 # @brief 仮想コールバック関数 00453 # 00454 # PortActionListener のコールバック関数 00455 # 00456 # @else 00457 # 00458 # @brief Virtual Callback function 00459 # 00460 # This is a the Callback function for PortActionListener 00461 # 00462 # @endif 00463 #virtual void operator()(const ::RTC::PortProfile& pprof) = 0; 00464 def __call__(self, pprof): 00465 pass 00466 00467 00468 #============================================================ 00469 ## 00470 # @if jp 00471 # @brief ExecutionContextActionListener のタイプ 00472 # 00473 # - EC_ATTACHED: ExecutionContext 追加時 00474 # - EC_DETACHED: ExecutionContext 削除時 00475 # 00476 # @else 00477 # @brief The types of ExecutionContextActionListener 00478 # 00479 # @endif 00480 class ExecutionContextActionListenerType: 00481 """ 00482 """ 00483 def __init__(self): 00484 pass 00485 00486 EC_ATTACHED = 0 00487 EC_DETACHED = 1 00488 EC_ACTION_LISTENER_NUM = 2 00489 00490 ## 00491 # @if jp 00492 # @class ExecutionContextActionListener クラス 00493 # @brief ExecutionContextActionListener クラス 00494 # 00495 # 各アクションに対応するユーザーコードが呼ばれる直前のタイミング 00496 # でコールされるリスなクラスの基底クラス。 00497 # 00498 # - ADD_PORT: 00499 # - REMOVE_PORT: 00500 # 00501 # @else 00502 # @class ExecutionContextActionListener class 00503 # @brief ExecutionContextActionListener class 00504 # 00505 # This class is abstract base class for listener classes that 00506 # provides callbacks for various events in rtobject. 00507 # 00508 # @endif 00509 class ExecutionContextActionListener: 00510 """ 00511 """ 00512 00513 def __init__(self): 00514 pass 00515 00516 00517 ## 00518 # @if jp 00519 # 00520 # @brief ExecutionContextActionListenerType を文字列に変換 00521 # 00522 # ExecutionContextActionListenerType を文字列に変換する 00523 # 00524 # @param type 変換対象 ExecutionContextActionListenerType 00525 # 00526 # @return 文字列変換結果 00527 # 00528 # @else 00529 # 00530 # @brief Convert ExecutionContextActionListenerType into the string. 00531 # 00532 # Convert ExecutionContextActionListenerType into the string. 00533 # 00534 # @param type The target ExecutionContextActionListenerType for transformation 00535 # 00536 # @return Trnasformation result of string representation 00537 # 00538 # @endif 00539 #static const char* toString(ExecutionContextActionListenerType type) 00540 def toString(type): 00541 typeString = ["ATTACH_EC", 00542 "DETACH_EC", 00543 "EC_ACTION_LISTENER_NUM"] 00544 if type < ExecutionContextActionListenerType.EC_ACTION_LISTENER_NUM: 00545 return typeString[type] 00546 return "" 00547 00548 toString = staticmethod(toString) 00549 00550 00551 ## 00552 # @if jp 00553 # @brief デストラクタ 00554 # @else 00555 # @brief Destructor 00556 # @endif 00557 def __del__(self): 00558 pass 00559 00560 ## 00561 # @if jp 00562 # 00563 # @brief 仮想コールバック関数 00564 # 00565 # ExecutionContextActionListener のコールバック関数 00566 # 00567 # @else 00568 # 00569 # @brief Virtual Callback function 00570 # 00571 # This is a the Callback function for ExecutionContextActionListener 00572 # 00573 # @endif 00574 #virtual void operator()(UniqueId ec_id) = 0; 00575 def __call__(self, ec_id): 00576 pass 00577 00578 00579 class Entry: 00580 def __init__(self,listener, autoclean): 00581 self.listener = listener 00582 self.autoclean = autoclean 00583 return 00584 00585 00586 #============================================================ 00587 ## 00588 # @if jp 00589 # @class PreComponentActionListenerHolder 00590 # @brief PreComponentActionListener ホルダクラス 00591 # 00592 # 複数の PreComponentActionListener を保持し管理するクラス。 00593 # 00594 # @else 00595 # @class PreComponentActionListenerHolder 00596 # @brief PreComponentActionListener holder class 00597 # 00598 # This class manages one ore more instances of 00599 # PreComponentActionListener class. 00600 # 00601 # @endif 00602 class PreComponentActionListenerHolder: 00603 """ 00604 """ 00605 00606 ## 00607 # @if jp 00608 # @brief コンストラクタ 00609 # @else 00610 # @brief Constructor 00611 # @endif 00612 def __init__(self): 00613 self._listeners = [] 00614 return 00615 00616 00617 ## 00618 # @if jp 00619 # @brief デストラクタ 00620 # @else 00621 # @brief Destructor 00622 # @endif 00623 def __del__(self): 00624 for (idx, listener) in enumerate(self._listeners): 00625 if listener.autoclean: 00626 self._listeners[idx] = None 00627 return 00628 00629 ## 00630 # @if jp 00631 # 00632 # @brief リスナーの追加 00633 # 00634 # リスナーを追加する。 00635 # 00636 # @param listener 追加するリスナ 00637 # @param autoclean true:デストラクタで削除する, 00638 # false:デストラクタで削除しない 00639 # @else 00640 # 00641 # @brief Add the listener. 00642 # 00643 # This method adds the listener. 00644 # 00645 # @param listener Added listener 00646 # @param autoclean true:The listener is deleted at the destructor., 00647 # false:The listener is not deleted at the destructor. 00648 # @endif 00649 #void addListener(PreComponentActionListener* listener, bool autoclean); 00650 def addListener(self, listener, autoclean): 00651 self._listeners.append(Entry(listener, autoclean)) 00652 return 00653 00654 ## 00655 # @if jp 00656 # 00657 # @brief リスナーの削除 00658 # 00659 # リスナを削除する。 00660 # 00661 # @param listener 削除するリスナ 00662 # @else 00663 # 00664 # @brief Remove the listener. 00665 # 00666 # This method removes the listener. 00667 # 00668 # @param listener Removed listener 00669 # @endif 00670 #void removeListener(PreComponentActionListener* listener); 00671 def removeListener(self, listener): 00672 len_ = len(self._listeners) 00673 for i in range(len_): 00674 idx = (len_ - 1) - i 00675 if self._listeners[idx].listener == listener: 00676 if self._listeners[idx].autoclean: 00677 self._listeners[idx].listener = None 00678 del self._listeners[idx] 00679 return 00680 return 00681 00682 ## 00683 # @if jp 00684 # 00685 # @brief リスナーへ通知する 00686 # 00687 # 登録されているリスナのコールバックメソッドを呼び出す。 00688 # 00689 # @param info ConnectorInfo 00690 # @else 00691 # 00692 # @brief Notify listeners. 00693 # 00694 # This calls the Callback method of the registered listener. 00695 # 00696 # @param info ConnectorInfo 00697 # @endif 00698 #void notify(UniqueId ec_id); 00699 def notify(self, ec_id): 00700 for listener in self._listeners: 00701 listener.listener(ec_id) 00702 return 00703 00704 00705 00706 ## 00707 # @if jp 00708 # @class PostComponentActionListenerHolder 00709 # @brief PostComponentActionListener ホルダクラス 00710 # 00711 # 複数の PostComponentActionListener を保持し管理するクラス。 00712 # 00713 # @else 00714 # @class PostComponentActionListenerHolder 00715 # @brief PostComponentActionListener holder class 00716 # 00717 # This class manages one ore more instances of 00718 # PostComponentActionListener class. 00719 # 00720 # @endif 00721 class PostComponentActionListenerHolder: 00722 """ 00723 """ 00724 00725 ## 00726 # @if jp 00727 # @brief コンストラクタ 00728 # @else 00729 # @brief Constructor 00730 # @endif 00731 def __init__(self): 00732 self._listeners = [] 00733 return 00734 00735 00736 ## 00737 # @if jp 00738 # @brief デストラクタ 00739 # @else 00740 # @brief Destructor 00741 # @endif 00742 def __del__(self): 00743 for (idx, listener) in enumerate(self._listeners): 00744 if listener.autoclean: 00745 self._listeners[idx] = None 00746 return 00747 00748 ## 00749 # @if jp 00750 # 00751 # @brief リスナーの追加 00752 # 00753 # リスナーを追加する。 00754 # 00755 # @param listener 追加するリスナ 00756 # @param autoclean true:デストラクタで削除する, 00757 # false:デストラクタで削除しない 00758 # @else 00759 # 00760 # @brief Add the listener. 00761 # 00762 # This method adds the listener. 00763 # 00764 # @param listener Added listener 00765 # @param autoclean true:The listener is deleted at the destructor., 00766 # false:The listener is not deleted at the destructor. 00767 # @endif 00768 #void addListener(PostComponentActionListener* listener, bool autoclean); 00769 def addListener(self, listener, autoclean): 00770 self._listeners.append(Entry(listener, autoclean)) 00771 return 00772 00773 ## 00774 # @if jp 00775 # 00776 # @brief リスナーの削除 00777 # 00778 # リスナを削除する。 00779 # 00780 # @param listener 削除するリスナ 00781 # @else 00782 # 00783 # @brief Remove the listener. 00784 # 00785 # This method removes the listener. 00786 # 00787 # @param listener Removed listener 00788 # @endif 00789 #void removeListener(PostComponentActionListener* listener); 00790 def removeListener(self, listener): 00791 len_ = len(self._listeners) 00792 for i in range(len_): 00793 idx = (len_ - 1) - i 00794 if self._listeners[idx].listener == listener: 00795 if self._listeners[idx].autoclean: 00796 self._listeners[idx].listener = None 00797 del self._listeners[idx] 00798 return 00799 return 00800 00801 00802 ## 00803 # @if jp 00804 # 00805 # @brief リスナーへ通知する 00806 # 00807 # 登録されているリスナのコールバックメソッドを呼び出す。 00808 # 00809 # @param info ConnectorInfo 00810 # @param cdrdata データ 00811 # @else 00812 # 00813 # @brief Notify listeners. 00814 # 00815 # This calls the Callback method of the registered listener. 00816 # 00817 # @param info ConnectorInfo 00818 # @param cdrdata Data 00819 # @endif 00820 #void notify(UniqueId ec_id, ReturnCode_t ret); 00821 def notify(self, ec_id, ret): 00822 for listener in self._listeners: 00823 listener.listener(ec_id, ret) 00824 return 00825 00826 00827 00828 #============================================================ 00829 ## 00830 # @if jp 00831 # @class PortActionListenerHolder 00832 # @brief PortActionListener ホルダクラス 00833 # 00834 # 複数の PortActionListener を保持し管理するクラス。 00835 # 00836 # @else 00837 # @class PortActionListenerHolder 00838 # @brief PortActionListener holder class 00839 # 00840 # This class manages one ore more instances of 00841 # PortActionListener class. 00842 # 00843 # @endif 00844 class PortActionListenerHolder: 00845 """ 00846 """ 00847 00848 ## 00849 # @if jp 00850 # @brief コンストラクタ 00851 # @else 00852 # @brief Constructor 00853 # @endif 00854 def __init__(self): 00855 self._listeners = [] 00856 return 00857 00858 00859 ## 00860 # @if jp 00861 # @brief デストラクタ 00862 # @else 00863 # @brief Destructor 00864 # @endif 00865 def __del__(self): 00866 for (idx, listener) in enumerate(self._listeners): 00867 if listener.autoclean: 00868 self._listeners[idx] = None 00869 pass 00870 00871 ## 00872 # @if jp 00873 # 00874 # @brief リスナーの追加 00875 # 00876 # リスナーを追加する。 00877 # 00878 # @param listener 追加するリスナ 00879 # @param autoclean true:デストラクタで削除する, 00880 # false:デストラクタで削除しない 00881 # @else 00882 # 00883 # @brief Add the listener. 00884 # 00885 # This method adds the listener. 00886 # 00887 # @param listener Added listener 00888 # @param autoclean true:The listener is deleted at the destructor., 00889 # false:The listener is not deleted at the destructor. 00890 # @endif 00891 #void addListener(PortActionListener* listener, bool autoclean); 00892 def addListener(self, listener, autoclean): 00893 self._listeners.append(Entry(listener, autoclean)) 00894 return 00895 00896 00897 ## 00898 # @if jp 00899 # 00900 # @brief リスナーの削除 00901 # 00902 # リスナを削除する。 00903 # 00904 # @param listener 削除するリスナ 00905 # @else 00906 # 00907 # @brief Remove the listener. 00908 # 00909 # This method removes the listener. 00910 # 00911 # @param listener Removed listener 00912 # @endif 00913 #void removeListener(PortActionListener* listener); 00914 def removeListener(self, listener): 00915 len_ = len(self._listeners) 00916 for i in range(len_): 00917 idx = (len_ - 1) - i 00918 if self._listeners[idx].listener == listener: 00919 if self._listeners[idx].autoclean: 00920 self._listeners[idx].listener = None 00921 del self._listeners[idx] 00922 return 00923 return 00924 00925 ## 00926 # @if jp 00927 # 00928 # @brief リスナーへ通知する 00929 # 00930 # 登録されているリスナのコールバックメソッドを呼び出す。 00931 # 00932 # @param info ConnectorInfo 00933 # @param cdrdata データ 00934 # @else 00935 # 00936 # @brief Notify listeners. 00937 # 00938 # This calls the Callback method of the registered listener. 00939 # 00940 # @param info ConnectorInfo 00941 # @param cdrdata Data 00942 # @endif 00943 #void notify(const RTC::PortProfile& pprofile); 00944 def notify(self, pprofile): 00945 for listener in self._listeners: 00946 listener.listener(pprofile) 00947 return 00948 00949 00950 00951 ## 00952 # @if jp 00953 # @class ExecutionContextActionListenerHolder 00954 # @brief ExecutionContextActionListener ホルダクラス 00955 # 00956 # 複数の ExecutionContextActionListener を保持し管理するクラス。 00957 # 00958 # @else 00959 # @class ExecutionContextActionListenerHolder 00960 # @brief ExecutionContextActionListener holder class 00961 # 00962 # This class manages one ore more instances of 00963 # ExecutionContextActionListener class. 00964 # 00965 # @endif 00966 class ExecutionContextActionListenerHolder: 00967 """ 00968 """ 00969 00970 ## 00971 # @if jp 00972 # @brief コンストラクタ 00973 # @else 00974 # @brief Constructor 00975 # @endif 00976 def __init__(self): 00977 self._listeners = [] 00978 return 00979 00980 00981 ## 00982 # @if jp 00983 # @brief デストラクタ 00984 # @else 00985 # @brief Destructor 00986 # @endif 00987 def __del__(self): 00988 for (idx, listener) in enumerate(self._listeners): 00989 if listener.autoclean: 00990 self._listeners[idx] = None 00991 pass 00992 00993 00994 ## 00995 # @if jp 00996 # 00997 # @brief リスナーの追加 00998 # 00999 # リスナーを追加する。 01000 # 01001 # @param listener 追加するリスナ 01002 # @param autoclean true:デストラクタで削除する, 01003 # false:デストラクタで削除しない 01004 # @else 01005 # 01006 # @brief Add the listener. 01007 # 01008 # This method adds the listener. 01009 # 01010 # @param listener Added listener 01011 # @param autoclean true:The listener is deleted at the destructor., 01012 # false:The listener is not deleted at the destructor. 01013 # @endif 01014 #void addListener(ExecutionContextActionListener* listener, bool autoclean); 01015 def addListener(self, listener, autoclean): 01016 self._listeners.append(Entry(listener, autoclean)) 01017 return 01018 01019 01020 ## 01021 # @if jp 01022 # 01023 # @brief リスナーの削除 01024 # 01025 # リスナを削除する。 01026 # 01027 # @param listener 削除するリスナ 01028 # @else 01029 # 01030 # @brief Remove the listener. 01031 # 01032 # This method removes the listener. 01033 # 01034 # @param listener Removed listener 01035 # @endif 01036 #void removeListener(ExecutionContextActionListener* listener); 01037 def removeListener(self, listener): 01038 len_ = len(self._listeners) 01039 for i in range(len_): 01040 idx = (len_ - 1) - i 01041 if self._listeners[idx].listener == listener: 01042 if self._listeners[idx].autoclean: 01043 self._listeners[idx].listener = None 01044 del self._listeners[idx] 01045 return 01046 return 01047 01048 01049 ## 01050 # @if jp 01051 # 01052 # @brief リスナーへ通知する 01053 # 01054 # 登録されているリスナのコールバックメソッドを呼び出す。 01055 # 01056 # @param info ConnectorInfo 01057 # @param cdrdata データ 01058 # @else 01059 # 01060 # @brief Notify listeners. 01061 # 01062 # This calls the Callback method of the registered listener. 01063 # 01064 # @param info ConnectorInfo 01065 # @param cdrdata Data 01066 # @endif 01067 #void notify(UniqueId ec_id); 01068 def notify(self, ec_id): 01069 for listener in self._listeners: 01070 listener.listener(ec_id) 01071 return 01072 01073 01074 01075 ## 01076 # @if jp 01077 # @class ComponentActionListeners 01078 # @brief ComponentActionListeners クラス 01079 # 01080 # 01081 # @else 01082 # @class ComponentActionListeners 01083 # @brief ComponentActionListeners class 01084 # 01085 # 01086 # @endif 01087 class ComponentActionListeners: 01088 """ 01089 """ 01090 01091 def __init__(self): 01092 pass 01093 01094 ## 01095 # @if jp 01096 # @brief PreComponentActionListenerTypeリスナ配列 01097 # PreComponentActionListenerTypeリスナを格納 01098 # @else 01099 # @brief PreComponentActionListenerType listener array 01100 # The PreComponentActionListenerType listener is stored. 01101 # @endif 01102 preaction_num = PreComponentActionListenerType.PRE_COMPONENT_ACTION_LISTENER_NUM 01103 preaction_ = [PreComponentActionListenerHolder() 01104 for i in range(preaction_num)] 01105 01106 ## 01107 # @if jp 01108 # @brief PostComponentActionListenerTypeリスナ配列 01109 # PostComponentActionListenerTypeリスナを格納 01110 # @else 01111 # @brief PostComponentActionListenerType listener array 01112 # The PostComponentActionListenerType listener is stored. 01113 # @endif 01114 postaction_num = PostComponentActionListenerType.POST_COMPONENT_ACTION_LISTENER_NUM 01115 postaction_ = [PostComponentActionListenerHolder() 01116 for i in range(postaction_num)] 01117 01118 ## 01119 # @if jp 01120 # @brief PortActionListenerTypeリスナ配列 01121 # PortActionListenerTypeリスナを格納 01122 # @else 01123 # @brief PortActionListenerType listener array 01124 # The PortActionListenerType listener is stored. 01125 # @endif 01126 portaction_num = PortActionListenerType.PORT_ACTION_LISTENER_NUM 01127 portaction_ = [PortActionListenerHolder() 01128 for i in range(portaction_num)] 01129 01130 ## 01131 # @if jp 01132 # @brief ExecutionContextActionListenerTypeリスナ配列 01133 # ExecutionContextActionListenerTypeリスナを格納 01134 # @else 01135 # @brief ExecutionContextActionListenerType listener array 01136 # The ExecutionContextActionListenerType listener is stored. 01137 # @endif 01138 ecaction_num = ExecutionContextActionListenerType.EC_ACTION_LISTENER_NUM 01139 ecaction_ = [ExecutionContextActionListenerHolder() 01140 for i in range(ecaction_num)]