InPortCorbaCdrConsumer.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 ##
00005 # @file  InPortCorbaCdrConsumer.py
00006 # @brief InPortCorbaCdrConsumer class
00007 # @date  $Date: 2007-12-31 03:08:03 $
00008 # @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara
00009 #
00010 # Copyright (C) 2006
00011 #     Noriaki Ando
00012 #     Task-intelligence Research Group,
00013 #     Intelligent Systems Research Institute,
00014 #     National Institute of
00015 #         Advanced Industrial Science and Technology (AIST), Japan
00016 #     All rights reserved.
00017 #
00018 
00019 import sys
00020 from omniORB import any
00021 from omniORB import CORBA
00022 import OpenRTM_aist
00023 import OpenRTM
00024 
00025 ##
00026 # @if jp
00027 #
00028 # @class InPortCorbaCdrConsumer
00029 #
00030 # @brief InPortCorbaCdrConsumer クラス
00031 #
00032 # 通信手段に CORBA を利用した入力ポートコンシューマの実装クラス。
00033 #
00034 # @param DataType 本ポートにて扱うデータ型
00035 #
00036 # @since 1.0
00037 #
00038 # @else
00039 # @class InPortCorbaCdrConsumer
00040 #
00041 # @brief InPortCorbaCdrConsumer class
00042 #
00043 # This is an implementation class of the input port Consumer 
00044 # that uses CORBA for means of communication.
00045 #
00046 # @param DataType Data type for this port
00047 #
00048 # @since 0.4.0
00049 #
00050 # @endif
00051 #
00052 class InPortCorbaCdrConsumer(OpenRTM_aist.InPortConsumer,OpenRTM_aist.CorbaConsumer):
00053   """
00054   """
00055 
00056   ##
00057   # @if jp
00058   # @brief コンストラクタ
00059   #
00060   # コンストラクタ
00061   #
00062   # @param buffer 当該コンシューマに割り当てるバッファオブジェクト
00063   #
00064   # @else
00065   # @brief Constructor
00066   #
00067   # Constructor
00068   #
00069   # @param buffer The buffer object that is attached to this Consumer
00070   #
00071   # @endif
00072   #
00073   def __init__(self):
00074     OpenRTM_aist.CorbaConsumer.__init__(self)
00075     self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("InPortCorbaCdrConsumer")
00076     self._properties = None
00077     return
00078 
00079   ##
00080   # @if jp
00081   # @brief デストラクタ
00082   #
00083   # デストラクタ
00084   #
00085   # @else
00086   # @brief Destructor
00087   #
00088   # Destructor
00089   #
00090   # @endif
00091   #
00092   def __del__(self, CorbaConsumer=OpenRTM_aist.CorbaConsumer):
00093     self._rtcout.RTC_PARANOID("~InPortCorbaCdrConsumer()")
00094     CorbaConsumer.__del__(self)
00095     return
00096 
00097   ##
00098   # @if jp
00099   # @brief 設定初期化
00100   #
00101   # InPortConsumerの各種設定を行う
00102   #
00103   # @else
00104   # @brief Initializing configuration
00105   #
00106   # This operation would be called to configure this consumer
00107   # in initialization.
00108   #
00109   # @endif
00110   #
00111   # virtual void init(coil::Properties& prop);
00112   def init(self, prop):
00113     self._rtcout.RTC_TRACE("init()")
00114     self._properties = prop
00115     return
00116 
00117   ##
00118   # @if jp
00119   # @brief 接続先へのデータ送信
00120   #
00121   # 接続先のポートへデータを送信するための純粋仮想関数。
00122   # 
00123   # この関数は、以下のリターンコードを返す。
00124   #
00125   # - PORT_OK:       正常終了。
00126   # - PORT_ERROR:    データ送信の過程で何らかのエラーが発生した。
00127   # - SEND_FULL:     データを送信したが、相手側バッファがフルだった。
00128   # - SEND_TIMEOUT:  データを送信したが、相手側バッファがタイムアウトした。
00129   # - UNKNOWN_ERROR: 原因不明のエラー
00130   #
00131   # @param data 送信するデータ
00132   # @return リターンコード
00133   #
00134   # @else
00135   # @brief Send data to the destination port
00136   #
00137   # Pure virtual function to send data to the destination port.
00138   #
00139   # This function might the following return codes
00140   #
00141   # - PORT_OK:       Normal return
00142   # - PORT_ERROR:    Error occurred in data transfer process
00143   # - SEND_FULL:     Buffer full although OutPort tried to send data
00144   # - SEND_TIMEOUT:  Timeout although OutPort tried to send data
00145   # - UNKNOWN_ERROR: Unknown error
00146   #
00147   # @endif
00148   #
00149   # virtual ReturnCode put(const cdrMemoryStream& data);
00150   def put(self, data):
00151     self._rtcout.RTC_PARANOID("put()")
00152 
00153     try:
00154       ref_ = self.getObject()
00155       if ref_:
00156         inportcdr = ref_._narrow(OpenRTM.InPortCdr)
00157         return self.convertReturnCode(inportcdr.put(data))
00158       return self.CONNECTION_LOST
00159     except:
00160       self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00161       return self.CONNECTION_LOST
00162         
00163     return self.UNKNOWN_ERROR
00164 
00165   ##
00166   # @if jp
00167   # @brief InterfaceProfile情報を公開する
00168   #
00169   # InterfaceProfile情報を公開する。
00170   # 引数で指定するプロパティ情報内の NameValue オブジェクトの
00171   # dataport.interface_type 値を調べ、当該ポートに設定されている
00172   # インターフェースタイプと一致する場合のみ情報を取得する。
00173   #
00174   # @param properties InterfaceProfile情報を受け取るプロパティ
00175   #
00176   # @else
00177   # @brief Publish InterfaceProfile information
00178   #
00179   # Publish interfaceProfile information.
00180   # Check the dataport.interface_type value of the NameValue object 
00181   # specified by an argument in property information and get information
00182   # only when the interface type of the specified port is matched.
00183   #
00184   # @param properties Properties to get InterfaceProfile information
00185   #
00186   # @endif
00187   #
00188   # virtual void publishInterfaceProfile(SDOPackage::NVList& properties);
00189   def publishInterfaceProfile(self, properties):
00190     return
00191 
00192   ##
00193   # @if jp
00194   # @brief データ送信通知への登録
00195   #
00196   # 指定されたプロパティに基づいて、データ送出通知の受け取りに登録する。
00197   #
00198   # @param properties 登録情報
00199   #
00200   # @return 登録処理結果(登録成功:true、登録失敗:false)
00201   #
00202   # @else
00203   # @brief Subscribe to the data sending notification
00204   #
00205   # Subscribe to the data sending notification based on specified 
00206   # property information.
00207   #
00208   # @param properties Information for subscription
00209   #
00210   # @return Subscription result (Successful:true, Failed:false)
00211   #
00212   # @endif
00213   #
00214   # virtual bool subscribeInterface(const SDOPackage::NVList& properties);
00215   def subscribeInterface(self, properties):
00216     self._rtcout.RTC_TRACE("subscribeInterface()")
00217     # self._rtcout.RTC_DEBUG_STR(OpenRTM_aist.NVUtil.toString(properties))
00218     
00219     # getting InPort's ref from IOR string
00220     if self.subscribeFromIor(properties):
00221       return True
00222     
00223     # getting InPort's ref from Object reference
00224     if self.subscribeFromRef(properties):
00225       return True
00226     
00227     return False
00228     
00229   ##
00230   # @if jp
00231   # @brief データ送信通知からの登録解除
00232   #
00233   # データ送出通知の受け取りから登録を解除する。
00234   #
00235   # @param properties 登録解除情報
00236   #
00237   # @else
00238   # @brief Unsubscribe the data send notification
00239   #
00240   # Unsubscribe the data send notification.
00241   #
00242   # @param properties Information for unsubscription
00243   #
00244   # @endif
00245   #
00246   # virtual void unsubscribeInterface(const SDOPackage::NVList& properties);
00247   def unsubscribeInterface(self, properties):
00248     self._rtcout.RTC_TRACE("unsubscribeInterface()")
00249     # self._rtcout.RTC_DEBUG_STR(OpenRTM_aist.NVUtil.toString(properties))
00250     
00251     if self.unsubscribeFromIor(properties):
00252       return
00253         
00254     self.unsubscribeFromRef(properties)
00255     return
00256 
00257   ##
00258   # @if jp
00259   # @brief IOR文字列からオブジェクト参照を取得する
00260   #
00261   # @return true: 正常取得, false: 取得失敗
00262   #
00263   # @else
00264   # @brief Getting object reference fromn IOR string
00265   #
00266   # @return true: succeeded, false: failed
00267   #
00268   # @endif
00269   #
00270   # bool subscribeFromIor(const SDOPackage::NVList& properties);
00271   def subscribeFromIor(self, properties):
00272     self._rtcout.RTC_TRACE("subscribeFromIor()")
00273     
00274     index = OpenRTM_aist.NVUtil.find_index(properties,
00275                                            "dataport.corba_cdr.inport_ior")
00276     if index < 0:
00277       self._rtcout.RTC_ERROR("inport_ior not found")
00278       return False
00279     
00280     ior = ""
00281     try:
00282       ior = any.from_any(properties[index].value, keep_structs=True)
00283     except:
00284       self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00285 
00286     if not ior:
00287       self._rtcout.RTC_ERROR("inport_ior has no string")
00288       return False
00289     
00290     orb = OpenRTM_aist.Manager.instance().getORB()
00291     obj = orb.string_to_object(ior)
00292     
00293     if CORBA.is_nil(obj):
00294       self._rtcout.RTC_ERROR("invalid IOR string has been passed")
00295       return False
00296     
00297     if not self.setObject(obj):
00298       self._rtcout.RTC_WARN("Setting object to consumer failed.")
00299       return False
00300 
00301     return True
00302 
00303   ##
00304   # @if jp
00305   # @brief Anyから直接オブジェクト参照を取得する
00306   #
00307   # @return true: 正常取得, false: 取得失敗
00308   #
00309   # @else
00310   # @brief Getting object reference fromn Any directry
00311   #
00312   # @return true: succeeded, false: failed
00313   #
00314   # @endif
00315   #
00316   # bool subscribeFromRef(const SDOPackage::NVList& properties);
00317   def subscribeFromRef(self, properties):
00318     self._rtcout.RTC_TRACE("subscribeFromRef()")
00319     index = OpenRTM_aist.NVUtil.find_index(properties,
00320                                            "dataport.corba_cdr.inport_ref")
00321     if index < 0:
00322       self._rtcout.RTC_ERROR("inport_ref not found")
00323       return False
00324     
00325     obj = None
00326     try:
00327       obj = any.from_any(properties[index].value, keep_structs=True)
00328     except:
00329       self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00330     
00331     if not obj:
00332       self._rtcout.RTC_ERROR("prop[inport_ref] is not objref")
00333       return False
00334     
00335     if CORBA.is_nil(obj):
00336       self._rtcout.RTC_ERROR("prop[inport_ref] is not objref")
00337       return False
00338     
00339     if not self.setObject(obj):
00340       self._rtcout.RTC_ERROR("Setting object to consumer failed.")
00341       return False
00342 
00343     return True
00344 
00345   ##
00346   # @if jp
00347   # @brief 接続解除(IOR版)
00348   #
00349   # @return true: 正常取得, false: 取得失敗
00350   #
00351   # @else
00352   # @brief ubsubscribing (IOR version)
00353   #
00354   # @return true: succeeded, false: failed
00355   #
00356   # @endif
00357   #
00358   # bool unsubscribeFromIor(const SDOPackage::NVList& properties);
00359   def unsubscribeFromIor(self, properties):
00360     self._rtcout.RTC_TRACE("unsubscribeFromIor()")
00361     index = OpenRTM_aist.NVUtil.find_index(properties,
00362                                            "dataport.corba_cdr.inport_ior")
00363     if index < 0:
00364       self._rtcout.RTC_ERROR("inport_ior not found")
00365       return False
00366     
00367     ior = ""
00368     try:
00369       ior = any.from_any(properties[index].value, keep_structs=True)
00370     except:
00371       self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00372 
00373     if not ior:
00374       self._rtcout.RTC_ERROR("prop[inport_ior] is not string")
00375       return False
00376     
00377     orb = OpenRTM_aist.Manager.instance().getORB()
00378     var = orb.string_to_object(ior)
00379     if not self._ptr()._is_equivalent(var):
00380       self._rtcout.RTC_ERROR("connector property inconsistency")
00381       return False
00382     
00383     self.releaseObject()
00384     return True
00385 
00386   ##
00387   # @if jp
00388   # @brief 接続解除(Object reference版)
00389   #
00390   # @return true: 正常取得, false: 取得失敗
00391   #
00392   # @else
00393   # @brief ubsubscribing (Object reference version)
00394   #
00395   # @return true: succeeded, false: failed
00396   #
00397   # @endif
00398   #
00399   # bool unsubscribeFromRef(const SDOPackage::NVList& properties);
00400   def unsubscribeFromRef(self, properties):
00401     self._rtcout.RTC_TRACE("unsubscribeFromRef()")
00402     index = OpenRTM_aist.NVUtil.find_index(properties,
00403                                            "dataport.corba_cdr.inport_ref")
00404 
00405     if index < 0:
00406       return False
00407     
00408     obj = None
00409     try:
00410       obj = any.from_any(properties[index].value, keep_structs=True)
00411     except:
00412       self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00413     
00414     if not obj:
00415       return False
00416 
00417     if not self._ptr()._is_equivalent(obj):
00418       return False
00419     
00420     self.releaseObject()
00421     return True
00422 
00423   ##
00424   # @if jp
00425   # @brief リターンコード変換
00426   # @else
00427   # @brief Return codes conversion
00428   # @endif
00429   #
00430     # ReturnCode convertReturnCode(OpenRTM::PortStatus ret)
00431   def convertReturnCode(self, ret):
00432     if ret == OpenRTM.PORT_OK:
00433       return self.PORT_OK
00434 
00435     elif ret == OpenRTM.PORT_ERROR:
00436       return self.PORT_ERROR
00437 
00438     elif ret == OpenRTM.BUFFER_FULL:
00439       return self.SEND_FULL
00440 
00441     elif ret == OpenRTM.BUFFER_TIMEOUT:
00442       return self.SEND_TIMEOUT
00443 
00444     elif ret == OpenRTM.UNKNOWN_ERROR:
00445       return self.UNKNOWN_ERROR
00446 
00447     else:
00448       return self.UNKNOWN_ERROR
00449 
00450 
00451 def InPortCorbaCdrConsumerInit():
00452   factory = OpenRTM_aist.InPortConsumerFactory.instance()
00453   factory.addFactory("corba_cdr",
00454                      OpenRTM_aist.InPortCorbaCdrConsumer,
00455                      OpenRTM_aist.Delete)


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28