def __setupNamesPanel(self): ''' Helper method sets up the panel displaying the names of all components that can be simulated. ''' #get a list from manager of all known components #note that this will NOT work with dynamic components! comp_info_list = getManager().get_component_info( getClient().token.h, [], "*", "*", 0) #must add active components to this list as well comp_info_list = comp_info_list + getManager().get_component_info( getClient().token.h, [], "*", "*", 1) #add all components to the list iff they are actually simulator objects for comp_info in comp_info_list: if comp_info.code == "Acssim.Servants.GUISimulator" and self.comp_names.count( comp_info.name) == 0: self.comp_names.append(comp_info.name) #tidy up the list self.comp_names.sort() #now add the widget self.comp_names_panel = Pmw.OptionMenu(self.interior(), command=self.compNameUpdate, labelpos='w', label_text='Component Name:', items=self.comp_names, menubutton_width=20) self.comp_names_panel.pack(anchor='w', padx=10, pady=10)
def releaseComponentAsync(self, comp_name, callback=None): ''' Release the component defined by comp_name in asynchronous way. Parameters: - comp_name is the name of the component to be released. - callback by default is None or it must be a subclass of relaseCallback Returns: The number of objects still attached to the released component Raises: TypeError if callback is not instance of ComponentReleaseCallback ''' myCBDescIn = CBDescIn(0, 0, "") if callback is None: myCBlong = MyCBlongImpl(None) try: getManager().release_component_async(self.__handle, comp_name, myCBlong._this(), myCBDescIn) except: self.getLogger().warning('Problem trying to release component ' + str(comp_name) + '. Check manager logs for more details') else: try: getManager().release_component_async(self.__handle, comp_name, callback.myCBlong, myCBDescIn) except maciErrType.NoPermissionEx, ex: callback.errorNoPermission(ex.message) callback.callOver() except ACSErr.ACSbaseEx, ex: e = ComponentDeactivationUncleanExImpl(exception = ex) callback.errorComponentReleaseFailed(e) callback.callOver()
def disconnect(self): ''' Disconnect notification. The disconnect method is called by the Manager to notify the client that it will be unavailable and that the client should log off. Also, the client developer is required to disconnect all connected clients before exiting the Python interpreter. Parameters: None Returns: None Raises: Nothing oneway void disconnect (); ''' self.logger.logInfo('Shutdown called for client') stopPeriodicFlush() try: #here we literally log out of manager getManager().logout(self.token.h) except Exception, e: self.logger.logWarning('Failed to log out of manager: ' + str(e)) print_exc()
def managerLogout(self): ''' Logout from manager Parameters: None Returns: None Raises: Nothing ''' with self.loggingIn: try: #here we literally log out of manager if self.isLoggedIn and self.token!=None: getManager().logout(self.token.h) except Exception, e: # The manager calls disconnect when it is going to be unavailble to # clients for example before shutting down # # A scenario that could generate this exception is when manager is about # to shutdown: it calls disconnect on the clients and shuts down immediately # At this point if a client tries to logout it can found the manager # in a shutdown state or already disappeared: both these situations # trigger a exception self.logger.logWarning('Failed to log out gracefully from the manager...') finally:
def managerLogout(self): ''' Logout from manager Parameters: None Returns: None Raises: Nothing ''' with self.loggingIn: try: #here we literally log out of manager if self.isLoggedIn and self.token != None: getManager().logout(self.token.h) except Exception, e: # The manager calls disconnect when it is going to be unavailble to # clients for example before shutting down # # A scenario that could generate this exception is when manager is about # to shutdown: it calls disconnect on the clients and shuts down immediately # At this point if a client tries to logout it can found the manager # in a shutdown state or already disappeared: both these situations # trigger a exception self.logger.logWarning( 'Failed to log out gracefully from the manager...') finally:
def getComponentNonSticky(self, comp_name): # pragma: NO COVER ''' Gets the component in a non stick way. The comp_name is a name of the component. Parameters: - comp_name is the name of the component. Returns: a narrowed reference to the component or None if that reference cannot be obtained. Raises: CannotGetComponentExImpl if the component stubs cannot be loaded or found ''' #Import the correct Python CORBA stub for the developer. comp_class = self.__importComponentStubs(comp_name) corba_obj = getManager().get_component_non_sticky(self.__handle, str(comp_name)) component = self.__narrowComponentReference(corba_obj, comp_class) try: component.find_characteristic('foo') except CORBA.Exception, ex: component.find_characteristic('foo')
def getCollocatedComp(self, comp_spec, mark_as_default, target_comp): # pragma: NO COVER ''' Activation of a component so that it runs in the same process as another given component. Parameters: - comp_spec (maci.ComponentSpec) Component to be obtained. - mark_as_default (bool) Mark component as default component of its type - target_comp Name of the target component (where to activate component) Returns: a narrowed reference to the component or None if that reference cannot be obtained. Raises: - IncompleteComponentSpec - InvalidComponentSpec - ComponentSpecIncompatibleWithActiveComponent ''' comp_info = getManager().get_collocated_component( self.__handle, comp_spec, mark_as_default, target_comp) if comp_info is not None: corba_obj = comp_info.reference comp_class = self.__importComponentStubs(None, comp_info.type) return self.__narrowComponentReference(corba_obj, comp_class) else: return None
def __init__(self, name="Python Client"): ''' Initialize the client. Parameters: - name is what manager will refer to this client instance as Returns: Nothing Raises: CORBAProblemExImpl ''' #security token given to us by the manager self.token = None #name we will call ourself when contacting the manager self.name = str(name) #Logger used by container/components try: self.logger except: self.logger = getLogger(name) startPeriodicFlush(3) #List of components manager says are active self.managerComponents = [] #CORBA reference to ourself self.corbaRef = None try: #get our token from manager self.token = getManager().login(self.getMyCorbaRef()) except Exception, e: #cannot go on if the login fails print_exc() raise CORBAProblemExImpl()
def availableComponents(self, name_wildcard="*", type_wildcard="*", activated=0): # pragma: NO COVER ''' Returns a list of ComponentInfos consisting of all Components known to manager. Parameters: - name_wildcard is a wildcard that the components name must match in order for its information to be returned - type_wildcard is a wildcard that the components type must match in order for its information to be returned. - activated is a boolean value which specifies whether the search should be limited to components which have already been activated. Returns: a list consisting of ComponentInfo structures for every component manager knows of Raises: ??? ''' #using these cryptic parameters we find out exactly which #components are available components = getManager().get_component_info(self.__handle, [], name_wildcard, type_wildcard, activated) return components
def getCollocatedComp(self, comp_spec, mark_as_default, target_comp): # pragma: NO COVER ''' Activation of a component so that it runs in the same process as another given component. Parameters: - comp_spec (maci.ComponentSpec) Component to be obtained. - mark_as_default (bool) Mark component as default component of its type - target_comp Name of the target component (where to activate component) Returns: a narrowed reference to the component or None if that reference cannot be obtained. Raises: - IncompleteComponentSpec - InvalidComponentSpec - ComponentSpecIncompatibleWithActiveComponent ''' comp_info = getManager().get_collocated_component(self.__handle, comp_spec, mark_as_default, target_comp) if comp_info is not None: corba_obj = comp_info.reference comp_class = self.__importComponentStubs(None, comp_info.type) return self.__narrowComponentReference(corba_obj, comp_class) else: return None
def updateMethods(self, selection): ''' Helper function returns a list of methods or attributes the component has available. Parameters: - selection ("Methods" or "Attributes") Returns: a list of available methods/attributes. ''' retList = [] #component name compName = self.current_comp_name #retrieve comp IDL type from manager compInfoList = [] compInfoList = getManager().get_component_info(getClient().token.h, [], compName, "*", 0) compInfoList = compInfoList + getManager().get_component_info( getClient().token.h, [], compName, "*", 1) if len(compInfoList) > 1: print "Potential error: more than 1 matching component found - ", compName, len( compInfoList) elif len(compInfoList) == 0: print "Bad...no matching component found:", compName return retList #need to know the IDL type in order to figure out the list of components compIDLType = compInfoList[0].type #Get a description from the IFR interf = IR.lookup_id(compIDLType)._narrow( CORBA.InterfaceDef).describe_interface() if selection == "Methods": for method in interf.operations: retList.append(method.name) else: #must be an attribute for method in interf.attributes: retList.append(method.name) retList.sort() return retList
def makeCompImmortal(self, comp_name, state): # pragma: NO COVER ''' Change mortality state of a component. Compnent must be already active. The caller must be owner of the component or have administator rights. Parameters: - comp_name name of the component - state new mortality state Returns: None Raises: ??? ''' #just delegate call directly to manager getManager().make_component_immortal(self.__handle, comp_name, state) return
def getDynamicComponent(self, name, #name of the component comp_type, #IR IDL location code, #shared library implementing comp container, #container to activate component ): # pragma: NO COVER ''' Gets a component whose instance is not registered in the CDB at deployment time. Parameters: - name is the components name in string format - comp_type is the interface repository IDL location of the component - code is a shared library implementing component - container is the name of the container to activate component. Returns: a narrowed reference to the component or None if that reference cannot be obtained. Raises: CannotGetComponentExImpl if the component stubs cannot be loaded or found ''' #Import the correct Python CORBA stub for the developer. comp_class = self.__importComponentStubs(None, comp_type) #convert the default values into something manager can handle if name is None: name = maci.COMPONENT_SPEC_ANY if comp_type is None: comp_type = maci.COMPONENT_SPEC_ANY if code is None: code = maci.COMPONENT_SPEC_ANY if container is None: container = maci.COMPONENT_SPEC_ANY comp_spec = maci.ComponentSpec(str(name), str(comp_type), str(code), str(container)) comp_info = getManager().get_dynamic_component(self.__handle, comp_spec, 0) corba_obj = comp_info.reference component = self.__narrowComponentReference(corba_obj, comp_class) try: component.find_characteristic('foo') except CORBA.Exception, ex: component.find_characteristic('foo')
def managerLogin(self): ''' Login into the manager Parameters: None Returns: The token received from the manager Raises: CORBAProblemExImpl If the login failed ''' token = None try: if getManager()==None: raise CORBAProblemExImpl() with self.loggingIn: token = getManager().login(self.getMyCorbaRef()) self.loggedIn = True except Exception, e: #cannot go on if the login fails raise CORBAProblemExImpl(exception=e)
def forceReleaseComponent(self, comp_name): # pragma: NO COVER ''' Forcefully releases the component defined by comp_name. Parameter: comp_name is the name of the component to be released. Returns: The number of objects still attached to the released component Raises: Nothing ''' return getManager().force_release_component(self.__handle, comp_name)
def managerLogin(self): ''' Login into the manager Parameters: None Returns: The token received from the manager Raises: CORBAProblemExImpl If the login failed ''' token = None try: if getManager() == None: raise CORBAProblemExImpl() with self.loggingIn: token = getManager().login(self.getMyCorbaRef()) self.loggedIn = True except Exception, e: #cannot go on if the login fails raise CORBAProblemExImpl(exception=e)
def releaseComponent(self, comp_name): # pragma: NO COVER ''' Release the component defined by comp_name. Parameter: comp_name is the name of the component to be released. Returns: The number of objects still attached to the released component Raises: Nothing ''' return getManager().release_component(self.__handle, comp_name)
def updateMethods(self, selection): ''' Helper function returns a list of methods or attributes the component has available. Parameters: - selection ("Methods" or "Attributes") Returns: a list of available methods/attributes. ''' retList = [] #component name compName = self.current_comp_name #retrieve comp IDL type from manager compInfoList = [] compInfoList = getManager().get_component_info(getClient().token.h, [], compName, "*", 0) compInfoList = compInfoList + getManager().get_component_info(getClient().token.h, [], compName, "*", 1) if len(compInfoList) > 1: print "Potential error: more than 1 matching component found - ", compName, len(compInfoList) elif len(compInfoList)==0: print "Bad...no matching component found:", compName return retList #need to know the IDL type in order to figure out the list of components compIDLType = compInfoList[0].type #Get a description from the IFR interf = IR.lookup_id(compIDLType)._narrow(CORBA.InterfaceDef).describe_interface() if selection == "Methods": for method in interf.operations: retList.append(method.name) else: #must be an attribute for method in interf.attributes: retList.append(method.name) retList.sort() return retList
def restartComp(self, comp_name): # pragma: NO COVER ''' Restarts a component. Parameters: - comp_name name of the component Returns: Reference to the restarted component. Raises: ??? ''' #just delegate call directly to manager return getManager().restart_component(self.__handle, comp_name)
def getDynamicComponent(self, name, #name of the component comp_type, #IR IDL location code, #shared library implementing comp container, #container to activate component ): # pragma: NO COVER ''' Gets a component whose instance is not registered in the CDB at deployment time. Parameters: - name is the components name in string format - comp_type is the interface repository IDL location of the component - code is a shared library implementing component - container is the name of the container to activate component. Returns: a narrowed reference to the component or None if that reference cannot be obtained. Raises: CannotGetComponentExImpl if the component stubs cannot be loaded or found ''' #Import the correct Python CORBA stub for the developer. comp_class = self.__importComponentStubs(None, comp_type) #convert the default values into something manager can handle if name is None: name = maci.COMPONENT_SPEC_ANY if comp_type is None: comp_type = maci.COMPONENT_SPEC_ANY if code is None: code = maci.COMPONENT_SPEC_ANY if container is None: container = maci.COMPONENT_SPEC_ANY comp_spec = maci.ComponentSpec(str(name), str(comp_type), str(code), str(container)) comp_info = getManager().get_dynamic_component(self.__handle, comp_spec, 0) corba_obj = comp_info.reference return self.__narrowComponentReference(corba_obj, comp_class)
def __setupNamesPanel(self): ''' Helper method sets up the panel displaying the names of all components that can be simulated. ''' #get a list from manager of all known components #note that this will NOT work with dynamic components! comp_info_list = getManager().get_component_info(getClient().token.h, [], "*", "*", 0) #must add active components to this list as well comp_info_list = comp_info_list + getManager().get_component_info(getClient().token.h, [], "*", "*", 1) #add all components to the list iff they are actually simulator objects for comp_info in comp_info_list: if comp_info.code == "Acssim.Servants.GUISimulator" and self.comp_names.count(comp_info.name)==0: self.comp_names.append(comp_info.name) #tidy up the list self.comp_names.sort() #now add the widget self.comp_names_panel = Pmw.OptionMenu(self.interior(), command = self.compNameUpdate, labelpos = 'w', label_text = 'Component Name:', items = self.comp_names, menubutton_width = 20) self.comp_names_panel.pack(anchor = 'w', padx = 10, pady = 10)
def getCompIfrID(comp_name): ''' Given a component's name, returns said component's interface repository ID or throws an exception if the ID cannot be determined. Raises: CORBA.NO_RESOURCES ''' #get a list of component info's comp_list = getManager().get_component_info(getClient().token.h, [], "*", "*", 0) for comp in comp_list: if comp.name == comp_name: return comp.type #sanity check raise CORBA.NO_RESOURCES()
def findComponents(self, curl_wildcard="*", type_wildcard="*", activated=CORBA.FALSE): # pragma: NO COVER ''' Finds components by their instance name and/or by their type. Wildcards can be used for the curl and type. This method returns a possibly empty array of component curls; for each curl, you may use getComponent to obtain the reference. Parameters: - name_wildcard (None is understood as "*") - type_wildcard (None is understood as "*") - activated is a boolean value which specifies whether the search should be limited to components which have already been activated. Return: the curls of the component(s) that match the search. Raises: ??? ''' #Set them to everything if undefined if curl_wildcard is None: curl_wildcard = "*" else: curl_wildcard = str(curl_wildcard) if type_wildcard is None: type_wildcard = "*" else: type_wildcard = str(type_wildcard) #Get all Component info comp_info_list = getManager().get_component_info(self.__handle, [], curl_wildcard, type_wildcard, activated) ret_string_list = [] #Take only the component names and return that for comp_info in comp_info_list: ret_string_list.append(comp_info.name) return ret_string_list
def getComponentNonSticky(self, comp_name): # pragma: NO COVER ''' Gets the component in a non stick way. The comp_name is a name of the component. Parameters: - comp_name is the name of the component. Returns: a narrowed reference to the component or None if that reference cannot be obtained. Raises: CannotGetComponentExImpl if the component stubs cannot be loaded or found ''' #Import the correct Python CORBA stub for the developer. comp_class = self.__importComponentStubs(comp_name) corba_obj = getManager().get_component_non_sticky(self.__handle, str(comp_name)) return self.__narrowComponentReference(corba_obj, comp_class)
def getDefaultComponent(self, comp_type): # pragma: NO COVER ''' Gets the default component specified by the component type. The type is the IDL type, such as "IDL:alma/PS/PowerSupply:1.0" Parameters: - comp_type is the interface repository IDL location of the component. Returns: a narrowed reference to the component or None if that reference cannot be obtained. Raises: CannotGetComponentExImpl if the component stubs cannot be loaded or found ''' #Import the correct Python CORBA stub for the developer. comp_class = self.__importComponentStubs(None, comp_type) comp_info = getManager().get_default_component(self.__handle, str(comp_type)) corba_obj = comp_info.reference return self.__narrowComponentReference(corba_obj, comp_class)
def getComponent(self, comp_name=None, activate=CORBA.TRUE, comp_idl_type=None, comp_code=None, container_name=None, is_dynamic=0): ''' NOTE: all keyword parameters with the exception of comp_name are deprecated! Get a component reference from the Manager. This seemingly simple method is actually quite complicated. First, its important to note that this method narrows the reference for the developer and even imports the proper IDL Python stub. Under certain circumstances though, the IDL Python stub may NOT exist in the correct place which has led some developers to believe this method was broken in the past. So if you see an error message beginning with "Unable to import...", please check that you really CAN import the CORBA stubs for the component you are trying to access using the infamous "python -i" command. The next important thing to realize is this method does not just retrieve named components as its own name implies - based on the parameters passed it could return default and dynamic components also. Parameters: - name is the components name. If not None and the rest of the default parameters are left as-is, this is assumed to be a static component. - activate tells manager whether the component should be activated if it has not already been instantiated. Not too useful. - comp_idl_type is the interface repository IDL location of the component. If not None and the rest of the default parameters are left as-is, it is assumed the developer wants a default component. - comp_code is a shared library implementing component. If not None, it is assumed the developer wants a dynamic component. - container_name is the name of the container to activate component. If not None, it is assumed the developer wants a dynamic component. - is_dynamic states whether a component should be retrieved as default or dynamic. In simple terms, when this parameter and comp_idl_type are the only params that have been changed from their original values, this is the difference between retrieving a reference to a dynamic component or a default component. Returns: a narrowed reference to the component or None if that reference cannot be obtained. Raises: CannotGetComponentExImpl if the component stubs cannot be loaded or found ''' #if the user is trying to get a "normal" static component if (comp_name is not None) and (comp_idl_type is None) and \ (comp_code is None) and (container_name is None) and \ (is_dynamic == 0): #Import the correct Python CORBA stub for the developer. comp_class = self.__importComponentStubs(comp_name, comp_idl_type) #get the component from manager corba_obj = getManager().get_component(self.__handle, comp_name, activate) #return the narrowed reference return self.__narrowComponentReference(corba_obj, comp_class) #if the user is trying to get a static default component elif (comp_idl_type is not None) and (comp_name is None) and \ (comp_code is None) and (container_name is None) and \ (is_dynamic == 0): return self.getDefaultComponent(str(comp_idl_type)) #user must be trying to get a dynamic component else: return self.getDynamicComponent(comp_name, comp_idl_type, comp_code, container_name)
#------------------------------------------------------------------------------ ''' Starts a Python Container. ''' #------------------------------------------------------------------------------ __version__ = "$Id: ACSStartContainerPy.py,v 1.5 2006/07/18 20:11:39 dfugate Exp $" #------------------------------------------------------------------------------ from Acspy.Util.ACSCorba import getManager from Acspy.Container import Container from sys import argv from time import sleep #------------------------------------------------------------------------------ if __name__ == "__main__": #this ensures that we don't log into manager until it's really #up and running. while getManager()==None: print "Failed to obtain the manager reference. Will keep trying!" sleep(3) g = Container(argv[1]) if argv.count("-interactive")==0 and argv.count("-i")==0: g.run() else: import atexit atexit.register(g.destroyCORBA) print "This container is now running in interactive mode." #------------------------------------------------------------------------------
def get_containers_info(self): h = 0x05000000 tmp = getManager().get_container_info(h, [], "*") return tmp
def getComponent(self, comp_name=None, activate=CORBA.TRUE, comp_idl_type=None, comp_code=None, container_name=None, is_dynamic=0): ''' NOTE: all keyword parameters with the exception of comp_name are deprecated! Get a component reference from the Manager. This seemingly simple method is actually quite complicated. First, its important to note that this method narrows the reference for the developer and even imports the proper IDL Python stub. Under certain circumstances though, the IDL Python stub may NOT exist in the correct place which has led some developers to believe this method was broken in the past. So if you see an error message beginning with "Unable to import...", please check that you really CAN import the CORBA stubs for the component you are trying to access using the infamous "python -i" command. The next important thing to realize is this method does not just retrieve named components as its own name implies - based on the parameters passed it could return default and dynamic components also. Parameters: - name is the components name. If not None and the rest of the default parameters are left as-is, this is assumed to be a static component. - activate tells manager whether the component should be activated if it has not already been instantiated. Not too useful. - comp_idl_type is the interface repository IDL location of the component. If not None and the rest of the default parameters are left as-is, it is assumed the developer wants a default component. - comp_code is a shared library implementing component. If not None, it is assumed the developer wants a dynamic component. - container_name is the name of the container to activate component. If not None, it is assumed the developer wants a dynamic component. - is_dynamic states whether a component should be retrieved as default or dynamic. In simple terms, when this parameter and comp_idl_type are the only params that have been changed from their original values, this is the difference between retrieving a reference to a dynamic component or a default component. Returns: a narrowed reference to the component or None if that reference cannot be obtained. Raises: CannotGetComponentExImpl if the component stubs cannot be loaded or found ''' #if the user is trying to get a "normal" static component if (comp_name is not None) and (comp_idl_type is None) and \ (comp_code is None) and (container_name is None) and \ (is_dynamic == 0): #Import the correct Python CORBA stub for the developer. comp_class = self.__importComponentStubs(comp_name, comp_idl_type) #get the component from manager corba_obj = getManager().get_component(self.__handle, comp_name, activate) #return the narrowed reference component = self.__narrowComponentReference(corba_obj, comp_class) #if the user is trying to get a static default component elif (comp_idl_type is not None) and (comp_name is None) and \ (comp_code is None) and (container_name is None) and \ (is_dynamic == 0): component = self.getDefaultComponent(str(comp_idl_type)) #user must be trying to get a dynamic component else: component = self.getDynamicComponent(comp_name, comp_idl_type, comp_code, container_name) try: component.find_characteristic('foo') except CORBA.Exception, ex: component.find_characteristic('foo')