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
00019
00020 import sys
00021 from omniORB import any
00022 import OpenRTM_aist
00023 import 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
00051 class OutPortCorbaCdrConsumer(OpenRTM_aist.OutPortConsumer,OpenRTM_aist.CorbaConsumer):
00052 """
00053 """
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 def __init__(self):
00073 OpenRTM_aist.CorbaConsumer.__init__(self)
00074 self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("OutPortCorbaCdrConsumer")
00075 self._buffer = None
00076 self._profile = None
00077 self._listeners = None
00078 return
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 def __del__(self, CorbaConsumer=OpenRTM_aist.CorbaConsumer):
00094 self._rtcout.RTC_PARANOID("~OutPortCorbaCdrConsumer()")
00095 CorbaConsumer.__del__(self)
00096 pass
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 def init(self, prop):
00128 self._rtcout.RTC_TRACE("init()")
00129 return
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 def setBuffer(self, buffer):
00159 self._rtcout.RTC_TRACE("setBuffer()")
00160 self._buffer = buffer
00161 return
00162
00163
00164
00165
00166 def setListener(self, info, listeners):
00167 self._rtcout.RTC_TRACE("setListener()")
00168 self._listeners = listeners
00169 self._profile = info
00170 return
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 def get(self, data):
00196 self._rtcout.RTC_PARANOID("get()")
00197
00198 try:
00199 outportcdr = self.getObject()._narrow(OpenRTM.OutPortCdr)
00200 ret,cdr_data = outportcdr.get()
00201
00202 if ret == OpenRTM.PORT_OK:
00203 self._rtcout.RTC_DEBUG("get() successful")
00204 data[0] = cdr_data
00205 self.onReceived(data[0])
00206 self.onBufferWrite(data[0])
00207
00208 if self._buffer.full():
00209 self._rtcout.RTC_INFO("InPort buffer is full.")
00210 self.onBufferFull(data[0])
00211 self.onReceiverFull(data[0])
00212
00213 self._buffer.put(data[0])
00214 self._buffer.advanceWptr()
00215 self._buffer.advanceRptr()
00216
00217 return self.PORT_OK
00218 return self.convertReturn(ret,data[0])
00219
00220 except:
00221 self._rtcout.RTC_WARN("Exception caught from OutPort.get().")
00222 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00223 return self.CONNECTION_LOST
00224
00225 self._rtcout.RTC_ERROR("get(): Never comes here.")
00226 return self.UNKNOWN_ERROR
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 def subscribeInterface(self, properties):
00253 self._rtcout.RTC_TRACE("subscribeInterface()")
00254 index = OpenRTM_aist.NVUtil.find_index(properties,"dataport.corba_cdr.outport_ior")
00255
00256 if index < 0:
00257 self._rtcout.RTC_DEBUG("dataport.corba_cdr.outport_ior not found.")
00258 return False
00259
00260 if OpenRTM_aist.NVUtil.isString(properties,"dataport.corba_cdr.outport_ior"):
00261 self._rtcout.RTC_DEBUG("dataport.corba_cdr.outport_ior found.")
00262 ior = ""
00263 try:
00264 ior = any.from_any(properties[index].value, keep_structs=True)
00265 except:
00266 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00267
00268 orb = OpenRTM_aist.Manager.instance().getORB()
00269 obj = orb.string_to_object(ior)
00270 ret = self.setObject(obj)
00271 if ret:
00272 self._rtcout.RTC_DEBUG("CorbaConsumer was set successfully.")
00273 else:
00274 self._rtcout.RTC_ERROR("Invalid object reference.")
00275
00276 return ret
00277
00278 return False
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 def unsubscribeInterface(self, properties):
00300 self._rtcout.RTC_TRACE("unsubscribeInterface()")
00301 index = OpenRTM_aist.NVUtil.find_index(properties,
00302 "dataport.corba_cdr.outport_ref")
00303 if index < 0:
00304 self._rtcout.RTC_DEBUG("dataport.corba_cdr.outport_ior not found.")
00305 return
00306
00307 ior = ""
00308 try:
00309 ior = any.from_any(properties[index].value, keep_structs=True)
00310
00311 if ior:
00312 self._rtcout.RTC_DEBUG("dataport.corba_cdr.outport_ior found.")
00313 orb = OpenRTM_aist.Manager.instance().getORB()
00314 obj = orb.string_to_object(ior)
00315 if self._ptr()._is_equivalent(obj):
00316 self.releaseObject()
00317 self._rtcout.RTC_DEBUG("CorbaConsumer's reference was released.")
00318 return
00319
00320 self._rtcout.RTC_ERROR("hmm. Inconsistent object reference.")
00321
00322 except:
00323 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00324
00325 return
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 def convertReturn(self, status, data):
00338 if status == OpenRTM.PORT_OK:
00339
00340 return self.PORT_OK
00341
00342 elif status == OpenRTM.PORT_ERROR:
00343 self.onSenderError()
00344 return self.PORT_ERROR
00345
00346 elif status == OpenRTM.BUFFER_FULL:
00347
00348 return self.BUFFER_FULL
00349
00350 elif status == OpenRTM.BUFFER_EMPTY:
00351 self.onSenderEmpty()
00352 return self.BUFFER_EMPTY
00353
00354 elif status == OpenRTM.BUFFER_TIMEOUT:
00355 self.onSenderTimeout()
00356 return self.BUFFER_TIMEOUT
00357
00358 elif status == OpenRTM.UNKNOWN_ERROR:
00359 self.onSenderError()
00360 return self.UNKNOWN_ERROR
00361
00362 else:
00363 self.onSenderError()
00364 return self.UNKNOWN_ERROR
00365
00366 self.onSenderError()
00367 return self.UNKNOWN_ERROR
00368
00369
00370
00371
00372
00373
00374 def onBufferWrite(self, data):
00375 if self._listeners is not None and self._profile is not None:
00376 self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE].notify(self._profile, data)
00377
00378 return
00379
00380
00381
00382 def onBufferFull(self, data):
00383 if self._listeners is not None and self._profile is not None:
00384 self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL].notify(self._profile, data)
00385
00386 return
00387
00388
00389
00390 def onReceived(self, data):
00391 if self._listeners is not None and self._profile is not None:
00392 self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED].notify(self._profile, data)
00393
00394 return
00395
00396
00397
00398 def onReceiverFull(self, data):
00399 if self._listeners is not None and self._profile is not None:
00400 self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL].notify(self._profile, data)
00401
00402 return
00403
00404
00405
00406
00407
00408
00409 def onSenderEmpty(self):
00410 if self._listeners is not None and self._profile is not None:
00411 self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_EMPTY].notify(self._profile)
00412
00413 return
00414
00415
00416
00417 def onSenderTimeout(self):
00418 if self._listeners is not None and self._profile is not None:
00419 self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_TIMEOUT].notify(self._profile)
00420
00421 return
00422
00423
00424
00425 def onSenderError(self):
00426 if self._listeners is not None and self._profile is not None:
00427 self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_ERROR].notify(self._profile)
00428
00429 return
00430
00431
00432 def OutPortCorbaCdrConsumerInit():
00433 factory = OpenRTM_aist.OutPortConsumerFactory.instance()
00434 factory.addFactory("corba_cdr",
00435 OpenRTM_aist.OutPortCorbaCdrConsumer,
00436 OpenRTM_aist.Delete)
00437 return