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 import sys
00020 from omniORB import *
00021 from omniORB import any
00022
00023 import OpenRTM_aist
00024 import OpenRTM__POA,OpenRTM
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 OutPortCorbaCdrProvider(OpenRTM_aist.OutPortProvider,
00051 OpenRTM__POA.OutPortCdr):
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 def __init__(self):
00070 OpenRTM_aist.OutPortProvider.__init__(self)
00071 self.setInterfaceType("corba_cdr")
00072
00073
00074 self._objref = self._this()
00075
00076 self._buffer = None
00077
00078
00079 orb = OpenRTM_aist.Manager.instance().getORB()
00080
00081 self._properties.append(OpenRTM_aist.NVUtil.newNV("dataport.corba_cdr.outport_ior",
00082 orb.object_to_string(self._objref)))
00083 self._properties.append(OpenRTM_aist.NVUtil.newNV("dataport.corba_cdr.outport_ref",
00084 self._objref))
00085
00086 self._listeners = None
00087 self._connector = None
00088 self._profile = None
00089 return
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 def __del__(self):
00106 oid = self._default_POA().servant_to_id(self)
00107 self._default_POA().deactivate_object(oid)
00108 return
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 def init(self, prop):
00140 pass
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 def setBuffer(self, buffer):
00170 self._buffer = buffer
00171 return
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 def setListener(self, info, listeners):
00221 self._profile = info
00222 self._listeners = listeners
00223 return
00224
00225
00226
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 def setConnector(self, connector):
00252 self._connector = connector
00253 return
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 def get(self):
00275 self._rtcout.RTC_PARANOID("OutPortCorbaCdrProvider.get()")
00276 if not self._buffer:
00277 self.onSenderError()
00278 return (OpenRTM.UNKNOWN_ERROR, None)
00279
00280 try:
00281 if self._buffer.empty():
00282 self._rtcout.RTC_ERROR("buffer is empty.")
00283 return (OpenRTM.BUFFER_EMPTY, None)
00284
00285 cdr = [None]
00286 ret = self._buffer.read(cdr)
00287
00288 if ret == OpenRTM_aist.BufferStatus.BUFFER_OK:
00289 if not cdr:
00290 self._rtcout.RTC_ERROR("buffer is empty.")
00291 return (OpenRTM.BUFFER_EMPTY, None)
00292
00293 except:
00294 self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
00295 return (OpenRTM.UNKNOWN_ERROR, None)
00296
00297 return self.convertReturn(ret, cdr[0])
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 def onBufferRead(self, data):
00310 if self._listeners and self._profile:
00311 self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ].notify(self._profile, data)
00312 return
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 def onSend(self, data):
00325 if self._listeners and self._profile:
00326 self._listeners.connectorData_[OpenRTM_aist.ConnectorDataListenerType.ON_SEND].notify(self._profile, data)
00327 return
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 def onBufferEmpty(self):
00338 if self._listeners and self._profile:
00339 self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_BUFFER_EMPTY].notify(self._profile)
00340 return
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350 def onBufferReadTimeout(self):
00351 if self._listeners and self._profile:
00352 self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_BUFFER_READ_TIMEOUT].notify(self._profile)
00353 return
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 def onSenderEmpty(self):
00364 if self._listeners and self._profile:
00365 self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_EMPTY].notify(self._profile)
00366 return
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 def onSenderTimeout(self):
00377 if self._listeners and self._profile:
00378 self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_TIMEOUT].notify(self._profile)
00379 return
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 def onSenderError(self):
00390 if self._listeners and self._profile:
00391 self._listeners.connector_[OpenRTM_aist.ConnectorListenerType.ON_SENDER_ERROR].notify(self._profile)
00392 return
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 def convertReturn(self, status, data):
00405 if status == OpenRTM_aist.BufferStatus.BUFFER_OK:
00406 self.onBufferRead(data)
00407 self.onSend(data)
00408 return (OpenRTM.PORT_OK, data)
00409
00410 elif status == OpenRTM_aist.BufferStatus.BUFFER_ERROR:
00411 self.onSenderError()
00412 return (OpenRTM.PORT_ERROR, data)
00413
00414 elif status == OpenRTM_aist.BufferStatus.BUFFER_FULL:
00415
00416 return (OpenRTM.BUFFER_FULL, data)
00417
00418 elif status == OpenRTM_aist.BufferStatus.BUFFER_EMPTY:
00419 self.onBufferEmpty()
00420 self.onSenderEmpty()
00421 return (OpenRTM.BUFFER_EMPTY, data)
00422
00423 elif status == OpenRTM_aist.BufferStatus.PRECONDITION_NOT_MET:
00424 self.onSenderError()
00425 return (OpenRTM.PORT_ERROR, data)
00426
00427 elif status == OpenRTM_aist.BufferStatus.TIMEOUT:
00428 self.onBufferReadTimeout()
00429 self.onSenderTimeout()
00430 return (OpenRTM.BUFFER_TIMEOUT, data)
00431
00432 else:
00433 return (OpenRTM.UNKNOWN_ERROR, data)
00434
00435 self.onSenderError()
00436 return (OpenRTM.UNKNOWN_ERROR, data)
00437
00438
00439 def OutPortCorbaCdrProviderInit():
00440 factory = OpenRTM_aist.OutPortProviderFactory.instance()
00441 factory.addFactory("corba_cdr",
00442 OpenRTM_aist.OutPortCorbaCdrProvider,
00443 OpenRTM_aist.Delete)