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 any
00021 from omniORB import CORBA
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
00052 class InPortCorbaCdrConsumer(OpenRTM_aist.InPortConsumer,OpenRTM_aist.CorbaConsumer):
00053 """
00054 """
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 def __init__(self):
00074 OpenRTM_aist.CorbaConsumer.__init__(self)
00075 self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("InPortCorbaCdrConsumer")
00076 self._properties = None
00077 return
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 def __del__(self, CorbaConsumer=OpenRTM_aist.CorbaConsumer):
00093 self._rtcout.RTC_PARANOID("~InPortCorbaCdrConsumer()")
00094 CorbaConsumer.__del__(self)
00095 return
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 def init(self, prop):
00113 self._rtcout.RTC_TRACE("init()")
00114 self._properties = prop
00115 return
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 def put(self, data):
00151 self._rtcout.RTC_PARANOID("put()")
00152
00153 try:
00154 ref_ = self.getObject()
00155 if ref_:
00156 inportcdr = ref_._narrow(OpenRTM.InPortCdr)
00157 return self.convertReturnCode(inportcdr.put(data))
00158 return self.CONNECTION_LOST
00159 except:
00160 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00161 return self.CONNECTION_LOST
00162
00163 return self.UNKNOWN_ERROR
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 def publishInterfaceProfile(self, properties):
00190 return
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 def subscribeInterface(self, properties):
00216 self._rtcout.RTC_TRACE("subscribeInterface()")
00217
00218
00219
00220 if self.subscribeFromIor(properties):
00221 return True
00222
00223
00224 if self.subscribeFromRef(properties):
00225 return True
00226
00227 return False
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 def unsubscribeInterface(self, properties):
00248 self._rtcout.RTC_TRACE("unsubscribeInterface()")
00249
00250
00251 if self.unsubscribeFromIor(properties):
00252 return
00253
00254 self.unsubscribeFromRef(properties)
00255 return
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 def subscribeFromIor(self, properties):
00272 self._rtcout.RTC_TRACE("subscribeFromIor()")
00273
00274 index = OpenRTM_aist.NVUtil.find_index(properties,
00275 "dataport.corba_cdr.inport_ior")
00276 if index < 0:
00277 self._rtcout.RTC_ERROR("inport_ior not found")
00278 return False
00279
00280 ior = ""
00281 try:
00282 ior = any.from_any(properties[index].value, keep_structs=True)
00283 except:
00284 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00285
00286 if not ior:
00287 self._rtcout.RTC_ERROR("inport_ior has no string")
00288 return False
00289
00290 orb = OpenRTM_aist.Manager.instance().getORB()
00291 obj = orb.string_to_object(ior)
00292
00293 if CORBA.is_nil(obj):
00294 self._rtcout.RTC_ERROR("invalid IOR string has been passed")
00295 return False
00296
00297 if not self.setObject(obj):
00298 self._rtcout.RTC_WARN("Setting object to consumer failed.")
00299 return False
00300
00301 return True
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 def subscribeFromRef(self, properties):
00318 self._rtcout.RTC_TRACE("subscribeFromRef()")
00319 index = OpenRTM_aist.NVUtil.find_index(properties,
00320 "dataport.corba_cdr.inport_ref")
00321 if index < 0:
00322 self._rtcout.RTC_ERROR("inport_ref not found")
00323 return False
00324
00325 obj = None
00326 try:
00327 obj = any.from_any(properties[index].value, keep_structs=True)
00328 except:
00329 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00330
00331 if not obj:
00332 self._rtcout.RTC_ERROR("prop[inport_ref] is not objref")
00333 return False
00334
00335 if CORBA.is_nil(obj):
00336 self._rtcout.RTC_ERROR("prop[inport_ref] is not objref")
00337 return False
00338
00339 if not self.setObject(obj):
00340 self._rtcout.RTC_ERROR("Setting object to consumer failed.")
00341 return False
00342
00343 return True
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 def unsubscribeFromIor(self, properties):
00360 self._rtcout.RTC_TRACE("unsubscribeFromIor()")
00361 index = OpenRTM_aist.NVUtil.find_index(properties,
00362 "dataport.corba_cdr.inport_ior")
00363 if index < 0:
00364 self._rtcout.RTC_ERROR("inport_ior not found")
00365 return False
00366
00367 ior = ""
00368 try:
00369 ior = any.from_any(properties[index].value, keep_structs=True)
00370 except:
00371 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00372
00373 if not ior:
00374 self._rtcout.RTC_ERROR("prop[inport_ior] is not string")
00375 return False
00376
00377 orb = OpenRTM_aist.Manager.instance().getORB()
00378 var = orb.string_to_object(ior)
00379 if not self._ptr()._is_equivalent(var):
00380 self._rtcout.RTC_ERROR("connector property inconsistency")
00381 return False
00382
00383 self.releaseObject()
00384 return True
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400 def unsubscribeFromRef(self, properties):
00401 self._rtcout.RTC_TRACE("unsubscribeFromRef()")
00402 index = OpenRTM_aist.NVUtil.find_index(properties,
00403 "dataport.corba_cdr.inport_ref")
00404
00405 if index < 0:
00406 return False
00407
00408 obj = None
00409 try:
00410 obj = any.from_any(properties[index].value, keep_structs=True)
00411 except:
00412 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00413
00414 if not obj:
00415 return False
00416
00417 if not self._ptr()._is_equivalent(obj):
00418 return False
00419
00420 self.releaseObject()
00421 return True
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431 def convertReturnCode(self, ret):
00432 if ret == OpenRTM.PORT_OK:
00433 return self.PORT_OK
00434
00435 elif ret == OpenRTM.PORT_ERROR:
00436 return self.PORT_ERROR
00437
00438 elif ret == OpenRTM.BUFFER_FULL:
00439 return self.SEND_FULL
00440
00441 elif ret == OpenRTM.BUFFER_TIMEOUT:
00442 return self.SEND_TIMEOUT
00443
00444 elif ret == OpenRTM.UNKNOWN_ERROR:
00445 return self.UNKNOWN_ERROR
00446
00447 else:
00448 return self.UNKNOWN_ERROR
00449
00450
00451 def InPortCorbaCdrConsumerInit():
00452 factory = OpenRTM_aist.InPortConsumerFactory.instance()
00453 factory.addFactory("corba_cdr",
00454 OpenRTM_aist.InPortCorbaCdrConsumer,
00455 OpenRTM_aist.Delete)