OpenRTM-aist-Python 2.0.2
OpenRTM_aist.ExecutionContextBase.ExecutionContextBase クラス

[詳解]

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase の継承関係図
OpenRTM_aist.ExecutionContextBase.ExecutionContextFactory OpenRTM_aist.ExtTrigExecutionContext.ExtTrigExecutionContext OpenRTM_aist.OpenHRPExecutionContext.OpenHRPExecutionContext OpenRTM_aist.PeriodicExecutionContext.PeriodicExecutionContext OpenRTM_aist.SimulatorExecutionContext.SimulatorExecutionContext OpenRTM_aist.EventDrivenExecutionContext.EventDrivenExecutionContext OpenRTM_aist.MultilayerCompositeEC.MultilayerCompositeEC

公開メンバ関数

 init (self, props)
 
 exit (self)
 
 bindComponent (self, rtc)
 
 isRunning (self)
 
 start (self)
 
 stop (self)
 
 getRate (self)
 
 setRate (self, rate)
 
 addComponent (self, comp)
 
 removeComponent (self, comp)
 
 activateComponent (self, comp)
 
 deactivateComponent (self, comp)
 
 resetComponent (self, comp)
 
 getComponentState (self, comp)
 
 getKind (self)
 
 getProfile (self)
 
 setObjRef (self, ec_ptr)
 
 getObjRef (self)
 
 getKindString (self, kind)
 
 setKind (self, kind)
 
 setOwner (self, comp)
 
 getOwner (self)
 
 getComponentList (self)
 
 setProperties (self, props)
 
 getProperties (self)
 
 isAllCurrentState (self, state)
 
 setExecutionRate (self, props)
 
 setTransitionMode (self, props, key, flag=False)
 
 setTimeout (self, props, key, timevalue=0.0)
 

詳解

ExecutionContext用基底クラス

ECの実装クラスでは、この基底クラスを継承し、かつECのCORBAオペレー ションを実装しなければならない。さらに、実際にロジックを駆動するた め、幾つかの約束に則りExecutionContextBaseの関数を呼び出す必要があ る。ECのCORBAオペレーションは以下のものがあり、それぞれ ExecutionContextBaseのメンバ関数に対応している。

実行状態に関係する関数と実装方法

実行状態に関係する関数は、is_running(), start(), stop() の3つがあ る。ExecutionContextBaseでは単純に running/stopped のフラグを持っ ており、start/stopでフラグのON/OFF切り替え、is_running()で状態読み 出しを行っている。通常、ECの実装クラスでは、protected な仮想メン バ関数 onStarting(), onStarted(), onStopping(), onStopped() 関数を 実装したうえで、CORBAオペレーションを以下のように実装する必要がある。

is_running() のCORBAオペレーションでは、単純に ExecutionContextBaseisRunning() を呼び出すだけである。この関数 に関連する protected 仮想関数はonIsRunning() が用意されているが、 通常特に実装する必要はない。あえて、現在の running/stopped 状態を 書き換えたい場合にこの関数を利用することができるが推奨はされない。

 public:
  CORBA.Boolean is_runing()
  {
    return ExecutionContextBase.isRunning();
  }
 protected:
  CORBA.Boolean onIsRunning(CORBA.Boolean running)
  {
    return running;
  }
 

start(), stop() CORBAオペレーションでは、通常 ExecutionContextBasestart(), stop() 関数を呼び出すよう実装する。 この関数に関連する protected 仮想関数は、start() および stop() に ついてそれぞれ2つづつの onStarting(), onStarted(), および onStopping(), onStopped() 関数がある。ECの実装クラスにおいては、そ れぞれ以下のように実装する。

  RTC.ReturnCode_t start()
  {
    return ExecutionContextBase.start();
  }
  RTC.ReturnCode_t stop()
  {
    return ExecutionContextBase.stop();
  }
 protected:
  RTC.ReturnCode_t onStarting()
  {
    RTC.ReturnCode_t ret = // スレッドを開始する処理など
    return ret;
  }
  RTC.ReturnCode_t onStarted()
  {
    RTC.ReturnCode_t ret = // スレッドを開始する処理など
    return ret;
  }
  RTC.ReturnCode_t onStopping()
  {
    // スレッドを停止する処理など
    return retcode;
  }
  RTC.ReturnCode_t onStopped()
  {
    // スレッドを停止する処理など
    return retcode;
  }
 
実行周期に関する関数と実装方法
  • get_rate(): ExecutionContextBase.gatRate()
  • set_rate(): ExecutioinContextBase.setRate()

実行周期に関する関数は set_rate(), get_rate() の2種類がある。実装 する実行コンテキストがもし set_rate() により指定される周期を利用する 場合、テンプレート関数 onSetRate() をオーバーライドし実装する。 onSetRate() は引数に double 型の周期を取り、この値は正当な値である ことが保証されている。onSetRate() がRTC.RTC_OK 以外の値を返した場 合、ECのProfileの周期は設定される以前の値を保持することが保証され る。

set_rate() 同様 get_rate() 呼び出し時にonGetRate() が呼び出される が、これは通常オーバーライドする必要はない。ただし、get_rate() が 返す値を変更したい場合、onGetRate() をオーバーライドすることでその 値を書き換えることができる。ただし、これは推奨されない。

 public:
  RTC.ReturnCode_t set_rate(double rate)
  {
    return setRate(rate);
  }
  double get_rate(void) const
  {
    return getRate();
  }
 protected:
  virtual RTC.ReturnCode_t onSetRate(double rate)
  {
    RTC.ReturnCode_t ret = // 周期を設定する何らかの処理
    if (ret != RTC.RTC_OK)
      {
        RTC_ERROR(("Error message"));
      }
    return ret;
  }
  virtual double onGetRate(rate)
  {
    // get_rate() が返す値を加工したい場合
    // 通常はこの関数を実装する必要はない。
    return rate;
  }
 
コンポーネントの追加と削除に関する関数

コンポーネントの追加と削除に関する関数は、add_component(), remove_component() の二種類がある。実行コンテキストの実装クラスに おいては、ExecutionContextBase のそれぞれ addComponent(), removeComponent() を呼び出す形で実装を行う。これらの関数に関連する protected 仮想関数は onAddingComponent(), onAddedComponent(), onRemovingComponent(), onRemovedComponent() の4種類ある。ただし、 これらの仮想関数は通常オーバーライドする必要はなく、使用は推奨され ない。

 public:
  RTC.ReturnCode_t add_component(RTC.LightweightRTObject_ptr comp)
  {
    return ExecutionContextBase.addComponent(comp);
  }
  RTC.ReturnCode_t remove_component(RTC.LightweightRTObject_ptr comp)
  {
    return ExecutionContextBase.removeComponent(comp);
  }
 protected:
  virtual RTC.ReturnCode_t
  onAddingComponent(RTC.LightweightRTObject rtobj)
  {
     // コンポーネント追加時に実行したい処理を記述
     // RTC.RTC_OK 以外を返した場合、コンポーネントの追加は行われない。
     return RTC.RTC_OK;
  }
  virtual RTC.ReturnCode_t
  onAddedComponent(RTC.LightweightRTObject rtobj)
  {
     // コンポーネント追加時に実行したい処理を記述
     // RTC.RTC_OK 以外を返した場合、removeComponent() が呼び出され、
     // 追加されたコンポーネントが削除される。
     return RTC.RTC_OK;
  }
  virtual RTC.ReturnCode_t
  onRemovingComponent(RTC.LightweightRTObject rtobj)
  {
     // コンポーネント削除時に実行したい処理を記述
     // RTC.RTC_OK 以外を返した場合、コンポーネントの削除は行われない。
     return RTC.RTC_OK;
  }
  virtual RTC.ReturnCode_t
  onRemovedComponent(RTC.LightweightRTObject rtobj)
  {
     // コンポーネント追加時に実行したい処理を記述
     // RTC.RTC_OK 以外を返した場合、addComponent() が呼び出され、
     // 削除されたコンポーネントが再び追加される。
     return RTC.RTC_OK;
  }
 
コンポーネントのアクティブ化等に関する関数

コンポーネントのアクティブ化等に関する関数は、 activate_component(), deactivate_component(), reset_component() の 三種類がある。実行コンテキストの実装クラスにおいては、 ExecutionContextBase のそれぞれ activateComponent(), deactivateComponent(), resetComponent() を呼び出す形で実装を行う。 これらの関数に関連する protected 仮想関数は onActivatingComponent(), onAtivatingComponent(), onActivatedComponent(), onDeactivatingComponent(), onDeactivatedComponent(), onResettingComponent(), onResetComponent() の6種類ある。ただし、これらの仮想関数は通常オー バーライドする必要はなく、使用は推奨されない。

 public:
  RTC.ReturnCode_t add_component(RTC.LightweightRTObject_ptr comp)
  {
    return ExecutionContextBase.addComponent(comp);
  }
  RTC.ReturnCode_t remove_component(RTC.LightweightRTObject_ptr comp)
  {
    return ExecutionContextBase.removeComponent(comp);
  }
 protected:
  virtual RTC.ReturnCode_t
  onAddingComponent(RTC.LightweightRTObject rtobj)
  {
    // コンポーネント追加時に実行したい処理を記述
    // RTC.RTC_OK 以外を返した場合、コンポーネントの追加は行われない。
    return RTC.RTC_OK;
  }
  virtual RTC.ReturnCode_t
  onAddedComponent(RTC.LightweightRTObject rtobj)
  {
    // コンポーネント追加時に実行したい処理を記述
    // RTC.RTC_OK 以外を返した場合、removeComponent() が呼び出され、
    // 追加されたコンポーネントが削除される。
    return RTC.RTC_OK;
  }
  virtual RTC.ReturnCode_t
  onRemovingComponent(RTC.LightweightRTObject rtobj)
  {
    // コンポーネント削除時に実行したい処理を記述
    // RTC.RTC_OK 以外を返した場合、コンポーネントの削除は行われない。
    return RTC.RTC_OK;
  }
  virtual RTC.ReturnCode_t
  onRemovedComponent(RTC.LightweightRTObject rtobj)
  {
    // コンポーネント追加時に実行したい処理を記述
    // RTC.RTC_OK 以外を返した場合、addComponent() が呼び出され、
    // 削除されたコンポーネントが再び追加される。
    return RTC.RTC_OK;
  }
 
実行コンテキストの情報取得に関する関数

実行コンテキストの情報取得に関する関数は、get_component_state(), get_kind(), get_profile() の3種類がある。実行コンテキストの実装ク ラスにおいては、ExecutionContextBase のそれぞれ getComponentState(), getKind(), getProfile() を呼び出す形で実装を 行う。これらの関数に関連する protected 仮想関数は onGetComponentState(), onGetKind(), onGetProfile() の3種類ある。こ れらの仮想関数は通常オーバーライドする必要はなく、使用は推奨されな い。ただし、返す情報を変更したい場合は、これらの関数を適切に実装す ることで、呼び出し側に返す値を上書きすることができる。

 public:
  LifeCycleState get_component_state(RTC.LightweightRTObject_ptr comp)
  {
    return getComponentState(comp);
  }
  ExecutionKind PeriodicExecutionContext.get_kind()
  {
    return getKind();
  }
  ExecutionContextProfile* get_profile()
  {
    return getProfile();
  }

 protected:
  virtual LifeCycleState onGetComponentState(LifeCycleState state)
  { // 返すstateを書き換えたい場合はこの関数を実装する
    return state;
  }
  virtual ExecutionKind onGetKind(ExecutionKind kind)
  { // 返すkindを書き換えたい場合はこの関数を実装する
    return kind;
  }
  virtual ExecutionContextProfile*
  onGetProfile(ExecutionContextProfile*& profile)
  { // 返すprofileを書き換えたい場合はこの関数を実装する
    return profile;
  }
 

ExecutionContextの基底クラス。

から
0.4.0

メソッド詳解

◆ activateComponent()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.activateComponent ( self,
comp )

RTコンポーネントをアクティブ化する RTC.ReturnCode_t ExecutionContextBase:: activateComponent(RTC.LightweightRTObject_ptr comp)

◆ addComponent()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.addComponent ( self,
comp )

RTコンポーネントを追加する RTC.ReturnCode_t ExecutionContextBase:: addComponent(RTC.LightweightRTObject_ptr comp)

◆ bindComponent()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.bindComponent ( self,
rtc )

ExecutionContextの処理を進める(サブクラス実装用)

ExecutionContextの処理を1周期分進める。
※サブクラスでの実装参照用

引数
self

def tick(self): pass

コンポーネントをバインドする。

コンポーネントをバインドする。

OpenRTM_aist.MultilayerCompositeEC.MultilayerCompositeECで再実装されています。

◆ deactivateComponent()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.deactivateComponent ( self,
comp )

RTコンポーネントを非アクティブ化する RTC.ReturnCode_t ExecutionContextBase:: deactivateComponent(RTC.LightweightRTObject_ptr comp)

◆ exit()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.exit ( self)

◆ getComponentList()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.getComponentList ( self)

RTコンポーネントの参加者リストを取得する

現在登録されている参加者RTCのリストを取得する。

戻り値
参加者RTCのリスト

const RTC.RTCList& getComponentList() const

◆ getComponentState()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.getComponentState ( self,
comp )

RTコンポーネントの状態を取得する

指定したRTコンポーネントの状態(LifeCycleState)を取得する。指定し たRTコンポーネントが参加者リストに含まれない場合は、 UNKNOWN_STATE が返される。

引数
comp状態取得対象RTコンポーネント
戻り値
現在の状態(LifeCycleState)

RTC.LifeCycleState ExecutionContextBase:: getComponentState(RTC.LightweightRTObject_ptr comp)

◆ getKind()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.getKind ( self)

ExecutionKind を取得する

本 ExecutionContext の ExecutionKind を取得する

戻り値
ExecutionKind

RTC.ExecutionKind ExecutionContextBase.getKind(void) const

◆ getKindString()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.getKindString ( self,
kind )

ExecutionKind を文字列化する

RTC.ExecutionKind で定義されている PERIODIC, EVENT_DRIVEN, OTHER を文字列化する。

引数
kindExecutionKind
戻り値
文字列化されたExecutionKind

const char* getKindString(RTC.ExecutionKind kind) const

◆ getObjRef()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.getObjRef ( self)

CORBA オブジェクト参照の取得

本オブジェクトの ExecutioncontextService としての CORBA オブジェ クト参照を取得する。

戻り値
CORBA オブジェクト参照

◆ getOwner()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.getOwner ( self)

Ownerコンポーネントの参照を取得する

このECのOwnerであるRTCの参照を取得する。

戻り値
OwnerRTコンポーネントの参照 const RTC.RTObject_ptr getOwner() const

◆ getProfile()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.getProfile ( self)

Profileを取得する

RTC.ExecutionContextProfile を取得する。取得した ExecutionContextProfile の所有権は呼び出し側にある。取得されたオ ブジェクトが不要になった場合、呼び出し側が開放する責任を負う。

戻り値
RTC.ExecutionContextProfile

RTC.ExecutionContextProfile* ExecutionContextBase.getProfile(void)

◆ getProperties()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.getProperties ( self)

Propertiesを取得する

ExecutionContextProfile.properties を取得する。

戻り値
coil.Propertiesに変換された ExecutionContextProfile.properties

const coil.Properties getProperties() const

◆ getRate()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.getRate ( self)

ExecutionContext の実行周期(Hz)を取得する

Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を取得す る。

戻り値
処理周期(単位:Hz)

double getRate(void) const

◆ init()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.init ( self,
props )

ExecutionContextの初期化処理

virtual void init(coil.Properties& props);

OpenRTM_aist.MultilayerCompositeEC.MultilayerCompositeEC, OpenRTM_aist.PeriodicExecutionContext.PeriodicExecutionContextで再実装されています。

◆ isAllCurrentState()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.isAllCurrentState ( self,
state )

Profileを取得する

RTC.ExecutionContextProfile を取得する。取得した ExecutionContextProfile の所有権は呼び出し側にある。取得されたオ ブジェクトが不要になった場合、呼び出し側が開放する責任を負う。

戻り値
RTC.ExecutionContextProfile

RTC.ExecutionContextProfile* getProfile(void) def getProfile(self): return self._profile.getProfile()

◆ isRunning()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.isRunning ( self)

ExecutionContext 実行状態確認関数 CORBA.Boolean ExecutionContextBase.isRunning()

◆ removeComponent()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.removeComponent ( self,
comp )

RTコンポーネントを参加者リストから削除する RTC.ReturnCode_t ExecutionContextBase:: removeComponent(RTC.LightweightRTObject_ptr comp)

◆ resetComponent()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.resetComponent ( self,
comp )

RTコンポーネントをリセットする RTC.ReturnCode_t ExecutionContextBase:: resetComponent(RTC.LightweightRTObject_ptr comp)

◆ setExecutionRate()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.setExecutionRate ( self,
props )

Propertiesから実行コンテキストをセットする bool ExecutionContextBase.setExecutionRate(coil.Properties& props)

◆ setKind()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.setKind ( self,
kind )

ExecutionKind を設定する

この ExecutionContext の ExecutionKind を設定する

引数
kindExecutionKind

RTC.ReturnCode_t setKind(RTC.ExecutionKind kind)

◆ setObjRef()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.setObjRef ( self,
ec_ptr )

CORBA オブジェクト参照の取得

本オブジェクトの ExecutioncontextService としての CORBA オブジェ クト参照を取得する。

戻り値
CORBA オブジェクト参照

void setObjRef(RTC.ExecutionContextService_ptr ec_ptr)

◆ setOwner()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.setOwner ( self,
comp )

Ownerコンポーネントをセットする。

このECのOwnerとなるRTCをセットする。

引数
compOwnerとなるRTコンポーネント
戻り値
ReturnCode_t 型のリターンコード RTC.ReturnCode_t setOwner(RTC.LightweightRTObject_ptr comp)

◆ setProperties()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.setProperties ( self,
props )

Propertiesをセットする

ExecutionContextProfile.properties をセットする。

引数
propsExecutionContextProfile.properties にセットするプ ロパティー

void setProperties(coil.Properties& props)

◆ setRate()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.setRate ( self,
rate )

ExecutionContext の実行周期(Hz)を設定する

Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を設定す る。実行周期の変更は、DataFlowComponentAction の on_rate_changed によって各RTコンポーネントに伝達される。

引数
rate処理周期(単位:Hz)
戻り値
ReturnCode_t 型のリターンコード RTC_OK: 正常終了 BAD_PARAMETER: 設定値が負の値

RTC.ReturnCode_t setRate(double rate)

◆ setTimeout()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.setTimeout ( self,
props,
key,
timevalue = 0.0 )

Propertiesから状態遷移Timeoutをセットする bool ExecutionContextBase:: setTimeout(coil.Properties& props, const char* key, coil.TimeValue& timevalue)

◆ setTransitionMode()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.setTransitionMode ( self,
props,
key,
flag = False )

Propertiesから状態遷移モードをセットする bool ExecutionContextBase:: setTransitionMode(coil.Properties& props, const char* key, bool& flag)

◆ start()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.start ( self)

◆ stop()

OpenRTM_aist.ExecutionContextBase.ExecutionContextBase.stop ( self)

このクラス詳解は次のファイルから抽出されました: