ExtTrigExecutionContext.py

説明を見る。
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 ##
00005 # @file ExtTrigExecutionContext.py
00006 # @brief ExtTrigExecutionContext class
00007 # @date $Date: 2007/09/06$
00008 # @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara
00009 #
00010 # Copyright (C) 2007-2008
00011 #    Task-intelligence Research Group,
00012 #    Intelligent Systems Research Institute,
00013 #    National Institute of
00014 #        Advanced Industrial Science and Technology (AIST), Japan
00015 #    All rights reserved.
00016 
00017 
00018 
00019 import threading
00020 import time
00021 
00022 import OpenRTM
00023 import RTC, RTC__POA
00024 
00025 
00026 
00027 ##
00028 # @if jp
00029 # @class ExtTrigExecutionContext
00030 # @brief ステップ実行が可能な ExecutionContext クラス
00031 #
00032 # 1周期毎の実行が可能なPeriodic Sampled Data Processing(周期実行用)
00033 # ExecutionContextクラス。
00034 # 外部からのメソッド呼びだしによって時間を1周期づつ進めることができる。
00035 #
00036 # @since 0.4.0
00037 #
00038 # @else
00039 # @class ExtTrigExecutionContext
00040 # @endif
00041 class ExtTrigExecutionContext(OpenRTM.PeriodicExecutionContext):
00042   """
00043   """
00044 
00045 
00046   ##
00047   # @if jp
00048   # @brief コンストラクタ
00049   #
00050   # コンストラクタ
00051   #
00052   # @param self
00053   #
00054   # @else
00055   # @brief Constructor
00056   # @endif
00057   def __init__(self):
00058     OpenRTM.PeriodicExecutionContext.__init__(self)
00059     self._worker = self.Worker()
00060 
00061 
00062   ##
00063   # @if jp
00064   # @brief 処理を1ステップ進める
00065   #
00066   # ExecutionContextの処理を1周期分進める。
00067   #
00068   # @param self
00069   #
00070   # @else
00071   #
00072   # @endif
00073   def tick(self):
00074     if not self._worker._cond.acquire(0):
00075       return
00076     self._worker._called = True
00077     self._worker._cond.notify()
00078     self._worker._cond.release()
00079     return
00080 
00081   ##
00082   # @if jp
00083   # @brief 各 Component の処理を呼び出す。
00084   # 
00085   # ExecutionContext に attach されている各 Component の処理を呼び出す。
00086   # 全 Component の処理を呼び出した後、次の呼出が発生するまで休止する。
00087   # 
00088   # @param self
00089   # 
00090   # @else
00091   # 
00092   # @endif
00093   # 
00094   def run(self):
00095     flag = True
00096 
00097     while flag:
00098       flag = self._running
00099       sec_ = float(self._usec)/1000000.0
00100       self._worker._cond.acquire()
00101       while not self._worker._called and self._running:
00102         self._worker._cond.wait()
00103       if self._worker._called:
00104         self._worker._called = False
00105         for comp in self._comps:
00106 #          self.invoke_worker()(comp)
00107           comp._sm.worker()
00108         while not self._running:
00109           time.sleep(sec_)
00110         time.sleep(sec_)
00111       self._worker._cond.release()
00112 
00113   ##
00114   # @if jp
00115   # @class Worker
00116   # @brief ExecutionContext 駆動クラス
00117   #
00118   # 実行処理に関する排他制御など、実際の処理を監視・制御するためのクラス。
00119   #
00120   # @since 0.4.0
00121   #
00122   # @else
00123   #
00124   # @endif
00125   class Worker:
00126     
00127     
00128     
00129     ##
00130     # @if jp
00131     # @brief コンストラクタ
00132     #
00133     # コンストラクタ
00134     #
00135     # @param self
00136     #
00137     # @else
00138     # @brief Constructor
00139     # @endif
00140     def __init__(self):
00141       self._mutex = threading.RLock()
00142       self._cond = threading.Condition(self._mutex)
00143       self._called = False
00144 
00145 
00146 
00147 ##
00148 # @if jp
00149 # @brief 当該 ExecutionContext 用Factoryクラスの登録。
00150 #
00151 # このExecutionContextを生成するFactoryクラスを
00152 # ExecutionContext管理用ObjectManagerに登録する。
00153 #
00154 # @else
00155 #
00156 # @endif
00157 def ExtTrigExecutionContextInit(manager):
00158   manager.registerECFactory("ExtTrigExecutionContext",
00159                 OpenRTM.ExtTrigExecutionContext,
00160                 OpenRTM.ECDelete)

OpenRTMに対してMon Mar 17 15:11:05 2008に生成されました。  doxygen 1.5.4