OutPortPullConnector.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 
00005 ##
00006 # @file OutPortPullConnector.py
00007 # @brief OutPortPull type connector class
00008 # @date $Date$
00009 # @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara
00010 #
00011 # Copyright (C) 2009
00012 #     Noriaki Ando
00013 #     Task-intelligence Research Group,
00014 #     Intelligent Systems Research Institute,
00015 #     National Institute of
00016 #         Advanced Industrial Science and Technology (AIST), Japan
00017 #     All rights reserved.
00018 #
00019 
00020 from omniORB import *
00021 from omniORB import any
00022 
00023 import OpenRTM_aist
00024 
00025 
00026 ##
00027 # @if jp
00028 # @class OutPortPullConnector
00029 # @brief OutPortPullConnector クラス
00030 #
00031 # OutPort の pull 型データフローのための Connector クラス。このオブ
00032 # ジェクトは、接続時に dataflow_type に pull が指定された場合、
00033 # OutPort によって生成・所有され、InPortPullConnector と対になって、
00034 # データポートの pull 型のデータフローを実現する。一つの接続に対して、
00035 # 一つのデータストリームを提供する唯一の Connector が対応する。
00036 # Connector は 接続時に生成される UUID 形式の ID により区別される。
00037 #
00038 # OutPortPullConnector は以下の三つのオブジェクトを所有し管理する。
00039 #
00040 # - InPortConsumer
00041 # - Buffer
00042 #
00043 # OutPort に書き込まれたデータは OutPortPullConnector::write() に渡
00044 # され Buffer に書き込まれる。InPortPullConnector が
00045 # OutPortPullConnector からデータを読み出すことで InPort にデータが
00046 # 転送される。
00047 #
00048 # @since 1.0.0
00049 #
00050 # @else
00051 # @class OutPortPullConnector
00052 # @brief OutPortPullConnector class
00053 #
00054 # Connector class of OutPort for pull type dataflow. When "pull" is
00055 # specified as dataflow_type at the time of establishing
00056 # connection, this object is generated and owned by the OutPort.
00057 # This connector and InPortPullConnector make a pair and realize
00058 # pull type dataflow of data ports. One connector corresponds to
00059 # one connection which provides a data stream. Connector is
00060 # distinguished by ID of the UUID that is generated at establishing
00061 # connection.
00062 #
00063 # OutPortPullConnector owns and manages the following objects.
00064 #
00065 # - InPortConsumer
00066 # - Buffer
00067 #
00068 # Data written into the OutPort is passed to
00069 # OutPortPullConnector::write(), and it is written into the buffer.
00070 # By reading data from OutPortPullConnector to InPortPullConnector,
00071 # data transfer is realized.
00072 #
00073 # @since 1.0.0
00074 #
00075 # @endif
00076 #
00077 class OutPortPullConnector(OpenRTM_aist.OutPortConnector):
00078   """
00079   """
00080 
00081   ##
00082   # @if jp
00083   # @brief コンストラクタ
00084   #
00085   # OutPortPullConnector のコンストラクタはオブジェクト生成時に下記
00086   # を引数にとる。ConnectorInfo は接続情報を含み、この情報に従いバッ
00087   # ファ等を生成する。OutPort インターフェースのプロバイダオブジェク
00088   # トへのポインタを取り、所有権を持つので、OutPortPullConnector は
00089   # OutPortProvider の解体責任を持つ。各種イベントに対するコールバッ
00090   # ク機構を提供する ConnectorListeners を持ち、適切なタイミングでコー
00091   # ルバックを呼び出す。データバッファがもし OutPortBase から提供さ
00092   # れる場合はそのポインタを取る。
00093   #
00094   # @param info ConnectorInfo
00095   # @param provider OutPortProvider
00096   # @param listeners ConnectorListeners 型のリスナオブジェクトリスト
00097   # @param buffer CdrBufferBase 型のバッファ
00098   #
00099   # @else
00100   # @brief Constructor
00101   #
00102   # OutPortPullConnector's constructor is given the following
00103   # arguments.  According to ConnectorInfo which includes
00104   # connection information, a buffer is created.  It is also given
00105   # a pointer to the provider object for the OutPort interface.
00106   # The owner-ship of the pointer is owned by this
00107   # OutPortPullConnector, it has responsibility to destruct the
00108   # OutPortProvider.  OutPortPullConnector also has
00109   # ConnectorListeners to provide event callback mechanisms, and
00110   # they would be called at the proper timing.  If data buffer is
00111   # given by OutPortBase, the pointer to the buffer is also given
00112   # as arguments.
00113   #
00114   # @param info ConnectorInfo
00115   # @param provider OutPortProvider
00116   # @param listeners ConnectorListeners type lsitener object list
00117   # @param buffer CdrBufferBase type buffer
00118   #
00119   # @endif
00120   #
00121   # OutPortPullConnector(ConnectorInfo info,
00122   #                      OutPortProvider* provider,
00123   #                      ConnectorListeners& listeners,
00124   #                      CdrBufferBase* buffer = 0);
00125   def __init__(self, info, provider, listeners, buffer = 0):
00126     OpenRTM_aist.OutPortConnector.__init__(self, info)
00127     self._provider = provider
00128     self._listeners = listeners
00129     self._buffer = buffer
00130 
00131     if not self._buffer:
00132       self._buffer = self.createBuffer(info)
00133 
00134     if not self._provider or not self._buffer:
00135       self._rtcout.RTC_ERROR("Exeption: in OutPortPullConnector.__init__().")
00136       raise
00137 
00138     self._buffer.init(info.properties.getNode("buffer"))
00139     self._provider.setBuffer(self._buffer)
00140     self._provider.setConnector(self)
00141     self._provider.setListener(info, self._listeners)
00142     self.onConnect()
00143     return
00144 
00145 
00146   ##
00147   # @if jp
00148   # @brief デストラクタ
00149   #
00150   # disconnect() が呼ばれ、provider, buffer が解体・削除される。
00151   #
00152   # @else
00153   #
00154   # @brief Destructor
00155   #
00156   # This operation calls disconnect(), which destructs and deletes
00157   # the consumer, the publisher and the buffer.
00158   #
00159   # @endif
00160   #
00161   def __del__(self):
00162     return
00163 
00164 
00165   ##
00166   # @if jp
00167   # @brief データの書き込み
00168   #
00169   # Publisherに対してデータを書き込み、これにより対応するInPortへ
00170   # データが転送される。
00171   #
00172   # @else
00173   #
00174   # @brief Writing data
00175   #
00176   # This operation writes data into publisher and then the data
00177   # will be transferred to correspondent InPort.
00178   #
00179   # @endif
00180   #
00181   # virtual ReturnCode write(const cdrMemoryStream& data);
00182   def write(self, data):
00183     # data -> (conversion) -> CDR stream
00184     cdr_data = None
00185     if self._endian is not None:
00186       cdr_data = cdrMarshal(any.to_any(data).typecode(), data, self._endian)
00187     else:
00188       self._rtcout.RTC_ERROR("write(): endian %s is not support.",self._endian)
00189       return self.UNKNOWN_ERROR
00190     
00191     self._buffer.write(cdr_data)
00192     return self.PORT_OK
00193 
00194 
00195   ##
00196   # @if jp
00197   # @brief 接続解除
00198   #
00199   # consumer, publisher, buffer が解体・削除される。
00200   #
00201   # @else
00202   #
00203   # @brief disconnect
00204   #
00205   # This operation destruct and delete the consumer, the publisher
00206   # and the buffer.
00207   #
00208   # @endif
00209   #
00210   # virtual ReturnCode disconnect();
00211   def disconnect(self):
00212     self._rtcout.RTC_TRACE("disconnect()")
00213     self.onDisconnect()
00214     # delete provider
00215     if self._provider:
00216       OpenRTM_aist.OutPortProviderFactory.instance().deleteObject(self._provider)
00217     self._provider = 0
00218 
00219     # delete buffer
00220     if self._buffer:
00221       OpenRTM_aist.CdrBufferFactory.instance().deleteObject(self._buffer)
00222     self._buffer = 0
00223 
00224     return self.PORT_OK
00225 
00226 
00227   ##
00228   # @if jp
00229   # @brief Buffer を取得する
00230   #
00231   # Connector が保持している Buffer を返す
00232   #
00233   # @else
00234   # @brief Getting Buffer
00235   #
00236   # This operation returns this connector's buffer
00237   #
00238   # @endif
00239   #
00240   # virtual CdrBufferBase* getBuffer();
00241   def getBuffer(self):
00242     return self._buffer
00243 
00244 
00245   ##
00246   # @if jp
00247   # @brief アクティブ化
00248   #
00249   # このコネクタをアクティブ化する
00250   #
00251   # @else
00252   #
00253   # @brief Connector activation
00254   #
00255   # This operation activates this connector
00256   #
00257   # @endif
00258   #
00259   # virtual void activate(){}; // do nothing
00260   def activate(self):  # do nothing
00261     pass
00262 
00263 
00264   ##
00265   # @if jp
00266   # @brief 非アクティブ化
00267   #
00268   # このコネクタを非アクティブ化する
00269   #
00270   # @else
00271   #
00272   # @brief Connector deactivation
00273   #
00274   # This operation deactivates this connector
00275   #
00276   # @endif
00277   #
00278   # virtual void deactivate(){}; // do nothing
00279   def deactivate(self): # do nothing
00280     pass
00281 
00282     
00283   ##
00284   # @if jp
00285   # @brief Bufferの生成
00286   # @else
00287   # @brief create buffer
00288   # @endif
00289   #
00290   # CdrBufferBase* createBuffer(ConnectorInfo& info);
00291   def createBuffer(self, info):
00292     buf_type = info.properties.getProperty("buffer_type","ring_buffer")
00293     return OpenRTM_aist.CdrBufferFactory.instance().createObject(buf_type)
00294 
00295 
00296   ##
00297   # @if jp
00298   # @brief 接続確立時にコールバックを呼ぶ
00299   # @else
00300   # @brief Invoke callback when connection is established
00301   # @endif
00302   # void onConnect()
00303   def onConnect(self):
00304     if self._listeners and self._profile:
00305       self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_CONNECT].notify(self._profile)
00306     return
00307 
00308 
00309   ##
00310   # @if jp
00311   # @brief 接続切断時にコールバックを呼ぶ
00312   # @else
00313   # @brief Invoke callback when connection is destroied
00314   # @endif
00315   # void onDisconnect()
00316   def onDisconnect(self):
00317     if self._listeners and self._profile:
00318       self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT].notify(self._profile)
00319     return


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