[openrtm-beginners:00332] Re: Deactivate RTC from onExecute

Ando Noriaki n-ando @ aist.go.jp
2012年 1月 31日 (火) 01:03:13 JST


Hello,

This is an example code in C++.

  ReturnCode_t RTObject_impl::onExecute(RTC::UniqueId ec_id)
  {
      : // you code
   if (gotoInactiveState)
     {
       RTC::ExecutionContext_var ec = get_context(ec_id);
       if (CORBA::is_nil(ec))
        {
           ec->deactivate_component(::RTC::RTObject::_duplicate(getObjRef()));
        }
     }
      : // your code
    return RTC::RTC_OK;
  }

 In the next execution tick, onDeactivated() will be called and
RTC will be in the INACTIVE state.

From OpenRTM-aist-1.1.0, getExecutionContext(), deactivate(),
activate() and reset() functions are introduced in DataflowComponentBase.

Best regards,
Noriaki Ando



-- 
Noriaki Ando, Ph.D.
    Senior Research Scientist, RT-Synthesis R.G., ISRI, AIST
    AIST Tsukuba Central 2, Tsukuba, Ibaraki 305-8568 JAPAN
    e-mail: n-ando @ aist.go.jp, web: http://staff.aist.go.jp/n-ando
    OpenRTM-aist: http://www.openrtm.org



2012年1月30日23:02 Geoffrey Biggs <geoffrey.biggs @ aist.go.jp>:
> onExecute receives the handle to the execution context that is executing it. You can use this with the component's get_context() method to get the execution context itself. Then you can use the EC's deactivate_component() method to deactivate the component. However, to avoid a deadlock, you will need to do this from a separate thread.
>
> In general, components are not meant to control their own life cycles, which is why it isn't so straight-forward to do. We usually prefer to signal an event somehow and have an external entity do the coordination.
>
> Geoff
>
> On Jan 30, 2012, at 8:59 PM, owh @ ieee.org wrote:
>
>> How can I deactivate RT-component from within the program? For example, from
>> onExecute, or from other method. An illustrative case is that a user input
>> toggled a bool variable, which is being checked in onExecute to decide if to
>> deactivate (NOT exit) the component. Hope to get some help.
>>
>> _______________________________________________
>> openrtm-beginners mailing list
>> openrtm-beginners @ openrtm.org
>> http://www.openrtm.org/mailman/listinfo/openrtm-beginners
>
> _______________________________________________
> openrtm-beginners mailing list
> openrtm-beginners @ openrtm.org
> http://www.openrtm.org/mailman/listinfo/openrtm-beginners


openrtm-beginners メーリングリストの案内