Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 class InPortCorbaCdrProvider(OpenRTM_aist.InPortProvider,
00051 OpenRTM__POA.InPortCdr):
00052
00053 """
00054 """
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 def __init__(self):
00082 OpenRTM_aist.InPortProvider.__init__(self)
00083
00084
00085 self.setInterfaceType("corba_cdr")
00086
00087
00088 self._objref = self._this()
00089
00090 self._buffer = None
00091
00092 self._profile = None
00093 self._listeners = None
00094
00095
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
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
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
00124 def init(self, prop):
00125 pass
00126
00127
00128 def setBuffer(self, buffer):
00129 self._buffer = buffer
00130 return
00131
00132
00133
00134 def setListener(self, info, listeners):
00135 self._profile = info
00136 self._listeners = listeners
00137 return
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
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
00216
00217
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
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
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
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
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
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
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
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)