[openrtm-commit:00592] r501 - in trunk/OpenRTM-aist-Python/OpenRTM_aist: . ext ext/local_service ext/local_service/nameservice_file test
openrtm @ openrtm.org
openrtm @ openrtm.org
2012年 1月 18日 (水) 17:24:10 JST
Author: kurihara
Date: 2012-01-18 17:24:10 +0900 (Wed, 18 Jan 2012)
New Revision: 501
Added:
trunk/OpenRTM-aist-Python/OpenRTM_aist/ListenerHolder.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceAdmin.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceBase.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/ManagerActionListener.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/ext/local_service/
trunk/OpenRTM-aist-Python/OpenRTM_aist/ext/local_service/nameservice_file/
trunk/OpenRTM-aist-Python/OpenRTM_aist/ext/local_service/nameservice_file/FileNameservice.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ListenerHolder.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_LocalServiceAdmin.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ManagerActionListener.py
Modified:
trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
Log:
LocalService framework to realize additional services in the manager has been introduced.
Manager's call-backs to hook manager's events (manager, naming, RTC creation, etc.) have been implemented.
Local service extention, File nameservice has been introduced. refs #2302
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py 2012-01-10 05:57:47 UTC (rev 500)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -75,6 +75,7 @@
"manager.name", "manager",
"manager.command", "rtcd",
"manager.language", "Python",
+ "manager.local_service.enabled_services","ALL",
"sdo.service.provider.enabled_service", "ALL",
"sdo.service.consumer.enabled_service", "ALL",
""]
Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/ListenerHolder.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/ListenerHolder.py (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/ListenerHolder.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -0,0 +1,202 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file ListnerHolder.py
+# @brief Listener holder class
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp> and Shinji Kurihara
+#
+# Copyright (C) 2011
+# Noriaki Ando
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+#
+# $Id$
+#
+
+import threading
+import OpenRTM_aist
+
+
+##
+# @if jp
+# @class Listener ホルダークラス
+#
+# このクラスは、リスナクラスの単純な保持、管理を行うリスナホルダクラ
+# スである。このクラスを利用するためには、テンプレートの第1引数に当
+# たるリスナクラス (Listenerクラス) および、このListenerHolderクラス
+# テンプレートを継承して、実際にリスナの呼び出しを行う
+# ListenerHolder実装クラスを実装する必要がある。
+#
+# このクラスは、スレッドセーブを実現するため、リスナの追加と削除につ
+# いてはミューテックスによるロックを行っている。完全にスレッドセーフ
+# なリスナ管理を実現するためにはリスナのコールバックをコールする際に
+# もミューテックによるロックを行う必要がある。
+#
+# @section Listenerクラスの定義
+#
+# イベント発生時にコールバックされるメンバ関数を持つ基底クラスを定義
+# する。コールバックのためのメンバ関数は、任意の戻り値、引数を持つも
+# のが定義でき、通常の関数であってもよいし、operator()などのファンク
+# タとして定義してもよい。実際には基底クラスにてこれらの関数を純粋仮
+# 想関数として定義し、このクラスを継承して、実際のリスナクラスを実装
+# することになる。また、ひとつのリスナクラスに複数のコールバック関数
+# を定義してもよい。実際には、これらのコールバック関数を実際に呼び出
+# す方法に関しては、次のListenerHolder実装クラスにて詳しく定義するこ
+# とになる。
+# <pre>
+# class MyListenerBase
+# {
+# public:
+# // コールバック関数1: 関数呼び出し演算子によるコールバック関数
+# // いわゆるファンクタのようにコールバック関数を定義する例。
+# virtual void operator()(std::string strarg) = 0; // 純粋仮想関数
+#
+# // コールバックの関数シグニチャが多様である場合、このように単な
+# // るメンバ関数として定義することも可能。
+# virtual void onEvent0(const char* arg0) = 0;
+# virtual void onEvent1(int arg0) = 0;
+# virtual void onEvent2(double arg0) = 0;
+# virtual void onEvent3(HogeProfile& arg0) = 0;
+# };
+# </pre>
+#
+# @section ListenerHolder実装クラス
+#
+# ListenerHolder実装クラスはこのLsitenerHolderクラステンプレートを継
+# 承して、上で定義した MyListenerBase クラスの追加と削除など管理を行
+# い、かつ実際にコールバック関数を呼び出す部分を実装することになる。
+# 実際にコールバックを呼び出す部分では、関数シグニチャが多種多様であっ
+# たり、ひとつのリスナクラスが複数のコールバック関数を持つ場合がある
+# ため、個別のリスナクラスに対応するため、この呼び出し部分が必要とな
+# る。ListenerHolder実装クラスは、MyListenerBaseクラスと同じシグニチャ
+# を持つメンバ関数をもち、関数内部では、ListenerHolderクラスが持つ、
+# m_listeners, m_mutex のこれら二つのメンバ変数を利用して、登録され
+# たリスナオブジェクトのメンバ変数を呼び出す。
+#
+# <pre>
+# class MyListenerHolderImpl
+# : public ::RTM::util::ListenerHolder<MyListenerBase>
+# {
+# public:
+# // 関数呼び出し演算子のコールバック関数の場合
+# virtual void operator()(std::string strarg)
+# {
+# Gurad gurad(m_mutex);
+# for (int i(0), len(m_listeners.size()); i < len; ++i)
+# {
+# m_listeners[i].first->operator()(strarg);
+# }
+# }
+#
+# virtual void onEvent0(const char* arg0)
+# {
+# Gurad gurad(m_mutex);
+# for (int i(0), len(m_listeners.size()); i < len; ++i)
+# {
+# m_listeners[i].first->onEvent(arg0);
+# }
+# }
+# };
+# </pre>
+#
+# リスナオブジェクトへのポインタを格納しているEntryオブジェクトは
+# std::pair<ListenerClass, bool> として定義されており、firstが
+# Listenerオブジェクトへのポインタ、secondが自動削除フラグである。し
+# たがって、リスナオブジェクトへアクセスする場合にはfirstを使用する。
+# マルチスレッド環境で利用することが想定される場合は、Guard
+# guard(m_mutex) によるロックを忘れずに行うこと。
+#
+# @section ListenerHolder実装クラスの利用
+# 実装されたMyListenerHolderImplは一例として以下のように利用する。
+#
+# <pre>
+# // たとえばクラスメンバとして宣言
+# MyListenerHolderImpl m_holder;
+#
+# // 登録、自動クリーンモードで登録、
+# // オブジェクトの削除はHolderクラスに任せる
+# m_holder.addListener(new MyListener0(), true); // MyListener0の
+#
+# // コールバックを呼び出す
+# m_holder.operator()(strarg);
+# m_holder.onEvent0("HogeHoge);
+# </pre>
+#
+# @else
+#
+# @class Listener holder class
+#
+# @endif
+#
+class ListenerHolder:
+ """
+ """
+
+ ##
+ # @if jp
+ # @brief ListenerHolderクラスコンストラクタ
+ # @else
+ # @brief ListenerHolder class ctor
+ # @endif
+ def __init__(self):
+ self.listener_mutex = threading.RLock()
+ self.listeners = []
+ return
+
+
+ ##
+ # @if jp
+ # @brief ListenerHolderデストラクタ
+ # @else
+ # @brief ListenerHolder class dtor
+ # @endif
+ def __del__(self):
+ guard = OpenRTM_aist.ScopedLock(self.listener_mutex)
+
+ for listener_ in self.listeners:
+ for (l,f) in listener_.iteritems():
+ if f:
+ del l
+ del guard
+ return
+
+ ##
+ # @if jp
+ # @brief リスナを追加する
+ # @else
+ # @brief add listener object
+ # @endif
+ # virtual void addListener(ListenerClass* listener,
+ # bool autoclean)
+ def addListener(self, listener, autoclean):
+ guard = OpenRTM_aist.ScopedLock(self.listener_mutex)
+ self.listeners.append({listener:autoclean})
+ del guard
+ return
+
+ ##
+ # @if jp
+ # @brief リスナを削除する
+ # @else
+ # @brief remove listener object
+ # @endif
+ # virtual void removeListener(ListenerClass* listener)
+ def removeListener(self, listener):
+ guard = OpenRTM_aist.ScopedLock(self.listener_mutex)
+ for (i, listener_) in enumerate(self.listeners):
+ if listener == listener:
+ del self.listeners[i]
+ return
+ return
+
+ def LISTENERHOLDER_CALLBACK(self, func, *args):
+ guard = OpenRTM_aist.ScopedLock(self.listener_mutex)
+ for listener in self.listeners:
+ for (l,f) in listener.iteritems():
+ func_ = getattr(l,func,None)
+ func_(*args)
+ return
Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceAdmin.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceAdmin.py (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceAdmin.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -0,0 +1,344 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file LocalServiceAdmin.py
+# @brief SDO service administration class
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp> and Shinji Kurihara
+#
+# Copyright (C) 2011
+# Noriaki Ando
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+#
+
+import threading
+import OpenRTM_aist
+
+localserviceadmin = None
+services_mutex = threading.RLock()
+
+##
+# @if jp
+#
+# @class LocalService administration class
+# @brief LocalService 管理クラス
+#
+# TODO: Documentation
+#
+# @since 1.1.0
+#
+#
+# @else
+#
+# @class SDO service administration class
+# @brief SDO service administration class
+#
+# TODO: Documentation
+#
+# @since 1.1.0
+#
+# @endif
+class LocalServiceAdmin:
+ """
+ """
+
+ ##
+ # @if jp
+ #
+ # @brief コンストラクタ
+ #
+ # コンストラクタ
+ #
+ # @else
+ #
+ # @brief Constructor
+ #
+ # Constructor
+ #
+ # @endif
+ def __init__(self):
+ self._services = []
+ self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("LocalServiceAdmin")
+ self._rtcout.RTC_TRACE("LocalServiceAdmin.__init__()")
+ return
+
+
+ ##
+ # @if jp
+ #
+ # @brief 仮想デストラクタ
+ #
+ # 仮想デストラクタ。
+ #
+ # @else
+ #
+ # @brief Virtual destractor
+ #
+ # Virtual destractor.
+ #
+ # @endif
+ def __del__(self):
+ self.finalize()
+ return
+
+
+ ##
+ # @if jp
+ #
+ # @brief LocaServiceAdminの初期化
+ #
+ # TODO: Documentation
+ #
+ # @else
+ #
+ # @brief Initialization of LocalServiceAdmin
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # void init(coil::Properties& props);
+ def init(self, props):
+ self._rtcout.RTC_TRACE("LocalServiceAdmin.init()")
+ svcs_ = props.getProperty("enabled_services").split(",")
+ svcs_lower_ = [s.lower() for s in svcs_]
+ all_enable_ = False
+ if "all" in svcs_lower_:
+ self._rtcout.RTC_INFO("All the local services are enabled.")
+ all_enable_ = True
+
+ factory_ = OpenRTM_aist.LocalServiceFactory.instance()
+ ids_ = factory_.getIdentifiers()
+ self._rtcout.RTC_DEBUG("Available services: %s", OpenRTM_aist.flatten(ids_))
+ for id_ in ids_:
+ if all_enable_ or self.isEnabled(id_, svcs_):
+ if self.notExisting(id_):
+ service_ = factory_.createObject(id_)
+ self._rtcout.RTC_DEBUG("Service created: %s", id_)
+ prop_ = props.getNode(id_)
+ service_.init(prop_)
+ self.addLocalService(service_)
+ return
+
+
+ ##
+ # @if jp
+ #
+ # @brief LocalserviceAdmin の終了処理
+ #
+ # TODO: Documentation
+ #
+ # @else
+ #
+ # @brief Finalization ofLocalServiceAdmin
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # void finalize();
+ def finalize(self):
+ factory_ = OpenRTM_aist.LocalServiceFactory.instance()
+ for svc_ in self._services:
+ svc_.finalize()
+ factory_.deleteObject(svc_)
+ self._services = []
+ return
+
+
+ ##
+ # @if jp
+ #
+ # @brief LocalServiceProfileListの取得
+ #
+ # TODO: Documentation
+ #
+ # @else
+ #
+ # @brief Getting LocalServiceProfileList
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # ::RTM::LocalServiceProfileList getServiceProfiles();
+ def getServiceProfiles(self):
+ profs_ = []
+ for svc_ in self._services:
+ profs_.append(svc_.getProfile())
+ return profs_
+
+
+ ##
+ # @if jp
+ #
+ # @brief LocalServiceProfile を取得する
+ #
+ # id で指定されたIDを持つLocalService の
+ # LocalServiceProfile を取得する。id が NULL ポインタの場合、指定された
+ # id に該当するServiceProfile が存在しない場合、falseを返す。
+ #
+ # @param id LocalService の IFR ID
+ # @return 指定された id を持つ LocalServiceProfile
+ #
+ # @else
+ #
+ # @brief Get LocalServiceProfile of an LocalService
+ #
+ # This operation returns LocalServiceProfile of a LocalService
+ # which has the specified id. If the specified id is
+ # NULL pointer or the specified id does not exist in the
+ # ServiceProfile list, false will be returned.
+ #
+ # @param id ID of an LocalService
+ # @return LocalServiceProfile which has the specified id
+ #
+ # @endif
+ # bool getServiceProfile(std::string name,
+ # ::RTM::LocalServiceProfile& prof);
+ def getServiceProfile(self, name, prof):
+ global services_mutex
+ guard_ = OpenRTM_aist.ScopedLock(services_mutex)
+ for svc_ in self._services:
+ if name == svc_.getProfile().name:
+ prof[0] = svc_.getProfile()
+ del guard_
+ return True
+ del guard_
+ return False
+
+
+ ##
+ # @if jp
+ #
+ # @brief LocalService の Service を取得する
+ #
+ # id で指定されたIDを持つLocalService のポインタを取得する。id が
+ # NULL ポインタの場合、指定された id に該当するServiceProfile が存
+ # 在しない場合、NULLを返す。
+ #
+ # @param id LocalService の ID
+ # @return 指定された id を持つ LocalService のポインタ
+ #
+ # @else
+ #
+ # @brief Get a pointer of a LocalService
+ #
+ # This operation returnes a pointer to the LocalService
+ # which has the specified id. If the specified id is
+ # NULL pointer or the specified id does not exist in the
+ # ServiceProfile list, NULL pointer will be returned.
+ #
+ # @param id ID of a LocalService
+ # @return a pointer which has the specified id
+ #
+ # @endif
+ # ::RTM::LocalServiceBase* getService(const char* id);
+ def getService(self, id):
+ for svc_ in self._services:
+ if svc_.getProfile().name == id:
+ return svc_
+ return None
+
+
+ ##
+ # @if jp
+ # @brief SDO service provider をセットする
+ #
+ # TODO: Documentation
+ #
+ # @else
+ # @brief Set a SDO service provider
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # bool addLocalService(::RTM::LocalServiceBase* service);
+ def addLocalService(self, service):
+ global services_mutex
+ if not service:
+ self._rtcout.RTC_ERROR("Invalid argument: addLocalService(service == NULL)")
+ return False
+ self._rtcout.RTC_TRACE("LocalServiceAdmin.addLocalService(%s)",
+ service.getProfile().name)
+ guard_ = OpenRTM_aist.ScopedLock(services_mutex)
+ self._services.append(service)
+ del guard_
+ return True
+
+
+ ##
+ # @if jp
+ # @brief LocalService を削除する
+ #
+ # TODO: Documentation
+ #
+ # @else
+ # @brief Remove a LocalService
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # bool removeLocalService(const std::string name);
+ def removeLocalService(self, name):
+ global services_mutex
+ self._rtcout.RTC_TRACE("removeLocalService(%s)", name)
+ guard_ = OpenRTM_aist.ScopedLock(services_mutex)
+
+ for (i,svc_) in enumerate(self._services):
+ if name == svc_.getProfile().name:
+ svc_.finalize()
+ factory_ = OpenRTM_aist.LocalServiceFactory.instance()
+ factory_.deleteObject(svc_)
+ del self._services[i]
+ self._rtcout.RTC_INFO("SDO service has been deleted: %s", name)
+ del guard_
+ return True;
+ self._rtcout.RTC_WARN("Specified SDO service not found: %s", name)
+ del guard_
+ return False
+
+
+ ##
+ # @if jp
+ # @brief 指定されたIDが有効かどうかチェックする
+ # @else
+ # @brief Check if specified ID is enabled
+ # @endif
+ # bool isEnabled(const std::string& id, const coil::vstring& enabled);
+ def isEnabled(self, id, enabled):
+ if id in enabled:
+ self._rtcout.RTC_DEBUG("Local service %s is enabled.", id)
+ return True
+ self._rtcout.RTC_DEBUG("Local service %s is not enabled.", id)
+ return False
+
+
+ ##
+ # @if jp
+ # @brief 指定されたIDがすでに存在するかどうかチェックする
+ # @else
+ # @brief Check if specified ID is existing
+ # @endif
+ # bool notExisting(const std::string& id);
+ def notExisting(self, id):
+ for svc_ in self._services:
+ if svc_.getProfile().name == id:
+ self._rtcout.RTC_WARN("Local service %s already exists.", id)
+ return False
+ self._rtcout.RTC_DEBUG("Local service %s does not exist.", id)
+ return True
+
+ def instance():
+ global localserviceadmin
+ global services_mutex
+
+ if localserviceadmin is None:
+ guard_ = OpenRTM_aist.ScopedLock(services_mutex)
+ if localserviceadmin is None:
+ localserviceadmin = LocalServiceAdmin()
+ del guard_
+ return localserviceadmin
+
+ instance = staticmethod(instance)
Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceBase.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceBase.py (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceBase.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -0,0 +1,270 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file LocalServiceBase.py
+# @brief Local service provider base class and its factory
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp> and Shinji Kurihara
+#
+# Copyright (C) 2011
+# Noriaki Ando
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+#
+# $Id$
+#
+
+import OpenRTM_aist
+
+##
+# @if jp
+# @brief LocalServiceのプロファイルデータ
+# @else
+# @brief Profile data structure of LocalService
+# @endif
+class LocalServiceProfile:
+ """
+ """
+
+ def __init__(self):
+ ##
+ # @if jp
+ # @brief LocalServiceのサービス名
+ # @else
+ # @brief The name of LocalService
+ # @endif
+ self.name = ""
+
+ ##
+ # @if jp
+ # @brief LocalServiceの固有ID
+ # @else
+ # @brief The unique ID of LocalService
+ # @endif
+ self.uuid = ""
+
+ ##
+ # @if jp
+ # @brief LocalServiceのプロパティ
+ # @else
+ # @brief Properties of LocalService
+ # @endif
+ self.properties = None
+
+ ##
+ # @if jp
+ # @brief LocalServiceのポインタ
+ # @else
+ # @brief The pointer to LocalService
+ # @endif
+ self.service = None
+
+ return
+
+##
+# @if jp
+#
+# @brief LocalService 基底クラス
+#
+# Local Service とは RT-Middlewareのマネージャデーモン内で各種サービ
+# スを提供するための仕組みである。Local Serviceにはいくつかのユース
+# ケースが考えられる。
+#
+# 1. RTCの内部ロジックに対してサービスを提供する。コンポーネントの開
+# 発者は、一定の艇順を経て、Local Serviceのインスタンスへの参照を得
+# て、このサービスを利用することができる。
+#
+# 2. マネージャ等に機能を追加するためのサービス。たとえは、RTCの名前
+# を登録するCORBAネームサービスの代わりに、新たなディレクトリサービ
+# スやブロードキャストによる名前通知機能などを新たな機能をマネージャ
+# に追加するために利用することができる。マネージャには、様々なアクショ
+# ンに対するフックが用意されており、これを利用することで、マネージャ
+# の様々なイベントに対してアクションを起こすことができる。
+#
+# 3. マネージャは自身のサービス以外に付加的に外部に対してサービスを
+# 提供する機能を有する。外部からCORBA経由で、ローカルの機能、たとえ
+# ばデバイスやリソースのマネジメント機能に対してアクセスする方法を提
+# 供する。サービスのインスタンス化後に、マネージャに対して、マネージャ
+# サービスとして登録することで、外部からのアクセスを受け付けることが
+# できるようになる。
+#
+# Local Service はモジュールとしてロードされ、通常唯一のインスタンス
+# が生成される。すなわち、LocalService はシングルトンとして実装され
+# る。インスタンス化されたサービスはサービスリストに登録され、RTC等
+# からは名前やUUIDによってインスタンスの参照を入手することができる。
+#
+# このオブジェクトのライフサイクルは以下の通り。
+#
+# -# オブジェクトは通常、共有オブジェクト (so, DLL) としてコンパイル・
+# リンクされる。
+# -# マネージャに対してロードされるとモジュール初期化関数によりオブ
+# ジェクトファクトリが、LocalServiceFactory に対して登録される。
+# 登録のキーにはUUIDと名前が利用され、これによりサービスが区別さ
+# れる。
+# -# rtc.conf等のコンフィギュレーション指定により、有効化することが
+# 指定されているサービスインプロバイダは、RTCの起動と同時にインス
+# タンス化される。
+# -# インスタンス化後、初期化関数 init() が呼ばれる。引数には当該サー
+# ビスのためのコンフィギュレーションオプションが coil::Propertyに
+# より渡される。
+# -# マネージャサービスオペレーション reinit が呼ばれると、すべての
+# Local Service お reinit が呼び出され、更新されたコンフィギュレー
+# ション情報が読み込まれる。
+# -# マネージャ解体時には、すべての Local Service の finalizeが呼び
+# 出され、解体されるので、ここでリソースの解放など終了処理を行
+# う。
+#
+# このクラスの実装に当たっては、少なくとも以下の純粋仮想関数を実装す
+# る必要がある。
+#
+# - init(): 初期化関数。与えられた RTObject および ServiceProfile か
+# ら、当該オブジェクトを初期化する。
+# - reinit(): 再初期化関数。ServiceProfile は設定情報更新のため同一
+# IDで呼び出されることが有るが、その際にこの関数が新たな
+# ServiceProfile とともに呼び出される。関数内では、設定の変更など
+# 再初期化処理を実装する。
+# - getProfile(): 設定されたプロファイルを返す関数。
+# - finalize(): 終了処理。コンシューマがデタッチされる際に呼び出され
+# る関数。関数内では終了処理を実装する。
+#
+# LocalService は通常共有オブジェクトとしてコンパイル・リンク
+# される。共有オブジェクトのエントリポイントは通常コンパイルされたファ
+# イル名の basename + "Init" にしておく。以下に、クラス名、ファイル
+# 名、エントリポイント関数名の推奨例を示す。
+#
+# - 実装クラス名: MyLocalService
+# - ファイル名: MyLocalService.h. MyLocalService.cpp
+# - 共有オブジェクト名: MyLocalService.so (or DLL)
+# - エントリポイント関数名: MyLocalServiceInit()
+#
+# エントリポイント関数は通常以下のように、LocalServiceFactory
+# に当該コンシューマのファクトリ (と解体ファンクタ) を登録する以下の
+# ような関数になる。
+#
+# <pre>
+# extern "C"
+# {
+# void MyLocalServiceInit()
+# {
+# RTC::LocalServiceFactory& factory
+# = RTC::LocalServiceFactory::instance();
+# factory.addFactory(::RTC::MyLocalSerivce::name,
+# ::coil::Creator< ::RTC::LocalServiceBase,
+# ::RTC::MyLocalService>,
+# ::coil::Destructor< ::RTC::LocalServiceBase,
+# ::RTC::MyLocalService>);
+# }
+# };
+# </pre>
+#
+# @else
+#
+# @endif
+class LocalServiceBase:
+ """
+ """
+
+ ##
+ # @if jp
+ # @brief LocalServiceクラスの初期化関数
+ #
+ # このオブジェクトの初期化を行う。LocalService を実装する場合、外
+ # 部からの設定情報は、このinit()関数により与えられる。
+ #
+ # @param profile 外部から与えられた LocalServiceProfile
+ # @return 与えられた LocalServiceProfile が不正の場合 false
+ #
+ # @else
+ # @brief Initialization function of the LocalService class
+ #
+ # @endif
+ # virtual bool
+ # init(const coil::Properties& props) = 0;
+ def init(self, props):
+ pass
+
+
+ ##
+ # @if jp
+ # @brief LocalServiceクラスの再初期化関数
+ #
+ # TODO: ドキュメント作成
+ #
+ # @param profile 新たに与えられた LocalServiceProfile
+ # @return 不正な LocalServiceProfile が与えられた場合は false
+ #
+ # @else
+ # @brief Reinitialization function of the LocalService class
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # virtual bool
+ # reinit(const coil::Properties& props) = 0;
+ def reinit(self, props):
+ pass
+
+
+ ##
+ # @if jp
+ # @brief LocalServiceProfile を返す
+ #
+ # init()/reinit()で与えられた LocalServiceProfile は通常オブジェク
+ # ト内で保持される。この関数では保持されている ServiceProfile を返
+ # す。
+ #
+ # @return このオブジェクトが保持している LocalServiceProfile
+ #
+ # @else
+ # @brief Getting LocalServiceProfile
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # virtual const LocalServiceProfile&
+ # getProfile() const = 0;
+ def getProfile(self):
+ pass
+
+
+ ##
+ # @if jp
+ # @brief 終了処理
+ #
+ # LocalService が終了する際に呼び出される終了処理用関数。当該オブ
+ # ジェクトが保持するリソースを解放するなどの処理を行う。
+ #
+ # @else
+ # @brief Finalization
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # virtual void
+ # finalize() = 0;
+ def finalize(self):
+ pass
+
+localservicefactory = None
+
+class LocalServiceFactory(OpenRTM_aist.Factory,LocalServiceBase):
+ def __init__(self):
+ OpenRTM_aist.Factory.__init__(self)
+ return
+
+ def __del__(self):
+ pass
+
+ def instance():
+ global localservicefactory
+
+ if localservicefactory is None:
+ localservicefactory = LocalServiceFactory()
+
+ return localservicefactory
+
+ instance = staticmethod(instance)
+
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py 2012-01-10 05:57:47 UTC (rev 500)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -113,6 +113,7 @@
self._poa = None
self._poaManager = None
self._finalized = self.Finalized()
+ self._listeners = OpenRTM_aist.ManagerActionListeners()
signal.signal(signal.SIGINT, handler)
return
@@ -264,6 +265,7 @@
# @endif
def shutdown(self):
self._rtcout.RTC_TRACE("Manager.shutdown()")
+ self._listeners.manager_.preShutdown()
self.shutdownComponents()
self.shutdownNaming()
self.shutdownORB()
@@ -274,6 +276,7 @@
else:
self.join()
+ self._listeners.manager_.postShutdown()
self.shutdownLogger()
global manager
if manager:
@@ -375,6 +378,17 @@
self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
return False
+ lsvc_ = [s.strip() for s in self._config.getProperty("manager.local_service.modules").split(",")]
+
+ for svc_ in lsvc_:
+ basename_ = svc_.split(".")[0]+"Init"
+ try:
+ self._module.load(svc_, basename_)
+ except:
+ self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
+
+ self.initLocalService()
+
mods = [s.strip() for s in self._config.getProperty("manager.modules.preload").split(",")]
for i in range(len(mods)):
@@ -394,6 +408,9 @@
self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
self.__try_direct_load(basename)
+ sdofactory_ = OpenRTM_aist.SdoServiceConsumerFactory.instance()
+ self._config.setProperty("sdo.service.consumer.available_services",
+ OpenRTM_aist.flatten(sdofactory_.getIdentifiers()))
if self._initProc:
self._initProc(self)
@@ -485,6 +502,7 @@
def load(self, fname, initfunc):
self._rtcout.RTC_TRACE("Manager.load(fname = %s, initfunc = %s)",
(fname, initfunc))
+ self._listeners.module_.preLoad(fname, initfunc)
try:
fname_ = fname.split(os.sep)
if len(fname_) > 1:
@@ -497,6 +515,7 @@
initfunc = mod[0]+"Init"
path = self._module.load(fname, initfunc)
self._rtcout.RTC_DEBUG("module path: %s", path)
+ self._listeners.module_.postLoad(path, initfunc)
except:
self.__try_direct_load(fname)
@@ -524,7 +543,9 @@
# @endif
def unload(self, fname):
self._rtcout.RTC_TRACE("Manager.unload()")
+ self._listeners.module_.preUnload(fname)
self._module.unload(fname)
+ self._listeners.module_.postUnload(fname)
return
@@ -766,6 +787,7 @@
#
def createComponent(self, comp_args):
self._rtcout.RTC_TRACE("Manager.createComponent(%s)", comp_args)
+ self._listeners.rtclifecycle_.preCreate(comp_args)
comp_prop = OpenRTM_aist.Properties()
comp_id = OpenRTM_aist.Properties()
@@ -857,6 +879,7 @@
comp_id.getProperty("implementation_id"))
return None
self._rtcout.RTC_TRACE("RTC Created: %s", comp_id.getProperty("implementation_id"))
+ self._listeners.rtclifecycle_.postCreate(comp)
# The property specified by the parameter of createComponent() is merged.
# The property("instance_name") specified by the parameter of createComponent()
@@ -869,7 +892,9 @@
# rtc.conf:
# [category].[type_name].config_file = file_name
# [category].[instance_name].config_file = file_name
+ self._listeners.rtclifecycle_.preConfigure(prop)
self.configureComponent(comp,prop)
+ self._listeners.rtclifecycle_.postConfigure(prop)
# The property specified by the parameter of createComponent() is set.
# The property("exported_ports") specified by the parameter of createComponent()
@@ -877,6 +902,7 @@
#comp.setProperties(comp_prop)
# Component initialization
+ self._listeners.rtclifecycle_.preInitialize()
if comp.initialize() != RTC.RTC_OK:
self._rtcout.RTC_TRACE("RTC initialization failed: %s",
comp_id.getProperty("implementation_id"))
@@ -886,6 +912,7 @@
self._rtcout.RTC_TRACE("RTC initialization succeeded: %s",
comp_id.getProperty("implementation_id"))
+ self._listeners.rtclifecycle_.postInitialize()
self.registerComponent(comp)
return comp
@@ -912,9 +939,11 @@
self._compManager.registerObject(comp)
names = comp.getNamingNames()
+ self._listeners.naming_.preBind(comp, names)
for name in names:
self._rtcout.RTC_TRACE("Bind name: %s", name)
self._namingManager.bindObject(name, comp)
+ self._listeners.naming_.postBind(comp, names)
return True
@@ -938,9 +967,11 @@
self._compManager.unregisterObject(comp.getInstanceName())
names = comp.getNamingNames()
+ self._listeners.naming_.preUnbind(comp, names)
for name in names:
self._rtcout.RTC_TRACE("Unbind name: %s", name)
self._namingManager.unbindObject(name)
+ self._listeners.naming_.postUnbind(comp, names)
return True
@@ -1067,6 +1098,81 @@
return self._compManager.getObjects()
+ # void Manager::
+ # addManagerActionListener(RTM::ManagerActionListener* listener,
+ # bool autoclean)
+ def addManagerActionListener(self, listener,autoclean=True):
+ self._listeners.manager_.addListener(listener, autoclean)
+ return
+
+
+ # void Manager::
+ # removeManagerActionListener(RTM::ManagerActionListener* listener)
+ def removeManagerActionListener(self, listener):
+ self._listeners.manager_.removeListener(listener)
+ return
+
+
+ # void Manager::
+ # addModuleActionListener(RTM::ModuleActionListener* listener,
+ # bool autoclean)
+ def addModuleActionListener(self, listener, autoclean=True):
+ self._listeners.module_.addListener(listener, autoclean)
+ return
+
+
+ # void Manager::
+ # removeModuleActionListener(RTM::ModuleActionListener* listener)
+ def removeModuleActionListener(self, listener):
+ self._listeners.module_.removeListener(listener)
+ return
+
+
+ # void Manager::
+ # addRtcLifecycleActionListener(RTM::RtcLifecycleActionListener* listener,
+ # bool autoclean)
+ def addRtcLifecycleActionListener(self, listener, autoclean=True):
+ self._listeners.rtclifecycle_.addListener(listener, autoclean)
+ return
+
+
+ # void Manager::
+ # removeRtcLifecycleActionListener(RTM::RtcLifecycleActionListener* listener)
+ def removeRtcLifecycleActionListener(self, listener):
+ self._listeners.rtclifecycle_.removeListener(listener)
+ return
+
+
+ # void Manager::
+ # addNamingActionListener(RTM::NamingActionListener* listener,
+ # bool autoclean)
+ def addNamingActionListener(self, listener, autoclean=True):
+ self._listeners.naming_.addListener(listener, autoclean)
+ return
+
+
+ # void Manager::
+ # removeNamingActionListener(RTM::NamingActionListener* listener)
+ def removeNamingActionListener(self, listener):
+ self._listeners.naming_.removeListener(listener)
+ return
+
+
+ # void Manager::
+ # addLocalServiceActionListener(RTM::LocalServiceActionListener* listener,
+ # bool autoclean)
+ def addLocalServiceActionListener(self, listener, autoclean=True):
+ self._listeners.localservice_.addListener(listener, autoclean)
+ return
+
+
+ # void Manager::
+ # removeLocalServiceActionListener(RTM::LocalServiceActionListener* listener)
+ def removeLocalServiceActionListener(self, listener):
+ self._listeners.localservice_.removeListener(listener)
+ return
+
+
#============================================================
# CORBA 関連
#============================================================
@@ -1619,7 +1725,17 @@
# @endif
def shutdownNaming(self):
self._rtcout.RTC_TRACE("Manager.shutdownNaming()")
+ comps = self.getComponents()
+
+ for copm in comps:
+ names = comp.getNamingNames()
+ self._listeners.naming_.preUnbind(comp, names);
+ for name in names:
+ self._namingNamager.unbindObject(name)
+ self._listeners.naming_.postUnbind(comp, names);
+
self._namingManager.unbindAll()
+ return
##
@@ -1758,6 +1874,23 @@
return True
+ # bool Manager::initLocalService()
+ def initLocalService(self):
+ self._rtcout.RTC_TRACE("Manager::initLocalService()")
+
+ admin_ = OpenRTM_aist.LocalServiceAdmin.instance()
+ prop_ = OpenRTM_aist.Properties(prop=self._config.getNode("manager.local_service"))
+ admin_.init(prop_)
+ self._rtcout.RTC_DEBUG("LocalServiceAdmin's properties:")
+ self._rtcout.RTC_DEBUG("%s",prop_)
+
+ svclist_ = admin_.getServiceProfiles()
+ for svc_ in svclist_:
+ self._rtcout.RTC_INFO("Available local service: %s (%s)",
+ (svc_.name, svc_.uuid))
+ return True
+
+
##
# @if jp
# @brief NamingManager に登録されている全コンポーネントの終了処理
@@ -1967,10 +2100,15 @@
type_prop = OpenRTM_aist.Properties()
name_prop = OpenRTM_aist.Properties()
+ config_fname = []
if self._config.getProperty(name_conf) != "":
try:
conff = open(self._config.getProperty(name_conf))
+ name_prop.load(conff)
+ self._rtcout.RTC_INFO("Component instance conf file: %s loaded.",
+ self._config.getProperty(name_conf))
+ config_fname.append(self._config.getProperty(name_conf))
except:
print "Not found. : %s" % self._config.getProperty(name_conf)
self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
@@ -1978,11 +2116,21 @@
name_prop.load(conff)
if self._config.findNode(category + "." + inst_name):
- name_prop.mergeProperties(self._config.getNode(category + "." + inst_name))
+ temp_ = OpenRTM_aist.Properties(prop=self._config.getNode(category+"."+inst_name))
+ keys_ = temp_.propertyNames()
+ if not (len(keys_) == 1 and keys[-1] == "config_file"):
+ name_prop.mergeProperties(self._config.getNode(category + "." + inst_name))
+ self._rtcout.RTC_INFO("Component name conf exists in rtc.conf. Merged.")
+ if self._config.findNode("config_file"):
+ config_fname.append(self._config.getProperty("config_file"))
if self._config.getProperty(type_conf) != "":
try:
conff = open(self._config.getProperty(type_conf))
+ type_prop.load(conff)
+ self._rtcout.RTC_INFO("Component type conf file: %s loaded.",
+ self._config.getProperty(type_conf))
+ config_fname.append(self._config.getProperty(type_conf))
except:
print "Not found. : %s" % self._config.getProperty(type_conf)
self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
@@ -1990,10 +2138,17 @@
type_prop.load(conff)
if self._config.findNode(category + "." + type_name):
- type_prop.mergeProperties(self._config.getNode(category + "." + type_name))
+ temp_ = OpenRTM_aist.Properties(prop=self._config.getNode(category+"."+type_name))
+ keys_ = temp_.propertyNames()
+ if not (len(keys_) == 1 and keys[-1] == "config_file"):
+ type_prop.mergeProperties(self._config.getNode(category + "." + type_name))
+ self._rtcout.RTC_INFO("Component type conf exists in rtc.conf. Merged.")
+ if self._config.findNode("config_file"):
+ config_fname.append(self._config.getProperty("config_file"))
comp.setProperties(prop)
type_prop.mergeProperties(name_prop)
+ type_prop.setProperty("config_file",OpenRTM_aist.flatten(OpenRTM_aist.unique_sv(config_fname)))
comp.setProperties(type_prop)
comp_prop = OpenRTM_aist.Properties(prop=comp.getProperties())
Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/ManagerActionListener.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/ManagerActionListener.py (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/ManagerActionListener.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -0,0 +1,576 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file ManagerActionListener.py
+# @brief component action listener class
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp> and Shinji Kurihara
+#
+# Copyright (C) 2011
+# Noriaki Ando
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+#
+# $Id$
+#
+
+import OpenRTM_aist
+
+##
+# @if jp
+# @class ManagerActionListenerHolder クラス
+# @else
+# @class ManagerActionListenerHolder class
+# @endif
+class ManagerActionListenerHolder(OpenRTM_aist.ListenerHolder):
+ """
+ """
+
+ def __init__(self):
+ OpenRTM_aist.ListenerHolder.__init__(self)
+ return
+
+ def __del__(self):
+ return
+
+
+ ##
+ # @if jp
+ # @brief preShutdown コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preShutdown callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preShutdown();
+ def preShutdown(self):
+ self.LISTENERHOLDER_CALLBACK("preShutdown")
+ return
+
+
+ ##
+ # @if jp
+ # @brief postShutdown コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postShutdown callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postShutdown();
+ def postShutdown(self):
+ self.LISTENERHOLDER_CALLBACK("postShutdown")
+ return
+
+
+ ##
+ # @if jp
+ # @brief preReinit コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preReinit callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preReinit();
+ def preReinit(self):
+ self.LISTENERHOLDER_CALLBACK("preReinit")
+ return
+
+
+ ##
+ # @if jp
+ # @brief postReinit コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postReinit callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postReinit();
+ def postReinit(self):
+ self.LISTENERHOLDER_CALLBACK("postReinit")
+ return
+
+
+##
+# @if jp
+# @class ModuleActionListenerHolder クラス
+# @brief ModuleActionListenerHolder クラス
+#
+# @else
+# @class ModuleActionListenerHolder class
+# @brief ModuleActionListenerHolder class
+#
+# @endif
+class ModuleActionListenerHolder(OpenRTM_aist.ListenerHolder):
+ """
+ """
+
+ def __init__(self):
+ OpenRTM_aist.ListenerHolder.__init__(self)
+ return
+
+
+ ##
+ # @if jp
+ # @brief デストラクタ
+ # @else
+ # @brief Destructor
+ # @endif
+ def __del__(self):
+ pass
+
+
+ ##
+ # @if jp
+ # @brief preLoad コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preLoad callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preLoad(std::string& modname,
+ # std::string& funcname);
+ def preLoad(self, modname, funcname):
+ self.LISTENERHOLDER_CALLBACK("preLoad", modname, funcname)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postLoad コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postLoad callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postLoad(std::string& modname,
+ # std::string& funcname);
+ def postLoad(self, modname, funcname):
+ self.LISTENERHOLDER_CALLBACK("postLoad", modname, funcname)
+ return
+
+
+ ##
+ # @if jp
+ # @brief preUnload コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preUnload callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preUnload(std::string& modname);
+ def preUnload(self, modname):
+ self.LISTENERHOLDER_CALLBACK("preUnload", modname)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postUnload コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postUnload callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postUnload(std::string& modname);
+ def postUnload(self, modname):
+ self.LISTENERHOLDER_CALLBACK("postUnload", modname)
+ return
+
+
+
+##
+# @if jp
+# @class RtcLifecycleActionListenerHolder クラス
+# @brief RtcLifecycleActionListenerHolder クラス
+#
+# @else
+# @class RtcLifecycleActionListenerHolder class
+# @brief RtcLifecycleActionListenerHolder class
+#
+# This class is abstract base class for listener classes that
+# provides callbacks for various events in rtobject.
+#
+# @endif
+class RtcLifecycleActionListenerHolder(OpenRTM_aist.ListenerHolder):
+ """
+ """
+
+ def __init__(self):
+ OpenRTM_aist.ListenerHolder.__init__(self)
+ return
+
+
+ ##
+ # @if jp
+ # @brief デストラクタ
+ # @else
+ # @brief Destructor
+ # @endif
+ def __del__(self):
+ pass
+
+
+ ##
+ # @if jp
+ # @brief preCreate コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preCreate callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preCreate(std::string& args);
+ def preCreate(self, args):
+ self.LISTENERHOLDER_CALLBACK("preCreate", args)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postCreate コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postCreate callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postCreate(RTC::RTObject_impl* rtobj);
+ def postCreate(self, rtobj):
+ self.LISTENERHOLDER_CALLBACK("postCreate", rtobj)
+ return
+
+
+ ##
+ # @if jp
+ # @brief preConfigure コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preConfigure callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preConfigure(coil::Properties& prop);
+ def preConfigure(self, prop):
+ self.LISTENERHOLDER_CALLBACK("preConfigure", prop)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postConfigure コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postConfigure callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postConfigure(coil::Properties& prop);
+ def postConfigure(self, prop):
+ self.LISTENERHOLDER_CALLBACK("postConfigure", prop)
+ return
+
+
+ ##
+ # @if jp
+ # @brief preInitialize コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preInitialize callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preInitialize(void);
+ def preInitialize(self):
+ self.LISTENERHOLDER_CALLBACK("preInitialize")
+ return
+
+
+ ##
+ # @if jp
+ # @brief postInitialize コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postInitialize callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postInitialize(void);
+ def postInitialize(self):
+ self.LISTENERHOLDER_CALLBACK("postInitialize")
+ return
+
+
+
+##
+# @if jp
+# @class NamingActionListenerHolder クラス
+# @brief NamingActionListenerHolder クラス
+#
+# @else
+# @class NamingActionListenerHolder class
+# @brief NamingActionListenerHolder class
+#
+# This class is abstract base class for listener classes that
+# provides callbacks for various events in rtobject.
+#
+# @endif
+class NamingActionListenerHolder(OpenRTM_aist.ListenerHolder):
+ """
+ """
+
+ def __init__(self):
+ OpenRTM_aist.ListenerHolder.__init__(self)
+ return
+
+
+ ##
+ # @if jp
+ # @brief デストラクタ
+ # @else
+ # @brief Destructor
+ # @endif
+ def __del__(self):
+ pass
+
+
+ ##
+ # @if jp
+ # @brief preBind コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preBind callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preBind(RTC::RTObject_impl# rtobj,
+ # coil::vstring& name);
+ def preBind(self, rtobj, name):
+ self.LISTENERHOLDER_CALLBACK("preBind", rtobj, name)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postBind コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postBind callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postBind(RTC::RTObject_impl* rtobj,
+ # coil::vstring& name);
+ def postBind(self, rtobj, name):
+ self.LISTENERHOLDER_CALLBACK("postBind", rtobj, name)
+ return
+
+
+ ##
+ # @if jp
+ # @brief preUnbind コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preUnbind callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preUnbind(RTC::RTObject_impl* rtobj,
+ # coil::vstring& name);
+ def preUnbind(self, rtobj, name):
+ self.LISTENERHOLDER_CALLBACK("preUnbind", rtobj, name)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postUnbind コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postUnbind callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postUnbind(RTC::RTObject_impl* rtobj,
+ # coil::vstring& name);
+ def postUnbind(self, rtobj, name):
+ self.LISTENERHOLDER_CALLBACK("postUnbind", rtobj, name)
+ return
+
+
+
+##
+# @if jp
+# @class LocalServiceActionListenerHolder クラス
+# @brief LocalServiceActionListenerHolder クラス
+#
+# 各アクションに対応するユーザーコードが呼ばれる直前のタイミング
+# でコールされるリスなクラスの基底クラス。
+#
+# - ADD_PORT:
+# - REMOVE_PORT:
+#
+# @else
+# @class LocalServiceActionListenerHolder class
+# @brief LocalServiceActionListenerHolder class
+#
+# This class is abstract base class for listener classes that
+# provides callbacks for various events in rtobject.
+#
+# @endif
+class LocalServiceActionListenerHolder(OpenRTM_aist.ListenerHolder):
+ """
+ """
+
+ def __init__(self):
+ OpenRTM_aist.ListenerHolder.__init__(self)
+ return
+
+
+ ##
+ # @if jp
+ # @brief デストラクタ
+ # @else
+ # @brief Destructor
+ # @endif
+ def __del__(self):
+ pass
+
+
+ # registration instance of service to svc admin
+ ##
+ # @if jp
+ # @brief preServiceRegister コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preServiceRegister callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preServiceRegister(std::string service_name);
+ def preServiceRegister(self, service_name):
+ self.LISTENERHOLDER_CALLBACK("preServiceRegister", service_name)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postServiceRegister コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postServiceRegister callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postServiceRegister(std::string service_name,
+ # RTM::LocalServiceBase* service);
+ def postServiceRegister(self, service_name, service):
+ self.LISTENERHOLDER_CALLBACK("postServiceRegister", service_name, service)
+ return
+
+
+ ##
+ # @if jp
+ # @brief preServiceInit コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preServiceInit callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preServiceInit(coil::Properties& prop,
+ # RTM::LocalServiceBase* service);
+ def preServiceInit(self, prop, service):
+ self.LISTENERHOLDER_CALLBACK("preServiceInit", prop, service)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postServiceInit コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postServiceInit callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postServiceInit(coil::Properties& prop,
+ # RTM::LocalServiceBase* service);
+ def postServiceInit(self, prop, service):
+ self.LISTENERHOLDER_CALLBACK("postServiceInit", prop, service)
+ return
+
+
+ ##
+ # @if jp
+ # @brief preServiceReinit コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preServiceReinit callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preServiceReinit(coil::Properties& prop,
+ # RTM::LocalServiceBase* service);
+ def preServiceReinit(self, prop, service):
+ self.LISTENERHOLDER_CALLBACK("preServiceReinit", prop, service)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postServiceReinit コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postServiceReinit callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postServiceReinit(coil::Properties& prop,
+ # RTM::LocalServiceBase* service);
+ def postServiceReinit(self, prop, service):
+ self.LISTENERHOLDER_CALLBACK("postServiceReinit", prop, service)
+ return
+
+
+ ##
+ # @if jp
+ # @brief preServiceFinalize コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preServiceFinalize callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preServiceFinalize(std::string service_name,
+ # RTM::LocalServiceBase* service);
+ def preServiceFinalize(self, service_name, service):
+ self.LISTENERHOLDER_CALLBACK("preServiceFinalize", service_name, service)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postServiceFinalize コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postServiceFinalize callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postServiceFinalize(std::string service_name,
+ # RTM::LocalServiceBase* service);
+ def postServiceFinalize(self, service_name, service):
+ self.LISTENERHOLDER_CALLBACK("postServiceFinalize", service_name, service)
+ return
+
+
+
+
+##
+# @if jp
+# @class ManagerActionListeners
+# @brief ManagerActionListeners クラス
+#
+#
+# @else
+# @class ManagerActionListeners
+# @brief ManagerActionListeners class
+#
+#
+# @endif
+class ManagerActionListeners:
+ """
+ """
+
+ def __init__(self):
+ self.manager_ = ManagerActionListenerHolder()
+ self.module_ = ModuleActionListenerHolder()
+ self.rtclifecycle_ = RtcLifecycleActionListenerHolder()
+ self.naming_ = NamingActionListenerHolder()
+ self.localservice_ = LocalServiceActionListenerHolder()
+
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py 2012-01-10 05:57:47 UTC (rev 500)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -31,6 +31,10 @@
from DataPortStatus import *
from NumberingPolicy import *
from Listener import *
+from ListenerHolder import *
+from LocalServiceBase import *
+from LocalServiceAdmin import *
+from ManagerActionListener import *
from ComponentActionListener import *
from Typename import *
from Guard import *
Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/ext/local_service/nameservice_file/FileNameservice.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/ext/local_service/nameservice_file/FileNameservice.py (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/ext/local_service/nameservice_file/FileNameservice.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -0,0 +1,476 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file FileNameservice.py
+# @brief FileNameservice
+# @date 2012/01/17
+# @author n-ando and Shinji Kurihara
+#
+# Copyright (C) 2011
+# Noriaki Ando
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+#
+# $Id$
+#
+
+import shutil
+import os.path
+import OpenRTM_aist
+
+service_name = "org.openrtm.local_service.nameservice.file_nameservice"
+service_uuid = "7288D080-F618-480B-B6D9-A199686F3101";
+default_config = ["base_path", "./openrtm_ns/",
+ "file_structure", "tree",
+ "context_delimiter", "|",
+ ""]
+
+
+##
+# @if jp
+# @class FileNameservice クラス
+# @brief FileNameservice クラス
+# @else
+# @class FileNameservice class
+# @brief FileNameservice class
+# @endif
+class FileNameservice(OpenRTM_aist.LocalServiceBase):
+ """
+ """
+
+ ##
+ # @if jp
+ # @brief FileNameService ctor
+ # @else
+ # @brief FileNameService ctor
+ # @endif
+ def __init__(self):
+ global service_name
+ global service_uuid
+ global default_config
+
+ self._profile = OpenRTM_aist.LocalServiceProfile()
+ self._profile.name = service_name
+ self._profile.uuid = service_uuid
+ prop = OpenRTM_aist.Properties(defaults_str=default_config)
+ self._profile.properties = prop
+ self._profile.service = self
+ self._files = []
+ self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("file_nameservice")
+ self._rtcout.RTC_DEBUG("FileNameservice was created(")
+ self._rtcout.RTC_DEBUG(" name = %s", self._profile.name)
+ self._rtcout.RTC_DEBUG(" uuid = %s", self._profile.uuid)
+ self._rtcout.RTC_DEBUG(" properties = %s", self._profile.properties)
+ self._rtcout.RTC_DEBUG(" service = %s)", self.__class__.__name__)
+ return
+
+
+ ##
+ # @if jp
+ # @brief FileNameService dtor
+ # @else
+ # @brief FileNameService dtor
+ # @endif
+ def __del__(self):
+ self._rtcout.RTC_TRACE("FileNameservice.__del__()")
+ self.cleanupFiles()
+ return
+
+
+ ##
+ # @if jp
+ # @brief 初期化関数
+ #
+ # TODO: Documentation
+ #
+ # @param profile 外部から与えられた property
+ # @return
+ #
+ # @else
+ # @brief Initialization function
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # virtual bool
+ # init(const ::coil::Properties& profile);
+ def init(self, profile):
+ self._rtcout.RTC_TRACE("init()")
+ self._rtcout.RTC_DEBUG(profile)
+ self._profile.properties.mergeProperties(profile)
+
+ manager_ = OpenRTM_aist.Manager.instance()
+ manager_.addNamingActionListener(NamingAction(self), True)
+ return True
+
+
+ ##
+ # @if jp
+ # @brief 再初期化関数
+ #
+ # TODO: Documentation
+ #
+ # @param profile 外部から与えられた property
+ # @return
+ #
+ # @else
+ # @brief Reinitialization function
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # virtual bool
+ # reinit(const ::coil::Properties& profile);
+ def reinit(self, profile):
+ self._rtcout.RTC_TRACE("reinit()")
+ self._rtcout.RTC_DEBUG(profile)
+ ret = self.processServiceProfile(profile)
+ self._profile.properties.mergeProperties(profile)
+ return ret
+
+
+ ##
+ # @if jp
+ # @brief LocalServiceProfile を取得する
+ #
+ # TODO: Documentation
+ #
+ # @return このオブジェクトが保持している LocalServiceProfile
+ #
+ # @else
+ # @brief Getting LocalServiceProfile
+ #
+ # TODO: Documentation
+ #
+ # @return LocalServiceProfile of this service class
+ #
+ # @endif
+ # virtual const LocalServiceProfile& getProfile() const;
+ def getProfile(self):
+ self._rtcout.RTC_TRACE("getProfile()")
+ return self._profile
+
+
+ ##
+ # @if jp
+ # @brief 終了関数
+ #
+ # TODO: Documentation
+ #
+ # @else
+ # @brief Finalization function
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # virtual void finalize();
+ def finalize(self):
+ self.cleanupFiles()
+ return
+
+
+ ##
+ # @if jp
+ # @brief 名前登録時に呼ばれるコールバック
+ #
+ # TODO: Documentation
+ #
+ # @else
+ # @brief A call-back at name registration
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # void
+ # onRegisterNameservice(coil::vstring& path, coil::vstring& ns_info);
+ def onRegisterNameservice(self, path, ns_info):
+ self._rtcout.RTC_TRACE("onRegisterNameservice(path = %s",
+ OpenRTM_aist.flatten(path))
+ self._rtcout.RTC_TRACE(" nsinfo = %s",
+ OpenRTM_aist.flatten(ns_info))
+
+ for i in range(len(path)):
+ filepath_ = self.getFname(path[i])
+ directory_ = os.path.dirname(filepath_)
+ self._rtcout.RTC_DEBUG("file path: %s", filepath_)
+ self._rtcout.RTC_DEBUG("directory: %s", directory_)
+ if not self.createDirectory(directory_):
+ continue;
+ try:
+ filename_ = os.path.basename(filepath_)
+ self._rtcout.RTC_DEBUG("file name: %s", filename_)
+ ofile_ = open(filepath_, 'w')
+ ofs_ = []
+ for info in ns_info:
+ ofs_.append(info)
+ ofile_.writelines(ofs_)
+ ofile_.close()
+ self._rtcout.RTC_INFO("RTC %s's IOR has been successfully registered: %s",
+ (filename_, filepath_))
+ self._files.append(filepath_)
+ except:
+ self._rtcout.RTC_ERROR("Creating file has been failed. %s",
+ filepath_)
+ return
+
+
+ ##
+ # @if jp
+ # @brief 名前登録解除に呼ばれるコールバック
+ #
+ # TODO: Documentation
+ #
+ # @else
+ # @brief A call-back at name runegistration
+ #
+ # TODO: Documentation
+ #
+ # @endif
+ # void
+ # onUnregisterNameservice(coil::vstring& path);
+ def onUnregisterNameservice(self, path):
+ self._rtcout.RTC_TRACE("onUnregisterNameservice(%s)",
+ OpenRTM_aist.flatten(path))
+ for i in range(len(path)):
+ filepath_ = self.getFname(path[i])
+ if not os.path.exists(filepath_):
+ self._rtcout.RTC_ERROR("No such file: %s", filepath_)
+ continue
+
+ found_path_ = self._files.count(filepath_)
+ if not found_path_:
+ self._rtcout.RTC_WARN("This file (%s) might not be my file.",
+ filepath_)
+ continue
+ found_idx_ = self._files.index(filepath_)
+ del self._files[found_idx_]
+
+ try:
+ os.remove(filepath_)
+ self._rtcout.RTC_DEBUG("Removing file: %s", filepath_)
+ except:
+ self._rtcout.RTC_ERROR("Removing a file has been failed. %s",
+ filepath_)
+ continue
+
+ self._rtcout.RTC_PARANOID("Removing a file done: %s", filepath_)
+
+ return
+
+
+ ##
+ # @if jp
+ # @brief ディレクトリ作成
+ # TODO: Documentation
+ # @else
+ # @brief Creating directories
+ # TODO: Documentation
+ # @endif
+ # bool createDirectory(fs::path& directory);
+ def createDirectory(self, directory):
+ self._rtcout.RTC_TRACE("createDirectory(%s)", directory)
+ if not os.path.exists(directory):
+ self._rtcout.RTC_DEBUG("Directory %s not found", directory)
+ try:
+ os.mkdir(directory)
+ self._rtcout.RTC_DEBUG("Creating directory: %s", directory)
+ except:
+ self._rtcout.RTC_ERROR("Creating directory has been failed. %s",
+ directory)
+ return False
+
+ self._rtcout.RTC_PARANOID("Creating directory done: %s",
+ directory)
+
+ elif os.path.exists(directory) and os.path.isdir(directory):
+ self._rtcout.RTC_DEBUG("Directory %s exists.", directory)
+
+ else:
+ self._rtcout.RTC_ERROR("File exists instead of base directory %s.",
+ directory)
+ return False
+
+ return True
+
+
+ ##
+ # @if jp
+ # @brief ファイル名取得
+ # TODO: Documentation
+ # @else
+ # @brief Getting file name
+ # TODO: Documentation
+ # @endif
+ # std::string getFname(std::string& path) const;
+ def getFname(self, path):
+ self._rtcout.RTC_TRACE("getFname(%s)", path)
+
+ pathstring_ = self._profile.properties.getProperty("base_path")
+ pathstring_ += "/"
+
+ fs_ = self._profile.properties.getProperty("file_structure")
+ fs_ = fs_.strip().lower()
+
+ if fs_ == "flat":
+ self._rtcout.RTC_DEBUG("file_structure = flat")
+ d_ = self._profile.properties.getProperty("context_delimiter")
+ ns_path_ = [path]
+ OpenRTM_aist.replaceString(ns_path_, "/", d_)
+ pathstring_ += ns_path_[0]
+
+ elif fs_ == "tree":
+ self._rtcout.RTC_DEBUG("file_structure = tree")
+ pathstring_ += path
+
+ self._rtcout.RTC_DEBUG("path string = %s", pathstring_)
+
+ return pathstring_
+
+
+ ##
+ # @if jp
+ # @brief 全ファイル削除
+ # TODO: Documentation
+ # @else
+ # @brief Deleting all files
+ # TODO: Documentation
+ # @endif
+ # void cleanupFiles();
+ def cleanupFiles(self):
+ self._rtcout.RTC_TRACE("cleanupFiles()")
+ for file in self._files:
+ os.remove(file)
+
+ self._files = []
+
+
+ ##
+ # @if jp
+ # @brief プロパティの処理
+ # TODO: Documentation
+ # @else
+ # @brief Processing properties
+ # TODO: Documentation
+ # @endif
+ # bool processServiceProfile(const ::coil::Properties& props);
+ def processServiceProfile(self, props):
+ return True
+
+
+##
+# @if jp
+# @class NamingAction class
+# TODO: Documentation
+# @else
+# @class NamingActin class
+# TODO: Documentation
+# @endif
+class NamingAction:
+ """
+ """
+
+ ##
+ # @if jp
+ # @brief コンストラクタ
+ # @else
+ # @brief Constructor
+ # @endif
+ def __init__(self, fns):
+ self._fns = fns
+ return
+
+
+ ##
+ # @if jp
+ # @brief デストラクタ
+ # @else
+ # @brief Destructor
+ # @endif
+ def __del__(self):
+ return
+
+
+ ##
+ # @if jp
+ # @brief preBind コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preBind callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preBind(RTC::RTObject_impl* rtobj,
+ # coil::vstring& name);
+ def preBind(self, rtobj, name):
+ objref_ = rtobj.getObjRef()
+ ior_ = OpenRTM_aist.Manager.instance().getORB().object_to_string(objref_)
+ ns_info_ = [ior_]
+ self._fns.onRegisterNameservice(name, ns_info_)
+ return
+
+
+ ##
+ # @if jp
+ # @brief postBind コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postBind callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postBind(RTC::RTObject_impl* rtobj,
+ # coil::vstring& name);
+ def postBind(self, rtobj, name):
+ return
+
+
+ ##
+ # @if jp
+ # @brief preUnbind コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief preUnbind callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void preUnbind(RTC::RTObject_impl* rtobj,
+ # coil::vstring& name);
+ def preUnbind(self, rtobj, name):
+ return
+
+
+ ##
+ # @if jp
+ # @brief postUnbind コールバック関数
+ # TODO: Documentation
+ # @else
+ # @brief postUnbind callback function
+ # TODO: Documentation
+ # @endif
+ # virtual void postUnbind(RTC::RTObject_impl* rtobj,
+ # coil::vstring& name);
+ def postUnbind(self, rtobj, name):
+ self._fns.onUnregisterNameservice(name)
+ return
+
+
+
+##
+# @if jp
+# @brief モジュール初期化関数
+#
+# FileNameserviceをファクトリに登録する初期化関数。
+#
+# @else
+# @brief Module initialization
+#
+# This initialization function registers FileNameservice to the factory.
+#
+# @endif
+def FileNameserviceInit(manager):
+ global service_name
+ factory_ = OpenRTM_aist.LocalServiceFactory.instance()
+ factory_.addFactory(service_name,
+ FileNameservice,
+ OpenRTM_aist.Delete)
+ return
Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ListenerHolder.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ListenerHolder.py (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ListenerHolder.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# -*- Python -*-
+
+#
+# \file test_ListenerHolder.py
+# \brief test for ListenerHolder class
+# \date $Date: 2012/01/13$
+# \author Shinji Kurihara
+#
+# Copyright (C) 2012
+# Task-intelligence Research Group,
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+#
+
+import sys
+sys.path.insert(1,"../")
+
+import unittest
+
+from ListenerHolder import *
+import OpenRTM_aist
+
+class MyListener:
+ def func(self, *args):
+ print "MyListener func args: ", args
+
+
+class TestListenerHolder(unittest.TestCase):
+ def setUp(self):
+ self.lholder = ListenerHolder()
+ self.listener = MyListener()
+
+
+ def tearDown(self):
+ OpenRTM_aist.Manager.instance().shutdownManager()
+ return
+
+ def test_addRemoveListener(self):
+ self.lholder.addListener(self.listener,True)
+ self.lholder.LISTENERHOLDER_CALLBACK(MyListener.func,"test"," ListenerHolder")
+ self.lholder.removeListener(self.listener)
+ return
+
+
+
+############### test #################
+if __name__ == '__main__':
+ unittest.main()
Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_LocalServiceAdmin.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_LocalServiceAdmin.py (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_LocalServiceAdmin.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+# -*- Python -*-
+
+#
+# \file test_LocalServiceAdmin.py
+# \brief test for LocalServiceAdmin class
+# \date $Date: 2012/01/13$
+# \author Shinji Kurihara
+#
+# Copyright (C) 2012
+# Task-intelligence Research Group,
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+#
+
+import sys
+sys.path.insert(1,"../")
+
+import unittest
+
+from LocalServiceAdmin import *
+import OpenRTM_aist
+
+class MyLocalService:
+ def __init__(self):
+ return
+
+ def init(self, props):
+ return
+
+ def reinit(self, props):
+ return
+
+ def getProfile(self):
+ prop = OpenRTM_aist.LocalServiceProfile()
+ prop.name = "MyLocalService"
+ prop.uuid = "1234"
+ p = OpenRTM_aist.Properties()
+ p.setProperty("id_", 4321)
+ prop.properties = p
+ prop.service = self
+ return prop
+
+ def finalize(self):
+ return
+
+def MyLocalServiceInit():
+ factory = OpenRTM_aist.LocalServiceFactory.instance()
+ factory.addFactory("MyLocalService",
+ MyLocalService,
+ OpenRTM_aist.Delete)
+ return
+
+
+
+class TestLocalServiceAdmin(unittest.TestCase):
+ def setUp(self):
+ self.ladmin = LocalServiceAdmin()
+ MyLocalServiceInit()
+ return
+
+ def tearDown(self):
+ OpenRTM_aist.Manager.instance().shutdownManager()
+ return
+
+ def test_init(self):
+ prop = OpenRTM_aist.Properties()
+ prop.setProperty("enabled_services","MyLocalService")
+ self.ladmin.init(prop)
+ self.ladmin.getServiceProfiles()
+
+ get_prop = [OpenRTM_aist.Properties()]
+ prof = self.ladmin.getServiceProfile("MyLocalService", get_prop)
+ lsvc = self.ladmin.getService("MyLocalService")
+ self.assertNotEqual(None, lsvc)
+ self.assertEqual(True, self.ladmin.addLocalService(lsvc))
+ self.assertEqual(True, self.ladmin.removeLocalService("MyLocalService"))
+ self.ladmin.finalize()
+ return
+
+
+
+############### test #################
+if __name__ == '__main__':
+ unittest.main()
Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ManagerActionListener.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ManagerActionListener.py (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ManagerActionListener.py 2012-01-18 08:24:10 UTC (rev 501)
@@ -0,0 +1,210 @@
+#!/usr/bin/env python
+# -*- Python -*-
+
+#
+# \file test_ManagerActionListener.py
+# \brief test for ManagerActionListener class
+# \date $Date: 2012/01/13$
+# \author Shinji Kurihara
+#
+# Copyright (C) 2012
+# Task-intelligence Research Group,
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+#
+
+import sys
+sys.path.insert(1,"../")
+
+import unittest
+
+from ManagerActionListener import *
+import OpenRTM_aist
+
+class MyManagerActionListener:
+ def __init__(self):
+ return
+
+ def preShutdown(self):
+ print "MyManagerActionListener.preShutdown "
+ return
+
+ def postShutdown(self):
+ print "MyManagerActionListener.postShutdown "
+ return
+
+ def preReinit(self):
+ print "MyManagerActionListener.preReinit "
+ return
+
+ def postReinit(self):
+ print "MyManagerActionListener.postReinit "
+ return
+
+class MyModuleActionListener:
+ def preLoad(self, modname, funcname):
+ print "MyModuleActionListener.preLoad "
+ return
+
+ def postLoad(self, modname, funcname):
+ print "MyModuleActionListener.postLoad "
+ return
+
+ def preUnload(self, modname):
+ print "MyModuleActionListener.preUnload "
+ return
+
+ def postUnload(self, modname):
+ print "MyModuleActionListener.postUnload "
+ return
+
+class MyRtcLifecycleActionListener:
+ def preCreate(self, args):
+ print "MyRtcLifecycleActionListener.preCreate "
+ return
+
+ def postCreate(self, args):
+ print "MyRtcLifecycleActionListener.postCreate "
+ return
+
+ def preConfigure(self, prop):
+ print "MyRtcLifecycleActionListener.preConfigure "
+ return
+
+ def postConfigure(self, prop):
+ print "MyRtcLifecycleActionListener.postConfigure "
+ return
+
+ def preInitialize(self):
+ print "MyRtcLifecycleActionListener.preInitialize "
+ return
+
+ def postInitialize(self):
+ print "MyRtcLifecycleActionListener.postInitialize "
+ return
+
+class MyNamingActionListener:
+ def preBind(self, rtobj, name):
+ print "MyNamingActionListener.preBind "
+ return
+
+ def postBind(self, rtobj, name):
+ print "MyNamingActionListener.postBind "
+ return
+
+ def preUnbind(self, rtobj, name):
+ print "MyNamingActionListener.preUnbind "
+ return
+
+ def postUnbind(self, rtobj, name):
+ print "MyNamingActionListener.postUnbind "
+ return
+
+class MyLocalServiceActionListener:
+ def preServiceRegister(self, service_name):
+ print "MyLocalServiceActionListener.preServiceRegister "
+ return
+
+ def postServiceRegister(self, service_name, service):
+ print "MyLocalServiceActionListener.postServiceRegister "
+ return
+
+ def preServiceInit(self, prop, service):
+ print "MyLocalServiceActionListener.preServiceInit "
+ return
+
+ def postServiceInit(self, prop, service):
+ print "MyLocalServiceActionListener.postServiceInit "
+ return
+
+ def preServiceReinit(self, prop, service):
+ print "MyLocalServiceActionListener.preServiceReinit "
+ return
+
+ def postServiceReinit(self, prop, service):
+ print "MyLocalServiceActionListener.postServiceReinit "
+ return
+
+ def preServiceFinalize(self, service_name, service):
+ print "MyLocalServiceActionListener.preServiceFinalize "
+ return
+
+ def postServiceFinalize(self, service_name, service):
+ print "MyLocalServiceActionListener.postServiceFinalize "
+ return
+
+
+
+
+class TestManagerActionListener(unittest.TestCase):
+ def setUp(self):
+ self.ma_listeners = ManagerActionListeners()
+ return
+
+ def tearDown(self):
+ OpenRTM_aist.Manager.instance().shutdownManager()
+ return
+
+ def test_ManagerActionListenerHolder(self):
+ listener = MyManagerActionListener()
+ self.ma_listeners.manager_.addListener(listener, True)
+ self.ma_listeners.manager_.preShutdown()
+ self.ma_listeners.manager_.postShutdown()
+ self.ma_listeners.manager_.preReinit()
+ self.ma_listeners.manager_.postReinit()
+ self.ma_listeners.manager_.removeListener(listener)
+ return
+
+ def test_ModuleActionListenerHolder(self):
+ listener = MyModuleActionListener()
+ self.ma_listeners.module_.addListener(listener, True)
+ self.ma_listeners.module_.preLoad("test_mod", "test_preLoad")
+ self.ma_listeners.module_.postLoad("test_mod", "test_postLoad")
+ self.ma_listeners.module_.preUnload("test_mod")
+ self.ma_listeners.module_.postUnload("test_mod")
+ self.ma_listeners.module_.removeListener(listener)
+ return
+
+ def test_RtcLifecycleActionListenerHolder(self):
+ listener = MyRtcLifecycleActionListener()
+ self.ma_listeners.rtclifecycle_.addListener(listener, True)
+ self.ma_listeners.rtclifecycle_.preCreate("preCreate")
+ self.ma_listeners.rtclifecycle_.postCreate("preCreate")
+ self.ma_listeners.rtclifecycle_.preConfigure("preConf")
+ self.ma_listeners.rtclifecycle_.postConfigure("preConf")
+ self.ma_listeners.rtclifecycle_.preInitialize()
+ self.ma_listeners.rtclifecycle_.postInitialize()
+ self.ma_listeners.rtclifecycle_.removeListener(listener)
+ return
+
+ def test_NamingActionListenerHolder(self):
+ listener = MyNamingActionListener()
+ self.ma_listeners.naming_.addListener(listener, True)
+ self.ma_listeners.naming_.preBind(None,"test_rtc")
+ self.ma_listeners.naming_.postBind(None,"test_rtc")
+ self.ma_listeners.naming_.preUnbind(None,"test_rtc")
+ self.ma_listeners.naming_.postUnbind(None,"test_rtc")
+ self.ma_listeners.naming_.removeListener(listener)
+ return
+
+ def test_LocalServiceActionListenerHolder(self):
+ listener = MyLocalServiceActionListener()
+ self.ma_listeners.localservice_.addListener(listener, True)
+ self.ma_listeners.localservice_.preServiceRegister("servicename")
+ self.ma_listeners.localservice_.postServiceRegister("servicename",None)
+ self.ma_listeners.localservice_.preServiceInit(None, "servicename")
+ self.ma_listeners.localservice_.postServiceInit(None, "servicename")
+ self.ma_listeners.localservice_.preServiceReinit(None, "servicename")
+ self.ma_listeners.localservice_.postServiceReinit(None, "servicename")
+ self.ma_listeners.localservice_.preServiceFinalize(None, "servicename")
+ self.ma_listeners.localservice_.postServiceFinalize(None, "servicename")
+ self.ma_listeners.localservice_.removeListener(listener)
+ return
+
+
+
+############### test #################
+if __name__ == '__main__':
+ unittest.main()
openrtm-commit メーリングリストの案内