[openrtm-commit:00694] r660 - in branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC: . executionContext

openrtm @ openrtm.org openrtm @ openrtm.org
2012年 2月 10日 (金) 17:03:09 JST


Author: fsi-katami
Date: 2012-02-10 17:03:08 +0900 (Fri, 10 Feb 2012)
New Revision: 660

Modified:
   branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryGlobal.java
   branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java
Log:
Daily check in. refs #2322  

Modified: branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryGlobal.java
===================================================================
--- branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryGlobal.java	2012-02-07 05:53:30 UTC (rev 659)
+++ branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryGlobal.java	2012-02-10 08:03:08 UTC (rev 660)
@@ -2,6 +2,7 @@
 
 import java.lang.reflect.Constructor;
 
+import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -187,6 +188,7 @@
      *  {@.en Map of FactoryEntry}
      */
     protected HashMap<IDENTIFIER, FactoryEntry> m_creators = new HashMap<IDENTIFIER, FactoryEntry>();
+    private HashMap<ABSTRACTCLASS, FactoryEntry> m_objects = new HashMap<ABSTRACTCLASS, FactoryEntry>();
 
     /**
      * {@.ja Identifierがマップに存在するかチェックする。}
@@ -233,7 +235,7 @@
         if (m_creators.containsKey(id)){
             return ReturnCode.ALREADY_EXISTS;
         }
-        FactoryEntry f = new FactoryEntry(creator, destructor);
+        FactoryEntry f = new FactoryEntry(id, creator, destructor);
         m_creators.put(id,f);
         return ReturnCode.FACTORY_OK;
     }
@@ -278,7 +280,9 @@
         if (!m_creators.containsKey(id)){
             return null;
         }
-        return m_creators.get(id).creator_.creator_();
+        ABSTRACTCLASS obj = m_creators.get(id).creator_.creator_();
+        m_objects.put(obj, m_creators.get(id));
+        return obj;
     }
     /**
      * {@.ja オブジェクト削除。}
@@ -296,11 +300,13 @@
      *   {@.en Deleteed object.}
      * 
      */
-    public void deleteObject(final IDENTIFIER id, ABSTRACTCLASS obj) {
+    public ReturnCode deleteObject(final IDENTIFIER id, ABSTRACTCLASS obj) {
         if (!m_creators.containsKey(id)){
-            return ;
+            return deleteObject(obj);
         }
         m_creators.get(id).destructor_.destructor_(obj);
+        m_objects.remove(obj);
+        return ReturnCode.FACTORY_OK;
     }
     /**
      * {@.ja オブジェクト削除。}
@@ -314,15 +320,127 @@
      *   {@.ja 削除するオブジェクト}
      *   {@.en Deleteed object.}
      */
-    public void deleteObject(ABSTRACTCLASS obj) {
-        Iterator it = m_creators.keySet().iterator();
+    public ReturnCode deleteObject(ABSTRACTCLASS obj) {
+        if(!m_objects.containsKey(obj)) {
+            return ReturnCode.NOT_FOUND; 
+        }
+        m_objects.get(obj).destructor_.destructor_(obj);
+        m_objects.remove(obj);
 
+        return ReturnCode.FACTORY_OK;
+    }
+
+    /**
+     * {@.ja 生成済みオブジェクトリストの取得}
+     * {@.en Getting created objects}
+     * <p>
+     * {@.ja このファクトリで生成されたオブジェクトのリストを取得する。}
+     * {@.en This operation returns a list of created objects by the factory.}
+     *
+     * @return 
+     *   {@.ja 生成済みオブジェクトリスト}
+     *   {@.en created object list}
+     *
+     */
+    public ArrayList<ABSTRACTCLASS> createdObjects() {
+        ArrayList<ABSTRACTCLASS> objects = new ArrayList<ABSTRACTCLASS>();
+        Iterator it = m_objects.keySet().iterator();
         while (it.hasNext()) {
-            m_creators.get(it.next()).destructor_.destructor_(obj);
+            objects.add((ABSTRACTCLASS)it.next());
         }
+        return objects;
     }
 
     /**
+     * {@.ja オブジェクトがこのファクトリの生成物かどうか調べる}
+     * {@.en Whether a object is a product of this factory}
+     * <p>
+     * @param obj 
+     *   {@.ja 対象オブジェクト}
+     *   {@.en A target object}
+     * @return 
+     *   {@.ja true: このファクトリの生成物
+     *         false: このファクトリの生成物ではない}
+     *   {@.en true: The object is a product of the factory
+     *         false: The object is not a product of the factory}
+     *
+     */
+    public boolean isProducerOf(ABSTRACTCLASS obj) {
+        return m_objects.containsKey(obj);
+    }
+
+    /**
+     * {@.ja オブジェクトからクラス識別子(ID)を取得する}
+     * {@.en Getting class identifier (ID) from a object}
+     * <p>
+     * {@.ja 当該オブジェクトのクラス識別子(ID)を取得する。}
+     * {@.en This operation returns a class identifier (ID) from a object.}
+     *
+     * @param obj [in] 
+     *   {@.ja クラス識別子(ID)を取得したいオブジェクト}
+     *   {@.en An object to investigate its class ID.}
+     * @param id [out] 
+     *   {@.ja クラス識別子(ID)}
+     *   {@.en Class identifier (ID)}
+     * @return 
+     *   {@.ja リターンコード NOT_FOUND: 識別子が存在しない
+     *                        FACTORY_OK: 正常終了}
+     *   {@.en Return code NOT_FOUND: ID not found
+     *                        FACTORY_OK: normal return}
+     */
+    public ReturnCode objectToIdentifier(ABSTRACTCLASS obj, IDENTIFIER id) {
+        if (!m_objects.containsKey(obj)) { 
+            return ReturnCode.NOT_FOUND; 
+        }
+        id = m_objects.get(obj).id_;
+        return ReturnCode.FACTORY_OK;
+    }
+
+    /**
+     * {@.ja オブジェクトのコンストラクタを取得する}
+     * {@.en Getting destructor of the object}
+     * <p>
+     * {@.ja このファクトリで生成されたオブジェクトのコンストラクタを取得する。
+     * obj はこのファクトリで生成されたものでなければならない。予め
+     * isProducerOf() 関数で当該オブジェクトがこのファクトリの生成物で
+     * あるかどうかをチェックしなければならない。}
+     * {@.en This operation returns a constructor of the object created by
+     * the factory.  obj must be a product of the factory.  User must
+     * check if the object is a product of the factory by using
+     * isProducerOf()-function, before using this function.}
+     *
+     * @return 
+     *   {@.ja オブジェクトのデストラクタ}
+     *   {@.en destructor of the object}
+     *
+     */
+    public ObjectCreator objectToCreator(ABSTRACTCLASS obj) {
+        return m_objects.get(obj).creator_;
+    }
+
+    /**
+     * {@.ja オブジェクトのデストラクタを取得する}
+     * {@.en Getting destructor of the object}
+     * <p>
+     * {@.ja このファクトリで生成されたオブジェクトのデストラクタを取得する。
+     * obj はこのファクトリで生成されたものでなければならない。予め
+     * isProducerOf() 関数で当該オブジェクトがこのファクトリの生成物で
+     * あるかどうかをチェックしなければならない。}
+     * {@.en This operation returns a destructor of the object created by
+     * the factory.  obj must be a product of the factory.  User must
+     * check if the object is a product of the factory by using
+     * isProducerOf()-function, before using this function.}
+     *
+     * @return 
+     *   {@.ja オブジェクトのデストラクタ}
+     *   {@.en destructor of the object}
+     *
+     */
+    public ObjectDestructor objectToDestructor(ABSTRACTCLASS obj) {
+        return m_objects.get(obj).destructor_;
+    }
+
+    /**
      * {@.ja 生成/削除インターフェース管理用クラス}
      * {@.en Class for creation/destruction interface management}
      */
@@ -343,8 +461,10 @@
          *   {@.ja 削除インターフェース}    
          *   {@.en Destruction interface}    
          */
-        public FactoryEntry(ObjectCreator creator, 
-                                                ObjectDestructor destructor) {
+        public FactoryEntry(IDENTIFIER id,
+                            ObjectCreator creator, 
+                            ObjectDestructor destructor) {
+          id_ = id;
           creator_ = creator;
           destructor_ = destructor;
         }
@@ -358,6 +478,11 @@
          * {@.en Destruction interface variable}
          */
         public ObjectDestructor destructor_;
+        /**
+         * {@.ja }
+         * {@.en }
+         */
+        public IDENTIFIER id_;
     };
     /**
      * {@.ja リターンコード}

Modified: branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java
===================================================================
--- branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java	2012-02-07 05:53:30 UTC (rev 659)
+++ branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java	2012-02-10 08:03:08 UTC (rev 660)
@@ -17,6 +17,7 @@
 import org.omg.CORBA.SystemException;
 
 import OpenRTM.ExtTrigExecutionContextServicePOA;
+import OpenRTM.ExtTrigExecutionContextServiceHelper;
 import OpenRTM.DataFlowComponent;
 import OpenRTM.DataFlowComponentHelper;
 import RTC.ExecutionContextService;
@@ -62,7 +63,7 @@
 
         if (this.m_ref == null) {
             try {
-                this.m_ref = ExecutionContextServiceHelper.narrow(POAUtil.getRef(this));
+                this.m_ref = ExtTrigExecutionContextServiceHelper.narrow(POAUtil.getRef(this));
                 
             } catch (Exception e) {
                 throw new IllegalStateException(e);
@@ -110,13 +111,25 @@
     }
 
     /**
+     * <p>ExecutionContext用のスレッドを生成します。</p>
+     */
+    public int open() {
+
+        rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.open()");
+
+        if(m_thread==null) {
+            m_thread = new Thread(this, "ExtTrigExecutionContext");
+            m_thread.start();
+        }
+        return 0;
+    }
+    /**
      * <p>ExecutionContextにattachされている各Componentの処理を呼び出します。
      * 全Componentの処理を呼び出した後、次のイベントが発生するまで休止します。</p>
      */
     public int svc() {
 
         rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.svc()");
-
         do {
             TimeValue tv = new TimeValue(0, m_usec); // (s, us)
 
@@ -133,6 +146,7 @@
                     for (int intIdx = 0; intIdx < m_comps.size(); ++intIdx) {
                         m_comps.get(intIdx).invoke();
                     }
+/*
                     while (!m_running) {
                         try {
                             Thread.sleep(0, (int) tv.getUsec());
@@ -145,6 +159,7 @@
                     } catch (InterruptedException e) {
                         e.printStackTrace();
                     }
+*/
                 }
             }
         } while (m_running);
@@ -225,7 +240,7 @@
             m_worker.notifyAll();
         }
 
-        //this.open();
+        this.open();
 
         return ReturnCode_t.RTC_OK;
     }
@@ -1010,6 +1025,7 @@
      * @param manager Managerオブジェクト
      */
     public static void ExtTrigExecutionContextInit(Manager manager) {
+
         ExecutionContextFactory<ExecutionContextBase,String> factory 
                                         = ExecutionContextFactory.instance();
         factory.addFactory("jp.go.aist.rtm.RTC.executionContext.ExtTrigExecutionContext",



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