def setAdditionalParameters(self, softwareProfile, application_registrar_ior, nic): self._softwareProfile = softwareProfile orb = __orb__ try: obj = orb.string_to_object(application_registrar_ior) applicationRegistrar = obj._narrow(CF.ApplicationRegistrar) if applicationRegistrar != None: self._domMgr = containers.DomainManagerContainer(applicationRegistrar._get_domMgr()) self._ecm = ossie.events.Manager.GetManager(self) except: self._domMgr = None
def start_service(serviceclass, thread_policy=None): import sys import CosNaming import copy import signal import getopt if len(sys.argv) == 2: if sys.argv[1] == '-i': print "Interactive mode (-i) no longer supported. Please use the sandbox to run Components/Devices/Services outside the scope of a Domain" sys.exit(-1) try: # IMPORTANT YOU CANNOT USE gnu_getopt OR OptionParser # because they will treat execparams with negative number # values as arguments. # # Since property ids *MUST* be valid XML names # they cannot start with -, therefore this is safe opts, args = getopt.getopt(sys.argv[1:], "", [""]) except getopt.GetoptError: print "usage: %s [options] [execparams]" % sys.argv[0] print print serviceclass.__doc__ sys.exit(2) options = {} for o, a in opts: pass # Turn the args into a dictionary execparams = {} while len(args) > 0: try: paramid = args.pop(0) paramvalue = args.pop(0) execparams[paramid] = paramvalue except IndexError: pass orb = None signal.signal(signal.SIGINT, __exit_handler) signal.signal(signal.SIGQUIT, __exit_handler) signal.signal(signal.SIGTERM, __exit_handler) try: devMgr = None component_Obj = None component_Var = None try: orb = CORBA.ORB_init() # get the POA obj_poa = orb.resolve_initial_references("RootPOA") poaManager = obj_poa._get_the_POAManager() if thread_policy != None: policyList = [] policyList.append(obj_poa.create_thread_policy(thread_policy)) servicePOA = obj_poa.create_POA("servicePOA", poaManager, policyList) else: servicePOA = obj_poa poaManager.activate() # If provided, get the device manager if execparams.has_key("DEVICE_MGR_IOR"): devMgr = orb.string_to_object(execparams["DEVICE_MGR_IOR"]) devMgr = devMgr._narrow(CF.DeviceManager) if not execparams.has_key("SERVICE_NAME"): logging.warning("No 'SERVICE_NAME' argument provided") execparams["SERVICE_NAME"] = "" # Configure logging context for the service name = execparams.get("SERVICE_NAME", "") log_config_uri = execparams.get("LOGGING_CONFIG_URI", None) debug_level = execparams.get("DEBUG_LEVEL", None) if debug_level != None: debug_level = int(debug_level) dpath = execparams.get("DOM_PATH", "") category = None try: if name != "": category = name.rsplit("_", 1)[0] except: pass ctx = ossie.logger.ServiceCtx(name, dpath) ossie.logger.Configure(log_config_uri, debug_level, ctx, category) # Create the component component_Obj = serviceclass(execparams["SERVICE_NAME"], execparams) servicePOA.activate_object(component_Obj) component_Var = component_Obj._this() # add required methods patchService(component_Obj) if devMgr != None: logging.debug("Registering service with device manager") #patchService(component_Obj) component_Obj._devMgr = containers.DeviceManagerContainer( devMgr) component_Obj._domMgr = containers.DomainManagerContainer( devMgr._get_domMgr()) devMgr.registerService(component_Var, execparams["SERVICE_NAME"]) else: print orb.object_to_string(component_Var) ## sets up logging context for resource to support CF::Logging component_Obj.saveLoggingContext(log_config_uri, debug_level, ctx) # Run the blocking main loop logging.debug("Starting ORB event loop") orb.run() except SystemExit: pass except KeyboardInterrupt: pass except: logging.exception("Unexpected Error") try: if devMgr != None: devMgr.unregisterService(component_Var, execparams["SERVICE_NAME"]) except: logging.warning("Error while unregistering service") if component_Obj != None and callable( getattr(component_Obj, "terminateService", None)): try: component_Obj.terminateService() except: logging.warning("Error releasing service object") # Call to a deprecated exit function. if component_Obj != None and callable( getattr(component_Obj, "releaseObject", None)): try: component_Obj.releaseObject() except: logging.warning("Error releasing service object") finally: if orb: orb.destroy()