InPortCorbaCdrProvider.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 ##
00005 # @file  InPortCorbaCdrProvider.py
00006 # @brief InPortCorbaCdrProvider class
00007 # @date  $Date: 2008-01-14 07:49:59 $
00008 # @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara
00009 #
00010 # Copyright (C) 2009
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 import sys
00019 from omniORB import *
00020 from omniORB import any
00021 
00022 import OpenRTM_aist
00023 import OpenRTM__POA,OpenRTM
00024 
00025 ##
00026 # @if jp
00027 # @class InPortCorbaCdrProvider
00028 # @brief InPortCorbaCdrProvider クラス
00029 #
00030 # 通信手段に CORBA を利用した入力ポートプロバイダーの実装クラス。
00031 #
00032 # @param DataType 当該プロバイダに割り当てたバッファが保持するデータ型
00033 #
00034 # @since 0.4.0
00035 #
00036 # @else
00037 # @class InPortCorbaCdrProvider
00038 # @brief InPortCorbaCdrProvider class
00039 #
00040 # This is an implementation class of the input port Provider 
00041 # that uses CORBA for means of communication.
00042 #
00043 # @param DataType Data type held by the buffer that attached 
00044 #                 to this provider.
00045 #
00046 # @since 0.4.0
00047 #
00048 # @endif
00049 #
00050 class InPortCorbaCdrProvider(OpenRTM_aist.InPortProvider,
00051                              OpenRTM__POA.InPortCdr):
00052     
00053   """
00054   """
00055 
00056   ##
00057   # @if jp
00058   # @brief コンストラクタ
00059   #
00060   # コンストラクタ
00061   # ポートプロパティに以下の項目を設定する。
00062   #  - インターフェースタイプ : CORBA_Any
00063   #  - データフロータイプ : Push, Pull
00064   #  - サブスクリプションタイプ : Any
00065   #
00066   # @param buffer 当該プロバイダに割り当てるバッファオブジェクト
00067   #
00068   # @else
00069   # @brief Constructor
00070   #
00071   # Constructor
00072   # Set the following items to port properties
00073   #  - Interface type : CORBA_Any
00074   #  - Data flow type : Push, Pull
00075   #  - Subscription type : Any
00076   #
00077   # @param buffer Buffer object that is attached to this provider
00078   #
00079   # @endif
00080   #
00081   def __init__(self):
00082     OpenRTM_aist.InPortProvider.__init__(self)
00083 
00084     # PortProfile setting
00085     self.setInterfaceType("corba_cdr")
00086     
00087     # ConnectorProfile setting
00088     self._objref = self._this()
00089     
00090     self._buffer = None
00091 
00092     self._profile = None
00093     self._listeners = None
00094 
00095     # set InPort's reference
00096     orb = OpenRTM_aist.Manager.instance().getORB()
00097 
00098     self._properties.append(OpenRTM_aist.NVUtil.newNV("dataport.corba_cdr.inport_ior",
00099                                                       orb.object_to_string(self._objref)))
00100     self._properties.append(OpenRTM_aist.NVUtil.newNV("dataport.corba_cdr.inport_ref",
00101                                                       self._objref))
00102 
00103     return
00104 
00105   ##
00106   # @if jp
00107   # @brief デストラクタ
00108   #
00109   # デストラクタ
00110   #
00111   # @else
00112   # @brief Destructor
00113   #
00114   # Destructor
00115   #
00116   # @endif
00117   #
00118   def __del__(self):
00119     oid = OpenRTM_aist.Manager.instance().getPOA.servant_to_id(self)
00120     OpenRTM_aist.Manager.instance().getPOA.deactivate_object(oid)
00121     return
00122 
00123   ## virtual void init(coil::Properties& prop);
00124   def init(self, prop):
00125     pass
00126 
00127   ## virtual void setBuffer(BufferBase<cdrMemoryStream>* buffer);
00128   def setBuffer(self, buffer):
00129     self._buffer = buffer
00130     return
00131 
00132   # void setListener(ConnectorInfo& info,
00133   #                  ConnectorListeners* listeners);
00134   def setListener(self, info, listeners):
00135     self._profile = info
00136     self._listeners = listeners
00137     return
00138 
00139   ##
00140   # @if jp
00141   # @brief [CORBA interface] バッファにデータを書き込む
00142   #
00143   # 設定されたバッファにデータを書き込む。
00144   #
00145   # @param data 書込対象データ
00146   #
00147   # @else
00148   # @brief [CORBA interface] Write data into the buffer
00149   #
00150   # Write data into the specified buffer.
00151   #
00152   # @param data The target data for writing
00153   #
00154   # @endif
00155   #
00156   # virtual ::OpenRTM::PortStatus put(const ::OpenRTM::CdrData& data)
00157   #  throw (CORBA::SystemException);
00158   def put(self, data):
00159     try:
00160       self._rtcout.RTC_PARANOID("InPortCorbaCdrProvider.put()")
00161             
00162       if not self._buffer:
00163         self.onReceiverError(data)
00164         return OpenRTM.PORT_ERROR
00165 
00166       self._rtcout.RTC_PARANOID("received data size: %d", len(data))
00167 
00168       self.onReceived(data)
00169 
00170       if not self._connector:
00171         return OpenRTM.PORT_ERROR
00172 
00173       ret = self._connector.write(data)
00174 
00175       return self.convertReturn(ret, data)
00176 
00177     except:
00178       self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
00179       return OpenRTM.UNKNOWN_ERROR
00180     return OpenRTM.UNKNOWN_ERROR
00181 
00182 
00183   def convertReturn(self, status, data):
00184     if status == OpenRTM_aist.BufferStatus.BUFFER_OK:
00185       self.onBufferWrite(data)
00186       return OpenRTM.PORT_OK
00187             
00188     elif status == OpenRTM_aist.BufferStatus.BUFFER_ERROR:
00189       self.onReceiverError(data)
00190       return OpenRTM.PORT_ERROR
00191 
00192     elif status == OpenRTM_aist.BufferStatus.BUFFER_FULL:
00193       self.onBufferFull(data)
00194       self.onReceiverFull(data)
00195       return OpenRTM.BUFFER_FULL
00196 
00197     elif status == OpenRTM_aist.BufferStatus.BUFFER_EMPTY:
00198       return OpenRTM.BUFFER_EMPTY
00199 
00200     elif status == OpenRTM_aist.BufferStatus.PRECONDITION_NOT_MET:
00201       self.onReceiverError(data)
00202       return OpenRTM.PORT_ERROR
00203 
00204     elif status == OpenRTM_aist.BufferStatus.TIMEOUT:
00205       self.onBufferWriteTimeout(data)
00206       self.onReceiverTimeout(data)
00207       return OpenRTM.BUFFER_TIMEOUT
00208 
00209     else:
00210       self.onReceiverError(data)
00211       return OpenRTM.UNKNOWN_ERROR
00212         
00213 
00214   ##
00215   # @brief Connector data listener functions
00216   #
00217   # inline void onBufferWrite(const cdrMemoryStream& data)
00218   def onBufferWrite(self, data):
00219     if self._listeners is not None and self._profile is not None:
00220       self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
00221     return
00222 
00223 
00224   ## inline void onBufferFull(const cdrMemoryStream& data)
00225   def onBufferFull(self, data):
00226     if self._listeners is not None and self._profile is not None:
00227       self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL].notify(self._profile, data)
00228     return
00229 
00230 
00231   ## inline void onBufferWriteTimeout(const cdrMemoryStream& data)
00232   def onBufferWriteTimeout(self, data):
00233     if self._listeners is not None and self._profile is not None:
00234       self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT].notify(self._profile, data)
00235     return
00236 
00237   ## inline void onBufferWriteOverwrite(const cdrMemoryStream& data)
00238   def onBufferWriteOverwrite(self, data):
00239     if self._listeners is not None and self._profile is not None:
00240       self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE].notify(self._profile, data)
00241     return
00242 
00243 
00244   ## inline void onReceived(const cdrMemoryStream& data)
00245   def onReceived(self, data):
00246     if self._listeners is not None and self._profile is not None:
00247       self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
00248     return
00249 
00250 
00251   ## inline void onReceiverFull(const cdrMemoryStream& data)
00252   def onReceiverFull(self, data):
00253     if self._listeners is not None and self._profile is not None:
00254       self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
00255     return
00256 
00257 
00258   ## inline void onReceiverTimeout(const cdrMemoryStream& data)
00259   def onReceiverTimeout(self, data):
00260     if self._listeners is not None and self._profile is not None:
00261       self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_TIMEOUT].notify(self._profile, data)
00262     return
00263 
00264 
00265   ## inline void onReceiverError(const cdrMemoryStream& data)
00266   def onReceiverError(self, data):
00267     if self._listeners is not None and self._profile is not None:
00268       self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_ERROR].notify(self._profile, data)
00269     return
00270 
00271 
00272 def InPortCorbaCdrProviderInit():
00273   factory = OpenRTM_aist.InPortProviderFactory.instance()
00274   factory.addFactory("corba_cdr",
00275                      OpenRTM_aist.InPortCorbaCdrProvider,
00276                      OpenRTM_aist.Delete)


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