Manager.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
16 
17 import threading
18 import string
19 import signal, os
20 import traceback
21 import sys
22 import time
23 from omniORB import CORBA, PortableServer
24 from types import IntType, ListType
25 
26 import OpenRTM_aist
27 import RTC
28 import SDOPackage
29 
30 
31 #------------------------------------------------------------
32 # static var
33 #------------------------------------------------------------
34 
35 
41 manager = None
42 
43 
49 mutex = threading.RLock()
50 
51 
52 
64 def handler(signum, frame):
65  mgr = OpenRTM_aist.Manager.instance()
66  mgr.terminate()
67 
68 
69 
70 
83 class Manager:
84  """
85  """
86 
87 
88 
89 
102  def __init__(self, _manager=None):
103  self._initProc = None
104  self._runner = None
105  self._terminator = None
109  self._terminate = self.Term()
110  self._ecs = []
111  self._timer = None
112  self._orb = None
113  self._poa = None
114  self._poaManager = None
115  self._finalized = self.Finalized()
116  signal.signal(signal.SIGINT, handler)
117 
118  return
119 
120 
121 
160  def init(*arg):
161  global manager
162  global mutex
163 
164  if len(arg) == 1:
165  argv = arg[0]
166  elif len(arg) == 2 and \
167  isinstance(arg[0], IntType) and \
168  isinstance(arg[1], ListType):
169  # for 0.4.x
170  argv = arg[1]
171  else:
172  print "Invalid arguments for init()"
173  print "init(argc,argv) or init(argv)"
174 
175  if manager is None:
176  guard = OpenRTM_aist.ScopedLock(mutex)
177  if manager is None:
178  manager = Manager()
179  manager.initManager(argv)
180  manager.initLogger()
181  manager.initORB()
182  manager.initNaming()
183  manager.initFactories()
184  manager.initExecContext()
185  manager.initComposite()
186  manager.initTimer()
187  manager.initManagerServant()
188 
189  return manager
190 
191  init = staticmethod(init)
192 
193 
194 
214  def instance():
215  global manager
216  global mutex
217 
218  if manager is None:
219  guard = OpenRTM_aist.ScopedLock(mutex)
220  if manager is None:
221  manager = Manager()
222  manager.initManager(None)
223  manager.initLogger()
224  manager.initORB()
225  manager.initNaming()
226  manager.initFactories()
227  manager.initExecContext()
228  manager.initComposite()
229  manager.initTimer()
230  #manager.initManagerServant()
231 
232  return manager
233 
234  instance = staticmethod(instance)
235 
236 
237 
248  def terminate(self):
249  if self._terminator:
250  self._terminator.terminate()
251 
252 
253 
265  def shutdown(self):
266  self._rtcout.RTC_TRACE("Manager.shutdown()")
267  self.shutdownComponents()
268  self.shutdownNaming()
269  self.shutdownORB()
270  self.shutdownManager()
271 
272  if self._runner:
273  self._runner.wait()
274  else:
275  self.join()
276 
277  self.shutdownLogger()
278  global manager
279  if manager:
280  manager = None
281 
282 
283 
294  def join(self):
295  self._rtcout.RTC_TRACE("Manager.wait()")
296  guard = OpenRTM_aist.ScopedLock(self._terminate.mutex)
297  self._terminate.waiting += 1
298  del guard
299  while 1:
300  guard = OpenRTM_aist.ScopedLock(self._terminate.mutex)
301  #if self._terminate.waiting > 1:
302  if self._terminate.waiting > 0:
303  break
304  del guard
305  time.sleep(0.001)
306 
307 
308 
332  def setModuleInitProc(self, proc):
333  self._initProc = proc
334  return
335 
336 
337 
367  def activateManager(self):
368  self._rtcout.RTC_TRACE("Manager.activateManager()")
369 
370  try:
371  self.getPOAManager().activate()
372  self._rtcout.RTC_TRACE("POA Manager activated.")
373  except:
374  self._rtcout.RTC_ERROR("Exception: POA Manager activation failed.")
375  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
376  return False
377 
378  mods = [s.strip() for s in self._config.getProperty("manager.modules.preload").split(",")]
379 
380  for i in range(len(mods)):
381  if mods[i] is None or mods[i] == "":
382  continue
383  tmp = [mods[i]]
384  OpenRTM_aist.eraseHeadBlank(tmp)
385  OpenRTM_aist.eraseTailBlank(tmp)
386  mods[i] = tmp[0]
387 
388  basename = os.path.basename(mods[i]).split(".")[0]
389  basename += "Init"
390 
391  try:
392  self._module.load(mods[i], basename)
393  except:
394  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
395  self.__try_direct_load(basename)
396 
397  if self._initProc:
398  self._initProc(self)
399 
400  comps = [s.strip() for s in self._config.getProperty("manager.components.precreate").split(",")]
401  for i in range(len(comps)):
402  if comps[i] is None or comps[i] == "":
403  continue
404  tmp = [comps[i]]
405  OpenRTM_aist.eraseHeadBlank(tmp)
406  OpenRTM_aist.eraseTailBlank(tmp)
407  comps[i] = tmp[0]
408 
409  self.createComponent(comps[i])
410 
411  return True
412 
413 
414 
444  def runManager(self, no_block=None):
445  if no_block is None:
446  no_block = False
447 
448  if no_block:
449  self._rtcout.RTC_TRACE("Manager.runManager(): non-blocking mode")
450  self._runner = self.OrbRunner(self._orb)
451  else:
452  self._rtcout.RTC_TRACE("Manager.runManager(): blocking mode")
453  try:
454  self._orb.run()
455  self._rtcout.RTC_TRACE("Manager.runManager(): ORB was terminated")
456  self.join()
457  except:
458  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
459 
460  return
461 
462 
463 
485  def load(self, fname, initfunc):
486  self._rtcout.RTC_TRACE("Manager.load(fname = %s, initfunc = %s)",
487  (fname, initfunc))
488  try:
489  fname_ = fname.split(os.sep)
490  if len(fname_) > 1:
491  fname_ = fname_[-1]
492  else:
493  fname_ = fname_[0]
494 
495  if not initfunc:
496  mod = [s.strip() for s in fname_.split(".")]
497  initfunc = mod[0]+"Init"
498  path = self._module.load(fname, initfunc)
499  self._rtcout.RTC_DEBUG("module path: %s", path)
500  except:
501  self.__try_direct_load(fname)
502 
503  return
504 
505 
506 
525  def unload(self, fname):
526  self._rtcout.RTC_TRACE("Manager.unload()")
527  self._module.unload(fname)
528  return
529 
530 
531 
547  def unloadAll(self):
548  self._rtcout.RTC_TRACE("Manager.unloadAll()")
549  self._module.unloadAll()
550  return
551 
552 
553 
567  def getLoadedModules(self):
568  self._rtcout.RTC_TRACE("Manager.getLoadedModules()")
569  return self._module.getLoadedModules()
570 
571 
572 
587  self._rtcout.RTC_TRACE("Manager.getLoadableModules()")
588  return self._module.getLoadableModules()
589 
590 
591  #============================================================
592  # Component Factory Management
593  #============================================================
594 
595 
612  def registerFactory(self, profile, new_func, delete_func):
613  self._rtcout.RTC_TRACE("Manager.registerFactory(%s)", profile.getProperty("type_name"))
614  try:
615  factory = OpenRTM_aist.FactoryPython(profile, new_func, delete_func)
616  self._factory.registerObject(factory)
617  return True
618  except:
619  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
620  return False
621 
622  return
623 
624 
625 
643  factories = self._factory.getObjects()
644 
645  if not factories:
646  return []
647 
648  props = []
649  for factory in factories:
650  props.append(factory.profile())
651 
652  return props
653 
654 
655 
671  def registerECFactory(self, name, new_func, delete_func):
672  self._rtcout.RTC_TRACE("Manager.registerECFactory(%s)", name)
673  try:
674  self._ecfactory.registerObject(OpenRTM_aist.ECFactoryPython(name, new_func, delete_func))
675  return True
676  except:
677  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
678  return False
679 
680  return False
681 
682 
683 
697  self._rtcout.RTC_TRACE("Manager.getModulesFactories()")
698 
699  self._modlist = []
700  for _obj in self._factory._objects._obj:
701  self._modlist.append(_obj.profile().getProperty("implementation_id"))
702  return self._modlist
703 
704 
705  #============================================================
706  # Component management
707  #============================================================
708 
709 
767  def createComponent(self, comp_args):
768  self._rtcout.RTC_TRACE("Manager.createComponent(%s)", comp_args)
769  comp_prop = OpenRTM_aist.Properties()
770  comp_id = OpenRTM_aist.Properties()
771 
772  print "comp_args:", comp_args
773  if not self.procComponentArgs(comp_args, comp_id, comp_prop):
774  return None
775 
776  if comp_prop.findNode("exported_ports"):
777  exported_ports = OpenRTM_aist.split(comp_prop.getProperty("exported_ports"),
778  ",")
779  exported_ports_str = ""
780  for i in range(len(exported_ports)):
781  keyval = OpenRTM_aist.split(exported_ports[i], ".")
782  if len(keyval) > 2:
783  exported_ports_str += (keyval[0] + "." + keyval[-1])
784  else:
785  exported_ports_str += exported_ports[i]
786 
787  if i != (len(exported_ports) - 1) :
788  exported_ports_str += ","
789 
790  comp_prop.setProperty("exported_ports", exported_ports_str)
791  comp_prop.setProperty("conf.default.exported_ports", exported_ports_str)
792 
793  factory = self._factory.find(comp_id)
794  if factory is None:
795  self._rtcout.RTC_ERROR("createComponent: Factory not found: %s",
796  comp_id.getProperty("implementation_id"))
797 
798  # automatic module loading
799  mp = self._module.getLoadableModules()
800  self._rtcout.RTC_INFO("%d loadable modules found", len(mp))
801 
802  found_obj = None
803  predicate = self.ModulePredicate(comp_id)
804  for _obj in mp:
805  if predicate(_obj):
806  found_obj = _obj
807  break
808 
809  if not found_obj:
810  self._rtcout.RTC_ERROR("No module for %s in loadable modules list",
811  comp_id.getProperty("implementation_id"))
812  return None
813 
814  if not found_obj.findNode("module_file_name"):
815  self._rtcout.RTC_ERROR("Hmm...module_file_name key not found.")
816  return 0
817 
818  # module loading
819  self._rtcout.RTC_INFO("Loading module: %s", found_obj.getProperty("module_file_name"))
820  self.load(found_obj.getProperty("module_file_name"), "")
821  factory = self._factory.find(comp_id)
822  if not factory:
823  self._rtcout.RTC_ERROR("Factory not found for loaded module: %s",
824  comp_id.getProperty("implementation_id"))
825  return 0
826 
827 
828  # get default configuration of component.
829  prop = factory.profile()
830 
831  inherit_prop = ["config.version",
832  "openrtm.name",
833  "openrtm.version",
834  "os.name",
835  "os.release",
836  "os.version",
837  "os.arch",
838  "os.hostname",
839  "corba.endpoint",
840  "corba.id",
841  "exec_cxt.periodic.type",
842  "exec_cxt.periodic.rate",
843  "exec_cxt.evdriven.type",
844  "logger.enable",
845  "logger.log_level",
846  "naming.enable",
847  "naming.type",
848  "naming.formats"]
849 
850  for i in range(len(inherit_prop)):
851  prop.setProperty(inherit_prop[i],self._config.getProperty(inherit_prop[i]))
852 
853  comp = factory.create(self)
854 
855  if comp is None:
856  self._rtcout.RTC_ERROR("createComponent: RTC creation failed: %s",
857  comp_id.getProperty("implementation_id"))
858  return None
859  self._rtcout.RTC_TRACE("RTC Created: %s", comp_id.getProperty("implementation_id"))
860 
861  # The property specified by the parameter of createComponent() is merged.
862  # The property("instance_name") specified by the parameter of createComponent()
863  # must be merged here.
864  prop.mergeProperties(comp_prop)
865 
866  #------------------------------------------------------------
867  # Load configuration file specified in "rtc.conf"
868  #
869  # rtc.conf:
870  # [category].[type_name].config_file = file_name
871  # [category].[instance_name].config_file = file_name
872  self.configureComponent(comp,prop)
873 
874  # The property specified by the parameter of createComponent() is set.
875  # The property("exported_ports") specified by the parameter of createComponent()
876  # must be set here.
877  #comp.setProperties(comp_prop)
878 
879  # Component initialization
880  if comp.initialize() != RTC.RTC_OK:
881  self._rtcout.RTC_TRACE("RTC initialization failed: %s",
882  comp_id.getProperty("implementation_id"))
883  comp.exit()
884  self._rtcout.RTC_TRACE("%s was finalized", comp_id.getProperty("implementation_id"))
885  return None
886 
887  self._rtcout.RTC_TRACE("RTC initialization succeeded: %s",
888  comp_id.getProperty("implementation_id"))
889  self.registerComponent(comp)
890  return comp
891 
892 
893 
894 
909  def registerComponent(self, comp):
910  self._rtcout.RTC_TRACE("Manager.registerComponent(%s)", comp.getInstanceName())
911 
912  self._compManager.registerObject(comp)
913  names = comp.getNamingNames()
914 
915  for name in names:
916  self._rtcout.RTC_TRACE("Bind name: %s", name)
917  self._namingManager.bindObject(name, comp)
918 
919  return True
920 
921 
922 
936  def unregisterComponent(self, comp):
937  self._rtcout.RTC_TRACE("Manager.unregisterComponent(%s)", comp.getInstanceName())
938  self._compManager.unregisterObject(comp.getInstanceName())
939  names = comp.getNamingNames()
940 
941  for name in names:
942  self._rtcout.RTC_TRACE("Unbind name: %s", name)
943  self._namingManager.unbindObject(name)
944 
945  return True
946 
947 
948 
962  def createContext(self, ec_args):
963  self._rtcout.RTC_TRACE("Manager.createContext()")
964  self._rtcout.RTC_TRACE("ExecutionContext type: %s",
965  self._config.getProperty("exec_cxt.periodic.type"))
966  ec_id = [""]
967  ec_prop = OpenRTM_aist.Properties()
968 
969  if not self.procContextArgs(ec_args, ec_id, ec_prop):
970  return None
971 
972  factory = self._ecfactory.find(ec_id[0])
973 
974  if factory == None:
975  self._rtcout.RTC_ERROR("Factory not found: %s", ec_id[0])
976  return None
977 
978  ec = factory.create()
979  return ec
980 
981 
982 
994  def deleteComponent(self, instance_name=None, comp=None):
995  if instance_name:
996  self._rtcout.RTC_TRACE("Manager.deleteComponent(%s)", instance_name)
997  _comp = self._compManager.find(instance_name)
998  if _comp is None:
999  self._rtcout.RTC_WARN("RTC %s was not found in manager.", instance_name)
1000  return
1001  self.deleteComponent(comp=_comp)
1002 
1003  elif comp:
1004  self._rtcout.RTC_TRACE("Manager.deleteComponent(RTObject_impl)")
1005  # cleanup from manager's table, and naming serivce
1006  self.unregisterComponent(comp)
1007 
1008  comp_id = comp.getProperties()
1009  factory = self._factory.find(comp_id)
1010 
1011  if not factory:
1012  self._rtcout.RTC_DEBUG("Factory not found: %s",
1013  comp_id.getProperty("implementation_id"))
1014  return
1015  else:
1016  self._rtcout.RTC_DEBUG("Factory found: %s",
1017  comp_id.getProperty("implementation_id"))
1018  factory.destroy(comp)
1019 
1020 
1021  if OpenRTM_aist.toBool(self._config.getProperty("manager.shutdown_on_nortcs"),
1022  "YES","NO",True) and \
1023  not OpenRTM_aist.toBool(self._config.getProperty("manager.is_master"),
1024  "YES","NO",False):
1025  comps = self.getComponents()
1026  if len(comps) == 0:
1027  self.shutdown()
1028 
1029  return
1030 
1031 
1032 
1047  def getComponent(self, instance_name):
1048  self._rtcout.RTC_TRACE("Manager.getComponent(%s)", instance_name)
1049  return self._compManager.find(instance_name)
1050 
1051 
1052 
1065  def getComponents(self):
1066  self._rtcout.RTC_TRACE("Manager.getComponents()")
1067  return self._compManager.getObjects()
1068 
1069 
1070  #============================================================
1071  # CORBA ´ØÏ¢
1072  #============================================================
1073 
1074 
1087  def getORB(self):
1088  self._rtcout.RTC_TRACE("Manager.getORB()")
1089  return self._orb
1090 
1091 
1092 
1105  def getPOA(self):
1106  self._rtcout.RTC_TRACE("Manager.getPOA()")
1107  return self._poa
1108 
1109 
1110 
1123  def getPOAManager(self):
1124  self._rtcout.RTC_TRACE("Manager.getPOAManager()")
1125  return self._poaManager
1126 
1127 
1128 
1129  #============================================================
1130  # Manager initialize and finalization
1131  #============================================================
1132 
1133 
1149  def initManager(self, argv):
1150  config = OpenRTM_aist.ManagerConfig(argv)
1152  config.configure(self._config)
1153  self._config.setProperty("logger.file_name",self.formatString(self._config.getProperty("logger.file_name"),
1154  self._config))
1156  self._terminator = self.Terminator(self)
1157  guard = OpenRTM_aist.ScopedLock(self._terminate.mutex)
1158  self._terminate.waiting = 0
1159  del guard
1160 
1161  if OpenRTM_aist.toBool(self._config.getProperty("timer.enable"), "YES", "NO", True):
1162  tm = OpenRTM_aist.TimeValue(0, 100000)
1163  tick = self._config.getProperty("timer.tick")
1164  if tick != "":
1165  tm = tm.set_time(float(tick))
1166  if self._timer:
1167  self._timer.stop()
1168  self._timer.join()
1169  self._timer = OpenRTM_aist.Timer(tm)
1170  self._timer.start()
1171 
1172  if OpenRTM_aist.toBool(self._config.getProperty("manager.shutdown_auto"),
1173  "YES", "NO", True) and \
1174  not OpenRTM_aist.toBool(self._config.getProperty("manager.is_master"),
1175  "YES", "NO", False):
1176  tm = OpenRTM_aist.TimeValue(10, 0)
1177  if self._config.findNode("manager.auto_shutdown_duration"):
1178  duration = float(self._config.getProperty("manager.auto_shutdown_duration"))
1179  if duration:
1180  tm.set_time(duration)
1181 
1182  if self._timer:
1183  self._timer.registerListenerObj(self,
1184  OpenRTM_aist.Manager.shutdownOnNoRtcs,
1185  tm)
1186 
1187  if self._timer:
1188  tm = OpenRTM_aist.TimeValue(1, 0)
1189  self._timer.registerListenerObj(self,
1190  OpenRTM_aist.Manager.cleanupComponents,
1191  tm)
1192 
1193  return
1194 
1195 
1196 
1208  def shutdownManager(self):
1209  self._rtcout.RTC_TRACE("Manager.shutdownManager()")
1210  if self._timer:
1211  self._timer.stop()
1212  self._timer.join()
1213  self._timer = None
1214 
1215  return
1216 
1217 
1218 
1235  def shutdownOnNoRtcs(self):
1236  self._rtcout.RTC_TRACE("Manager::shutdownOnNoRtcs()")
1237  if OpenRTM_aist.toBool(self._config.getProperty("manager.shutdown_on_nortcs"),
1238  "YES", "NO", True):
1239 
1240  comps = self.getComponents()
1241 
1242  if len(comps) == 0:
1243  self.shutdown()
1244 
1245  return
1246 
1247 
1248  #============================================================
1249  # Logger initialize and terminator
1250  #============================================================
1251 
1252 
1267  def initLogger(self):
1268 
1269  if not OpenRTM_aist.toBool(self._config.getProperty("logger.enable"), "YES", "NO", True):
1271  return True
1272 
1273  logfile = "./rtc.log"
1274 
1275  logouts = self._config.getProperty("logger.file_name")
1276  logouts = [s.strip() for s in logouts.split(",")]
1277 
1278  self._rtcout = None
1279 
1280  for i in range(len(logouts)):
1281  tmp = [logouts[i]]
1282  OpenRTM_aist.eraseHeadBlank(tmp)
1283  OpenRTM_aist.eraseTailBlank(tmp)
1284  logouts[i] = tmp[0]
1285  if logouts[i].lower() == "stdout":
1286  if self._rtcout is None:
1287  self._rtcout = OpenRTM_aist.LogStream("manager","STDOUT")
1288  else:
1289  self._rtcout.addHandler(logouts[i])
1290  else:
1291  if logouts[i] == "":
1292  logfile = "./rtc.log"
1293  else:
1294  logfile = logouts[i]
1295 
1296  if self._rtcout is None:
1297  self._rtcout = OpenRTM_aist.LogStream("manager","FILE", logfile)
1298  else:
1299  self._rtcout.addHandler("FILE",logfile)
1300 
1301  self._rtcout.setLogLevel(self._config.getProperty("logger.log_level"))
1302  self._rtcout.setLogLock(OpenRTM_aist.toBool(self._config.getProperty("logger.stream_lock"),
1303  "enable", "disable", False))
1304 
1305  self._rtcout.RTC_INFO("%s", self._config.getProperty("openrtm.version"))
1306  self._rtcout.RTC_INFO("Copyright (C) 2003-2010")
1307  self._rtcout.RTC_INFO(" Noriaki Ando")
1308  self._rtcout.RTC_INFO(" Intelligent Systems Research Institute, AIST")
1309  self._rtcout.RTC_INFO("Manager starting.")
1310  self._rtcout.RTC_INFO("Starting local logging.")
1311 
1312  return True
1313 
1314 
1315 
1327  def shutdownLogger(self):
1328  self._rtcout.RTC_TRACE("Manager.shutdownLogger()")
1329  self._rtcout.shutdown()
1330  return
1331 
1332 
1333  #============================================================
1334  # ORB initialization and finalization
1335  #============================================================
1336 
1337 
1350  def initORB(self):
1351  self._rtcout.RTC_TRACE("Manager.initORB()")
1352  try:
1353  args = OpenRTM_aist.split(self.createORBOptions(), " ")
1354  args.insert(0,"manager")
1355  argv = OpenRTM_aist.toArgv(args)
1356  self._orb = CORBA.ORB_init(argv)
1357 
1358  self._poa = self._orb.resolve_initial_references("RootPOA")
1359  if CORBA.is_nil(self._poa):
1360  self._rtcout.RTC_ERROR("Could not resolve RootPOA")
1361  return False
1362 
1363  self._poaManager = self._poa._get_the_POAManager()
1364 
1365  except:
1366  self._rtcout.RTC_ERROR("Exception: Caught unknown exception in initORB().")
1367  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
1368  return False
1369 
1370  return True
1371 
1372 
1373 
1387  def createORBOptions(self):
1388  opt = self._config.getProperty("corba.args")
1389  self._rtcout.RTC_DEBUG("corba.args: %s",opt)
1390 
1391  endpoints = []
1392  self.createORBEndpoints(endpoints)
1393  opt = [opt]
1394  self.createORBEndpointOption(opt,endpoints)
1395 
1396  self._rtcout.RTC_PARANOID("ORB options: %s", opt[0])
1397 
1398  return opt[0]
1399 
1400 
1401 
1419  def createORBEndpoints(self, endpoints):
1420 
1421  # corba.endpoint is obsolete
1422  # corba.endpoints with comma separated values are acceptable
1423  if self._config.findNode("corba.endpoints"):
1424  endpoints_ = [s.strip() for s in self._config.getProperty("corba.endpoints").split(",")]
1425  for ep in endpoints_:
1426  endpoints.append(ep)
1427 
1428  self._rtcout.RTC_DEBUG("corba.endpoints: %s", self._config.getProperty("corba.endpoints"))
1429 
1430  if self._config.findNode("corba.endpoint"):
1431  endpoints_ = [s.strip() for s in self._config.getProperty("corba.endpoint").split(",")]
1432  for ep in endpoints_:
1433  endpoints.append(ep)
1434  self._rtcout.RTC_DEBUG("corba.endpoint: %s", self._config.getProperty("corba.endpoint"))
1435 
1436  # If this process has master manager,
1437  # master manager's endpoint inserted at the top of endpoints
1438  self._rtcout.RTC_DEBUG("manager.is_master: %s",
1439  self._config.getProperty("manager.is_master"))
1440 
1441  if OpenRTM_aist.toBool(self._config.getProperty("manager.is_master"), "YES", "NO", False):
1442  mm = self._config.getProperty("corba.master_manager", ":2810")
1443  mmm = [s.strip() for s in mm.split(":")]
1444  if len(mmm) == 2:
1445  endpoints.insert(0, ":" + mmm[1])
1446  else:
1447  endpoints.insert(0, ":2810")
1448 
1449  endpoints = OpenRTM_aist.unique_sv(endpoints)
1450 
1451  return
1452 
1453 
1454 
1467  def createORBEndpointOption(self, opt, endpoints):
1468  corba = self._config.getProperty("corba.id")
1469  self._rtcout.RTC_DEBUG("corba.id: %s", corba)
1470 
1471  for i in range(len(endpoints)):
1472  if endpoints[i]:
1473  endpoint = endpoints[i]
1474  else:
1475  continue
1476 
1477  self._rtcout.RTC_DEBUG("Endpoint is : %s", endpoint)
1478  if endpoint.find(":") == -1:
1479  endpoint += ":"
1480 
1481  if corba == "omniORB":
1482  endpoint = OpenRTM_aist.normalize([endpoint])
1483  if OpenRTM_aist.normalize([endpoint]) == "all:":
1484  opt[0] += " -ORBendPointPublishAllIFs 1"
1485  else:
1486  opt[0] += " -ORBendPoint giop:tcp:" + endpoint
1487 
1488  elif corba == "TAO":
1489  opt[0] += "-ORBEndPoint iiop://" + endpoint
1490  elif corba == "MICO":
1491  opt[0] += "-ORBIIOPAddr inet:" + endpoint
1492 
1493  endpoints[i] = endpoint
1494 
1495  return
1496 
1497 
1498 
1512  def shutdownORB(self):
1513  self._rtcout.RTC_TRACE("Manager.shutdownORB()")
1514  if not self._orb:
1515  return
1516 
1517  try:
1518  while self._orb.work_pending():
1519  self._rtcout.RTC_PARANOID("Pending work still exists.")
1520  if self._orb.work_pending():
1521  self._orb.perform_work()
1522  pass
1523 
1524  self._rtcout.RTC_DEBUG("No pending works of ORB. Shutting down POA and ORB.")
1525  except:
1526  self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
1527  pass
1528 
1529  if not CORBA.is_nil(self._poa):
1530  try:
1531  if not CORBA.is_nil(self._poaManager):
1532  self._poaManager.deactivate(False, True)
1533  self._rtcout.RTC_DEBUG("POA Manager was deactivated.")
1534  self._poa.destroy(False, True)
1535  self._poa = PortableServer.POA._nil
1536  self._rtcout.RTC_DEBUG("POA was destroyed.")
1537  except CORBA.SystemException, ex:
1538  self._rtcout.RTC_ERROR("Caught SystemException during root POA destruction")
1539  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
1540  except:
1541  self._rtcout.RTC_ERROR("Caught unknown exception during destruction")
1542  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
1543 
1544  if self._orb:
1545  try:
1546  self._orb.shutdown(True)
1547  self._rtcout.RTC_DEBUG("ORB was shutdown.")
1548  self._orb = CORBA.Object._nil
1549  except CORBA.SystemException, ex:
1550  self._rtcout.RTC_ERROR("Caught CORBA::SystemException during ORB shutdown.")
1551  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
1552  except:
1553  self._rtcout.RTC_ERROR("Caught unknown exception during ORB shutdown.")
1554  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
1555 
1556 
1557  #============================================================
1558  # NamingService initialization and finalization
1559  #============================================================
1560 
1561 
1581  def initNaming(self):
1582  self._rtcout.RTC_TRACE("Manager.initNaming()")
1584 
1585  if not OpenRTM_aist.toBool(self._config.getProperty("naming.enable"), "YES", "NO", True):
1586  return True
1587 
1588  meths = OpenRTM_aist.split(self._config.getProperty("naming.type"),",")
1589 
1590  for meth in meths:
1591  names = OpenRTM_aist.split(self._config.getProperty(meth+".nameservers"), ",")
1592  for name in names:
1593  self._rtcout.RTC_TRACE("Register Naming Server: %s/%s", (meth, name))
1594  self._namingManager.registerNameServer(meth,name)
1595 
1596  if OpenRTM_aist.toBool(self._config.getProperty("naming.update.enable"), "YES", "NO", True):
1597  tm = OpenRTM_aist.TimeValue(10,0)
1598  intr = self._config.getProperty("naming.update.interval")
1599  if intr != "":
1600  tm = OpenRTM_aist.TimeValue(intr)
1601 
1602  if self._timer:
1603  self._timer.registerListenerObj(self._namingManager,OpenRTM_aist.NamingManager.update,tm)
1604 
1605  return True
1606 
1607 
1608 
1620  def shutdownNaming(self):
1621  self._rtcout.RTC_TRACE("Manager.shutdownNaming()")
1622  self._namingManager.unbindAll()
1623 
1624 
1625 
1640  def initExecContext(self):
1641  self._rtcout.RTC_TRACE("Manager.initExecContext()")
1642  OpenRTM_aist.PeriodicExecutionContextInit(self)
1643  OpenRTM_aist.ExtTrigExecutionContextInit(self)
1644  OpenRTM_aist.OpenHRPExecutionContextInit(self)
1645  return True
1646 
1647 
1648 
1663  def initComposite(self):
1664  self._rtcout.RTC_TRACE("Manager.initComposite()")
1665  OpenRTM_aist.PeriodicECSharedCompositeInit(self)
1666  return True
1667 
1668 
1669 
1690  def initFactories(self):
1691  self._rtcout.RTC_TRACE("Manager.initFactories()")
1693  return True
1694 
1695 
1696 
1710  def initTimer(self):
1711  return True
1712 
1713 
1714 
1728  self._rtcout.RTC_TRACE("Manager.initManagerServant()")
1729  if not OpenRTM_aist.toBool(self._config.getProperty("manager.corba_servant"),
1730  "YES","NO",True):
1731  return True
1732 
1734  prop = self._config.getNode("manager")
1735  names = OpenRTM_aist.split(prop.getProperty("naming_formats"),",")
1736 
1737  if OpenRTM_aist.toBool(prop.getProperty("is_master"),
1738  "YES","NO",True):
1739  for name in names:
1740  mgr_name = self.formatString(name, prop)
1741  self._namingManager.bindManagerObject(mgr_name, self._mgrservant)
1742 
1743  otherref = None
1744 
1745  try:
1746  otherref = file(self._config.getProperty("manager.refstring_path"),'r')
1747  refstring = otherref.readline()
1748  otherref.close()
1749  except:
1750  try:
1751  reffile = file(self._config.getProperty("manager.refstring_path"),'w')
1752  except:
1753  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
1754  return False
1755  else:
1756  reffile.write(self._orb.object_to_string(self._mgrservant.getObjRef()))
1757  reffile.close()
1758  return True
1759 
1760 
1761 
1774  self._rtcout.RTC_TRACE("Manager.shutdownComponents()")
1775  comps = self._namingManager.getObjects()
1776  for comp in comps:
1777  try:
1778  comp.exit()
1779  p = OpenRTM_aist.Properties(key=comp.getInstanceName())
1780  p.mergeProperties(comp.getProperties())
1781  except:
1782  self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
1783  pass
1784 
1785  for ec in self._ecs:
1786  try:
1787  self._poa.deactivate_object(self._poa.servant_to_id(ec))
1788  except:
1789  self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
1790  pass
1791 
1792 
1793 
1806  def cleanupComponent(self, comp):
1807  self._rtcout.RTC_TRACE("Manager.cleanupComponent()")
1808  self.unregisterComponent(comp)
1809 
1810  return
1811 
1812 
1813 
1828  self._rtcout.RTC_VERBOSE("Manager.cleanupComponents()")
1829  guard = OpenRTM_aist.ScopedLock(self._finalized.mutex)
1830  self._rtcout.RTC_VERBOSE("%d components are marked as finalized.",
1831  len(self._finalized.comps))
1832  for _comp in self._finalized.comps:
1833  self.deleteComponent(comp=_comp)
1834 
1835  self._finalized.comps = []
1836  del guard
1837  return
1838 
1839 
1840 
1859  def notifyFinalized(self, comp):
1860  self._rtcout.RTC_TRACE("Manager.notifyFinalized()")
1861  guard = OpenRTM_aist.ScopedLock(self._finalized.mutex)
1862  self._finalized.comps.append(comp)
1863  del guard
1864  return
1865 
1866 
1867 
1882  def procComponentArgs(self, comp_arg, comp_id, comp_conf):
1883  id_and_conf = [s.strip() for s in comp_arg.split("?")]
1884  if len(id_and_conf) != 1 and len(id_and_conf) != 2:
1885  self._rtcout.RTC_ERROR("Invalid arguments. Two or more '?'")
1886  return False
1887 
1888  if id_and_conf[0].find(":") == -1:
1889  id_and_conf[0] = "RTC:::" + id_and_conf[0] + ":"
1890 
1891  id = [s.strip() for s in id_and_conf[0].split(":")]
1892 
1893  if len(id) != 5:
1894  self._rtcout.RTC_ERROR("Invalid RTC id format.")
1895  return False
1896 
1897  prof = ["RTC", "vendor", "category", "implementation_id", "version"]
1898 
1899  if id[0] != prof[0]:
1900  self._rtcout.RTC_ERROR("Invalid id type.")
1901  return False
1902 
1903  for i in [1,2,3,4]:
1904  comp_id.setProperty(prof[i], id[i])
1905  self._rtcout.RTC_TRACE("RTC basic profile %s: %s", (prof[i], id[i]))
1906 
1907  if len(id_and_conf) == 2:
1908  conf = [s.strip() for s in id_and_conf[1].split("&")]
1909  for i in range(len(conf)):
1910  keyval = [s.strip() for s in conf[i].split("=")]
1911  if len(keyval) > 1:
1912  comp_conf.setProperty(keyval[0],keyval[1])
1913  self._rtcout.RTC_TRACE("RTC property %s: %s", (keyval[0], keyval[1]))
1914 
1915  return True
1916 
1917 
1918  # bool procContextArgs(const char* ec_args,
1919  # std::string& ec_id,
1920  # coil::Properties& ec_conf);
1921  def procContextArgs(self, ec_args, ec_id, ec_conf):
1922  id_and_conf = [s.strip() for s in ec_args.split("?")]
1923 
1924  if len(id_and_conf) != 1 and len(id_and_conf) != 2:
1925  self._rtcout.RTC_ERROR("Invalid arguments. Two or more '?'")
1926  return False
1927 
1928  if (id_and_conf[0] == "") or id_and_conf[0] is None:
1929  self._rtcout.RTC_ERROR("Empty ExecutionContext's name")
1930  return False
1931 
1932  ec_id[0] = id_and_conf[0]
1933 
1934  if len(id_and_conf) == 2:
1935  conf = [s.strip() for s in id_and_conf[1].split("&")]
1936  for i in range(len(conf)):
1937  k = [s.strip() for s in conf[i].split("=")]
1938  ec_conf.setProperty(k[0],k[1])
1939  self._rtcout.RTC_TRACE("EC property %s: %s",(k[0],k[1]))
1940 
1941  return True
1942 
1943 
1944 
1959  def configureComponent(self, comp, prop):
1960  category = comp.getCategory()
1961  type_name = comp.getTypeName()
1962  inst_name = comp.getInstanceName()
1963 
1964  type_conf = category + "." + type_name + ".config_file"
1965  name_conf = category + "." + inst_name + ".config_file"
1966 
1967  type_prop = OpenRTM_aist.Properties()
1968 
1969  name_prop = OpenRTM_aist.Properties()
1970 
1971  if self._config.getProperty(name_conf) != "":
1972  try:
1973  conff = open(self._config.getProperty(name_conf))
1974  except:
1975  print "Not found. : %s" % self._config.getProperty(name_conf)
1976  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
1977  else:
1978  name_prop.load(conff)
1979 
1980  if self._config.findNode(category + "." + inst_name):
1981  name_prop.mergeProperties(self._config.getNode(category + "." + inst_name))
1982 
1983  if self._config.getProperty(type_conf) != "":
1984  try:
1985  conff = open(self._config.getProperty(type_conf))
1986  except:
1987  print "Not found. : %s" % self._config.getProperty(type_conf)
1988  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
1989  else:
1990  type_prop.load(conff)
1991 
1992  if self._config.findNode(category + "." + type_name):
1993  type_prop.mergeProperties(self._config.getNode(category + "." + type_name))
1994 
1995  comp.setProperties(prop)
1996  type_prop.mergeProperties(name_prop)
1997  comp.setProperties(type_prop)
1998 
1999  comp_prop = OpenRTM_aist.Properties(prop=comp.getProperties())
2000 
2001  naming_formats = self._config.getProperty("naming.formats")
2002  if comp_prop.findNode("naming.formats"):
2003  naming_formats = comp_prop.getProperty("naming.formats")
2004  naming_formats = OpenRTM_aist.flatten(OpenRTM_aist.unique_sv(OpenRTM_aist.split(naming_formats, ",")))
2005 
2006  naming_names = self.formatString(naming_formats, comp.getProperties())
2007  comp.getProperties().setProperty("naming.formats",naming_formats)
2008  comp.getProperties().setProperty("naming.names",naming_names)
2009  return
2010 
2011 
2012 
2028  def mergeProperty(self, prop, file_name):
2029  if file_name == "":
2030  self._rtcout.RTC_ERROR("Invalid configuration file name.")
2031  return False
2032 
2033  if file_name[0] != '\0':
2034 
2035  try:
2036  conff = open(file_name)
2037  except:
2038  print "Not found. : %s" % file_name
2039  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
2040  else:
2041  prop.load(conff)
2042  conff.close()
2043  return True
2044 
2045  return False
2046 
2047 
2048 
2075  def formatString(self, naming_format, prop):
2076  name_ = naming_format
2077  str_ = ""
2078  count = 0
2079  len_ = len(name_)
2080  it = iter(name_)
2081 
2082  try:
2083  while 1:
2084  n = it.next()
2085  if n == '%':
2086  count+=1
2087  if not (count % 2):
2088  str_ += n
2089  elif n == '$':
2090  count = 0
2091  n = it.next()
2092  if n == '{' or n == '(':
2093  n = it.next()
2094  env = ""
2095  for i in xrange(len_):
2096  if n == '}' or n == ')':
2097  break
2098  env += n
2099  n = it.next()
2100  envval = os.getenv(env)
2101  if envval:
2102  str_ += envval
2103  else:
2104  str_ += n
2105  else:
2106  if count > 0 and (count % 2):
2107  count = 0
2108  if n == "n": str_ += prop.getProperty("instance_name")
2109  elif n == "t": str_ += prop.getProperty("type_name")
2110  elif n == "m": str_ += prop.getProperty("type_name")
2111  elif n == "v": str_ += prop.getProperty("version")
2112  elif n == "V": str_ += prop.getProperty("vendor")
2113  elif n == "c": str_ += prop.getProperty("category")
2114  elif n == "h": str_ += self._config.getProperty("manager.os.hostname")
2115  elif n == "M": str_ += self._config.getProperty("manager.name")
2116  elif n == "p": str_ += str(self._config.getProperty("manager.pid"))
2117  else: str_ += n
2118  else:
2119  count = 0
2120  str_ += n
2121  except:
2122  # Caught StopIteration exception.
2123  return str_
2124 
2125  return str_
2126 
2127 
2128 
2141  def getLogbuf(self,name="manager"):
2142  if not OpenRTM_aist.toBool(self._config.getProperty("logger.enable"), "YES", "NO", True):
2143  return OpenRTM_aist.LogStream()
2144 
2145  logbuf = OpenRTM_aist.LogStream(name)
2146  logbuf.setLogLevel(self._config.getProperty("logger.log_level"))
2147  return logbuf
2148 
2149 
2150 
2163  def getConfig(self):
2164  return self._config
2165 
2166 
2167 
2180  def __try_direct_load(self, file_name):
2181  try:
2182  pathChanged=False
2183  splitted_name = os.path.split(file_name)
2184  save_path = sys.path[:]
2185  sys.path.append(splitted_name[0])
2186  import_name = splitted_name[-1].split(".py")[0]
2187  mo = __import__(import_name)
2188  sys.path = save_path
2189  _spec = getattr(mo,import_name.lower()+"_spec",None)
2190  _klass = getattr(mo,import_name,None)
2191  if _spec and _klass:
2192  prof = OpenRTM_aist.Properties(defaults_str=_spec)
2193  self.registerFactory(prof,
2194  _klass,
2195  OpenRTM_aist.Delete)
2196  except:
2197  self._rtcout.RTC_ERROR("Module load error: %s", file_name)
2198  self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
2199 
2200  return
2201 
2202 
2203 
2204  #============================================================
2205  # ¥³¥ó¥Ý¡¼¥Í¥ó¥È¥Þ¥Í¡¼¥¸¥ã #============================================================ ## # @if jp # @class InstanceName # @brief ObjectManager ¸¡º÷ÍÑ¥Õ¥¡¥ó¥¯¥¿ # # @else # # @endif class InstanceName: """ """ ## # @if jp # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿ # # ¥³¥ó¥¹¥È¥é¥¯¥¿ # # @param self # @param name ¸¡º÷Âоݥ³¥ó¥Ý¡¼¥Í¥ó¥È̾¾Î(¥Ç¥Õ¥©¥ë¥ÈÃÍ:None) # @param factory ¸¡º÷Âоݥե¡¥¯¥È¥ê̾¾Î(¥Ç¥Õ¥©¥ë¥ÈÃÍ:None) # # @else # # @endif def __init__(self, name=None, factory=None, prop=None): if prop: self._name = prop.getInstanceName() if factory: self._name = factory.getInstanceName() elif name: self._name = name def __call__(self, factory): return self._name == factory.getInstanceName() #============================================================ # ¥³¥ó¥Ý¡¼¥Í¥ó¥È¥Õ¥¡¥¯¥È¥ê #============================================================ ## # @if jp # @class FactoryPredicate # @brief ¥³¥ó¥Ý¡¼¥Í¥ó¥È¥Õ¥¡¥¯¥È¥ê¸¡º÷ÍÑ¥Õ¥¡¥ó¥¯¥¿ # # @else # # @endif class FactoryPredicate: def __init__(self, name=None, prop=None, factory=None): if name: self._vendor = "" self._category = "" self._impleid = name self._version = "" elif prop: self._vendor = prop.getProperty("vendor") self._category = prop.getProperty("category") self._impleid = prop.getProperty("implementation_id") self._version = prop.getProperty("version") elif factory: self._vendor = factory.profile().getProperty("vendor") self._category = factory.profile().getProperty("category") self._impleid = factory.profile().getProperty("implementation_id") self._version = factory.profile().getProperty("version") def __call__(self, factory): if self._impleid == "": return False _prop = OpenRTM_aist.Properties(prop=factory.profile()) if self._impleid != _prop.getProperty("implementation_id"): return False if self._vendor != "" and self._vendor != _prop.getProperty("vendor"): return False if self._category != "" and self._category != _prop.getProperty("category"): return False if self._version != "" and self._version != _prop.getProperty("version"): return False return True #============================================================ # ExecutionContext¥Õ¥¡¥¯¥È¥ê #============================================================ ## # @if jp # @class ECFactoryPredicate # @brief ExecutionContext¥Õ¥¡¥¯¥È¥ê¸¡º÷ÍÑ¥Õ¥¡¥ó¥¯¥¿ # # @else # # @endif class ECFactoryPredicate: def __init__(self, name=None, factory=None): if name: self._name = name elif factory: self._name = factory.name() def __call__(self, factory): return self._name == factory.name() #============================================================ # Module Fanctor #============================================================ ## # @if jp # @class ModulePredicate # @brief Module¸¡º÷ÍÑ¥Õ¥¡¥ó¥¯¥¿ # # @else # # @endif class ModulePredicate: # ModulePredicate(coil::Properties& prop) def __init__(self, prop): self._prop = prop return # bool operator()(coil::Properties& prop) def __call__(self, prop): if self._prop.getProperty("implementation_id") != prop.getProperty("implementation_id"): return False if self._prop.getProperty("vendor") and \ self._prop.getProperty("vendor") != prop.getProperty("vendor"): return False if self._prop.getProperty("category") and \ self._prop.getProperty("category") != prop.getProperty("category"): return False if self._prop.getProperty("version") and \ self._prop.getProperty("version") != prop.getProperty("version"): return False return True #------------------------------------------------------------ # ORB runner #------------------------------------------------------------ ## # @if jp # @class OrbRunner # @brief OrbRunner ¥¯¥é¥¹ # # ORB ¼Â¹ÔÍѥإë¥Ñ¡¼¥¯¥é¥¹¡£ # # @since 0.4.0 # # @else # @class OrbRunner # @brief OrbRunner class # @endif class OrbRunner: """ """ ## # @if jp # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿ # # ¥³¥ó¥¹¥È¥é¥¯¥¿ # # @param self # @param orb ORB # # @else # @brief Constructor # # @endif def __init__(self, orb): self._orb = orb self._th = threading.Thread(target=self.run) self._th.start() def __del__(self): self._th.join() self._th = None return ## # @if jp # @brief ORB ¼Â¹Ô½èÍý # # ORB ¼Â¹Ô # # @param self # # @else # # @endif def run(self): try: self._orb.run() #Manager.instance().shutdown() except: print OpenRTM_aist.Logger.print_exception() pass return ## # @if jp # @brief ORB wait½èÍý # # ORB wait # # @param self # # @else # # @endif def wait(self): return ## # @if jp # @brief ORB ½ªÎ»½èÍý(̤¼ÂÁõ) # # ORB ½ªÎ»½èÍý # # @param self # @param flags ½ªÎ»½èÍý¥Õ¥é¥° # # @return ½ªÎ»½èÍý·ë²Ì # # @else # # @endif def close(self, flags): return 0 #------------------------------------------------------------ # Manager Terminator #------------------------------------------------------------ ## # @if jp # @class Terminator # @brief Terminator ¥¯¥é¥¹ # # ORB ½ªÎ»Íѥإë¥Ñ¡¼¥¯¥é¥¹¡£ # # @since 0.4.0 # # @else # # @endif class Terminator: """ """ ## # @if jp # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿ # # ¥³¥ó¥¹¥È¥é¥¯¥¿ # # @param self # @param manager ¥Þ¥Í¡¼¥¸¥ã¡¦¥ª¥Ö¥¸¥§¥¯¥È # # @else # @brief Constructor # # @endif def __init__(self, manager): self._manager = manager ## # @if jp # @brief ½ªÎ»½èÍý # # ORB¡¤¥Þ¥Í¡¼¥¸¥ã½ªÎ»½èÍý¤ò³«»Ï¤¹¤ë¡£ # # @param self # # @else # # @endif def terminate(self): self._manager.shutdown() ## # @if jp # @class Term # @brief Term ¥¯¥é¥¹ # # ½ªÎ»Íѥإë¥Ñ¡¼¥¯¥é¥¹¡£ # # @since 0.4.0 # # @else # # @endif class Term: def __init__(self): self.waiting = 0 self.mutex = threading.RLock() class Finalized: def __init__(self): self.mutex = threading.RLock() self.comps = []
2206  #============================================================
2207 
2216  """
2217  """
2218 
2219 
2232  def __init__(self, name=None, factory=None, prop=None):
2233  if prop:
2234  self._name = prop.getInstanceName()
2235  if factory:
2236  self._name = factory.getInstanceName()
2237  elif name:
2238  self._name = name
2239 
2240  def __call__(self, factory):
2241  return self._name == factory.getInstanceName()
2242 
2243 
2244 
2245  #============================================================
2246  # ¥³¥ó¥Ý¡¼¥Í¥ó¥È¥Õ¥¡¥¯¥È¥ê #============================================================ ## # @if jp # @class FactoryPredicate # @brief ¥³¥ó¥Ý¡¼¥Í¥ó¥È¥Õ¥¡¥¯¥È¥ê¸¡º÷ÍÑ¥Õ¥¡¥ó¥¯¥¿ # # @else # # @endif class FactoryPredicate: def __init__(self, name=None, prop=None, factory=None): if name: self._vendor = "" self._category = "" self._impleid = name self._version = "" elif prop: self._vendor = prop.getProperty("vendor") self._category = prop.getProperty("category") self._impleid = prop.getProperty("implementation_id") self._version = prop.getProperty("version") elif factory: self._vendor = factory.profile().getProperty("vendor") self._category = factory.profile().getProperty("category") self._impleid = factory.profile().getProperty("implementation_id") self._version = factory.profile().getProperty("version") def __call__(self, factory): if self._impleid == "": return False _prop = OpenRTM_aist.Properties(prop=factory.profile()) if self._impleid != _prop.getProperty("implementation_id"): return False if self._vendor != "" and self._vendor != _prop.getProperty("vendor"): return False if self._category != "" and self._category != _prop.getProperty("category"): return False if self._version != "" and self._version != _prop.getProperty("version"): return False return True #============================================================ # ExecutionContext¥Õ¥¡¥¯¥È¥ê #============================================================ ## # @if jp # @class ECFactoryPredicate # @brief ExecutionContext¥Õ¥¡¥¯¥È¥ê¸¡º÷ÍÑ¥Õ¥¡¥ó¥¯¥¿ # # @else # # @endif class ECFactoryPredicate: def __init__(self, name=None, factory=None): if name: self._name = name elif factory: self._name = factory.name() def __call__(self, factory): return self._name == factory.name() #============================================================ # Module Fanctor #============================================================ ## # @if jp # @class ModulePredicate # @brief Module¸¡º÷ÍÑ¥Õ¥¡¥ó¥¯¥¿ # # @else # # @endif class ModulePredicate: # ModulePredicate(coil::Properties& prop) def __init__(self, prop): self._prop = prop return # bool operator()(coil::Properties& prop) def __call__(self, prop): if self._prop.getProperty("implementation_id") != prop.getProperty("implementation_id"): return False if self._prop.getProperty("vendor") and \ self._prop.getProperty("vendor") != prop.getProperty("vendor"): return False if self._prop.getProperty("category") and \ self._prop.getProperty("category") != prop.getProperty("category"): return False if self._prop.getProperty("version") and \ self._prop.getProperty("version") != prop.getProperty("version"): return False return True #------------------------------------------------------------ # ORB runner #------------------------------------------------------------ ## # @if jp # @class OrbRunner # @brief OrbRunner ¥¯¥é¥¹ # # ORB ¼Â¹ÔÍѥإë¥Ñ¡¼¥¯¥é¥¹¡£ # # @since 0.4.0 # # @else # @class OrbRunner # @brief OrbRunner class # @endif class OrbRunner: """ """ ## # @if jp # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿ # # ¥³¥ó¥¹¥È¥é¥¯¥¿ # # @param self # @param orb ORB # # @else # @brief Constructor # # @endif def __init__(self, orb): self._orb = orb self._th = threading.Thread(target=self.run) self._th.start() def __del__(self): self._th.join() self._th = None return ## # @if jp # @brief ORB ¼Â¹Ô½èÍý # # ORB ¼Â¹Ô # # @param self # # @else # # @endif def run(self): try: self._orb.run() #Manager.instance().shutdown() except: print OpenRTM_aist.Logger.print_exception() pass return ## # @if jp # @brief ORB wait½èÍý # # ORB wait # # @param self # # @else # # @endif def wait(self): return ## # @if jp # @brief ORB ½ªÎ»½èÍý(̤¼ÂÁõ) # # ORB ½ªÎ»½èÍý # # @param self # @param flags ½ªÎ»½èÍý¥Õ¥é¥° # # @return ½ªÎ»½èÍý·ë²Ì # # @else # # @endif def close(self, flags): return 0 #------------------------------------------------------------ # Manager Terminator #------------------------------------------------------------ ## # @if jp # @class Terminator # @brief Terminator ¥¯¥é¥¹ # # ORB ½ªÎ»Íѥإë¥Ñ¡¼¥¯¥é¥¹¡£ # # @since 0.4.0 # # @else # # @endif class Terminator: """ """ ## # @if jp # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿ # # ¥³¥ó¥¹¥È¥é¥¯¥¿ # # @param self # @param manager ¥Þ¥Í¡¼¥¸¥ã¡¦¥ª¥Ö¥¸¥§¥¯¥È # # @else # @brief Constructor # # @endif def __init__(self, manager): self._manager = manager ## # @if jp # @brief ½ªÎ»½èÍý # # ORB¡¤¥Þ¥Í¡¼¥¸¥ã½ªÎ»½èÍý¤ò³«»Ï¤¹¤ë¡£ # # @param self # # @else # # @endif def terminate(self): self._manager.shutdown() ## # @if jp # @class Term # @brief Term ¥¯¥é¥¹ # # ½ªÎ»Íѥإë¥Ñ¡¼¥¯¥é¥¹¡£ # # @since 0.4.0 # # @else # # @endif class Term: def __init__(self): self.waiting = 0 self.mutex = threading.RLock() class Finalized: def __init__(self): self.mutex = threading.RLock() self.comps = []
2247  #============================================================
2248 
2257 
2258  def __init__(self, name=None, prop=None, factory=None):
2259  if name:
2260  self._vendor = ""
2261  self._category = ""
2262  self._impleid = name
2263  self._version = ""
2264  elif prop:
2265  self._vendor = prop.getProperty("vendor")
2266  self._category = prop.getProperty("category")
2267  self._impleid = prop.getProperty("implementation_id")
2268  self._version = prop.getProperty("version")
2269  elif factory:
2270  self._vendor = factory.profile().getProperty("vendor")
2271  self._category = factory.profile().getProperty("category")
2272  self._impleid = factory.profile().getProperty("implementation_id")
2273  self._version = factory.profile().getProperty("version")
2274 
2275 
2276  def __call__(self, factory):
2277  if self._impleid == "":
2278  return False
2279 
2280  _prop = OpenRTM_aist.Properties(prop=factory.profile())
2281 
2282  if self._impleid != _prop.getProperty("implementation_id"):
2283  return False
2284 
2285  if self._vendor != "" and self._vendor != _prop.getProperty("vendor"):
2286  return False
2287 
2288  if self._category != "" and self._category != _prop.getProperty("category"):
2289  return False
2290 
2291  if self._version != "" and self._version != _prop.getProperty("version"):
2292  return False
2293 
2294  return True
2295 
2296 
2297 
2298  #============================================================
2299  # ExecutionContext¥Õ¥¡¥¯¥È¥ê #============================================================ ## # @if jp # @class ECFactoryPredicate # @brief ExecutionContext¥Õ¥¡¥¯¥È¥ê¸¡º÷ÍÑ¥Õ¥¡¥ó¥¯¥¿ # # @else # # @endif class ECFactoryPredicate: def __init__(self, name=None, factory=None): if name: self._name = name elif factory: self._name = factory.name() def __call__(self, factory): return self._name == factory.name() #============================================================ # Module Fanctor #============================================================ ## # @if jp # @class ModulePredicate # @brief Module¸¡º÷ÍÑ¥Õ¥¡¥ó¥¯¥¿ # # @else # # @endif class ModulePredicate: # ModulePredicate(coil::Properties& prop) def __init__(self, prop): self._prop = prop return # bool operator()(coil::Properties& prop) def __call__(self, prop): if self._prop.getProperty("implementation_id") != prop.getProperty("implementation_id"): return False if self._prop.getProperty("vendor") and \ self._prop.getProperty("vendor") != prop.getProperty("vendor"): return False if self._prop.getProperty("category") and \ self._prop.getProperty("category") != prop.getProperty("category"): return False if self._prop.getProperty("version") and \ self._prop.getProperty("version") != prop.getProperty("version"): return False return True #------------------------------------------------------------ # ORB runner #------------------------------------------------------------ ## # @if jp # @class OrbRunner # @brief OrbRunner ¥¯¥é¥¹ # # ORB ¼Â¹ÔÍѥإë¥Ñ¡¼¥¯¥é¥¹¡£ # # @since 0.4.0 # # @else # @class OrbRunner # @brief OrbRunner class # @endif class OrbRunner: """ """ ## # @if jp # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿ # # ¥³¥ó¥¹¥È¥é¥¯¥¿ # # @param self # @param orb ORB # # @else # @brief Constructor # # @endif def __init__(self, orb): self._orb = orb self._th = threading.Thread(target=self.run) self._th.start() def __del__(self): self._th.join() self._th = None return ## # @if jp # @brief ORB ¼Â¹Ô½èÍý # # ORB ¼Â¹Ô # # @param self # # @else # # @endif def run(self): try: self._orb.run() #Manager.instance().shutdown() except: print OpenRTM_aist.Logger.print_exception() pass return ## # @if jp # @brief ORB wait½èÍý # # ORB wait # # @param self # # @else # # @endif def wait(self): return ## # @if jp # @brief ORB ½ªÎ»½èÍý(̤¼ÂÁõ) # # ORB ½ªÎ»½èÍý # # @param self # @param flags ½ªÎ»½èÍý¥Õ¥é¥° # # @return ½ªÎ»½èÍý·ë²Ì # # @else # # @endif def close(self, flags): return 0 #------------------------------------------------------------ # Manager Terminator #------------------------------------------------------------ ## # @if jp # @class Terminator # @brief Terminator ¥¯¥é¥¹ # # ORB ½ªÎ»Íѥإë¥Ñ¡¼¥¯¥é¥¹¡£ # # @since 0.4.0 # # @else # # @endif class Terminator: """ """ ## # @if jp # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿ # # ¥³¥ó¥¹¥È¥é¥¯¥¿ # # @param self # @param manager ¥Þ¥Í¡¼¥¸¥ã¡¦¥ª¥Ö¥¸¥§¥¯¥È # # @else # @brief Constructor # # @endif def __init__(self, manager): self._manager = manager ## # @if jp # @brief ½ªÎ»½èÍý # # ORB¡¤¥Þ¥Í¡¼¥¸¥ã½ªÎ»½èÍý¤ò³«»Ï¤¹¤ë¡£ # # @param self # # @else # # @endif def terminate(self): self._manager.shutdown() ## # @if jp # @class Term # @brief Term ¥¯¥é¥¹ # # ½ªÎ»Íѥإë¥Ñ¡¼¥¯¥é¥¹¡£ # # @since 0.4.0 # # @else # # @endif class Term: def __init__(self): self.waiting = 0 self.mutex = threading.RLock() class Finalized: def __init__(self): self.mutex = threading.RLock() self.comps = []
2300  #============================================================
2301 
2310 
2311 
2312 
2313  def __init__(self, name=None, factory=None):
2314  if name:
2315  self._name = name
2316  elif factory:
2317  self._name = factory.name()
2318 
2319  def __call__(self, factory):
2320  return self._name == factory.name()
2321 
2322 
2323  #============================================================
2324  # Module Fanctor
2325  #============================================================
2326 
2335 
2336  # ModulePredicate(coil::Properties& prop)
2337  def __init__(self, prop):
2338  self._prop = prop
2339  return
2340 
2341  # bool operator()(coil::Properties& prop)
2342  def __call__(self, prop):
2343 
2344  if self._prop.getProperty("implementation_id") != prop.getProperty("implementation_id"):
2345  return False
2346 
2347  if self._prop.getProperty("vendor") and \
2348  self._prop.getProperty("vendor") != prop.getProperty("vendor"):
2349  return False
2350 
2351  if self._prop.getProperty("category") and \
2352  self._prop.getProperty("category") != prop.getProperty("category"):
2353  return False
2354 
2355  if self._prop.getProperty("version") and \
2356  self._prop.getProperty("version") != prop.getProperty("version"):
2357  return False
2358 
2359  return True
2360 
2361 
2362  #------------------------------------------------------------
2363  # ORB runner
2364  #------------------------------------------------------------
2365 
2378  class OrbRunner:
2379  """
2380  """
2381 
2382 
2395  def __init__(self, orb):
2396  self._orb = orb
2397  self._th = threading.Thread(target=self.run)
2398  self._th.start()
2399 
2400 
2401  def __del__(self):
2402  self._th.join()
2403  self._th = None
2404  return
2405 
2406 
2407 
2418  def run(self):
2419  try:
2420  self._orb.run()
2421  #Manager.instance().shutdown()
2422  except:
2423  print OpenRTM_aist.Logger.print_exception()
2424  pass
2425  return
2426 
2427 
2428 
2439  def wait(self):
2440  return
2441 
2442 
2456  def close(self, flags):
2457  return 0
2458 
2459 
2460  #------------------------------------------------------------
2461  # Manager Terminator
2462  #------------------------------------------------------------
2463 
2475  class Terminator:
2476  """
2477  """
2478 
2479 
2492  def __init__(self, manager):
2493  self._manager = manager
2494 
2495 
2496 
2507  def terminate(self):
2508  self._manager.shutdown()
2509 
2510 
2511 
2512 
2524  class Term:
2525  def __init__(self):
2526  self.waiting = 0
2527  self.mutex = threading.RLock()
2528 
2529 
2530  class Finalized:
2531  def __init__(self):
2532  self.mutex = threading.RLock()
2533  self.comps = []
def getComponent(self, instance_name)
Get RT-Component's pointer.
Definition: Manager.py:1047
def initFactories(self)
Factories initialization.
Definition: Manager.py:1690
def formatString(self, naming_format, prop)
Definition: Manager.py:2075
def cleanupComponent(self, comp)
Definition: Manager.py:1806
def unregisterComponent(self, comp)
Register RT-Component directly without Factory.
Definition: Manager.py:936
def registerECFactory(self, name, new_func, delete_func)
Register ExecutionContext Factory.
Definition: Manager.py:671
def split(input, delimiter)
Split string by delimiter.
Definition: StringUtil.py:323
def registerComponent(self, comp)
Register RT-Component directly without Factory.
Definition: Manager.py:909
def load(self, fname, initfunc)
[CORBA interface] Load module
Definition: Manager.py:485
def setModuleInitProc(self, proc)
Run the Manager.
Definition: Manager.py:332
def createORBEndpoints(self, endpoints)
Create Endpoints.
Definition: Manager.py:1419
Manager configuration class.
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
def __init__(self, name=None, factory=None, prop=None)
Definition: Manager.py:2232
def registerFactory(self, profile, new_func, delete_func)
Register RT-Component Factory.
Definition: Manager.py:612
def initManager(self, argv)
Manager internal initialization.
Definition: Manager.py:1149
def getModulesFactories(self)
Get the list of all RT-Component Factory.
Definition: Manager.py:696
def getLoadableModules(self)
Get loadable module names.
Definition: Manager.py:586
def shutdownLogger(self)
System Logger finalization.
Definition: Manager.py:1327
def getFactoryProfiles(self)
Get profiles of factories.
Definition: Manager.py:642
def createContext(self, ec_args)
Create Context.
Definition: Manager.py:962
def __init__(self, _manager=None)
Protected Copy Constructor.
Definition: Manager.py:102
def mergeProperty(self, prop, file_name)
Definition: Manager.py:2028
def unload(self, fname)
Unload module.
Definition: Manager.py:525
def configureComponent(self, comp, prop)
void configureComponent(RTObject_impl* comp, const coil::Properties& prop);
Definition: Manager.py:1959
def createComponent(self, comp_args)
Create RT-Components.
Definition: Manager.py:767
def getComponents(self)
Get all RT-Component's pointer.
Definition: Manager.py:1065
def __init__(self, name=None, factory=None)
Definition: Manager.py:2313
def initORB(self)
CORBA ORB initialization.
Definition: Manager.py:1350
def createORBEndpointOption(self, opt, endpoints)
Create a command optional line of Endpoint of ORB.
Definition: Manager.py:1467
Timer class.
Definition: Timer.py:44
FactoryPython class.
Definition: Factory.py:203
def shutdownORB(self)
ORB finalization.
Definition: Manager.py:1512
def deleteComponent(self, instance_name=None, comp=None)
Unregister RT-Component that is registered in the Manager.
Definition: Manager.py:994
def shutdownOnNoRtcs(self)
Shutdown Manager.
Definition: Manager.py:1235
def __init__(self, orb)
Constructor.
Definition: Manager.py:2395
def find(seq, f)
Return the index of CORBA sequence element that functor matches.
def createORBOptions(self)
ORB command option creation.
Definition: Manager.py:1387
def __init__(self, name=None, prop=None, factory=None)
Definition: Manager.py:2258
def runManager(self, no_block=None)
Run the Manager.
Definition: Manager.py:444
def getLogbuf(self, name="manager")
Definition: Manager.py:2141
def getORB(self)
Get the pointer to the ORB.
Definition: Manager.py:1087
def initManagerServant(self)
ManagerServant initialization.
Definition: Manager.py:1727
def handler(signum, frame)
Definition: Manager.py:64
def append(dest, src)
Definition: NVUtil.py:386
def procComponentArgs(self, comp_arg, comp_id, comp_conf)
bool procComponentArgs(const char* comp_arg, coil::Properties& comp_id, coil::Properties& comp_conf) ...
Definition: Manager.py:1882
def unloadAll(self)
Unload module.
Definition: Manager.py:547
def __try_direct_load(self, file_name)
Definition: Manager.py:2180
def getPOA(self)
Get the pointer to the RootPOA.
Definition: Manager.py:1105
def initLogger(self)
System logger initialization.
Definition: Manager.py:1267
def instance()
Get instance of the manager.
Definition: Manager.py:214
def activateManager(self)
Activate Manager.
Definition: Manager.py:367
def notifyFinalized(self, comp)
This method deletes RT-Components.
Definition: Manager.py:1859
def getLoadedModules(self)
Get loaded module names std::vector<coil::Properties> getLoadedModules();.
Definition: Manager.py:567
def procContextArgs(self, ec_args, ec_id, ec_conf)
Definition: Manager.py:1921
def initComposite(self)
PeriodicECSharedComposite initialization.
Definition: Manager.py:1663
def cleanupComponents(self)
This method deletes RT-Components.
Definition: Manager.py:1827
def __init__(self, manager)
Constructor.
Definition: Manager.py:2492


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Feb 28 2022 23:01:06