Exemple #1
0
def getCompLocalNS(comp_name):
    '''
    Gets the local namespace dictionary for a component.
    
    Parameters:
    	comp_name - name of the component
    
    Returns: A dictionary conforming to the return value of the native 
    "locals()" function.
    
    Raises: Nothing
    '''
    #sanity check
    if COMPONENTS_NS.has_key(comp_name) == 0:

        #initialize the temporary local namespace to be empty (in case
        #of some failure with the CDB)
        t_dict = {}
        comp_cdb_list = [comp_name]

        COMPONENTS_NS_LIST[comp_name] = []

        #because we must check the inherited IDL interfaces as well
        cdb_location = "interfaces/"
        try:
            comp_ifr_id = getCompIfrID(comp_name)
        except:
            comp_ifr_id = "IDL:alma/ACS/ACSComponent:1.0"

        comp_cdb_list.append(cdb_location +
                             comp_ifr_id.split('IDL:')[1].replace(":", "/"))

        comp_ifr_ids = getSuperIDs(comp_ifr_id)
        for temp_id in comp_ifr_ids:

            temp_id = temp_id.split('IDL:')[1].replace(":", "/")
            temp_id = cdb_location + temp_id
            comp_cdb_list.append(temp_id)

        for name in comp_cdb_list:
            #-------------------------------
            #get the CDB helper object
            xml_obj = getComponentXMLObj(name)

            if xml_obj != None:
                try:  #use a try here because pythonImports section is not required
                    #get the imports
                    dom = xml_obj.SimulatedComponent.pythonImports
                    py_imports = dom.getValue().rstrip().lstrip().split('\n')

                    COMPONENTS_NS_LIST[
                        comp_name] = COMPONENTS_NS_LIST[comp_name] + py_imports

                    #populate the locals dictionary
                    for py_import in py_imports:
                        exec py_import in globals(), t_dict
                except:
                    pass
            #-------------------------------
        COMPONENTS_NS[comp_name] = t_dict

    return COMPONENTS_NS[comp_name]
Exemple #2
0
    def __setupSpecialCases(self):
        '''
        Helper method designed to handle special cases that we do not necessarily
        want being 100% simulated like BACI properties, callbacks, etc.
        '''
        #look in the CDB for instructions on how to setup the special cases. This
        #is mainly used to see if the end-user has specified some devIO class to
        #be used with a BACI property.
        if_list = getSuperIDs(self.ir)
        if_list.append(self.ir)
        simCDB = getSimProxy(self._get_name(), self.ir).cdb_handler
        simServer = getSimProxy(self._get_name(), self.ir).server_handler

        #IFR
        ir = interfaceRepository()

        #_executeXyz methods need an argument list
        args = [self]

        #get an interface description for this component
        interf = ir.lookup_id(self._NP_RepositoryId)
        interf = interf._narrow(CORBA.InterfaceDef)
        interf = interf.describe_interface()

        #use the IFR descrip to go searching for BACI properties
        for attribute in interf.attributes:
            
            #if the typecode is NOT an object reference it cannot be a BACI property.
            #that implies it's OK to skip
            if not isinstance(attribute.type, omniORB.tcInternal.TypeCode_objref):
                continue

            #save the short version of the attribute's ID (i.e., ROdouble)
            tempType = attribute.type.id().split(":")[1].split("/").pop()

            #sequence BACI property
            if (tempType=="ROstringSeq")or(tempType=="ROdoubleSeq")or(tempType=="RWdoubleSeq")or(tempType=="ROlongSeq")or(tempType=="RWlongSeq")or(tempType=="ROfloatSeq")or(tempType=="RWfloatSeq"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO([])                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            #double BACI property
            elif (tempType=="ROdouble")or(tempType=="RWdouble"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)

                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO(float(0))                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            #float BACI property
            elif (tempType=="ROfloat")or(tempType=="RWfloat"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)

                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO(float(0))                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue


            #long BACI property
            elif (tempType=="ROlong")or(tempType=="RWlong"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO(0)                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            #long (Python long also) BACI property
            elif (tempType=="ROpattern")or(tempType=="RWpattern")or(tempType=="ROlongLong")or(tempType=="RWlongLong")or(tempType=="ROuLongLong")or(tempType=="ROuLongLong"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO(0L)                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            #string BACI property
            elif (tempType=="ROstring")or(tempType=="RWstring"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO("")                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            else:
                
                ifrName = attribute.type.id()
                
                try:
                    #get an interface description for this property
                    tIfr = ir.lookup_id(ifrName)
                    tIfr = tIfr._narrow(CORBA.InterfaceDef)
                    tIfr = tIfr.describe_interface()

                    for tAttr in tIfr.attributes:
                        #check if it's a default_value AND an enum!
                        if (tAttr.name=="default_value") and (tAttr.type.kind()==CORBA.tk_enum):
                            #GREAT! It's completely safe to add!
                            attrDict = simServer.getMethod(attribute.name)
                            if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                            if  attrDict!= None:
                                devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                            else:
                                devio = DevIO(getRandomEnum(tAttr.type))
                            addProperty(self, attribute.name, devio_ref=devio)
                                              
                            break

                except:
                    print_exc()
                    continue
Exemple #3
0
def getCompLocalNS(comp_name):
    '''
    Gets the local namespace dictionary for a component.
    
    Parameters:
    	comp_name - name of the component
    
    Returns: A dictionary conforming to the return value of the native 
    "locals()" function.
    
    Raises: Nothing
    '''
    #sanity check
    if COMPONENTS_NS.has_key(comp_name)==0:
        
        #initialize the temporary local namespace to be empty (in case
        #of some failure with the CDB)
        t_dict = {}
        comp_cdb_list = [comp_name]

        COMPONENTS_NS_LIST[comp_name] = []
        
        #because we must check the inherited IDL interfaces as well
        cdb_location = "interfaces/"
        try:
            comp_ifr_id = getCompIfrID(comp_name)
        except:
            comp_ifr_id = "IDL:alma/ACS/ACSComponent:1.0"
        
        comp_cdb_list.append(cdb_location + 
                             comp_ifr_id.split('IDL:')[1].replace(":", "/"))
        
        comp_ifr_ids = getSuperIDs(comp_ifr_id)
        for temp_id in comp_ifr_ids:
            
            temp_id = temp_id.split('IDL:')[1].replace(":", "/")
            temp_id = cdb_location + temp_id
            comp_cdb_list.append(temp_id)
        
        for name in comp_cdb_list:
            #-------------------------------
            #get the CDB helper object
            xml_obj = getComponentXMLObj(name)
            
            if xml_obj!=None:
                try: #use a try here because pythonImports section is not required
                    #get the imports
                    dom = xml_obj.SimulatedComponent.pythonImports
                    py_imports = dom.getValue().rstrip().lstrip().split('\n')

                    COMPONENTS_NS_LIST[comp_name] = COMPONENTS_NS_LIST[comp_name] + py_imports

                    #populate the locals dictionary
                    for py_import in py_imports:
                        exec py_import in globals(), t_dict
                except:
                    pass
            #-------------------------------
        COMPONENTS_NS[comp_name] = t_dict
        
        
    return COMPONENTS_NS[comp_name]