[openrtm-commit:01884] r809 - in trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC: . port
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 4月 11日 (月) 15:28:33 JST
Author: win-ei
Date: 2016-04-11 15:28:33 +0900 (Mon, 11 Apr 2016)
New Revision: 809
Added:
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NamingOnManager.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NamingServiceNumberingPolicy.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NumberingPolicyFactory.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortDirectConsumer.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortDirectProvider.java
Modified:
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/DefaultConfiguration.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/DefaultNumberingPolicy.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryInit.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/Manager.java
Log:
Added Policy factories. refs #3397
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/DefaultConfiguration.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/DefaultConfiguration.java 2016-04-11 06:22:03 UTC (rev 808)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/DefaultConfiguration.java 2016-04-11 06:28:33 UTC (rev 809)
@@ -63,6 +63,7 @@
"manager.name", "manager",
"manager.command", "rtcd",
"manager.nameservers", "default",
+ "manager.components.naming_policy", "process_unique",
"sdo.service.provider.enabled_services", "ALL",
"sdo.service.consumer.enabled_services", "ALL",
"manager.local_service.enabled_services","ALL",
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/DefaultNumberingPolicy.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/DefaultNumberingPolicy.java 2016-04-11 06:22:03 UTC (rev 808)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/DefaultNumberingPolicy.java 2016-04-11 06:28:33 UTC (rev 809)
@@ -11,7 +11,7 @@
* 管理するためのクラス。}
* {@.en This is a class to manage the naming policy when creating objects.}
*/
-class DefaultNumberingPolicy implements NumberingPolicy {
+class DefaultNumberingPolicy implements NumberingPolicy, ObjectCreator<NumberingPolicy>, ObjectDestructor {
/**
* {@.ja コンストラクタ}
@@ -120,6 +120,49 @@
throw new Exception("ObjectNotFound");
}
+ /**
+ * {@.ja DefaultNumberingPolicy を生成する}
+ * {@.en Creats DefaultNumberingPolicy}
+ *
+ * @return
+ * {@.ja 生成されたNumberingPolicy}
+ * {@.en Object Created instances}
+ *
+ *
+ */
+ public NumberingPolicy creator_() {
+ return new DefaultNumberingPolicy();
+ }
+ /**
+ * {@.ja Object を破棄する}
+ * {@.en Destructs Object}
+ *
+ * @param obj
+ * {@.ja 破棄するインタスタンス}
+ * {@.en The target instances for destruction}
+ *
+ */
+ public void destructor_(Object obj) {
+ obj = null;
+ }
+ /**
+ * {@.ja モジュール初期化関数}
+ * {@.en Module initialization}
+ * <p>
+ * {@.ja DefaultNumberingPolicy のファクトリを登録する初期化関数。}
+ * {@.en This initialization function registers DefaultNumberingPolicy's
+ * factory.}
+ */
+ public static void DefaultNumberingPolicyInit() {
+ final NumberingPolicyFactory<NumberingPolicy,String>
+ factory
+ = NumberingPolicyFactory.instance();
+
+ factory.addFactory("process_unique",
+ new DefaultNumberingPolicy(),
+ new DefaultNumberingPolicy());
+
+ }
private int m_num;
private Vector m_objects = new Vector();
}
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryInit.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryInit.java 2016-04-11 06:22:03 UTC (rev 808)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryInit.java 2016-04-11 06:28:33 UTC (rev 809)
@@ -61,5 +61,9 @@
InPortSHMConsumer.InPortSHMConsumerInit();
OutPortSHMProvider.OutPortSHMProviderInit();
OutPortSHMConsumer.OutPortSHMConsumerInit();
+
+ DefaultNumberingPolicy.DefaultNumberingPolicyInit();
+ NodeNumberingPolicy.NodeNumberingPolicyInit();
+ NamingServiceNumberingPolicy.NamingServiceNumberingPolicyInit();
}
}
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/Manager.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/Manager.java 2016-04-11 06:22:03 UTC (rev 808)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/Manager.java 2016-04-11 06:28:33 UTC (rev 809)
@@ -1351,7 +1351,20 @@
+ profile.getProperty("type_name") + ")");
try {
- FactoryBase factory = new FactoryJava(profile, new_func, delete_func);
+ String policy_name
+ = m_config.getProperty("manager.components.naming_policy");
+
+ if(!policy_name.isEmpty()){
+ policy_name = "process_unique";
+ }
+ final NumberingPolicyFactory<NumberingPolicy,String> np_factory
+ = NumberingPolicyFactory.instance();
+ NumberingPolicy policy
+ = np_factory.createObject(policy_name);
+ //NumberingPolicy policy
+ // = NumberingPolicyFactory.instance().createObject(policy_name);
+ FactoryBase factory
+ = new FactoryJava(profile, new_func, delete_func, policy);
m_factory.registerObject(factory, new FactoryPredicate(factory));
return true;
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NamingOnManager.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NamingOnManager.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NamingOnManager.java 2016-04-11 06:28:33 UTC (rev 809)
@@ -0,0 +1,393 @@
+package jp.go.aist.rtm.RTC;
+
+import jp.go.aist.rtm.RTC.log.Logbuf;
+import jp.go.aist.rtm.RTC.port.CorbaConsumer;
+import jp.go.aist.rtm.RTC.port.PortBase;
+import jp.go.aist.rtm.RTC.util.CORBA_SeqUtil;
+import jp.go.aist.rtm.RTC.util.Properties;
+
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Object;
+import org.omg.CosNaming.NamingContext;
+import org.omg.CosNaming.NamingContextExtHelper;
+import org.omg.CosNaming.BindingIteratorHolder;
+import org.omg.CosNaming.BindingHolder;
+import org.omg.CosNaming.Binding;
+import org.omg.CosNaming.BindingListHolder;
+import org.omg.CosNaming.BindingType;
+
+import RTC.RTCListHolder;
+import RTC.RTObject;
+import RTC.RTObjectHelper;
+ /**
+ * {@.ja Manager 用 NamingServer 管理クラス}
+ * {@.en NamingServer management class for Manager}
+ *
+ * <p>
+ * {@.ja Manager 用 NamingServer 管理用クラス。
+ * Manager コンポーネントの NamingService への登録、解除などを管理する。}
+ * {@.en NamingServer management class for Manager.
+ * Manage to register and unregister Manager components to NamingService.}
+ */
+class NamingOnManager implements NamingBase {
+
+ /**
+ * {@.ja コンストラクタ}
+ * {@.en Constructor}
+ *
+ * <p>
+ *
+ * @param orb
+ * {@.ja ORB}
+ * {@.en ORB}
+ * @param mgr
+ * {@.ja Manager}
+ * {@.en Manager}
+ *
+ */
+ public NamingOnManager(ORB orb, Manager mgr) {
+/*
+ try {
+ m_cosnaming = new CorbaNaming(orb, names);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+*/
+ rtcout = new Logbuf("NamingOnManager");
+ m_cosnaming = null;
+ m_orb = orb;
+ m_mgr = mgr;
+
+ }
+
+ /**
+ * {@.en Checks that the string is IPaddress. }
+ */
+ private boolean isIpAddressFormat(String string){
+ java.util.regex.Pattern pattern
+ = java.util.regex.Pattern.compile(
+ "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})");
+ java.util.regex.Matcher matcher = pattern.matcher(string);
+ return matcher.matches();
+ }
+
+ /**
+ * {@.ja 指定したオブジェクトのNamingServiceへバインド}
+ * {@.en Bind the specified objects to NamingService}
+ *
+ * <p>
+ * {@.ja 指定したオブジェクトを指定した名称で CORBA NamingService へバイ
+ * ンドする。}
+ * {@.en Bind the specified objects to CORBA NamingService
+ * by specified names.}
+ * </p>
+ *
+ * @param name
+ * {@.ja バインド時の名称}
+ * {@.en Names at the binding}
+ * @param rtobj
+ * {@.ja バインド対象オブジェクト}
+ * {@.en The target objects for the binding}
+ *
+ */
+ public void bindObject(final String name, final RTObject_impl rtobj) {
+ rtcout.println(Logbuf.TRACE, "bindObject(" + name + ",rtobj)");
+/*
+ try{
+ m_cosnaming.rebindByString(name, rtobj.getObjRef(), true);
+ } catch ( Exception ex ) {
+ }
+*/
+ }
+
+ public void bindObject(final String name, final PortBase port) {
+ rtcout.println(Logbuf.TRACE, "bindObject(" + name + ",rtobj)");
+/*
+ try{
+ m_cosnaming.rebindByString(name, port.getPortRef(), true);
+ } catch ( Exception ex ) {
+ }
+*/
+ }
+ /**
+ * {@.ja 指定したManagerServantをNamingServiceへバインド}
+ * {@.en Bind the specified ManagerServants to NamingService}
+ *
+ * @param name
+ * {@.ja バインド時の名称}
+ * {@.en Names at the binding}
+ * @param mgr
+ * {@.ja バインド対象ManagerServant}
+ * {@.en The target ManagerServants for the binding}
+ */
+ public void bindObject(final String name, final ManagerServant mgr) {
+ rtcout.println(Logbuf.TRACE, "bindObject(" + name + ",mgr)");
+/*
+ try{
+ m_cosnaming.rebindByString(name, mgr.getObjRef(), true);
+ } catch ( Exception ex ) {
+ }
+*/
+ }
+ /**
+ *
+ * {@.ja 指定した CORBA オブジェクトのNamingServiceへバインド}
+ * {@.en Binds specified CORBA object to NamingService.}
+ * <p>
+ * {@.ja 指定した CORBA オブジェクトを指定した名称で CORBA NamingService へ
+ * バインドする。}
+ * {@.en Binds specified CORBA object to NamingService.}
+ *
+ * @param name
+ * {@.ja バインド時の名称}
+ * {@.en The name to be bound to the NamingService}
+ *
+ * @param port
+ * {@.ja バインド対象オブジェクト}
+ * {@.en The target objects to be bound to the object}
+ */
+ public void bindPortObject(final String name, final PortBase port){
+ rtcout.println(Logbuf.TRACE,
+ "bindPortObject(name = " + name + ",port)");
+/*
+ try{
+ m_cosnaming.rebindByString(name, port.getPortRef(), true);
+ }
+ catch ( Exception ex ) {
+ rtcout.println(Logbuf.ERROR, ex.toString());
+ }
+*/
+ return;
+ }
+
+
+ /**
+ * {@.ja 指定した CORBA オブジェクトをNamingServiceからアンバインド}
+ * {@.en Unbind the specified CORBA objects from NamingService}
+ *
+ * <p>
+ * {@.ja 指定した CORBA オブジェクトを CORBA NamingService から
+ * アンバインドする。}
+ * {@.en Unbind the specified CORBA objects from CORBA NamingService.}
+ *
+ * @param name
+ * {@.ja アンバインド対象オブジェクト}
+ * {@.en The target objects for the unbinding}
+ *
+ *
+ */
+ public void unbindObject(final String name) {
+ rtcout.println(Logbuf.TRACE, "unbindObject(name = " +name+")");
+/*
+ try {
+ m_cosnaming.unbind(name);
+ } catch (Exception ex) {
+ }
+*/
+ }
+
+ /**
+ * {@.ja ネームサーバの生存を確認する。}
+ * {@.en Check if the name service is alive}
+ *
+ * @return
+ * {@.ja true:生存している, false:生存していない}
+ * {@.en rue: alive, false:non not alive}
+ *
+ *
+ */
+ public boolean isAlive() {
+ rtcout.println(Logbuf.TRACE, "isAlive()");
+ //return m_cosnaming.isAlive();
+ return true;
+ }
+
+ /**
+ *
+ * {@.ja RTCの検索}
+ * {@.en Finds RTCs}
+ * <p>
+ * {@.ja ネーミングサービスからRTCをインスタンス名から検索し、
+ * 一致するRTCのリストを取得する}
+ * {@.en Finds RTCis from the inside of NamingService}
+ *
+ *
+ * @param context
+ * {@.ja 現在検索中のコンテキスト}
+ * {@.en context}
+ *
+ * @param name
+ * {@.ja RTCのインスタンス名}
+ * {@.en Instance name of RTC}
+ *
+ * @param rtcs
+ * {@.ja RTCのリスト}
+ * {@.en List of RTC}
+ *
+ */
+ public void get_RTC_by_Name(NamingContext context, String name,
+ RTCListHolder rtcs){
+
+ int length = 500;
+ BindingListHolder bl = new BindingListHolder();
+ BindingIteratorHolder bi = new BindingIteratorHolder();
+
+ context.list(length,bl,bi);
+ BindingHolder bindholder = new BindingHolder();
+ while (bi.value.next_one(bindholder)) {
+ if(bindholder.value.binding_type==BindingType.ncontext){
+ try{
+ NamingContext next_context
+ = NamingContextExtHelper.narrow(
+ context.resolve(bindholder.value.binding_name));
+ get_RTC_by_Name(next_context, name, rtcs);
+ }
+ catch(Exception ex){
+ rtcout.println(Logbuf.ERROR, "catch exception");
+ rtcout.println(Logbuf.ERROR, ex.toString());
+ return;
+ }
+ }
+ else if(bindholder.value.binding_type==BindingType.nobject){
+ if(bindholder.value.binding_name[0].id.equals(name) &&
+ bindholder.value.binding_name[0].kind.equals("rtc")){
+ try{
+ CorbaConsumer cc = new CorbaConsumer();
+ cc.setObject(context.resolve(
+ bindholder.value.binding_name));
+ RTObject obj = RTObjectHelper.narrow(cc.getObject());
+ CORBA_SeqUtil.push_back(rtcs, obj);
+ }
+ catch (Exception ex) {
+ rtcout.println(Logbuf.ERROR, "catch exception");
+ rtcout.println(Logbuf.ERROR, ex.toString());
+ }
+ }
+ }
+ }
+ }
+ /**
+ *
+ * {@.ja rtcname形式でRTCのオブジェクトリファレンスを取得する}
+ * {@.en Gets RTC objects by rtcname form.}
+ *
+ * @return
+ * {@.ja RTCのオブジェクトリファレンス}
+ * {@.en List of RTObjects}
+ * virtual RTCList string_to_component(string name) = 0;
+ */
+ public RTObject[] string_to_component(String name){
+ rtcout.println(Logbuf.PARANOID, "string_to_component("+name+")");
+ RTCListHolder rtc_list = new RTCListHolder();
+ String[] tmps = name.split("//");
+ if(tmps.length > 1){
+ rtcout.println(Logbuf.PARANOID, "tmps[0]:"+tmps[0]);
+ if(tmps[0].equals("rtcloc:")){
+ String tag = tmps[0];
+ String url = tmps[1];
+ rtcout.println(Logbuf.PARANOID, "tmps[1]:"+tmps[1]);
+ String[] elements = url.split("/");
+ if(elements.length > 1){
+ String host = elements[0];
+ rtcout.println(Logbuf.PARANOID, "host:"+host);
+
+ String rtc_name = url.substring(host.length()+1);
+ rtcout.println(Logbuf.PARANOID, "rtc_name:"+rtc_name);
+
+ RTM.Manager mgr = getManager(host);
+ if(mgr!=null){
+ rtc_list.value =
+ mgr.get_components_by_name(rtc_name);
+
+ RTM.Manager[] slaves = mgr.get_slave_managers();
+ for(int ic=0;ic<slaves.length;++ic){
+ try{
+ RTObject[] rtobjects =
+ slaves[ic].get_components_by_name(rtc_name);
+ System.arraycopy(
+ rtobjects, 0,
+ rtc_list.value, rtc_list.value.length,
+ rtobjects.length);
+// rtc_list.extend(
+// slaves[ic].get_components_by_name(rtc_name));
+ }
+ catch (Exception ex) {
+ rtcout.println(Logbuf.DEBUG, ex.toString());
+ mgr.remove_slave_manager(slaves[ic]);
+ }
+ }
+ }
+ return rtc_list.value;
+ }
+ }
+ }
+
+
+ return rtc_list.value;
+ }
+ /**
+ *
+ * {@.ja 指定ホスト名、ポート名でManagerのオブジェクトリファレンスを取得}
+ * {@.en Gets RTC objects of Manager.}
+ * @param name
+ * {@.ja 指定ホスト名、ポート名}
+ * {@.en hostname portname}
+ * @return
+ * {@.ja Managerのオブジェクトリファレンス}
+ * {@.en Manager object}
+ * virtual Manager_ptr getManager(string name);
+ */
+ public RTM.Manager getManager(String name){
+ RTM.Manager mgr;
+ if(name.equals("*")){
+ ManagerServant mgr_sev = m_mgr.getManagerServant();
+ if(mgr_sev.is_master()){
+ mgr = mgr_sev.getObjRef();
+ }
+ else{
+ RTM.Manager[] masters = mgr_sev.get_master_managers();
+ if(masters.length >0){
+ mgr = masters[0];
+ }
+ else{
+ mgr = mgr_sev.getObjRef();
+ }
+ }
+ return mgr;
+ }
+ try{
+ String mgrloc = "corbaloc:iiop:";
+ Properties prop = m_mgr.getConfig();
+ String manager_name = prop.getProperty("manager.name");
+ mgrloc += name;
+ mgrloc += "/" + manager_name;
+
+ Object mobj = m_orb.string_to_object(mgrloc);
+ mgr = RTM.ManagerHelper.narrow(mobj);
+
+ rtcout.println(Logbuf.DEBUG, "corbaloc: "+mgrloc);
+ return mgr;
+ }
+ catch (Exception ex) {
+ rtcout.println(Logbuf.DEBUG, ex.toString());
+ }
+ return null;
+ }
+
+ public CorbaNaming getCorbaNaming() {
+ return m_cosnaming;
+ }
+
+
+
+ private CorbaNaming m_cosnaming;
+ /**
+ * {@.ja Logging用フォーマットオブジェクト}
+ * {@.en Format object for Logging}
+ */
+ protected Logbuf rtcout;
+
+ private ORB m_orb;
+ private Manager m_mgr;
+}
+
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NamingServiceNumberingPolicy.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NamingServiceNumberingPolicy.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NamingServiceNumberingPolicy.java 2016-04-11 06:28:33 UTC (rev 809)
@@ -0,0 +1,151 @@
+package jp.go.aist.rtm.RTC;
+
+import java.util.Vector;
+
+import java.lang.Integer;
+/**
+ * {@.ja オブジェクト生成時ネーミング・ポリシー(命名規則)管理用クラス.}
+ * {@.en This class manages a naming policy.}
+ *
+ * <p>
+ * {@.ja ネーミングサービスからRTCを検索してナンバリングを行うi}
+ * {@.en This class searches for RTC from naming service and does a numbering.}
+ */
+class NamingServiceNumberingPolicy implements NumberingPolicy, ObjectCreator<NumberingPolicy>, ObjectDestructor {
+ /**
+ * {@.ja コンストラクタ}
+ * {@.en Constructor}
+ * <p>
+ *
+ */
+ public NamingServiceNumberingPolicy() {
+ m_num = 0;
+ m_mgr = Manager.instance();
+ }
+ /**
+ * {@.ja オブジェクト生成時の名称作成。}
+ * {@.en Create the name when creating object}
+ *
+ * <p>
+ * {@.ja オブジェクト生成時の名称を生成する。
+ * 生成済みインスタンスの数に応じた名称を生成する。}
+ * {@.en Create the name when creating object.
+ * Create the name corresponding to the number of generated instances.}
+ *
+ * @param obj
+ * {@.ja 名称生成対象オブジェクト}
+ * {@.en The target object for the name creation}
+ *
+ * @return
+ * {@.ja 生成したオブジェクト名称}
+ * {@.en Names of the created object}
+ *
+ */
+ public String onCreate(RTObject_impl obj) {
+ int num = 0;
+ while(true) {
+ String num_str = Integer.toString(num);
+ String name = obj.getTypeName() + num_str;
+ long pos = 0;
+ try {
+ pos = this.find(obj);
+ } catch (Exception e) {
+ return num_str;
+ }
+ num = num + 1;
+
+ }
+ }
+ /**
+ * {@.ja オブジェクト削除時の名称解放。}
+ * {@.en Delete the name when deleting object}
+ *
+ * <p>
+ * {@.ja オブジェクト削除時に名称を解放する。
+ * オブジェクト削除時に生成済みインスタンス数を減算する。}
+ * {@.en Delete the name when deleting object.
+ * Substract the generated number of instances when deleting the object.}
+ *
+ * @param obj
+ * {@.ja 名称解放対象オブジェクト}
+ * {@.en The target object for the name delete}
+ */
+ public void onDelete(RTObject_impl obj) {
+ }
+ /**
+ * {@.ja オブジェクトの検索}
+ * {@.en Find the object}
+ *
+ * <p>
+ * {@.ja オブジェクトリストから指定されたオブジェクトを検索し、
+ * 該当するオブジェクトが格納されている場合にはインデックスを返す。}
+ * {@.en Find the specified object in the object list and return its index
+ * when it is stored.}
+ *
+ * @param obj
+ * {@.ja 検索対象オブジェクト}
+ * {@.en The target object for the find}
+ *
+ * @return
+ * {@.ja オブジェクト格納インデックス}
+ * {@.en Object index for storage}
+ *
+ * @exception Exception
+ * {@.ja 検索対象オブジェクトが存在しない。}
+ * {@.en The object doesn't exist.}
+ */
+ protected long find(Object obj) throws Exception {
+ for(int intIdx=0;intIdx<m_objects.size();++intIdx) {
+ if(m_objects.elementAt(intIdx) == obj) return intIdx;
+ }
+ throw new Exception("ObjectNotFound");
+ }
+ /**
+ * {@.ja NamingServiceNumberingPolicy を生成する}
+ * {@.en Creats NamingServiceNumberingPolicy}
+ *
+ * @return
+ * {@.ja 生成されたNumberingPolicy}
+ * {@.en Object Created instances}
+ *
+ *
+ */
+ public NumberingPolicy creator_() {
+ return new NamingServiceNumberingPolicy();
+ }
+ /**
+ * {@.ja Object を破棄する}
+ * {@.en Destructs Object}
+ *
+ * @param obj
+ * {@.ja 破棄するインタスタンス}
+ * {@.en The target instances for destruction}
+ *
+ */
+ public void destructor_(Object obj) {
+ obj = null;
+ }
+ /**
+ * {@.ja モジュール初期化関数}
+ * {@.en Module initialization}
+ * <p>
+ * {@.ja DefaultNumberingPolicy のファクトリを登録する初期化関数。}
+ * {@.en This initialization function registers DefaultNumberingPolicy's
+ * factory.}
+ */
+ public static void NamingServiceNumberingPolicyInit() {
+ final NumberingPolicyFactory<NamingServiceNumberingPolicy,String>
+ factory
+ = NumberingPolicyFactory.instance();
+
+ factory.addFactory("ns_unique",
+ new NamingServiceNumberingPolicy(),
+ new NamingServiceNumberingPolicy());
+
+ }
+
+ private Manager m_mgr;
+ private int m_num;
+ private Vector m_objects = new Vector();
+}
+
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NumberingPolicyFactory.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NumberingPolicyFactory.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/NumberingPolicyFactory.java 2016-04-11 06:28:33 UTC (rev 809)
@@ -0,0 +1,54 @@
+package jp.go.aist.rtm.RTC;
+/**
+ * {@.ja NumberingPolicy用ファクトリの実装}
+ * {@.en Implement of factory for NumberingPolicy}
+ */
+public class NumberingPolicyFactory<ABSTRACTCLASS,IDENTIFIER> extends FactoryGlobal<ABSTRACTCLASS,IDENTIFIER> {
+ /**
+ * {@.ja コンストラクタ}
+ * {@.en Constructor}
+ *
+ * @param profile
+ * {@.ja コンポーネントのプロファイル}
+ * {@.en Component profile}
+ */
+ private NumberingPolicyFactory() {
+ }
+
+ /**
+ * {@.ja インスタンス生成。}
+ * {@.en Create instance}
+ *
+ * <p>
+ * {@.ja インスタンスを生成する。}
+ *
+ * @return
+ * {@.ja インスタンス}
+ * {@.en InPortProviderFactory object}
+ *
+ */
+ public static NumberingPolicyFactory instance() {
+ if (factory_global == null) {
+ synchronized (factory_global_mutex) {
+ if (factory_global == null) {
+ try {
+ factory_global = new NumberingPolicyFactory();
+ } catch (Exception e) {
+ factory_global = null;
+ }
+ }
+ }
+ }
+
+ return factory_global;
+ }
+ /**
+ * <p> mutex </p>
+ */
+ private static String factory_global_mutex = new String();
+ /**
+ * <p> object </p>
+ */
+ private static NumberingPolicyFactory factory_global;
+}
+
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortDirectConsumer.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortDirectConsumer.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortDirectConsumer.java 2016-04-11 06:28:33 UTC (rev 809)
@@ -0,0 +1,457 @@
+package jp.go.aist.rtm.RTC.port;
+
+import jp.go.aist.rtm.RTC.OutPortConsumerFactory;
+import jp.go.aist.rtm.RTC.ObjectCreator;
+import jp.go.aist.rtm.RTC.ObjectDestructor;
+import jp.go.aist.rtm.RTC.log.Logbuf;
+//import jp.go.aist.rtm.RTC.util.NVUtil;
+//import jp.go.aist.rtm.RTC.util.ORBUtil;
+import jp.go.aist.rtm.RTC.buffer.BufferBase;
+import jp.go.aist.rtm.RTC.util.Properties;
+
+//import org.omg.CORBA.BAD_OPERATION;
+//import org.omg.CORBA.TCKind;
+import org.omg.CORBA.portable.OutputStream;
+
+import _SDOPackage.NVListHolder;
+
+/**
+ * {@.ja OutPortDirectConsumer クラス}
+ * {@.en OutPortDirectConsumer class}
+ * <p>
+ * {@.ja データ転送に CORBA の OpenRTM::OutPortCdr インターフェースを利用し
+ * た、push 型データフロー型を実現する OutPort コンシューマクラス。}
+ * {@.en This is an implementation class of the input port Consumer </p>
+ * that uses CORBA for means of communication. </p>
+ * The OutPort consumer class which uses the OpenRTM::OutPortCdr
+ * interface in CORBA for data transfer and realizes a push-type
+ * dataflow.}
+ */
+
+public class OutPortDirectConsumer implements OutPortConsumer, ObjectCreator<OutPortConsumer>, ObjectDestructor {
+ /**
+ * {@.ja コンストラクタ}
+ * {@.en Constructor}
+ * <p>
+ * {@.en buffer 当該コンシューマに割り当てるバッファオブジェクト}
+ * {@.en buffer The buffer object that is attached to this Consumer}
+ *
+ */
+ public OutPortDirectConsumer() {
+ //super(OpenRTM.OutPortCdr.class);
+ rtcout = new Logbuf("OutPortDirectConsumer");
+ //m_orb = ORBUtil.getOrb();
+ }
+ /**
+ * {@.ja 設定初期化}
+ * {@.en Initializing configuration}
+ * <p>
+ * {@.ja OutPortConsumerの各種設定を行う。実装クラスでは、与えられた
+ * Propertiesから必要な情報を取得して各種設定を行う。この init() 関
+ * 数は、OutPortProvider生成直後および、接続時にそれぞれ呼ばれる可
+ * 能性がある。したがって、この関数は複数回呼ばれることを想定して記
+ * 述されるべきである。}
+ * {@.en This operation would be called to configure in initialization.
+ * In the concrete class, configuration should be performed
+ * getting appropriate information from the given Properties data.
+ * This function might be called right after instantiation and
+ * connection sequence respectivly. Therefore, this function
+ * should be implemented assuming multiple call.}
+ *
+ * @param prop
+ * {@.ja 設定情報}
+ * {@.en Configuration information}
+ */
+ public void init(Properties prop) {
+ m_properties = prop;
+ }
+
+ /**
+ * <p> Send data to the destination port </p>
+ * <p> Pure virtual function to send data to the destination port. </p>
+ *
+ */
+ /**
+ * {@.ja 接続先へのデータ送信}
+ * {@.en Send data to the destination port}
+ * <p>
+ * {@.ja 接続先のポートへデータを送信するための純粋仮想関数。
+ *
+ * この関数は、以下のリターンコードを返す。
+ * <ul>
+ * <li>- PORT_OK: 正常終了。
+ * <li>- PORT_ERROR: データ送信の過程で何らかのエラーが発生した。
+ * <li>- SEND_FULL: データを送信したが、相手側バッファがフルだった。
+ * <li>- SEND_TIMEOUT:データを送信したが、相手側バッファがタイムアウトした。
+ * <li>- UNKNOWN_ERROR:原因不明のエラー</ul>}
+ * {@.en Pure virtual function to send data to the destination port.
+ *
+ * This function might the following return codes
+ * <ul>
+ * <li>- PORT_OK: Normal return
+ * <li>- PORT_ERROR: Error occurred in data transfer process
+ * <li>- SEND_FULL: Buffer full although OutPort tried to send data
+ * <li>- SEND_TIMEOUT: Timeout although OutPort tried to send data
+ * <li>- UNKNOWN_ERROR: Unknown error</ul>}
+ *
+ * @param data
+ * {@.ja 送信するデータ}
+ * {@.en Data sent by this operation.}
+ * @return
+ * {@.ja リターンコード}
+ * {@.en ReturnCode}
+ */
+ public ReturnCode put(final OutputStream data) {
+ rtcout.println(Logbuf.PARANOID, "put(): never called.");
+
+ return ReturnCode.UNKNOWN_ERROR;
+ }
+ /**
+ * {@.ja InterfaceProfile情報を公開する}
+ * {@.en Publish InterfaceProfile information}
+ * <p>
+ * {@.ja InterfaceProfile情報を公開する。
+ * 引数で指定するプロパティ情報内の NameValue オブジェクトの
+ * dataport.interface_type 値を調べ、当該ポートに設定されている
+ * インターフェースタイプと一致する場合のみ情報を取得する。}
+ * {@.en Publish interfaceProfile information.
+ * Check the dataport.interface_type value of the NameValue object
+ * specified by an argument in property information and get information
+ * only when the interface type of the specified port is matched.}
+ *
+ * @param properties
+ * {@.ja InterfaceProfile情報を受け取るプロパティ}
+ * {@.en Properties to get InterfaceProfile information}
+ */
+ public void publishInterfaceProfile(NVListHolder properties) {
+ return;
+ }
+ /**
+ * {@.ja データ送信通知への登録}
+ * {@.en Subscribe to the data sending notification}
+ * <p>
+ * {@.ja 指定されたプロパティに基づいて、データ送出通知の受け取り
+ * に登録する。}
+ * {@.en Subscribe to the data sending notification based on specified
+ * property information.}
+ *
+ * @param properties
+ * {@.ja 登録情報}
+ * {@.en Information for subscription}
+ *
+ * @return
+ * {@.ja 登録処理結果(登録成功:true、登録失敗:false)}
+ * {@.en Subscription result (Successful:true, Failed:false)}
+ */
+ public boolean subscribeInterface(final NVListHolder properties) {
+ rtcout.println(Logbuf.TRACE, "subscribeInterface(): do nothing");
+ return true;
+ }
+
+ /**
+ * {@.ja データ送信通知からの登録解除}
+ * {@.en Unsubscribe the data send notification}
+ * <p>
+ * {@.ja データ送出通知の受け取りから登録を解除する。}
+ * {@.en Unsubscribe the data send notification.}
+ *
+ * @param properties
+ * {@.ja 登録解除情報}
+ * {@.en Information for unsubscription}
+ */
+ public void unsubscribeInterface(final NVListHolder properties) {
+ rtcout.println(Logbuf.TRACE, "unsubscribeInterface(): do nothing");
+ }
+
+ /**
+ * {@.ja IOR文字列からオブジェクト参照を取得する}
+ * {@.en Getting object reference fromn IOR string}
+ * @param properties
+ * {@.ja Information for subscription}
+ * {@.en Information for subscription}
+ *
+ * @return
+ * {@.ja true: 正常取得, false: 取得失敗}
+ * {@.en true: succeeded, false: failed}
+ */
+/*
+ private boolean subscribeFromIor(final NVListHolder properties) {
+ rtcout.println(Logbuf.TRACE, "subscribeFromIor()");
+
+ int index;
+ index = NVUtil.find_index(properties,
+ "dataport.corba_cdr.inport_ior");
+ if (index < 0) {
+ rtcout.println(Logbuf.ERROR, "inport_ior not found");
+ return false;
+ }
+ rtcout.println(Logbuf.DEBUG, "index:"+index);
+
+ final String ior;
+
+ try {
+ rtcout.println(Logbuf.DEBUG,
+ "type:"+properties.value[index].value.type());
+ if( properties.value[index].value.type().kind() ==
+ TCKind.tk_wstring ) {
+ ior = properties.value[index].value.extract_wstring();
+ } else {
+ ior = properties.value[index].value.extract_string();
+ }
+ }
+ catch(BAD_OPERATION e) {
+ rtcout.println(Logbuf.ERROR, "inport_ior has no string");
+ return false;
+ }
+
+ ORB orb = ORBUtil.getOrb();
+ org.omg.CORBA.Object obj = orb.string_to_object(ior);
+
+ if (obj==null) {
+ rtcout.println(Logbuf.ERROR, "invalid IOR string has been passed");
+ return false;
+ }
+
+ if (!super.setObject(obj)) {
+ rtcout.println(Logbuf.WARN, "Setting object to consumer failed.");
+ return false;
+ }
+ return true;
+ }
+*/
+ /**
+ * {@.ja Anyから直接オブジェクト参照を取得する}
+ * {@.en Getting object reference fromn Any directry}
+ * @param properties
+ * {@.ja Information for subscription}
+ * {@.en Information for subscription}
+ * @return
+ * {@.ja true: 正常取得, false: 取得失敗}
+ * {@.en true: succeeded, false: failed}
+ *
+ */
+/*
+ private boolean subscribeFromRef(final NVListHolder properties) {
+ rtcout.println(Logbuf.TRACE, "subscribeFromRef()");
+ int index;
+ index = NVUtil.find_index(properties,
+ "dataport.corba_cdr.inport_ref");
+ if (index < 0) {
+ rtcout.println(Logbuf.ERROR, "inport_ref not found");
+ return false;
+ }
+
+ org.omg.CORBA.Object obj;
+ try {
+ obj = properties.value[index].value.extract_Object();
+ }
+ catch(BAD_OPERATION e){
+ rtcout.println(Logbuf.ERROR, "prop[inport_ref] is not objref");
+ return true;
+ }
+
+ if (obj==null) {
+ rtcout.println(Logbuf.ERROR, "prop[inport_ref] is not objref");
+ return false;
+ }
+
+ if (!super.setObject(obj)) {
+ rtcout.println(Logbuf.ERROR, "Setting object to consumer failed.");
+ return false;
+ }
+ return true;
+ }
+*/
+ /**
+ * {@.ja 接続解除(IOR版)}
+ * {@.en ubsubscribing (IOR version)}
+ *
+ * @param properties
+ * {@.ja Information for unsubscription}
+ * {@.en Information for unsubscription}
+ *
+ * @return
+ * {@.ja true: 正常取得, false: 取得失敗}
+ * {@.en true: succeeded, false: failed}
+ */
+/*
+ private boolean unsubscribeFromIor(final NVListHolder properties) {
+ rtcout.println(Logbuf.TRACE, "unsubscribeFromIor()");
+ int index;
+ index = NVUtil.find_index(properties,
+ "dataport.corba_cdr.inport_ior");
+ if (index < 0) {
+ rtcout.println(Logbuf.ERROR, "inport_ior not found");
+ return false;
+ }
+
+ final String ior;
+ try {
+ if( properties.value[index].value.type().kind() ==
+ TCKind.tk_wstring ) {
+ ior = properties.value[index].value.extract_wstring();
+ } else {
+ ior = properties.value[index].value.extract_string();
+ }
+ }
+ catch(BAD_OPERATION e) {
+ rtcout.println(Logbuf.ERROR, "inport_ior has no string");
+ return false;
+ }
+
+ ORB orb = ORBUtil.getOrb();
+ org.omg.CORBA.Object var = orb.string_to_object(ior);
+ if (!(_ptr()._is_equivalent(var))) {
+ rtcout.println(Logbuf.ERROR, "connector property inconsistency");
+ return false;
+ }
+
+ releaseObject();
+ return true;
+ }
+*/
+ /**
+ * {@.ja 接続解除(Object reference版)}
+ * {@.en ubsubscribing (Object reference version)}
+ *
+ * @param properties
+ * {@.ja Information for unsubscription}
+ * {@.en Information for unsubscription}
+ * @return
+ * {@.ja true: 正常取得, false: 取得失敗}
+ * {@.en true: succeeded, false: failed}
+ */
+/*
+ private boolean unsubscribeFromRef(final NVListHolder properties) {
+ rtcout.println(Logbuf.TRACE, "unsubscribeFromRef()");
+ int index;
+ index = NVUtil.find_index(properties,
+ "dataport.corba_cdr.inport_ref");
+ if (index < 0) {
+ return false;
+ }
+
+ org.omg.CORBA.Object obj;
+ try {
+ obj = properties.value[index].value.extract_Object();
+ }
+ catch(BAD_OPERATION e){
+ rtcout.println(Logbuf.ERROR, "prop[inport_ref] is not objref");
+ return false;
+ }
+
+ if (!(_ptr()._is_equivalent(obj))) {
+ rtcout.println(Logbuf.ERROR, "connector property inconsistency");
+ return false;
+ }
+
+ releaseObject();
+ return true;
+ }
+*/
+ /**
+ * {@.ja PortStatusをReturnCodeに変換する。}
+ * {@.en Converts PortStatus into ReturnCode.}
+ *
+ * @param status
+ * {@.ja PortStatus}
+ * {@.en PortStatus}
+ * @return
+ * {@.ja ReturnCode}
+ * {@.en ReturnCode}
+ */
+ protected ReturnCode convertReturn(OpenRTM.PortStatus status) {
+ switch (status.value()) {
+ case 0:
+ return ReturnCode.PORT_OK;
+ case 1:
+ return ReturnCode.PORT_ERROR;
+ case 2:
+ return ReturnCode.BUFFER_FULL;
+ case 3:
+ return ReturnCode.BUFFER_EMPTY;
+ case 4:
+ return ReturnCode.BUFFER_TIMEOUT;
+ default:
+ return ReturnCode.UNKNOWN_ERROR;
+ }
+ }
+
+ /**
+ * {@.ja OutPortDirectConsumer を生成する}
+ * {@.en Creats OutPortDirectConsumer}
+ *
+ * @return
+ * {@.ja 生成されたOutPortConsumer}
+ * {@.en Object Created instances}
+ *
+ *
+ */
+ public OutPortConsumer creator_() {
+ return new OutPortDirectConsumer();
+ }
+ /**
+ * {@.ja Object を破棄する}
+ * {@.en Destructs Object}
+ *
+ * @param obj
+ * {@.ja 破棄するインタスタンス}
+ * {@.en The target instances for destruction}
+ *
+ */
+ public void destructor_(Object obj) {
+ obj = null;
+ }
+ /**
+ * {@.ja モジュール初期化関数}
+ * {@.en Module initialization}
+ * <p>
+ * {@.ja OutPortDirectConsumer のファクトリを登録する初期化関数。}
+ * {@.en This initialization function registers OutPortDirectConsumer's
+ * factory.}
+ */
+ public static void OutPortDirectConsumerInit() {
+ final OutPortConsumerFactory<OutPortConsumer,String> factory
+ = OutPortConsumerFactory.instance();
+
+ factory.addFactory("direct",
+ new OutPortDirectConsumer(),
+ new OutPortDirectConsumer());
+
+ }
+ /**
+ * {@.ja Connectorを設定する。}
+ * {@.en set Connector}
+ *
+ * @param connector
+ * {@.ja InPortConnector}
+ * {@.en InPortConnector}
+ */
+ public void setConnector(InPortConnector connector) {
+ m_connector = connector;
+ }
+ public void setListener(ConnectorBase.ConnectorInfo info,
+ ConnectorListeners listeners){
+ rtcout.println(Logbuf.TRACE, "setListener()");
+ m_listeners = listeners;
+ m_profile = info;
+ }
+ public ReturnCode get(OutputStream data) {
+ rtcout.println(Logbuf.TRACE, "OutPutDirectConsumer.get()");
+ return ReturnCode.PORT_OK;
+ }
+ public void setBuffer(BufferBase<OutputStream> buffer) {
+ rtcout.println(Logbuf.TRACE, "setBuffer()");
+ m_buffer = buffer;
+ }
+ private BufferBase<OutputStream> m_buffer;
+ private Logbuf rtcout;
+ private Properties m_properties;
+ private InPortConnector m_connector;
+// private ORB m_orb;
+
+ private ConnectorListeners m_listeners;
+ private ConnectorBase.ConnectorInfo m_profile;
+}
+
+
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortDirectProvider.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortDirectProvider.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortDirectProvider.java 2016-04-11 06:28:33 UTC (rev 809)
@@ -0,0 +1,632 @@
+package jp.go.aist.rtm.RTC.port;
+
+import jp.go.aist.rtm.RTC.OutPortProviderFactory;
+import jp.go.aist.rtm.RTC.ObjectCreator;
+import jp.go.aist.rtm.RTC.ObjectDestructor;
+import jp.go.aist.rtm.RTC.buffer.BufferBase;
+import jp.go.aist.rtm.RTC.log.Logbuf;
+//import jp.go.aist.rtm.RTC.util.CORBA_SeqUtil;
+import jp.go.aist.rtm.RTC.util.NVListHolderFactory;
+import jp.go.aist.rtm.RTC.util.NVUtil;
+//import jp.go.aist.rtm.RTC.util.ORBUtil;
+//import jp.go.aist.rtm.RTC.util.POAUtil;
+import jp.go.aist.rtm.RTC.util.Properties;
+
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.SystemException;
+import org.omg.CORBA.portable.OutputStream;
+
+//import OpenRTM.OutPortCdrPOA;
+import _SDOPackage.NVListHolder;
+
+
+/**
+ * {@.ja OutPortDirectProvider クラス}
+ * {@.en OutPortDirectProvider class}
+ * <p>
+ * {@.ja データ転送に CORBA の OpenRTM::OutPortCdr インターフェースを利用し
+ * た、push 型データフロー型を実現する OutPort プロバイダクラス。}
+ * {@.en This is an implementation class of the input port Provider
+ * that uses CORBA for means of communication.}
+ *
+ *
+ */
+public class OutPortDirectProvider implements OutPortProvider, ObjectCreator<OutPortProvider>, ObjectDestructor {
+ /**
+ * {@.ja コンストラクタ}
+ * {@.en Constructor}
+ *
+ *
+ */
+ public OutPortDirectProvider() {
+ m_buffer = null;
+ rtcout = new Logbuf("OutPortDirectProvider");
+ // PortProfile setting
+ setInterfaceType("direct");
+
+/*
+ // ConnectorProfile setting
+ m_objref = this._this();
+
+ // set OutPort's reference
+ ORB orb = ORBUtil.getOrb();
+ CORBA_SeqUtil.push_back(m_properties,
+ NVUtil.newNVString("dataport.corba_cdr.inport_ior",
+ orb.object_to_string(m_objref)));
+ CORBA_SeqUtil.push_back(m_properties,
+ NVUtil.newNV("dataport.corba_cdr.inport_ref",
+ m_objref, OpenRTM.OutPortCdr.class ));
+
+ m_orb = ORBUtil.getOrb();
+*/
+
+ }
+ /**
+ * {@.ja 当該OpenRTM.OutPortCdrのCORBAオブジェクト参照を取得する。}
+ * {@.en Gets CORBA object referense of this OpenRTM.OutPortCdr}
+ *
+ * @return
+ * {@.ja 当該PortのCORBAオブジェクト参照}
+ * {@.en CORBA object referense of this OpenRTM.OutPortCdr}
+ *
+ */
+/*
+ public OpenRTM.OutPortCdr _this() {
+
+ if (this.m_objref == null) {
+ try {
+ this.m_objref =
+ OpenRTM.OutPortCdrHelper.narrow(POAUtil.getRef(this));
+ } catch (Exception e) {
+ rtcout.println(Logbuf.WARN, "The exception was caught.");
+ throw new IllegalStateException(e);
+ }
+ }
+
+ return this.m_objref;
+ }
+*/
+ /**
+ * {@.ja 設定初期化}
+ * {@.en Initializing configuration}
+ * <p>
+ * {@.ja OutPortDirectProvider の各種設定を行う。与えられた
+ * Propertiesから必要な情報を取得して各種設定を行う。この init() 関
+ * 数は、OutPortProvider生成直後および、接続時にそれぞれ呼ばれる可
+ * 能性がある。したがって、この関数は複数回呼ばれることを想定して記
+ * 述されるべきである。}
+ * {@.en This operation would be called to configure in initialization.
+ * In the concrete class, configuration should be performed
+ * getting appropriate information from the given Properties data.
+ * This function might be called right after instantiation and
+ * connection sequence respectivly. Therefore, this function
+ * should be implemented assuming multiple call.}
+ *
+ * @param prop
+ * {@.ja 設定情報}
+ * {@.en Configuration information}
+ */
+ public void init(Properties prop){
+ }
+ /**
+ * {@.ja バッファをセットする}
+ * {@.en Setting outside buffer's pointer}
+ * <p>
+ * {@.ja OutPortProvider がデータを取り出すバッファをセットする。
+ * すでにセットされたバッファがある場合、以前のバッファへの
+ * ポインタに対して上書きされる。
+ * OutPortProviderはバッファの所有権を仮定していないので、
+ * バッファの削除はユーザの責任で行わなければならない。}
+ * {@.en A pointer to a buffer from which OutPortProvider retrieve data.
+ * If already buffer is set, previous buffer's pointer will be
+ * overwritten by the given pointer to a buffer. Since
+ * OutPortProvider does not assume ownership of the buffer
+ * pointer, destructor of the buffer should be done by user.}
+ *
+ * @param buffer
+ * {@.ja OutPortProviderがデータを取り出すバッファへのポインタ}
+ * {@.en A pointer to a data buffer to be used by OutPortProvider}
+ */
+ public void setBuffer(BufferBase<OutputStream> buffer) {
+ m_buffer = buffer;
+ }
+
+ /**
+ * {@.ja [CORBA interface] バッファにデータを書き込む}
+ * {@.en [CORBA interface] Write data into the buffer}
+ *
+ * <p>
+ * {@.ja 設定されたバッファにデータを書き込む。}
+ * {@.en Write data into the specified buffer.}
+ * </p>
+ *
+ * @param data
+ * {@.ja 書込対象データ}
+ * {@.en The target data for writing}
+ *
+ */
+ public OpenRTM.PortStatus put(byte[] data)
+ throws SystemException {
+
+ rtcout.println(Logbuf.PARANOID, "OutPortDirectProvider.put()");
+/*
+ if (m_buffer == null) {
+ EncapsOutputStreamExt cdr
+ = new EncapsOutputStreamExt(m_orb,m_connector.isLittleEndian());
+ cdr.write_octet_array(data, 0, data.length);
+ onReceiverError(cdr);
+ return OpenRTM.PortStatus.PORT_ERROR;
+ }
+
+
+ rtcout.println(Logbuf.PARANOID, "received data size: "+data.length);
+
+
+ EncapsOutputStreamExt cdr
+ = new EncapsOutputStreamExt(m_orb,m_connector.isLittleEndian());
+ cdr.write_octet_array(data, 0, data.length);
+
+ int len = cdr.getByteArray().length;
+ rtcout.println(Logbuf.PARANOID, "converted CDR data size: "+len);
+ onReceived(cdr);
+ jp.go.aist.rtm.RTC.buffer.ReturnCode ret = m_buffer.write(cdr);
+ return convertReturn(ret,cdr);
+*/
+ return OpenRTM.PortStatus.from_int(
+ OpenRTM.PortStatus._UNKNOWN_ERROR);
+ }
+
+ /**
+ * {@.ja [CORBA interface] バッファにデータを書き込む}
+ * {@.en [CORBA interface] Write data into the buffer}
+ * <p>
+ * {@.ja 設定されたバッファにデータを書き込む。}
+ * {@.en Write data into the specified buffer.}
+ *
+ * @param data
+ * {@.ja 書込対象データ}
+ * {@.en The target data for writing}
+ *
+ * @return
+ * {@.ja ステータス}
+ * {@.en Prot status}
+ */
+ public OpenRTM.PortStatus put(final OpenRTM.CdrDataHolder data)
+ throws SystemException {
+ return put(data.value);
+
+ }
+ /**
+ * {@.ja リターンコード変換}
+ * {p.en Return codes conversion}
+ *
+ * @param status
+ * {@.ja ReturnCode}
+ * {@.en ReturnCode}
+ * @return
+ * {@.ja PortStatus}
+ * {@.en PortStatus}
+ */
+ protected OpenRTM.PortStatus
+ convertReturn(jp.go.aist.rtm.RTC.buffer.ReturnCode status,
+ final EncapsOutputStreamExt data) {
+ switch (status) {
+ case BUFFER_OK:
+ onBufferWrite(data);
+ return OpenRTM.PortStatus.from_int(OpenRTM.PortStatus._PORT_OK);
+ case BUFFER_ERROR:
+ onReceiverError(data);
+ return OpenRTM.PortStatus.from_int(
+ OpenRTM.PortStatus._PORT_ERROR);
+
+ case BUFFER_FULL:
+ onBufferFull(data);
+ onReceiverFull(data);
+ return OpenRTM.PortStatus.from_int(
+ OpenRTM.PortStatus._BUFFER_FULL);
+
+ case BUFFER_EMPTY:
+ // never come here
+ return OpenRTM.PortStatus.from_int(
+ OpenRTM.PortStatus._BUFFER_EMPTY);
+ case TIMEOUT:
+ onBufferWriteTimeout(data);
+ onReceiverTimeout(data);
+ return OpenRTM.PortStatus.from_int(
+ OpenRTM.PortStatus._BUFFER_TIMEOUT);
+ case PRECONDITION_NOT_MET:
+ onReceiverError(data);
+ return OpenRTM.PortStatus.from_int(
+ OpenRTM.PortStatus._PORT_ERROR);
+ default:
+ onReceiverError(data);
+ return OpenRTM.PortStatus.from_int(
+ OpenRTM.PortStatus._UNKNOWN_ERROR);
+ }
+ }
+
+ private Logbuf rtcout;
+
+ /**
+ * {@.ja OutPortDirectProvider を生成する}
+ * {@.en Creats OutPortDirectProvider}
+ *
+ * @return
+ * {@.ja 生成されたOutPortProvider}
+ * {@.en Object Created instances}
+ *
+ */
+ public OutPortProvider creator_() {
+ return new OutPortDirectProvider();
+ }
+ /**
+ * {@.ja OutPortDirectProvider を破棄する}
+ * {@.en Destructs OutPortDirectProvider}
+ *
+ * @param obj
+ * {@.ja 破棄するインタスタンス}
+ * {@.en The target instances for destruction}
+ *
+ */
+ public void destructor_(Object obj) {
+/*
+ try{
+ byte[] oid
+ = _default_POA().servant_to_id((OutPortDirectProvider)obj);
+ _default_POA().deactivate_object(oid);
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+*/
+ obj = null;
+ }
+
+ /**
+ * {@.ja モジュール初期化関数}
+ * {@.en Module initialization}
+ * <p>
+ * {@.ja OutPortCorbaCdrConsumer のファクトリを登録する初期化関数。}
+ * {@.en This initialization function registers OutPortCorbaCdrConsumer's
+ * factory.}
+ */
+ public static void OutPortDirectProviderInit() {
+ final OutPortProviderFactory<OutPortProvider,String> factory
+ = OutPortProviderFactory.instance();
+
+ factory.addFactory("direct",
+ new OutPortDirectProvider(),
+ new OutPortDirectProvider());
+
+ }
+ /**
+ * <p>InterfaceProfile情報を公開します。</p>
+ *
+ * @param properties InterfaceProfile情報を受け取るホルダオブジェクト
+ */
+ /**
+ * {@.ja InterfaceProfile情報を公開する}
+ * {@.en Publish InterfaceProfile information}
+ *
+ * <p>
+ * {@.ja InterfaceProfile情報を公開する。
+ * 引数で指定するプロパティ情報内の NameValue オブジェクトの
+ * dataport.interface_type 値を調べ、当該ポートに設定されている
+ * インターフェースタイプと一致する場合のみ情報を取得する。}
+ * {@.en Publish interfaceProfile information.
+ * Check the dataport.interface_type value of the NameValue object
+ * specified by an argument in property information and get information
+ * only when the interface type of the specified port is matched.}
+ *
+ * @param properties
+ * {@.ja InterfaceProfile情報を受け取るホルダオブジェクト}
+ * {@.en Holder object to get InterfaceProfile information}
+ *
+ */
+ public void publishInterfaceProfile(NVListHolder properties) {
+
+ NVUtil.appendStringValue(properties, "dataport.interface_type",
+ this.m_interfaceType);
+ NVUtil.append(properties, this.m_properties);
+ }
+
+ /**
+ * {@.ja Interface情報を公開する}
+ * {@.en Publish interface information}
+ * <p>
+ * {@.ja Interface情報を公開する。引数で指定するプロパティ情報内の
+ * NameValue オブジェクトのdataport.interface_type 値を調べ、当該ポー
+ * トに設定されていなければNameValue に情報を追加する。すでに同一イ
+ * ンターフェースが登録済みの場合は何も行わない。}
+ * {@.en Publish interface information. Check the
+ * dataport.interface_type value of the NameValue object specified
+ * by an argument in the property information, and add the
+ * information to the NameValue if this port is not specified.
+ * This does not do anything if the same interface is already
+ * subscribed.}
+ *
+ * @param properties
+ * {@.ja properties Interface情報を受け取るホルダオブジェクト}
+ * {@.en Holder object to receive interface information}
+ * @return
+ * {@.ja true: 正常終了}
+ * {@.en true: normal return}
+ */
+ public boolean publishInterface(NVListHolder properties) {
+
+ rtcout.println(Logbuf.TRACE, "publishInterface()");
+ rtcout.println(Logbuf.DEBUG, NVUtil.toString(properties));
+
+
+ if (! NVUtil.isStringValue(properties,
+ "dataport.interface_type",
+ this.m_interfaceType)) {
+ return false;
+ }
+
+ NVUtil.append(properties, this.m_properties);
+ return true;
+
+ }
+
+ /**
+ * {@.ja リスナを設定する。}
+ * {@.en Set the listener.}
+ *
+ * <p>
+ * {@.ja OutPort はデータ送信処理における各種イベントに対して特定のリスナ
+ * オブジェクトをコールするコールバック機構を提供する。詳細は
+ * ConnectorListener.h の ConnectorDataListener, ConnectorListener
+ * 等を参照のこと。OutPortDirectProvider では、以下のコールバック
+ * が提供される。}
+ * {@.en OutPort provides callback functionality that calls specific
+ * listener objects according to the events in the data publishing
+ * process. For details, see documentation of
+ * ConnectorDataListener class and ConnectorListener class in
+ * ConnectorListener.h. In this OutPortDirectProvider provides
+ * the following callbacks.}
+ * <ul>
+ * <li>- ON_BUFFER_WRITE
+ * <li>- ON_BUFFER_FULL
+ * <li>- ON_BUFFER_WRITE_TIMEOUT
+ * <li>- ON_BUFFER_OVERWRITE
+ * <li>- ON_RECEIVED
+ * <li>- ON_RECEIVER_FULL
+ * <li>- ON_RECEIVER_FULL
+ * <li>- ON_RECEIVER_TIMEOUT
+ * <li>- ON_RECEIVER_ERROR </li></ul>
+ *
+ *
+ * @param info
+ * {@.ja 接続情報}
+ * {@.en Connector information}
+ * @param listeners
+ * {@.ja リスナオブジェクト}
+ * {@.en Listener objects}
+ */
+ public void setListener(ConnectorBase.ConnectorInfo info,
+ ConnectorListeners listeners) {
+ m_profile = info;
+ m_listeners = listeners;
+ }
+ /**
+ * {@.ja Connectorを設定する。}
+ * {@.en set Connector}
+ * <p>
+ * {@.ja OutPort は接続確立時に OutPortConnector オブジェクトを生成し、生
+ * 成したオブジェクトのポインタと共にこの関数を呼び出す。所有権は
+ * OutPort が保持するので OutPortProvider は OutPortConnector を削
+ * 除してはいけない。}
+ * {@.en OutPort creates OutPortConnector object when it establishes
+ * connection between OutPort and OutPort, and it calls this
+ * function with a pointer to the connector object. Since the
+ * OutPort has the ownership of this connector, OutPortProvider
+ * should not delete it.}
+ *
+ * @param connector
+ * {@.ja OutPortConnector}
+ * {@.en OutPortConnector}
+ */
+ public void setConnector(OutPortConnector connector) {
+ m_connector = connector;
+ }
+
+ /**
+ * {@.ja インタフェースプロフィールのデータタイプを設定する。}
+ * {@.en Sets DataType of the interface profile}
+ *
+ * @param dataType
+ * {@.ja データタイプ}
+ * {@.en dataType}
+ */
+/*
+ protected void setDataType(final String dataType) {
+ this.m_dataType = dataType;
+ }
+*/
+ /**
+ * {@.ja インタフェースプロフィールのインタフェースタイプを設定する。}
+ * {@.en Sets interface Type of the interface profile}
+ *
+ * @param interfaceType
+ * {@.ja インタフェースタイプ}
+ * {@.en Intereface Type}
+ */
+ protected void setInterfaceType(final String interfaceType) {
+ rtcout.println(Logbuf.TRACE, "setInterfaceType("+interfaceType+")");
+ this.m_interfaceType = interfaceType;
+ }
+
+ /**
+ * {@.ja インタフェースプロフィールのデータフロータイプを設定する。}
+ * {@.en Sets data flow type of the interface profile}
+ *
+ * @param dataflowType
+ * {@.ja データフロータイプ}
+ * {@.en Data flow type}
+ */
+/*
+ protected void setDataFlowType(final String dataflowType) {
+ rtcout.println(Logbuf.TRACE, "setDataFlowType("+dataflowType+")");
+ this.m_dataflowType = dataflowType;
+ }
+*/
+ /**
+ * {@.ja インタフェースプロフィールのサブスクリプションタイプを設定する。}
+ * {@.en Sets subscription type of the interface profile}
+ *
+ * @param subscriptionType
+ * {@.ja サブスクリプションタイプ}
+ * {@.en Subscription type}
+ */
+/*
+ protected void setSubscriptionType(final String subscriptionType) {
+ rtcout.println(Logbuf.TRACE,
+ "setSubscriptionType("+subscriptionType+")");
+ this.m_subscriptionType = subscriptionType;
+ }
+*/
+
+ /**
+ * <p> Connector data listener functions </p>
+ */
+ /**
+ * {@.ja ON_BUFFER_WRITE のリスナへ通知する。}
+ * {@.en Notify an ON_BUFFER_WRITE event to listeners}
+ * @param data
+ * {@.ja OutputStream}
+ * {@.en OutputStream}
+ */
+ private void onBufferWrite(final OutputStream data) {
+ m_listeners.connectorData_[ConnectorDataListenerType.ON_BUFFER_WRITE].notify(m_profile, data);
+ }
+
+ /**
+ * {@.ja ON_BUFFER_FULL のリスナへ通知する。}
+ * {@.en Notify an ON_BUFFER_FULL event to listeners}
+ * @param data
+ * {@.ja OutputStream}
+ * {@.en OutputStream}
+ */
+ private void onBufferFull(final OutputStream data) {
+ m_listeners.connectorData_[ConnectorDataListenerType.ON_BUFFER_FULL].notify(m_profile, data);
+ }
+
+ /**
+ * {@.ja ON_BUFFER_WRITE_TIMEOUT のリスナへ通知する。}
+ * {@.en Notify an ON_BUFFER_WRITE_TIMEOUT event to listeners}
+ * @param data
+ * {@.ja OutputStream}
+ * {@.en OutputStream}
+ */
+ private void onBufferWriteTimeout(final OutputStream data) {
+ m_listeners.connectorData_[ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT].notify(m_profile, data);
+ }
+
+ /**
+ * {@.ja ON_BUFFER_WRITE_OVERWRITE のリスナへ通知する。}
+ * {@.en Notify an ON_BUFFER_WRITE_OVERWRITE event to listeners}
+ * @param data
+ * {@.ja OutputStream}
+ * {@.en OutputStream}
+ */
+ private void onBufferWriteOverwrite(final OutputStream data) {
+ m_listeners.connectorData_[ConnectorDataListenerType.ON_BUFFER_OVERWRITE].notify(m_profile, data);
+ }
+
+// private void onBufferRead(final OutputStream data) {
+// m_listeners.connectorData_[ConnectorDataListenerType.ON_BUFFER_READ].notify(m_profile, data);
+// }
+
+// private void onSend(final OutputStream data) {
+// m_listeners.connectorData_[ConnectorDataListenerType.ON_SEND].notify(m_profile, data);
+// }
+
+ /**
+ * {@.ja ON_RECEIVED のリスナへ通知する。}
+ * {@.en Notify an ON_RECEIVED event to listeners}
+ * @param data
+ * {@.ja OutputStream}
+ * {@.en OutputStream}
+ */
+ private void onReceived(final OutputStream data) {
+ m_listeners.connectorData_[ConnectorDataListenerType.ON_RECEIVED].notify(m_profile, data);
+ }
+
+ /**
+ * {@.ja ON_RECEIVER_FULL のリスナへ通知する。}
+ * {@.en Notify an ON_RECEIVER_FULL event to listeners}
+ * @param data
+ * {@.ja OutputStream}
+ * {@.en OutputStream}
+ */
+ private void onReceiverFull(final OutputStream data) {
+ m_listeners.connectorData_[ConnectorDataListenerType.ON_RECEIVER_FULL].notify(m_profile, data);
+ }
+
+ /**
+ * {@.ja ON_RECEIVER_TIMEOUT のリスナへ通知する。}
+ * {@.en Notify an ON_RECEIVER_TIMEOUT event to listeners}
+ * @param data
+ * {@.ja OutputStream}
+ * {@.en OutputStream}
+ */
+ private void onReceiverTimeout(final OutputStream data) {
+ m_listeners.connectorData_[ConnectorDataListenerType.ON_RECEIVER_TIMEOUT].notify(m_profile, data);
+ }
+
+ /**
+ * {@.ja ON_RECEIVER_ERRORのリスナへ通知する。}
+ * {@.en Notify an ON_RECEIVER_ERROR event to listeners}
+ * @param data
+ * {@.ja OutputStream}
+ * {@.en OutputStream}
+ */
+ private void onReceiverError(final OutputStream data) {
+ m_listeners.connectorData_[ConnectorDataListenerType.ON_RECEIVER_ERROR].notify(m_profile, data);
+ }
+
+ /**
+ * <p> Connector listener functions </p>
+ */
+// private void onBufferEmpty() {
+// m_listeners.connector_[ConnectorDataListenerType.ON_BUFFER_EMPTY].notify(m_profile);
+// }
+
+// privaet void onBufferReadTimeout(){
+// m_listeners.connector_[ConnectorDataListenerType.ON_BUFFER_READ_TIMEOUT].notify(m_profile);
+// }
+
+// privaet void onSenderEmpty() {
+// m_listeners.connector_[ConnectorDataListenerType.ON_SENDER_EMPTY].notify(m_profile);
+// }
+
+// privaet void onSenderTimeout() {
+// m_listeners.connector_[ConnectorDataListenerType.ON_SENDER_TIMEOUT].notify(m_profile);
+// }
+
+// private void onSenderError(){
+// m_listeners.connector_[ConnectorDataListenerType.ON_SENDER_ERROR].notify(m_profile);
+// }
+
+
+
+ /**
+ * <p>インタフェース情報を保持するオブジェクトです。</p>
+ */
+ protected NVListHolder m_properties = NVListHolderFactory.create();
+
+ private String m_dataType = new String();
+ private String m_interfaceType = new String();
+ private String m_dataflowType = new String();
+ private String m_subscriptionType = new String();
+
+ private BufferBase<OutputStream> m_buffer;
+ private OpenRTM.OutPortCdr m_objref;
+
+// private ORB m_orb;
+ private OutPortConnector m_connector;
+ private ConnectorListeners m_listeners;
+ private ConnectorBase.ConnectorInfo m_profile;
+}
+
More information about the openrtm-commit
mailing list