OpenRTM / OpenRTM-aist

OpenRTM-aist: RT-Middleware and OMG RTC implementation in C++ implemented by AIST
https://openrtm.org/
Other
19 stars 12 forks source link

shutdown関数とfinalize関数の違いが不明 #668

Closed Nobu19800 closed 3 years ago

Nobu19800 commented 4 years ago

RTObject_implクラスにshutdown関数とfinalize関数が定義されているが違いが分からない。 finalize関数は実質shutdown関数を呼ぶだけのため存在意義が不明。

n-ando commented 3 years ago

5.2.2.2.4 exit Description Stop the RTC’s execution context(s) and finalize it along with its contents. Semantics Any execution contexts for which the RTC is the owner shall be stopped. If the RTC participates in any execution contexts belonging to another RTC that contains it, directly or indirectly (i.e., the containing RTC is the owner of the ExecutionContext), it shall be deactivated in those contexts. After the RTC is no longer Active in any Running execution context, it and any RTCs contained transitively within it shall be finalized. Constraints

  • An RTC cannot be exited if it has not yet been initialized. Any attempt to exit an RTC that is in the Created state shall fail with ReturnCode_t::PRECONDITION_NOT_MET.

5.2.2.2.2 finalize Description Finalize the RTC that realizes this interface, preparing it for destruction. Semantics This invocation of this operation shall result in the invocation of the callback ComponentAction::on_finalize. Constraints

  • An RTC may not be finalized while it is participating in any execution context. It must first be removed with ExecutionContextOperations::remove_component. Otherwise, this operation shall fail with
  • ReturnCode_t::PRECONDITION_NOT_MET. See Figure 5.10 .
  • An RTC may not be finalized while it is in the Created state. Any attempt to invoke this operation while in that state shall fail with ReturnCode_t::PRECONDITION_NOT_MET.
  • Application developers are not expected to call this operation directly; it exists for use by the RTC infrastructure.
Nobu19800 commented 3 years ago

それだとexit関数やinitialize関数には実装のための関数がないので、finalize関数にも実装のためのshutdown関数は必要ないという事にはならないのでしょうか?

n-ando commented 3 years ago

単なる関数分割の問題です。

逆に、exitとinitializeは、finalize/on_initialize をコールする以外の雑多な仕事がそのまま書かれているので、別の関数に移したほうがいいかもしれない。

  ReturnCode_t RTObject_impl::initialize()
  {
    RTC_TRACE(("initialize()"));

   initSdoService(); // これは initを呼ぶだけだから、そのままでもいいけど
   createOwnedContext();

    ReturnCode_t ret;
    ret = on_initialize();
    m_created = false;
    if (ret != RTC::RTC_OK)
      {
        RTC_ERROR(("on_initialize() failed."));
        return ret;
      }
    startOwnecContext()

    assert(ret == RTC::RTC_OK);
    return ret;
  }

  ReturnCode_t RTObject_impl::exit()
  {
    RTC_TRACE(("exit()"));
    if (m_created) { return RTC::PRECONDITION_NOT_MET; }
    if (m_exiting) { return RTC::RTC_OK; }

    deactivateContexts();
    detachOtherContexts();
    m_exiting = true;
    ReturnCode_t ret(finalize());

    return ret;
  }

CORBA関数はできるだけ抽象度は高くして全体の見通しが付きやすいようにしておきたいので。

Nobu19800 commented 3 years ago

923 のissueを新たに作成したのでcloseします。