[openrtm-commit:01618] r2672 - trunk/OpenRTM-aist/src/lib/rtm

openrtm @ openrtm.org openrtm @ openrtm.org
2015年 10月 27日 (火) 16:18:14 JST


Author: n-ando
Date: 2015-10-27 16:18:13 +0900 (Tue, 27 Oct 2015)
New Revision: 2672

Modified:
   trunk/OpenRTM-aist/src/lib/rtm/CorbaNaming.cpp
   trunk/OpenRTM-aist/src/lib/rtm/CorbaNaming.h
Log:
[incompat,new_func] Two new functions list() and listByKind() have been added. These functions returns all or specified kind binding list according to specified absolute string path. refs #3263

Modified: trunk/OpenRTM-aist/src/lib/rtm/CorbaNaming.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/CorbaNaming.cpp	2015-10-20 02:40:00 UTC (rev 2671)
+++ trunk/OpenRTM-aist/src/lib/rtm/CorbaNaming.cpp	2015-10-27 07:18:13 UTC (rev 2672)
@@ -556,9 +556,9 @@
    * @endif
    */
   void CorbaNaming::list(CosNaming::NamingContext_ptr name_cxt,
-			 CORBA::ULong how_many,
-			 CosNaming::BindingList_var& bl,
-			 CosNaming::BindingIterator_var& bi)
+                         CORBA::ULong how_many,
+                         CosNaming::BindingList_var& bl,
+                         CosNaming::BindingIterator_var& bi)
   {
 #ifndef ORB_IS_RTORB
     name_cxt->list(how_many, bl.out(), bi.out());
@@ -571,6 +571,93 @@
   
   /*!
    * @if jp
+   * @brief 与えられた Naming パス以下のすべてのバインディングを取得する
+   * @else
+   * @brief Get all the binding under given naming path
+   * @endif
+   */
+  void CorbaNaming::list(const char* string_name,
+                         CosNaming::BindingList_var& bl)
+  {
+    if (string_name == 0) { return; }
+    CORBA::Object_var obj = resolveStr(string_name);
+    CosNaming::NamingContext_var nc;
+    nc = CosNaming::NamingContext::_narrow(obj);
+    if (CORBA::is_nil(nc))
+      {
+        bl->length(0);
+        return;
+      }
+    CORBA::Long max_list_size(65536);
+    CosNaming::BindingIterator_var bi;
+#ifndef ORB_IS_RTORB
+    nc->list(max_list_size, bl.out(), bi.out());
+#else // ORB_IS_RTORB
+    nc->list(max_list_size, (CosNaming::BindingList_out)bl,
+             (CosNaming::BindingIterator_ptr)bi);
+#endif // ORB_IS_RTORB
+    CORBA::Long   max_remaining = max_list_size - bl->length();
+    CORBA::Boolean more_bindings = !CORBA::is_nil(bi);
+    
+    if (more_bindings)
+      {
+        while (more_bindings && (max_remaining > 0))
+          {
+            CosNaming::BindingList_var tmp_bl;
+            more_bindings = bi->next_n(max_remaining, tmp_bl.out());
+            //Append 'tmp_bl' to 'bl'
+            CORBA::ULong bl_len = bl->length();
+            bl->length(bl_len + tmp_bl->length());
+            for (CORBA::ULong i(0); i < tmp_bl->length(); ++i)
+              {
+                bl[i + bl_len] = tmp_bl[i];
+              }
+            max_remaining = max_list_size - bl->length();
+          }
+        bi->destroy();
+      }
+    return;
+  }
+  
+  /*!
+   * @if jp
+   * @brief 与えられたパス以下の指定されたkindのバインディングを取得する
+   * @else
+   * @brief Get all the binding with specified kind under given naming path
+   * @endif
+   */
+  void CorbaNaming::listByKind(const char* string_name,
+                               const char* string_kind,
+                               CosNaming::BindingList_var& bl)
+  {
+    if (string_name == 0) { bl->length(0); return; }
+    if (string_kind == 0) { bl->length(0); return; }
+    std::string kind(string_kind);
+
+    CosNaming::BindingList_var tmp_bl; // = new CosNaming::BindingList();
+    list(string_name, tmp_bl);
+
+    CORBA::ULong tmp_len(tmp_bl->length());
+    bl->length(tmp_bl->length());
+    CORBA::ULong list_len(0);
+    for (CORBA::ULong i(0); i < tmp_len; ++i)
+      {
+        if (tmp_bl[i].binding_type != CosNaming::nobject) { continue; }
+        CORBA::ULong last_index = tmp_bl[i].binding_name.length() - 1;
+        const char* tmp = tmp_bl[i].binding_name[last_index].kind;
+        if (kind != tmp) { continue; }
+
+        bl[list_len] = tmp_bl[i];
+        ++list_len;
+        const char* tmp_char = toString(tmp_bl[i].binding_name);
+        delete tmp_char;
+      }
+    bl->length(list_len);
+    return;
+  }
+
+  /*!
+   * @if jp
    * @brief 与えられた NameComponent の文字列表現を返す
    * @else
    * @brief Get string representation of given NameComponent

Modified: trunk/OpenRTM-aist/src/lib/rtm/CorbaNaming.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/CorbaNaming.h	2015-10-20 02:40:00 UTC (rev 2671)
+++ trunk/OpenRTM-aist/src/lib/rtm/CorbaNaming.h	2015-10-27 07:18:13 UTC (rev 2672)
@@ -1106,9 +1106,97 @@
      * @endif
      */
     void list(CosNaming::NamingContext_ptr name_cxt,
-	      CORBA::ULong how_many,
-	      CosNaming::BindingList_var& bl,
-	      CosNaming::BindingIterator_var& bi);
+              CORBA::ULong how_many,
+              CosNaming::BindingList_var& bl,
+              CosNaming::BindingIterator_var& bi);
+    /*!
+     * @if jp
+     * @brief 与えられた Naming パス以下のすべてのバインディングを取得する
+     *
+     * 文字列で指定されたネーミング絶対パス以下のすべてのバインディング
+     * すなわちバインディングのタイプと参照のセットを取得する。パスは、
+     * ルートコンテキストから階層を "/"、名前とコンテキストを "." で区
+     * 切った文字列である。
+     *
+     * 例えば、<name0>.<context0>/.../<name[n]>.<context[n]> を指定する
+     * と<name[n]>.<context[n]> の下にバインドされているコンテキストま
+     * たはオブジェクトリファレンスのリストが BindingList として返され
+     * る。
+     *
+     * @param string_name [in] 文字列で指定されるターゲットのパス
+     * @param bl [out] 指定されたパスの下のバインディングリスト
+     *
+     * @else
+     *
+     * @brief Get all the binding under given naming path
+     *
+     * This operation obtains all the binding list, which are a pair
+     * of binding type and reference, under specified absolute naming
+     * path. The path string consists of the path from root context
+     * delimited by "/" and name and context delimited by ".".
+     *
+     * For example, when <name0>.<context0>/.../<name[n]>.<context[n]>
+     * is specified as the path, this operation returns all the
+     * contexts and references under the "<name[n]>.<context[n]>"
+     * context in a BindingList.
+     *
+     * @param string_name [in] The target path specified by a string
+     * @param bl [out] Binding list under the specified path
+     *
+     * @endif
+     */
+    void list(const char* string_name,
+              CosNaming::BindingList_var& bl);
+
+    /*!
+     * @if jp
+     * @brief 与えられたパス以下の指定されたkindのバインディングを取得する
+     *
+     * 文字列で指定されたネーミング絶対パス以下のうち、指定された kind
+     * を持つすべてのバインディングを取得する。パスは、ルートコンテキス
+     * トから階層を "/"、名前とコンテキストを "." で区切った文字列であ
+     * る。
+     *
+     * 例えば、第1引数にパス
+     * <name0>.<context0>/.../<name[n]>.<context[n]> を指定し、第2引数
+     * の kind "hoge" を指定すると、と<name[n]>.<context[n]> の下にバイ
+     * ンドされているコンテキストまたはオブジェクトリファレンスのリスト
+     * のうち kind が "hoge" のものが BindingList として返される。
+     *
+     * 例えば、<name0>.<context0>/.../<name[n]>.<context[n]> を指定する
+     * と<name[n]>.<context[n]> の下にバインドされているコンテキストま
+     * たはオブジェクトリファレンスのリストが BindingList として返され
+     * る。
+     *
+     * @param string_name [in] 文字列で指定されるターゲットのパス
+     * @param string_kind [in] 文字列で指定されるターゲットのkind
+     * @param bl [out] 指定されたパスの下のバインディングリスト
+     *
+     * @else
+     *
+     * @brief Get all the binding with specified kind under given naming path
+     *
+     * This operation obtains all the binding list with specified kind
+     * under specified absolute naming path. The path string consists
+     * of the path from root context delimited by "/" and name and
+     * context delimited by ".".
+     *
+     * For example, when <name0>.<context0>/.../<name[n]>.<context[n]>
+     * is specified in the first argument as the path, and "hoge" is
+     * specified the second argument as the kind, this operation
+     * returns all the contexts and references under the
+     * "<name[n]>.<context[n]>" context with kind "hoge" in a
+     * BindingList.
+     *
+     * @param string_name [in] The target path specified by a string
+     * @param string_kind [in] The target kind specified by a string
+     * @param bl [out] Binding list under the specified path
+     *
+     * @endif
+     */
+    void listByKind(const char* string_name,
+                    const char* string_kind,
+                    CosNaming::BindingList_var& bl);
     
     //============================================================
     // interface of NamingContextExt



More information about the openrtm-commit mailing list