00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import threading
00018 import string
00019 import signal, os
00020 import sys
00021 import traceback
00022 import time
00023 from omniORB import CORBA
00024
00025 import OpenRTM
00026 import RTC
00027 import SDOPackage
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 manager = None
00042
00043
00044
00045
00046
00047
00048
00049 mutex = threading.RLock()
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 def handler(signum, frame):
00065 mgr = OpenRTM.Manager.instance()
00066 mgr.terminate()
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 class ScopedLock:
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 def __init__(self, mutex):
00099 self.mutex = mutex
00100 self.mutex.acquire()
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 def __del__(self):
00115 self.mutex.release()
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 class Manager:
00133 """
00134 """
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 def __init__(self, _manager=None):
00152 self._initProc = None
00153 self._runner = None
00154 self._terminator = None
00155 self._compManager = OpenRTM.ObjectManager(self.InstanceName)
00156 self._factory = OpenRTM.ObjectManager(self.FactoryPredicate)
00157 self._ecfactory = OpenRTM.ObjectManager(self.ECFactoryPredicate)
00158 self._terminate = self.Term()
00159 self._ecs = []
00160 self._timer = None
00161 signal.signal(signal.SIGINT, handler)
00162
00163 return
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
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 def init(argv):
00206 global manager
00207 global mutex
00208
00209 if manager is None:
00210 guard = ScopedLock(mutex)
00211 if manager is None:
00212 manager = Manager()
00213 manager.initManager(argv)
00214 manager.initLogger()
00215 manager.initORB()
00216 manager.initNaming()
00217 manager.initExecContext()
00218 manager.initTimer()
00219
00220 return manager
00221
00222 init = staticmethod(init)
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 def instance():
00246 global manager
00247 global mutex
00248
00249 if manager is None:
00250 guard = ScopedLock(mutex)
00251 if manager is None:
00252 manager = Manager()
00253 manager.initManager(None)
00254 manager.initLogger()
00255 manager.initORB()
00256 manager.initNaming()
00257 manager.initExecContext()
00258 manager.initTimer()
00259
00260 return manager
00261
00262 instance = staticmethod(instance)
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 def terminate(self):
00277 if self._terminator:
00278 self._terminator.terminate()
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 def shutdown(self):
00294 self._rtcout.RTC_DEBUG("Manager::shutdown()")
00295 self.shutdownComponents()
00296 self.shutdownNaming()
00297 self.shutdownORB()
00298 self.shutdownManager()
00299
00300 if self._runner:
00301 self._runner.wait()
00302 else:
00303 self.join()
00304
00305 self.shutdownLogger()
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 def join(self):
00320 self._rtcout.RTC_DEBUG("Manager::wait()")
00321 guard = ScopedLock(self._terminate.mutex)
00322 self._terminate.waiting += 1
00323 del guard
00324 while 1:
00325 guard = ScopedLock(self._terminate.mutex)
00326
00327 if self._terminate.waiting > 0:
00328 break
00329 del guard
00330 time.sleep(0.001)
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 def setModuleInitProc(self, proc):
00358 self._initProc = proc
00359 return
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 def activateManager(self):
00393 self._rtcout.RTC_DEBUG("Manager::activateManager()")
00394
00395 try:
00396 self.getPOAManager().activate()
00397 if self._initProc:
00398 self._initProc(self)
00399 except:
00400 print "Exception: Manager.activateManager()"
00401 return False
00402
00403 return True
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436 def runManager(self, no_block=None):
00437 if no_block:
00438 no_block = False
00439
00440 if no_block:
00441 self._rtcout.RTC_DEBUG("Manager::runManager(): non-blocking mode")
00442 self._runner = self.OrbRunner(self._orb)
00443
00444 else:
00445 self._rtcout.RTC_DEBUG("Manager::runManager(): blocking mode")
00446 self._orb.run()
00447 self._rtcout.RTC_DEBUG("Manager::runManager(): ORB was terminated")
00448 self.join()
00449 return
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474 def load(self, fname, initfunc):
00475 self._rtcout.RTC_DEBUG("Manager::load()")
00476 self._module.load(fname, initfunc)
00477 return
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 def unload(self, fname):
00500 self._rtcout.RTC_DEBUG("Manager::unload()")
00501 self._module.unload(fname)
00502 return
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521 def unloadAll(self):
00522 self._rtcout.RTC_DEBUG("Manager::unloadAll()")
00523 self._module.unloadAll()
00524 return
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540 def getLoadedModules(self):
00541 self._rtcout.RTC_DEBUG("Manager::getLoadedModules()")
00542 return self._module.getLoadedModules()
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 def getLoadableModules(self):
00560 self._rtcout.RTC_DEBUG("Manager::getLoadableModules()")
00561 return self._module.getLoadableModules()
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585 def registerFactory(self, profile, new_func, delete_func):
00586 self._rtcout.RTC_DEBUG("Manager::registerFactory(%s)", profile.getProperty("type_name"))
00587 try:
00588 factory = OpenRTM.FactoryPython(profile, new_func, delete_func)
00589 self._factory.registerObject(factory)
00590 return True
00591 except:
00592 return False
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611 def registerECFactory(self, name, new_func, delete_func):
00612 self._rtcout.RTC_DEBUG("Manager::registerECFactory(%s)", name)
00613 try:
00614 self._ecfactory.registerObject(OpenRTM.ECFactoryPython(name, new_func, delete_func))
00615 return True
00616 except:
00617 return False
00618
00619 return False
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635 def getModulesFactories(self):
00636 self._rtcout.RTC_DEBUG("Manager::getModulesFactories()")
00637
00638 self._modlist = []
00639 for _obj in self._factory._objects._obj:
00640 self._modlist.append(_obj.profile().getProperty("implementation_id"))
00641 return self._modlist
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666 def createComponent(self, module_name):
00667 self._rtcout.RTC_DEBUG("Manager::createComponent(%s)", module_name)
00668
00669 obj = self._factory.find(module_name)
00670 comp = obj.create(self)
00671 if comp is None:
00672 return None
00673 self._rtcout.RTC_DEBUG("RTC Created: %s", module_name)
00674
00675 self.configureComponent(comp)
00676
00677 if comp.initialize() != RTC.RTC_OK:
00678 self._rtcout.RTC_DEBUG("RTC initialization failed: %s", module_name)
00679 comp.exit()
00680 self._rtcout.RTC_DEBUG("%s was finalized", module_name)
00681 return None
00682
00683 self._rtcout.RTC_DEBUG("RTC initialization succeeded: %s", module_name)
00684 self.bindExecutionContext(comp)
00685 self.registerComponent(comp)
00686 return comp
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704 def registerComponent(self, comp):
00705 self._rtcout.RTC_DEBUG("Manager::registerComponent(%s)", comp.getInstanceName())
00706
00707 self._compManager.registerObject(comp)
00708 names = comp.getNamingNames()
00709
00710 for name in names:
00711 self._rtcout.RTC_DEBUG("Bind name: %s", name)
00712 self._namingManager.bindObject(name, comp)
00713
00714 return True
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731 def unregisterComponent(self, comp):
00732 self._rtcout.RTC_DEBUG("Manager::unregisterComponent(%s)", comp.getInstanceName())
00733 self._compManager.unregisterObject(comp.getInstanceName())
00734 names = comp.getNamingNames()
00735
00736 for name in names:
00737 self._rtcout.RTC_DEBUG("Unbind name: %s", name)
00738 self._namingManager.unbindObject(name)
00739
00740 return True
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759 def bindExecutionContext(self, comp):
00760 self._rtcout.RTC_DEBUG("Manager::bindExecutionContext()")
00761 self._rtcout.RTC_DEBUG("ExecutionContext type: %s",
00762 self._config.getProperty("exec_cxt.periodic.type"))
00763
00764 rtobj = comp.getObjRef()
00765
00766 exec_cxt = None
00767
00768 if OpenRTM.isDataFlowParticipant(rtobj):
00769 ectype = self._config.getProperty("exec_cxt.periodic.type")
00770 exec_cxt = self._ecfactory.find(ectype).create()
00771 rate = self._config.getProperty("exec_cxt.periodic.rate")
00772 exec_cxt.set_rate(float(rate))
00773 else:
00774 ectype = self._config.getProperty("exec_cxt.evdriven.type")
00775 exec_cxt = self._ecfactory.find(ectype).create()
00776 exec_cxt.add(rtobj)
00777 exec_cxt.start()
00778 self._ecs.append(exec_cxt)
00779 return True
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794 def deleteComponent(self, instance_name):
00795 self._rtcout.RTC_DEBUG("Manager::deleteComponent(%s)", instance_name)
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813 def getComponent(self, instance_name):
00814 self._rtcout.RTC_DEBUG("Manager::getComponent(%s)", instance_name)
00815 return self._compManager.find(instance_name)
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831 def getComponents(self):
00832 self._rtcout.RTC_DEBUG("Manager::getComponents()")
00833 return self._compManager.getObjects()
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853 def getORB(self):
00854 self._rtcout.RTC_DEBUG("Manager::getORB()")
00855 return self._orb
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871 def getPOA(self):
00872 self._rtcout.RTC_DEBUG("Manager::getPOA()")
00873 return self._poa
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889 def getPOAManager(self):
00890 self._rtcout.RTC_DEBUG("Manager::getPOAManager()")
00891 return self._poaManager
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915 def initManager(self, argv):
00916 config = OpenRTM.ManagerConfig(argv)
00917 self._config = config.configure(OpenRTM.Properties())
00918 self._config.setProperty("logger.file_name",self.formatString(self._config.getProperty("logger.file_name"), self._config))
00919
00920 self._module = OpenRTM.ModuleManager(self._config)
00921 self._terminator = self.Terminator(self)
00922 guard = ScopedLock(self._terminate.mutex)
00923 self._terminate.waiting = 0
00924 del guard
00925
00926 if OpenRTM.toBool(self._config.getProperty("timer.enable"), "YES", "NO", True):
00927 tm = OpenRTM.TimeValue(0, 100000)
00928 tick = self._config.getProperty("timer.tick")
00929 if tick != "":
00930 tm = tm.set_time(float(tick))
00931 self._timer = OpenRTM.Timer(tm)
00932 self._timer.start()
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947 def shutdownManager(self):
00948 self._rtcout.RTC_DEBUG("Manager::shutdownManager()")
00949 if self._timer:
00950 self._timer.stop()
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972 def initLogger(self):
00973 logfile = self._config.getProperty("logger.file_name")
00974 if logfile == "":
00975 logfile = "./rtc.log"
00976
00977 if OpenRTM.toBool(self._config.getProperty("logger.enable"), "YES", "NO", True):
00978 self._Logbuf = OpenRTM.Logbuf(fileName = logfile)
00979 self._rtcout = OpenRTM.LogStream(self._Logbuf)
00980 self._rtcout.setLogLevel(self._config.getProperty("logger.log_level"))
00981 self._rtcout.setLogLock(OpenRTM.toBool(self._config.getProperty("logger.stream_lock"),
00982 "enable", "disable", False))
00983
00984 self._rtcout.RTC_INFO("%s", self._config.getProperty("openrtm.version"))
00985 self._rtcout.RTC_INFO("Copyright (C) 2003-2007")
00986 self._rtcout.RTC_INFO(" Noriaki Ando")
00987 self._rtcout.RTC_INFO(" Task-intelligence Research Group,")
00988 self._rtcout.RTC_INFO(" Intelligent Systems Research Institute, AIST")
00989 self._rtcout.RTC_INFO("Manager starting.")
00990 self._rtcout.RTC_INFO("Starting local logging.")
00991 else:
00992 self._rtcout = OpenRTM.LogStream()
00993
00994 return True
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009 def shutdownLogger(self):
01010 self._rtcout.RTC_DEBUG("Manager::shutdownLogger()")
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030 def initORB(self):
01031 self._rtcout.RTC_DEBUG("Manager::initORB()")
01032
01033 try:
01034 args = OpenRTM.split(self.createORBOptions(), " ")
01035 argv = OpenRTM.toArgv(args)
01036 self._orb = CORBA.ORB_init(argv)
01037
01038 self._poa = self._orb.resolve_initial_references("RootPOA")
01039
01040 if CORBA.is_nil(self._poa):
01041 self._rtcout.RTC_ERROR("Could not resolve RootPOA")
01042 return False
01043
01044 self._poaManager = self._poa._get_the_POAManager()
01045 self._objManager = OpenRTM.CorbaObjectManager(self._orb, self._poa)
01046 except:
01047 self._rtcout.RTC_ERROR("Exception: Caught unknown exception in initORB().")
01048 return False
01049
01050 return True
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067 def createORBOptions(self):
01068 opt = self._config.getProperty("corba.args")
01069 corba = self._config.getProperty("corba.id")
01070 endpoint = self._config.getProperty("corba.endpoint")
01071
01072 if endpoint != "":
01073 if opt != "":
01074 opt += " "
01075 if corba == "omniORB":
01076 opt = "-ORBendPoint giop:tcp:" + endpoint
01077 elif corba == "TAO":
01078 opt = "-ORBEndPoint iiop://" + endpoint
01079 elif corba == "MICO":
01080 opt = "-ORBIIOPAddr inet:" + endpoint
01081 return opt
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098 def shutdownORB(self):
01099 self._rtcout.RTC_DEBUG("Manager::shutdownORB()")
01100 try:
01101 while self._orb.work_pending():
01102 self._rtcout.RTC_PARANOID("Pending work still exists.")
01103 if self._orb.work_pending():
01104 self._orb.perform_work()
01105 except:
01106 traceback.print_exception(*sys.exc_info())
01107 pass
01108
01109 self._rtcout.RTC_DEBUG("No pending works of ORB. Shutting down POA and ORB.")
01110
01111 if not CORBA.is_nil(self._poa):
01112 try:
01113 if not CORBA.is_nil(self._poaManager):
01114 self._poaManager.deactivate(False, True)
01115 self._rtcout.RTC_DEBUG("POA Manager was deactivated.")
01116 self._poa.destroy(False, True)
01117 self._poa = PortableServer.POA._nil
01118 self._rtcout.RTC_DEBUG("POA was destroid.")
01119 except CORBA.SystemException, ex:
01120 self._rtcout.RTC_ERROR("Caught SystemException during root POA destruction")
01121 except:
01122 self._rtcout.RTC_ERROR("Caught unknown exception during destruction")
01123
01124 if self._orb:
01125 try:
01126 self._orb.shutdown(True)
01127 self._rtcout.RTC_DEBUG("ORB was shutdown.")
01128 self._orb = CORBA.Object._nil
01129 except CORBA.SystemException, ex:
01130 self._rtcout.RTC_ERROR("Caught CORBA::SystemException during ORB shutdown.")
01131 except:
01132 self._rtcout.RTC_ERROR("Caught unknown exception during ORB shutdown.")
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159 def initNaming(self):
01160 self._rtcout.RTC_DEBUG("Manager::initNaming()")
01161 self._namingManager = OpenRTM.NamingManager(self)
01162
01163 if not OpenRTM.toBool(self._config.getProperty("naming.enable"), "YES", "NO", True):
01164 return True
01165
01166 meths = OpenRTM.split(self._config.getProperty("naming.type"),",")
01167
01168 for meth in meths:
01169 names = OpenRTM.split(self._config.getProperty(meth+".nameservers"), ",")
01170 for name in names:
01171 self._rtcout.RTC_DEBUG("Register Naming Server: %s/%s", (meth, name))
01172 self._namingManager.registerNameServer(meth,name)
01173
01174 if OpenRTM.toBool(self._config.getProperty("naming.update.enable"), "YES", "NO", True):
01175 tm = OpenRTM.TimeValue(10,0)
01176 intr = self._config.getProperty("naming.update.interval")
01177 if intr != "":
01178 tm = OpenRTM.TimeValue(intr)
01179
01180 if self._timer:
01181 self._timer.registerListenerObj(self._namingManager,OpenRTM.NamingManager.update,tm)
01182
01183 return True
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198 def shutdownNaming(self):
01199 self._rtcout.RTC_DEBUG("Manager::shutdownNaming()")
01200 self._namingManager.unbindAll()
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218 def initExecContext(self):
01219 self._rtcout.RTC_DEBUG("Manager::initExecContext()")
01220 OpenRTM.PeriodicExecutionContextInit(self)
01221 OpenRTM.ExtTrigExecutionContextInit(self)
01222 return True
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239 def initTimer(self):
01240 return True
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255 def shutdownComponents(self):
01256 self._rtcout.RTC_DEBUG("Manager::shutdownComponents()")
01257 comps = self._namingManager.getObjects()
01258 for comp in comps:
01259 try:
01260 comp.exit()
01261 p = OpenRTM.Properties(key=comp.getInstanceName())
01262 p.mergeProperties(comp.getProperties())
01263 except:
01264 traceback.print_exception(*sys.exc_info())
01265 pass
01266
01267 for ec in self._ecs:
01268 try:
01269 self._poa.deactivate_object(self._poa.servant_to_id(ec))
01270 except:
01271 traceback.print_exception(*sys.exc_info())
01272 pass
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288 def cleanupComponent(self, comp):
01289 self._rtcout.RTC_DEBUG("Manager::cleanupComponents")
01290 self.unregisterComponent(comp)
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307 def configureComponent(self, comp):
01308 category = comp.getCategory()
01309 type_name = comp.getTypeName()
01310 inst_name = comp.getInstanceName()
01311
01312 type_conf = category + "." + type_name + ".config_file"
01313 name_conf = category + "." + inst_name + ".config_file"
01314
01315 type_prop = OpenRTM.Properties()
01316
01317 name_prop = OpenRTM.Properties()
01318
01319 if self._config.getProperty(name_conf) != "":
01320 try:
01321 conff = open(self._config.getProperty(name_conf))
01322 except:
01323 print "Not found. : %s" % self._config.getProperty(name_conf)
01324 else:
01325 name_prop.load(conff)
01326
01327 if self._config.getProperty(type_conf) != "":
01328 try:
01329 conff = open(self._config.getProperty(type_conf))
01330 except:
01331 print "Not found. : %s" % self._config.getProperty(type_conf)
01332 else:
01333 type_prop.load(conff)
01334
01335 type_prop = type_prop.mergeProperties(name_prop)
01336 comp.getProperties().mergeProperties(type_prop)
01337
01338 naming_formats = ""
01339 comp_prop = OpenRTM.Properties(prop=comp.getProperties())
01340
01341 naming_formats += self._config.getProperty("naming.formats")
01342 naming_formats += ", " + comp_prop.getProperty("naming.formats")
01343
01344 naming_formats = OpenRTM.flatten(OpenRTM.unique_sv(OpenRTM.split(naming_formats, ",")))
01345
01346 naming_names = self.formatString(naming_formats, comp.getProperties())
01347 comp.getProperties().setProperty("naming.formats",naming_formats)
01348 comp.getProperties().setProperty("naming.names",naming_names)
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367 def mergeProperty(self, prop, file_name):
01368 if file_name == "":
01369 self._rtcout.RTC_ERROR("Invalid configuration file name.")
01370 return False
01371
01372 if file_name[0] != '\0':
01373
01374 try:
01375 conff = open(file_name)
01376 except:
01377 print "Not found. : %s" % file_name
01378 else:
01379 prop.load(conff)
01380 conff.close()
01381 return True
01382
01383 return False
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412 def formatString(self, naming_format, prop):
01413 name_ = naming_format
01414 str_ = ""
01415 count = 0
01416
01417 for n in name_:
01418 if n == '%':
01419 count+=1
01420 if not (count % 2):
01421 str_ += n
01422 else:
01423 if count > 0 and (count % 2):
01424 count = 0
01425 if n == "n": str_ += prop.getProperty("instance_name")
01426 elif n == "t": str_ += prop.getProperty("type_name")
01427 elif n == "m": str_ += prop.getProperty("type_name")
01428 elif n == "v": str_ += prop.getProperty("version")
01429 elif n == "V": str_ += prop.getProperty("vendor")
01430 elif n == "c": str_ += prop.getProperty("category")
01431 elif n == "h": str_ += self._config.getProperty("manager.os.hostname")
01432 elif n == "M": str_ += self._config.getProperty("manager.name")
01433 elif n == "p": str_ += str(self._config.getProperty("manager.pid"))
01434 else: str_ += n
01435 else:
01436 count = 0
01437 str_ += n
01438
01439 return str_
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455 def getLogbuf(self):
01456 return self._rtcout
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472 def getConfig(self):
01473 return self._config
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487 class InstanceName:
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504 def __init__(self, name=None, factory=None):
01505 if factory:
01506 self._name = factory.getInstanceName()
01507 elif name:
01508 self._name = name
01509
01510 def __call__(self, factory):
01511 return self._name == factory.getInstanceName()
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526 class FactoryPredicate:
01527
01528
01529
01530 def __init__(self, name=None, factory=None):
01531 if name:
01532 self._name = name
01533 elif factory:
01534 self._name = factory.profile().getProperty("implementation_id")
01535
01536 def __call__(self, factory):
01537 return self._name == factory.profile().getProperty("implementation_id")
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552 class ECFactoryPredicate:
01553
01554
01555
01556 def __init__(self, name=None, factory=None):
01557 if name:
01558 self._name = name
01559 elif factory:
01560 self._name = factory.name()
01561
01562 def __call__(self, factory):
01563 return self._name == factory.name()
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582 class OrbRunner:
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599 def __init__(self, orb):
01600 self._orb = orb
01601 self._th = threading.Thread(target=self.run)
01602 self._th.start()
01603 self._evt = threading.Event()
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617 def run(self):
01618 try:
01619 self._orb.run()
01620
01621 self._evt.set()
01622 except:
01623 traceback.print_exception(*sys.exc_info())
01624 pass
01625 self._evt.set()
01626 return
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640 def wait(self):
01641 self._evt.wait()
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657 def close(self, flags):
01658 return 0
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676 class Terminator:
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693 def __init__(self, manager):
01694 self._manager = manager
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708 def terminate(self):
01709 self._manager.shutdown()
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725 class Term:
01726
01727
01728
01729 def __init__(self):
01730 self.waiting = 0
01731 self.mutex = threading.RLock()