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 traceback
00021 import sys
00022 import time
00023 from omniORB import CORBA, PortableServer
00024 from types import IntType, ListType
00025
00026 import OpenRTM_aist
00027 import RTC
00028 import SDOPackage
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_aist.Manager.instance()
00066 mgr.terminate()
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 class Manager:
00084 """
00085 """
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 def __init__(self, _manager=None):
00103 self._initProc = None
00104 self._runner = None
00105 self._terminator = None
00106 self._compManager = OpenRTM_aist.ObjectManager(self.InstanceName)
00107 self._factory = OpenRTM_aist.ObjectManager(self.FactoryPredicate)
00108 self._ecfactory = OpenRTM_aist.ObjectManager(self.ECFactoryPredicate)
00109 self._terminate = self.Term()
00110 self._ecs = []
00111 self._timer = None
00112 self._orb = None
00113 self._poa = None
00114 self._poaManager = None
00115 self._finalized = self.Finalized()
00116 signal.signal(signal.SIGINT, handler)
00117
00118 return
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
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 def init(*arg):
00161 global manager
00162 global mutex
00163
00164 if len(arg) == 1:
00165 argv = arg[0]
00166 elif len(arg) == 2 and \
00167 isinstance(arg[0], IntType) and \
00168 isinstance(arg[1], ListType):
00169
00170 argv = arg[1]
00171 else:
00172 print "Invalid arguments for init()"
00173 print "init(argc,argv) or init(argv)"
00174
00175 if manager is None:
00176 guard = OpenRTM_aist.ScopedLock(mutex)
00177 if manager is None:
00178 manager = Manager()
00179 manager.initManager(argv)
00180 manager.initLogger()
00181 manager.initORB()
00182 manager.initNaming()
00183 manager.initFactories()
00184 manager.initExecContext()
00185 manager.initComposite()
00186 manager.initTimer()
00187 manager.initManagerServant()
00188
00189 return manager
00190
00191 init = staticmethod(init)
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 def instance():
00215 global manager
00216 global mutex
00217
00218 if manager is None:
00219 guard = OpenRTM_aist.ScopedLock(mutex)
00220 if manager is None:
00221 manager = Manager()
00222 manager.initManager(None)
00223 manager.initLogger()
00224 manager.initORB()
00225 manager.initNaming()
00226 manager.initFactories()
00227 manager.initExecContext()
00228 manager.initComposite()
00229 manager.initTimer()
00230
00231
00232 return manager
00233
00234 instance = staticmethod(instance)
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 def terminate(self):
00249 if self._terminator:
00250 self._terminator.terminate()
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 def shutdown(self):
00266 self._rtcout.RTC_TRACE("Manager.shutdown()")
00267 self.shutdownComponents()
00268 self.shutdownNaming()
00269 self.shutdownORB()
00270 self.shutdownManager()
00271
00272 if self._runner:
00273 self._runner.wait()
00274 else:
00275 self.join()
00276
00277 self.shutdownLogger()
00278 global manager
00279 if manager:
00280 manager = None
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 def join(self):
00295 self._rtcout.RTC_TRACE("Manager.wait()")
00296 guard = OpenRTM_aist.ScopedLock(self._terminate.mutex)
00297 self._terminate.waiting += 1
00298 del guard
00299 while 1:
00300 guard = OpenRTM_aist.ScopedLock(self._terminate.mutex)
00301
00302 if self._terminate.waiting > 0:
00303 break
00304 del guard
00305 time.sleep(0.001)
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 def setModuleInitProc(self, proc):
00333 self._initProc = proc
00334 return
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 def activateManager(self):
00368 self._rtcout.RTC_TRACE("Manager.activateManager()")
00369
00370 try:
00371 self.getPOAManager().activate()
00372 self._rtcout.RTC_TRACE("POA Manager activated.")
00373 except:
00374 self._rtcout.RTC_ERROR("Exception: POA Manager activation failed.")
00375 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00376 return False
00377
00378 mods = [s.strip() for s in self._config.getProperty("manager.modules.preload").split(",")]
00379
00380 for i in range(len(mods)):
00381 if mods[i] is None or mods[i] == "":
00382 continue
00383 tmp = [mods[i]]
00384 OpenRTM_aist.eraseHeadBlank(tmp)
00385 OpenRTM_aist.eraseTailBlank(tmp)
00386 mods[i] = tmp[0]
00387
00388 basename = os.path.basename(mods[i]).split(".")[0]
00389 basename += "Init"
00390
00391 try:
00392 self._module.load(mods[i], basename)
00393 except:
00394 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00395 self.__try_direct_load(basename)
00396
00397 if self._initProc:
00398 self._initProc(self)
00399
00400 comps = [s.strip() for s in self._config.getProperty("manager.components.precreate").split(",")]
00401 for i in range(len(comps)):
00402 if comps[i] is None or comps[i] == "":
00403 continue
00404 tmp = [comps[i]]
00405 OpenRTM_aist.eraseHeadBlank(tmp)
00406 OpenRTM_aist.eraseTailBlank(tmp)
00407 comps[i] = tmp[0]
00408
00409 self.createComponent(comps[i])
00410
00411 return True
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
00437
00438
00439
00440
00441
00442
00443
00444 def runManager(self, no_block=None):
00445 if no_block is None:
00446 no_block = False
00447
00448 if no_block:
00449 self._rtcout.RTC_TRACE("Manager.runManager(): non-blocking mode")
00450 self._runner = self.OrbRunner(self._orb)
00451 else:
00452 self._rtcout.RTC_TRACE("Manager.runManager(): blocking mode")
00453 try:
00454 self._orb.run()
00455 self._rtcout.RTC_TRACE("Manager.runManager(): ORB was terminated")
00456 self.join()
00457 except:
00458 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00459
00460 return
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 def load(self, fname, initfunc):
00486 self._rtcout.RTC_TRACE("Manager.load(fname = %s, initfunc = %s)",
00487 (fname, initfunc))
00488 try:
00489 fname_ = fname.split(os.sep)
00490 if len(fname_) > 1:
00491 fname_ = fname_[-1]
00492 else:
00493 fname_ = fname_[0]
00494
00495 if not initfunc:
00496 mod = [s.strip() for s in fname_.split(".")]
00497 initfunc = mod[0]+"Init"
00498 path = self._module.load(fname, initfunc)
00499 self._rtcout.RTC_DEBUG("module path: %s", path)
00500 except:
00501 self.__try_direct_load(fname)
00502
00503 return
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525 def unload(self, fname):
00526 self._rtcout.RTC_TRACE("Manager.unload()")
00527 self._module.unload(fname)
00528 return
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 def unloadAll(self):
00548 self._rtcout.RTC_TRACE("Manager.unloadAll()")
00549 self._module.unloadAll()
00550 return
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567 def getLoadedModules(self):
00568 self._rtcout.RTC_TRACE("Manager.getLoadedModules()")
00569 return self._module.getLoadedModules()
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 def getLoadableModules(self):
00587 self._rtcout.RTC_TRACE("Manager.getLoadableModules()")
00588 return self._module.getLoadableModules()
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612 def registerFactory(self, profile, new_func, delete_func):
00613 self._rtcout.RTC_TRACE("Manager.registerFactory(%s)", profile.getProperty("type_name"))
00614 try:
00615 factory = OpenRTM_aist.FactoryPython(profile, new_func, delete_func)
00616 self._factory.registerObject(factory)
00617 return True
00618 except:
00619 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00620 return False
00621
00622 return
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642 def getFactoryProfiles(self):
00643 factories = self._factory.getObjects()
00644
00645 if not factories:
00646 return []
00647
00648 props = []
00649 for factory in factories:
00650 props.append(factory.profile())
00651
00652 return props
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671 def registerECFactory(self, name, new_func, delete_func):
00672 self._rtcout.RTC_TRACE("Manager.registerECFactory(%s)", name)
00673 try:
00674 self._ecfactory.registerObject(OpenRTM_aist.ECFactoryPython(name, new_func, delete_func))
00675 return True
00676 except:
00677 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00678 return False
00679
00680 return False
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696 def getModulesFactories(self):
00697 self._rtcout.RTC_TRACE("Manager.getModulesFactories()")
00698
00699 self._modlist = []
00700 for _obj in self._factory._objects._obj:
00701 self._modlist.append(_obj.profile().getProperty("implementation_id"))
00702 return self._modlist
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767 def createComponent(self, comp_args):
00768 self._rtcout.RTC_TRACE("Manager.createComponent(%s)", comp_args)
00769 comp_prop = OpenRTM_aist.Properties()
00770 comp_id = OpenRTM_aist.Properties()
00771
00772 print "comp_args:", comp_args
00773 if not self.procComponentArgs(comp_args, comp_id, comp_prop):
00774 return None
00775
00776 if comp_prop.findNode("exported_ports"):
00777 exported_ports = OpenRTM_aist.split(comp_prop.getProperty("exported_ports"),
00778 ",")
00779 exported_ports_str = ""
00780 for i in range(len(exported_ports)):
00781 keyval = OpenRTM_aist.split(exported_ports[i], ".")
00782 if len(keyval) > 2:
00783 exported_ports_str += (keyval[0] + "." + keyval[-1])
00784 else:
00785 exported_ports_str += exported_ports[i]
00786
00787 if i != (len(exported_ports) - 1) :
00788 exported_ports_str += ","
00789
00790 comp_prop.setProperty("exported_ports", exported_ports_str)
00791 comp_prop.setProperty("conf.default.exported_ports", exported_ports_str)
00792
00793 factory = self._factory.find(comp_id)
00794 if factory is None:
00795 self._rtcout.RTC_ERROR("createComponent: Factory not found: %s",
00796 comp_id.getProperty("implementation_id"))
00797
00798
00799 mp = self._module.getLoadableModules()
00800 self._rtcout.RTC_INFO("%d loadable modules found", len(mp))
00801
00802 found_obj = None
00803 predicate = self.ModulePredicate(comp_id)
00804 for _obj in mp:
00805 if predicate(_obj):
00806 found_obj = _obj
00807 break
00808
00809 if not found_obj:
00810 self._rtcout.RTC_ERROR("No module for %s in loadable modules list",
00811 comp_id.getProperty("implementation_id"))
00812 return None
00813
00814 if not found_obj.findNode("module_file_name"):
00815 self._rtcout.RTC_ERROR("Hmm...module_file_name key not found.")
00816 return 0
00817
00818
00819 self._rtcout.RTC_INFO("Loading module: %s", found_obj.getProperty("module_file_name"))
00820 self.load(found_obj.getProperty("module_file_name"), "")
00821 factory = self._factory.find(comp_id)
00822 if not factory:
00823 self._rtcout.RTC_ERROR("Factory not found for loaded module: %s",
00824 comp_id.getProperty("implementation_id"))
00825 return 0
00826
00827
00828
00829 prop = factory.profile()
00830
00831 inherit_prop = ["config.version",
00832 "openrtm.name",
00833 "openrtm.version",
00834 "os.name",
00835 "os.release",
00836 "os.version",
00837 "os.arch",
00838 "os.hostname",
00839 "corba.endpoint",
00840 "corba.id",
00841 "exec_cxt.periodic.type",
00842 "exec_cxt.periodic.rate",
00843 "exec_cxt.evdriven.type",
00844 "logger.enable",
00845 "logger.log_level",
00846 "naming.enable",
00847 "naming.type",
00848 "naming.formats"]
00849
00850 for i in range(len(inherit_prop)):
00851 prop.setProperty(inherit_prop[i],self._config.getProperty(inherit_prop[i]))
00852
00853 comp = factory.create(self)
00854
00855 if comp is None:
00856 self._rtcout.RTC_ERROR("createComponent: RTC creation failed: %s",
00857 comp_id.getProperty("implementation_id"))
00858 return None
00859 self._rtcout.RTC_TRACE("RTC Created: %s", comp_id.getProperty("implementation_id"))
00860
00861
00862
00863
00864 prop.mergeProperties(comp_prop)
00865
00866
00867
00868
00869
00870
00871
00872 self.configureComponent(comp,prop)
00873
00874
00875
00876
00877
00878
00879
00880 if comp.initialize() != RTC.RTC_OK:
00881 self._rtcout.RTC_TRACE("RTC initialization failed: %s",
00882 comp_id.getProperty("implementation_id"))
00883 comp.exit()
00884 self._rtcout.RTC_TRACE("%s was finalized", comp_id.getProperty("implementation_id"))
00885 return None
00886
00887 self._rtcout.RTC_TRACE("RTC initialization succeeded: %s",
00888 comp_id.getProperty("implementation_id"))
00889 self.registerComponent(comp)
00890 return comp
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909 def registerComponent(self, comp):
00910 self._rtcout.RTC_TRACE("Manager.registerComponent(%s)", comp.getInstanceName())
00911
00912 self._compManager.registerObject(comp)
00913 names = comp.getNamingNames()
00914
00915 for name in names:
00916 self._rtcout.RTC_TRACE("Bind name: %s", name)
00917 self._namingManager.bindObject(name, comp)
00918
00919 return True
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936 def unregisterComponent(self, comp):
00937 self._rtcout.RTC_TRACE("Manager.unregisterComponent(%s)", comp.getInstanceName())
00938 self._compManager.unregisterObject(comp.getInstanceName())
00939 names = comp.getNamingNames()
00940
00941 for name in names:
00942 self._rtcout.RTC_TRACE("Unbind name: %s", name)
00943 self._namingManager.unbindObject(name)
00944
00945 return True
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962 def createContext(self, ec_args):
00963 self._rtcout.RTC_TRACE("Manager.createContext()")
00964 self._rtcout.RTC_TRACE("ExecutionContext type: %s",
00965 self._config.getProperty("exec_cxt.periodic.type"))
00966 ec_id = [""]
00967 ec_prop = OpenRTM_aist.Properties()
00968
00969 if not self.procContextArgs(ec_args, ec_id, ec_prop):
00970 return None
00971
00972 factory = self._ecfactory.find(ec_id[0])
00973
00974 if factory == None:
00975 self._rtcout.RTC_ERROR("Factory not found: %s", ec_id[0])
00976 return None
00977
00978 ec = factory.create()
00979 return ec
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994 def deleteComponent(self, instance_name=None, comp=None):
00995 if instance_name:
00996 self._rtcout.RTC_TRACE("Manager.deleteComponent(%s)", instance_name)
00997 _comp = self._compManager.find(instance_name)
00998 if _comp is None:
00999 self._rtcout.RTC_WARN("RTC %s was not found in manager.", instance_name)
01000 return
01001 self.deleteComponent(comp=_comp)
01002
01003 elif comp:
01004 self._rtcout.RTC_TRACE("Manager.deleteComponent(RTObject_impl)")
01005
01006 self.unregisterComponent(comp)
01007
01008 comp_id = comp.getProperties()
01009 factory = self._factory.find(comp_id)
01010
01011 if not factory:
01012 self._rtcout.RTC_DEBUG("Factory not found: %s",
01013 comp_id.getProperty("implementation_id"))
01014 return
01015 else:
01016 self._rtcout.RTC_DEBUG("Factory found: %s",
01017 comp_id.getProperty("implementation_id"))
01018 factory.destroy(comp)
01019
01020
01021 if OpenRTM_aist.toBool(self._config.getProperty("manager.shutdown_on_nortcs"),
01022 "YES","NO",True) and \
01023 not OpenRTM_aist.toBool(self._config.getProperty("manager.is_master"),
01024 "YES","NO",False):
01025 comps = self.getComponents()
01026 if len(comps) == 0:
01027 self.shutdown()
01028
01029 return
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047 def getComponent(self, instance_name):
01048 self._rtcout.RTC_TRACE("Manager.getComponent(%s)", instance_name)
01049 return self._compManager.find(instance_name)
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065 def getComponents(self):
01066 self._rtcout.RTC_TRACE("Manager.getComponents()")
01067 return self._compManager.getObjects()
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087 def getORB(self):
01088 self._rtcout.RTC_TRACE("Manager.getORB()")
01089 return self._orb
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105 def getPOA(self):
01106 self._rtcout.RTC_TRACE("Manager.getPOA()")
01107 return self._poa
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123 def getPOAManager(self):
01124 self._rtcout.RTC_TRACE("Manager.getPOAManager()")
01125 return self._poaManager
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149 def initManager(self, argv):
01150 config = OpenRTM_aist.ManagerConfig(argv)
01151 self._config = OpenRTM_aist.Properties()
01152 config.configure(self._config)
01153 self._config.setProperty("logger.file_name",self.formatString(self._config.getProperty("logger.file_name"),
01154 self._config))
01155 self._module = OpenRTM_aist.ModuleManager(self._config)
01156 self._terminator = self.Terminator(self)
01157 guard = OpenRTM_aist.ScopedLock(self._terminate.mutex)
01158 self._terminate.waiting = 0
01159 del guard
01160
01161 if OpenRTM_aist.toBool(self._config.getProperty("timer.enable"), "YES", "NO", True):
01162 tm = OpenRTM_aist.TimeValue(0, 100000)
01163 tick = self._config.getProperty("timer.tick")
01164 if tick != "":
01165 tm = tm.set_time(float(tick))
01166 if self._timer:
01167 self._timer.stop()
01168 self._timer.join()
01169 self._timer = OpenRTM_aist.Timer(tm)
01170 self._timer.start()
01171
01172 if OpenRTM_aist.toBool(self._config.getProperty("manager.shutdown_auto"),
01173 "YES", "NO", True) and \
01174 not OpenRTM_aist.toBool(self._config.getProperty("manager.is_master"),
01175 "YES", "NO", False):
01176 tm = OpenRTM_aist.TimeValue(10, 0)
01177 if self._config.findNode("manager.auto_shutdown_duration"):
01178 duration = float(self._config.getProperty("manager.auto_shutdown_duration"))
01179 if duration:
01180 tm.set_time(duration)
01181
01182 if self._timer:
01183 self._timer.registerListenerObj(self,
01184 OpenRTM_aist.Manager.shutdownOnNoRtcs,
01185 tm)
01186
01187 if self._timer:
01188 tm = OpenRTM_aist.TimeValue(1, 0)
01189 self._timer.registerListenerObj(self,
01190 OpenRTM_aist.Manager.cleanupComponents,
01191 tm)
01192
01193 return
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208 def shutdownManager(self):
01209 self._rtcout.RTC_TRACE("Manager.shutdownManager()")
01210 if self._timer:
01211 self._timer.stop()
01212 self._timer.join()
01213 self._timer = None
01214
01215 return
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235 def shutdownOnNoRtcs(self):
01236 self._rtcout.RTC_TRACE("Manager::shutdownOnNoRtcs()")
01237 if OpenRTM_aist.toBool(self._config.getProperty("manager.shutdown_on_nortcs"),
01238 "YES", "NO", True):
01239
01240 comps = self.getComponents()
01241
01242 if len(comps) == 0:
01243 self.shutdown()
01244
01245 return
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267 def initLogger(self):
01268
01269 if not OpenRTM_aist.toBool(self._config.getProperty("logger.enable"), "YES", "NO", True):
01270 self._rtcout = OpenRTM_aist.LogStream()
01271 return True
01272
01273 logfile = "./rtc.log"
01274
01275 logouts = self._config.getProperty("logger.file_name")
01276 logouts = [s.strip() for s in logouts.split(",")]
01277
01278 self._rtcout = None
01279
01280 for i in range(len(logouts)):
01281 tmp = [logouts[i]]
01282 OpenRTM_aist.eraseHeadBlank(tmp)
01283 OpenRTM_aist.eraseTailBlank(tmp)
01284 logouts[i] = tmp[0]
01285 if logouts[i].lower() == "stdout":
01286 if self._rtcout is None:
01287 self._rtcout = OpenRTM_aist.LogStream("manager","STDOUT")
01288 else:
01289 self._rtcout.addHandler(logouts[i])
01290 else:
01291 if logouts[i] == "":
01292 logfile = "./rtc.log"
01293 else:
01294 logfile = logouts[i]
01295
01296 if self._rtcout is None:
01297 self._rtcout = OpenRTM_aist.LogStream("manager","FILE", logfile)
01298 else:
01299 self._rtcout.addHandler("FILE",logfile)
01300
01301 self._rtcout.setLogLevel(self._config.getProperty("logger.log_level"))
01302 self._rtcout.setLogLock(OpenRTM_aist.toBool(self._config.getProperty("logger.stream_lock"),
01303 "enable", "disable", False))
01304
01305 self._rtcout.RTC_INFO("%s", self._config.getProperty("openrtm.version"))
01306 self._rtcout.RTC_INFO("Copyright (C) 2003-2010")
01307 self._rtcout.RTC_INFO(" Noriaki Ando")
01308 self._rtcout.RTC_INFO(" Intelligent Systems Research Institute, AIST")
01309 self._rtcout.RTC_INFO("Manager starting.")
01310 self._rtcout.RTC_INFO("Starting local logging.")
01311
01312 return True
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327 def shutdownLogger(self):
01328 self._rtcout.RTC_TRACE("Manager.shutdownLogger()")
01329 self._rtcout.shutdown()
01330 return
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350 def initORB(self):
01351 self._rtcout.RTC_TRACE("Manager.initORB()")
01352 try:
01353 args = OpenRTM_aist.split(self.createORBOptions(), " ")
01354 args.insert(0,"manager")
01355 argv = OpenRTM_aist.toArgv(args)
01356 self._orb = CORBA.ORB_init(argv)
01357
01358 self._poa = self._orb.resolve_initial_references("RootPOA")
01359 if CORBA.is_nil(self._poa):
01360 self._rtcout.RTC_ERROR("Could not resolve RootPOA")
01361 return False
01362
01363 self._poaManager = self._poa._get_the_POAManager()
01364
01365 except:
01366 self._rtcout.RTC_ERROR("Exception: Caught unknown exception in initORB().")
01367 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
01368 return False
01369
01370 return True
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387 def createORBOptions(self):
01388 opt = self._config.getProperty("corba.args")
01389 self._rtcout.RTC_DEBUG("corba.args: %s",opt)
01390
01391 endpoints = []
01392 self.createORBEndpoints(endpoints)
01393 opt = [opt]
01394 self.createORBEndpointOption(opt,endpoints)
01395
01396 self._rtcout.RTC_PARANOID("ORB options: %s", opt[0])
01397
01398 return opt[0]
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419 def createORBEndpoints(self, endpoints):
01420
01421
01422
01423 if self._config.findNode("corba.endpoints"):
01424 endpoints_ = [s.strip() for s in self._config.getProperty("corba.endpoints").split(",")]
01425 for ep in endpoints_:
01426 endpoints.append(ep)
01427
01428 self._rtcout.RTC_DEBUG("corba.endpoints: %s", self._config.getProperty("corba.endpoints"))
01429
01430 if self._config.findNode("corba.endpoint"):
01431 endpoints_ = [s.strip() for s in self._config.getProperty("corba.endpoint").split(",")]
01432 for ep in endpoints_:
01433 endpoints.append(ep)
01434 self._rtcout.RTC_DEBUG("corba.endpoint: %s", self._config.getProperty("corba.endpoint"))
01435
01436
01437
01438 self._rtcout.RTC_DEBUG("manager.is_master: %s",
01439 self._config.getProperty("manager.is_master"))
01440
01441 if OpenRTM_aist.toBool(self._config.getProperty("manager.is_master"), "YES", "NO", False):
01442 mm = self._config.getProperty("corba.master_manager", ":2810")
01443 mmm = [s.strip() for s in mm.split(":")]
01444 if len(mmm) == 2:
01445 endpoints.insert(0, ":" + mmm[1])
01446 else:
01447 endpoints.insert(0, ":2810")
01448
01449 endpoints = OpenRTM_aist.unique_sv(endpoints)
01450
01451 return
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467 def createORBEndpointOption(self, opt, endpoints):
01468 corba = self._config.getProperty("corba.id")
01469 self._rtcout.RTC_DEBUG("corba.id: %s", corba)
01470
01471 for i in range(len(endpoints)):
01472 if endpoints[i]:
01473 endpoint = endpoints[i]
01474 else:
01475 continue
01476
01477 self._rtcout.RTC_DEBUG("Endpoint is : %s", endpoint)
01478 if endpoint.find(":") == -1:
01479 endpoint += ":"
01480
01481 if corba == "omniORB":
01482 endpoint = OpenRTM_aist.normalize([endpoint])
01483 if OpenRTM_aist.normalize([endpoint]) == "all:":
01484 opt[0] += " -ORBendPointPublishAllIFs 1"
01485 else:
01486 opt[0] += " -ORBendPoint giop:tcp:" + endpoint
01487
01488 elif corba == "TAO":
01489 opt[0] += "-ORBEndPoint iiop://" + endpoint
01490 elif corba == "MICO":
01491 opt[0] += "-ORBIIOPAddr inet:" + endpoint
01492
01493 endpoints[i] = endpoint
01494
01495 return
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512 def shutdownORB(self):
01513 self._rtcout.RTC_TRACE("Manager.shutdownORB()")
01514 if not self._orb:
01515 return
01516
01517 try:
01518 while self._orb.work_pending():
01519 self._rtcout.RTC_PARANOID("Pending work still exists.")
01520 if self._orb.work_pending():
01521 self._orb.perform_work()
01522 pass
01523
01524 self._rtcout.RTC_DEBUG("No pending works of ORB. Shutting down POA and ORB.")
01525 except:
01526 self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
01527 pass
01528
01529 if not CORBA.is_nil(self._poa):
01530 try:
01531 if not CORBA.is_nil(self._poaManager):
01532 self._poaManager.deactivate(False, True)
01533 self._rtcout.RTC_DEBUG("POA Manager was deactivated.")
01534 self._poa.destroy(False, True)
01535 self._poa = PortableServer.POA._nil
01536 self._rtcout.RTC_DEBUG("POA was destroyed.")
01537 except CORBA.SystemException, ex:
01538 self._rtcout.RTC_ERROR("Caught SystemException during root POA destruction")
01539 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
01540 except:
01541 self._rtcout.RTC_ERROR("Caught unknown exception during destruction")
01542 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
01543
01544 if self._orb:
01545 try:
01546 self._orb.shutdown(True)
01547 self._rtcout.RTC_DEBUG("ORB was shutdown.")
01548 self._orb = CORBA.Object._nil
01549 except CORBA.SystemException, ex:
01550 self._rtcout.RTC_ERROR("Caught CORBA::SystemException during ORB shutdown.")
01551 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
01552 except:
01553 self._rtcout.RTC_ERROR("Caught unknown exception during ORB shutdown.")
01554 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581 def initNaming(self):
01582 self._rtcout.RTC_TRACE("Manager.initNaming()")
01583 self._namingManager = OpenRTM_aist.NamingManager(self)
01584
01585 if not OpenRTM_aist.toBool(self._config.getProperty("naming.enable"), "YES", "NO", True):
01586 return True
01587
01588 meths = OpenRTM_aist.split(self._config.getProperty("naming.type"),",")
01589
01590 for meth in meths:
01591 names = OpenRTM_aist.split(self._config.getProperty(meth+".nameservers"), ",")
01592 for name in names:
01593 self._rtcout.RTC_TRACE("Register Naming Server: %s/%s", (meth, name))
01594 self._namingManager.registerNameServer(meth,name)
01595
01596 if OpenRTM_aist.toBool(self._config.getProperty("naming.update.enable"), "YES", "NO", True):
01597 tm = OpenRTM_aist.TimeValue(10,0)
01598 intr = self._config.getProperty("naming.update.interval")
01599 if intr != "":
01600 tm = OpenRTM_aist.TimeValue(intr)
01601
01602 if self._timer:
01603 self._timer.registerListenerObj(self._namingManager,OpenRTM_aist.NamingManager.update,tm)
01604
01605 return True
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620 def shutdownNaming(self):
01621 self._rtcout.RTC_TRACE("Manager.shutdownNaming()")
01622 self._namingManager.unbindAll()
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640 def initExecContext(self):
01641 self._rtcout.RTC_TRACE("Manager.initExecContext()")
01642 OpenRTM_aist.PeriodicExecutionContextInit(self)
01643 OpenRTM_aist.ExtTrigExecutionContextInit(self)
01644 OpenRTM_aist.OpenHRPExecutionContextInit(self)
01645 return True
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663 def initComposite(self):
01664 self._rtcout.RTC_TRACE("Manager.initComposite()")
01665 OpenRTM_aist.PeriodicECSharedCompositeInit(self)
01666 return True
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690 def initFactories(self):
01691 self._rtcout.RTC_TRACE("Manager.initFactories()")
01692 OpenRTM_aist.FactoryInit()
01693 return True
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710 def initTimer(self):
01711 return True
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727 def initManagerServant(self):
01728 self._rtcout.RTC_TRACE("Manager.initManagerServant()")
01729 if not OpenRTM_aist.toBool(self._config.getProperty("manager.corba_servant"),
01730 "YES","NO",True):
01731 return True
01732
01733 self._mgrservant = OpenRTM_aist.ManagerServant()
01734 prop = self._config.getNode("manager")
01735 names = OpenRTM_aist.split(prop.getProperty("naming_formats"),",")
01736
01737 if OpenRTM_aist.toBool(prop.getProperty("is_master"),
01738 "YES","NO",True):
01739 for name in names:
01740 mgr_name = self.formatString(name, prop)
01741 self._namingManager.bindManagerObject(mgr_name, self._mgrservant)
01742
01743 otherref = None
01744
01745 try:
01746 otherref = file(self._config.getProperty("manager.refstring_path"),'r')
01747 refstring = otherref.readline()
01748 otherref.close()
01749 except:
01750 try:
01751 reffile = file(self._config.getProperty("manager.refstring_path"),'w')
01752 except:
01753 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
01754 return False
01755 else:
01756 reffile.write(self._orb.object_to_string(self._mgrservant.getObjRef()))
01757 reffile.close()
01758 return True
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773 def shutdownComponents(self):
01774 self._rtcout.RTC_TRACE("Manager.shutdownComponents()")
01775 comps = self._namingManager.getObjects()
01776 for comp in comps:
01777 try:
01778 comp.exit()
01779 p = OpenRTM_aist.Properties(key=comp.getInstanceName())
01780 p.mergeProperties(comp.getProperties())
01781 except:
01782 self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
01783 pass
01784
01785 for ec in self._ecs:
01786 try:
01787 self._poa.deactivate_object(self._poa.servant_to_id(ec))
01788 except:
01789 self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
01790 pass
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806 def cleanupComponent(self, comp):
01807 self._rtcout.RTC_TRACE("Manager.cleanupComponent()")
01808 self.unregisterComponent(comp)
01809
01810 return
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827 def cleanupComponents(self):
01828 self._rtcout.RTC_VERBOSE("Manager.cleanupComponents()")
01829 guard = OpenRTM_aist.ScopedLock(self._finalized.mutex)
01830 self._rtcout.RTC_VERBOSE("%d components are marked as finalized.",
01831 len(self._finalized.comps))
01832 for _comp in self._finalized.comps:
01833 self.deleteComponent(comp=_comp)
01834
01835 self._finalized.comps = []
01836 del guard
01837 return
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859 def notifyFinalized(self, comp):
01860 self._rtcout.RTC_TRACE("Manager.notifyFinalized()")
01861 guard = OpenRTM_aist.ScopedLock(self._finalized.mutex)
01862 self._finalized.comps.append(comp)
01863 del guard
01864 return
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882 def procComponentArgs(self, comp_arg, comp_id, comp_conf):
01883 id_and_conf = [s.strip() for s in comp_arg.split("?")]
01884 if len(id_and_conf) != 1 and len(id_and_conf) != 2:
01885 self._rtcout.RTC_ERROR("Invalid arguments. Two or more '?'")
01886 return False
01887
01888 if id_and_conf[0].find(":") == -1:
01889 id_and_conf[0] = "RTC:::" + id_and_conf[0] + ":"
01890
01891 id = [s.strip() for s in id_and_conf[0].split(":")]
01892
01893 if len(id) != 5:
01894 self._rtcout.RTC_ERROR("Invalid RTC id format.")
01895 return False
01896
01897 prof = ["RTC", "vendor", "category", "implementation_id", "version"]
01898
01899 if id[0] != prof[0]:
01900 self._rtcout.RTC_ERROR("Invalid id type.")
01901 return False
01902
01903 for i in [1,2,3,4]:
01904 comp_id.setProperty(prof[i], id[i])
01905 self._rtcout.RTC_TRACE("RTC basic profile %s: %s", (prof[i], id[i]))
01906
01907 if len(id_and_conf) == 2:
01908 conf = [s.strip() for s in id_and_conf[1].split("&")]
01909 for i in range(len(conf)):
01910 keyval = [s.strip() for s in conf[i].split("=")]
01911 if len(keyval) > 1:
01912 comp_conf.setProperty(keyval[0],keyval[1])
01913 self._rtcout.RTC_TRACE("RTC property %s: %s", (keyval[0], keyval[1]))
01914
01915 return True
01916
01917
01918
01919
01920
01921 def procContextArgs(self, ec_args, ec_id, ec_conf):
01922 id_and_conf = [s.strip() for s in ec_args.split("?")]
01923
01924 if len(id_and_conf) != 1 and len(id_and_conf) != 2:
01925 self._rtcout.RTC_ERROR("Invalid arguments. Two or more '?'")
01926 return False
01927
01928 if (id_and_conf[0] == "") or id_and_conf[0] is None:
01929 self._rtcout.RTC_ERROR("Empty ExecutionContext's name")
01930 return False
01931
01932 ec_id[0] = id_and_conf[0]
01933
01934 if len(id_and_conf) == 2:
01935 conf = [s.strip() for s in id_and_conf[1].split("&")]
01936 for i in range(len(conf)):
01937 k = [s.strip() for s in conf[i].split("=")]
01938 ec_conf.setProperty(k[0],k[1])
01939 self._rtcout.RTC_TRACE("EC property %s: %s",(k[0],k[1]))
01940
01941 return True
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959 def configureComponent(self, comp, prop):
01960 category = comp.getCategory()
01961 type_name = comp.getTypeName()
01962 inst_name = comp.getInstanceName()
01963
01964 type_conf = category + "." + type_name + ".config_file"
01965 name_conf = category + "." + inst_name + ".config_file"
01966
01967 type_prop = OpenRTM_aist.Properties()
01968
01969 name_prop = OpenRTM_aist.Properties()
01970
01971 if self._config.getProperty(name_conf) != "":
01972 try:
01973 conff = open(self._config.getProperty(name_conf))
01974 except:
01975 print "Not found. : %s" % self._config.getProperty(name_conf)
01976 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
01977 else:
01978 name_prop.load(conff)
01979
01980 if self._config.findNode(category + "." + inst_name):
01981 name_prop.mergeProperties(self._config.getNode(category + "." + inst_name))
01982
01983 if self._config.getProperty(type_conf) != "":
01984 try:
01985 conff = open(self._config.getProperty(type_conf))
01986 except:
01987 print "Not found. : %s" % self._config.getProperty(type_conf)
01988 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
01989 else:
01990 type_prop.load(conff)
01991
01992 if self._config.findNode(category + "." + type_name):
01993 type_prop.mergeProperties(self._config.getNode(category + "." + type_name))
01994
01995 comp.setProperties(prop)
01996 type_prop.mergeProperties(name_prop)
01997 comp.setProperties(type_prop)
01998
01999 comp_prop = OpenRTM_aist.Properties(prop=comp.getProperties())
02000
02001 naming_formats = self._config.getProperty("naming.formats")
02002 if comp_prop.findNode("naming.formats"):
02003 naming_formats = comp_prop.getProperty("naming.formats")
02004 naming_formats = OpenRTM_aist.flatten(OpenRTM_aist.unique_sv(OpenRTM_aist.split(naming_formats, ",")))
02005
02006 naming_names = self.formatString(naming_formats, comp.getProperties())
02007 comp.getProperties().setProperty("naming.formats",naming_formats)
02008 comp.getProperties().setProperty("naming.names",naming_names)
02009 return
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028 def mergeProperty(self, prop, file_name):
02029 if file_name == "":
02030 self._rtcout.RTC_ERROR("Invalid configuration file name.")
02031 return False
02032
02033 if file_name[0] != '\0':
02034
02035 try:
02036 conff = open(file_name)
02037 except:
02038 print "Not found. : %s" % file_name
02039 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
02040 else:
02041 prop.load(conff)
02042 conff.close()
02043 return True
02044
02045 return False
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075 def formatString(self, naming_format, prop):
02076 name_ = naming_format
02077 str_ = ""
02078 count = 0
02079 len_ = len(name_)
02080 it = iter(name_)
02081
02082 try:
02083 while 1:
02084 n = it.next()
02085 if n == '%':
02086 count+=1
02087 if not (count % 2):
02088 str_ += n
02089 elif n == '$':
02090 count = 0
02091 n = it.next()
02092 if n == '{' or n == '(':
02093 n = it.next()
02094 env = ""
02095 for i in xrange(len_):
02096 if n == '}' or n == ')':
02097 break
02098 env += n
02099 n = it.next()
02100 envval = os.getenv(env)
02101 if envval:
02102 str_ += envval
02103 else:
02104 str_ += n
02105 else:
02106 if count > 0 and (count % 2):
02107 count = 0
02108 if n == "n": str_ += prop.getProperty("instance_name")
02109 elif n == "t": str_ += prop.getProperty("type_name")
02110 elif n == "m": str_ += prop.getProperty("type_name")
02111 elif n == "v": str_ += prop.getProperty("version")
02112 elif n == "V": str_ += prop.getProperty("vendor")
02113 elif n == "c": str_ += prop.getProperty("category")
02114 elif n == "h": str_ += self._config.getProperty("manager.os.hostname")
02115 elif n == "M": str_ += self._config.getProperty("manager.name")
02116 elif n == "p": str_ += str(self._config.getProperty("manager.pid"))
02117 else: str_ += n
02118 else:
02119 count = 0
02120 str_ += n
02121 except:
02122
02123 return str_
02124
02125 return str_
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141 def getLogbuf(self,name="manager"):
02142 if not OpenRTM_aist.toBool(self._config.getProperty("logger.enable"), "YES", "NO", True):
02143 return OpenRTM_aist.LogStream()
02144
02145 logbuf = OpenRTM_aist.LogStream(name)
02146 logbuf.setLogLevel(self._config.getProperty("logger.log_level"))
02147 return logbuf
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163 def getConfig(self):
02164 return self._config
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180 def __try_direct_load(self, file_name):
02181 try:
02182 pathChanged=False
02183 splitted_name = os.path.split(file_name)
02184 save_path = sys.path[:]
02185 sys.path.append(splitted_name[0])
02186 import_name = splitted_name[-1].split(".py")[0]
02187 mo = __import__(import_name)
02188 sys.path = save_path
02189 _spec = getattr(mo,import_name.lower()+"_spec",None)
02190 _klass = getattr(mo,import_name,None)
02191 if _spec and _klass:
02192 prof = OpenRTM_aist.Properties(defaults_str=_spec)
02193 self.registerFactory(prof,
02194 _klass,
02195 OpenRTM_aist.Delete)
02196 except:
02197 self._rtcout.RTC_ERROR("Module load error: %s", file_name)
02198 self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
02199
02200 return
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215 class InstanceName:
02216 """
02217 """
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232 def __init__(self, name=None, factory=None, prop=None):
02233 if prop:
02234 self._name = prop.getInstanceName()
02235 if factory:
02236 self._name = factory.getInstanceName()
02237 elif name:
02238 self._name = name
02239
02240 def __call__(self, factory):
02241 return self._name == factory.getInstanceName()
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256 class FactoryPredicate:
02257
02258 def __init__(self, name=None, prop=None, factory=None):
02259 if name:
02260 self._vendor = ""
02261 self._category = ""
02262 self._impleid = name
02263 self._version = ""
02264 elif prop:
02265 self._vendor = prop.getProperty("vendor")
02266 self._category = prop.getProperty("category")
02267 self._impleid = prop.getProperty("implementation_id")
02268 self._version = prop.getProperty("version")
02269 elif factory:
02270 self._vendor = factory.profile().getProperty("vendor")
02271 self._category = factory.profile().getProperty("category")
02272 self._impleid = factory.profile().getProperty("implementation_id")
02273 self._version = factory.profile().getProperty("version")
02274
02275
02276 def __call__(self, factory):
02277 if self._impleid == "":
02278 return False
02279
02280 _prop = OpenRTM_aist.Properties(prop=factory.profile())
02281
02282 if self._impleid != _prop.getProperty("implementation_id"):
02283 return False
02284
02285 if self._vendor != "" and self._vendor != _prop.getProperty("vendor"):
02286 return False
02287
02288 if self._category != "" and self._category != _prop.getProperty("category"):
02289 return False
02290
02291 if self._version != "" and self._version != _prop.getProperty("version"):
02292 return False
02293
02294 return True
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309 class ECFactoryPredicate:
02310
02311
02312
02313 def __init__(self, name=None, factory=None):
02314 if name:
02315 self._name = name
02316 elif factory:
02317 self._name = factory.name()
02318
02319 def __call__(self, factory):
02320 return self._name == factory.name()
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334 class ModulePredicate:
02335
02336
02337 def __init__(self, prop):
02338 self._prop = prop
02339 return
02340
02341
02342 def __call__(self, prop):
02343
02344 if self._prop.getProperty("implementation_id") != prop.getProperty("implementation_id"):
02345 return False
02346
02347 if self._prop.getProperty("vendor") and \
02348 self._prop.getProperty("vendor") != prop.getProperty("vendor"):
02349 return False
02350
02351 if self._prop.getProperty("category") and \
02352 self._prop.getProperty("category") != prop.getProperty("category"):
02353 return False
02354
02355 if self._prop.getProperty("version") and \
02356 self._prop.getProperty("version") != prop.getProperty("version"):
02357 return False
02358
02359 return True
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378 class OrbRunner:
02379 """
02380 """
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395 def __init__(self, orb):
02396 self._orb = orb
02397 self._th = threading.Thread(target=self.run)
02398 self._th.start()
02399
02400
02401 def __del__(self):
02402 self._th.join()
02403 self._th = None
02404 return
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418 def run(self):
02419 try:
02420 self._orb.run()
02421
02422 except:
02423 print OpenRTM_aist.Logger.print_exception()
02424 pass
02425 return
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439 def wait(self):
02440 return
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456 def close(self, flags):
02457 return 0
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475 class Terminator:
02476 """
02477 """
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492 def __init__(self, manager):
02493 self._manager = manager
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507 def terminate(self):
02508 self._manager.shutdown()
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524 class Term:
02525 def __init__(self):
02526 self.waiting = 0
02527 self.mutex = threading.RLock()
02528
02529
02530 class Finalized:
02531 def __init__(self):
02532 self.mutex = threading.RLock()
02533 self.comps = []