Ejemplo n.º 1
0
    def __init__(self, name, charCompRef, devIORef):
        '''
        Constructor

        Params:
        - name is the quite literally the name of the property
        - charCompRef is the characteristic component object which contains this
        property
        - devIORef is a reference to a DevIO to be used with this property

        Returns: Nothing

        Raises: Nothing.
        '''
        #------------------------------------------------------------------------------
        #determine the real type of the BACI property using the IFR
        #First determine the property's name
        self.enumIFRName = None

        IR = interfaceRepository()
        interf = IR.lookup_id(self._NP_RepositoryId)

        #determine the underlying enumeration type
        for attr in interf._narrow(
                CORBA.InterfaceDef).describe_interface().attributes:
            #we can use the default_value to get at an instance of the real enumeration
            if attr.name == "default_value":
                #ifr name of the enum
                self.enumIFRName = attr.type.id()
                break

        #determine the IDL type
        self.enumName = self.enumIFRName.split(':')[1].split('/')[1:]
        self.modName = self.enumName[0]

        #convert the list to a stringified Python package structure which can
        #be used with eval
        self.enumName = reduce((lambda x, y: str(x) + '.' + str(y)),
                               self.enumName)

        #now comes the complicated part...importing the correct CORBA stub
        #without polluting the local namespace...
        self.tGlobals = {}
        self.tLocals = {}
        exec "import " + self.modName in self.tGlobals, self.tLocals

        GenericProperty.__init__(self, name, charCompRef, devIORef)

        return
Ejemplo n.º 2
0
    def __init__(self, name, charCompRef, devIORef):
        """
        Constructor

        Params:
        - name is the quite literally the name of the property
        - charCompRef is the characteristic component object which contains this
        property
        - devIORef is a reference to a DevIO to be used with this property

        Returns: Nothing

        Raises: Nothing.
        """
        # ------------------------------------------------------------------------------
        # determine the real type of the BACI property using the IFR
        # First determine the property's name
        self.enumIFRName = None

        IR = interfaceRepository()
        interf = IR.lookup_id(self._NP_RepositoryId)

        # determine the underlying enumeration type
        for attr in interf._narrow(CORBA.InterfaceDef).describe_interface().attributes:
            # we can use the default_value to get at an instance of the real enumeration
            if attr.name == "default_value":
                # ifr name of the enum
                self.enumIFRName = attr.type.id()
                break

        # determine the IDL type
        self.enumName = self.enumIFRName.split(":")[1].split("/")[1:]
        self.modName = self.enumName[0]

        # convert the list to a stringified Python package structure which can
        # be used with eval
        self.enumName = reduce((lambda x, y: str(x) + "." + str(y)), self.enumName)

        # now comes the complicated part...importing the correct CORBA stub
        # without polluting the local namespace...
        self.tGlobals = {}
        self.tLocals = {}
        exec "import " + self.modName in self.tGlobals, self.tLocals

        GenericProperty.__init__(self, name, charCompRef, devIORef)

        return
Ejemplo n.º 3
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
Ejemplo n.º 4
0
from Acspy.Util.ACSCorba  import interfaceRepository

from ACSImpl.Double       import ROdouble, RWdouble
from ACSImpl.DoubleSeq    import ROdoubleSeq, RWdoubleSeq
from ACSImpl.Long         import ROlong, RWlong
from ACSImpl.LongSeq      import ROlongSeq, RWlongSeq
from ACSImpl.LongLong     import ROlongLong, RWlongLong
from ACSImpl.ULongLong    import ROuLongLong, RWuLongLong
from ACSImpl.Pattern      import ROpattern, RWpattern
from ACSImpl.String       import ROstring, RWstring
from ACSImpl.StringSeq    import ROstringSeq
from ACSImpl.Enum         import getEnumClass
from Acssim.Float import ROfloat, RWfloat
from Acssim.FloatSeq import ROfloatSeq, RWfloatSeq
#--GLOBALS---------------------------------------------------------------------
IFR = interfaceRepository()

#a dictionary mapping IFR IDs to interface descriptions. this is in place to
#save time (IFR operations are slow)
INTERFACE_DICT = {}
#------------------------------------------------------------------------------
def addProperty(comp_ref,
                prop_name,
                devio_ref=None,
                cdb_location=None,
                prop_type=""):
    '''
    This function automatically adds a BACI property implementation to a
    component and it is designed to be used from the initialize lifecyle
    method of components. If the IFR is not working correctly, this function 
    will NOT work at all as it is dependent upon the IFR to obtain the 
Ejemplo n.º 5
0
    def __init__(self, ir_id=None):
        '''
        Standard constructor dynamically changes this objects inheritance.
        Also implements all IDL methods/attributes on the fly which just pass
        the call to the invoke method (which should be overriden in subclasses!!!).

        Parameters:
        - irLoc is the interface repository ID of the IDL interface we want to
        inherit from.  If this is None, it is assumed _get_interface() has
        been defined in a subclass (as-per the CORBA specs).

        Returns: Nothing

        Raises: ???
        '''
        #set member variables
        if ir_id == None:
            #assume the _get_interface method is implemented in a subclass...
            self.__ir_id = self._get_interface()
            self.__ir_id = self.__ir_id._narrow(CORBA.InterfaceDef)
            self.__ir_id = self.__ir_id._get_id()
        else:
            self.__ir_id = ir_id

        self.__real_mod = None
        self.__real_class = None

        #create the POA class first...
        classname = self.__ir_id.split(':')[1].split(
            '/').pop()  #get interface name
        self.__real_mod = self.__ir_id.split(':')[1].split(
            '/'
        )[1] + "__POA"  #"IDL:alma/acspytest/PyTest:1.0" becomes "acspytest__POA"
        self.__real_mod = __import__(self.__real_mod, globals(), locals(),
                                     [classname])  #get module
        self.__real_class = self.__real_mod.__dict__.get(classname)  #get class
        if self.__real_class is None:
            reload(self.__real_mod)
            self.__real_class = self.__real_mod.__dict__.get(
                classname)  #get class

        #copy it's class locally thereby converting DynamicImplementation
        #into the POA object!
        self.__dict__ = _mergeClasses(self.__dict__, self.__real_class)
        """
        temp_list = list(self.__class__.__bases__)
        try:
            #OK for subclasses...
            temp_list.insert(temp_list.index(DynamicImplementation), self.__real_class)
        except:
            #should really never be the case...
            temp_list.insert(0, self.__real_class)
        self.__class__.__bases__ = tuple(temp_list)
	"""

        #now that all the underlying infrastructure is in place, we can finally use
        #CORBA introspection to start adding methods!
        #get the interface repository.
        ifr = interfaceRepository()

        #assume this can be found in a subclass as well.
        self.__interf = ifr.lookup_id(self._NP_RepositoryId)
        if self.__interf is None:
            print "Failed to find interface", self._NP_RepositoryId
        self.__interf = self.__interf._narrow(CORBA.InterfaceDef)
        self.__interf = self.__interf.describe_interface()

        #add methods
        for method in self.__interf.operations:
            _createMethodImplementation(self, method.name)

        #add attributes
        for attribute in self.__interf.attributes:
            #read-only and read-write attributes need the _get_ method...
            _createMethodImplementation(self, "_get_" + attribute.name)
            #but only normal attributes have the _set_ method defined
            if attribute.mode == CORBA.ATTR_NORMAL:
                _createMethodImplementation(self, "_set_" + attribute.name)
Ejemplo n.º 6
0
    def __init__(self, ir_id=None):
        '''
        Standard constructor dynamically changes this objects inheritance.
        Also implements all IDL methods/attributes on the fly which just pass
        the call to the invoke method (which should be overriden in subclasses!!!).

        Parameters:
        - irLoc is the interface repository ID of the IDL interface we want to
        inherit from.  If this is None, it is assumed _get_interface() has
        been defined in a subclass (as-per the CORBA specs).

        Returns: Nothing

        Raises: ???
        '''
        #set member variables
        if ir_id == None:
            #assume the _get_interface method is implemented in a subclass...
            self.__ir_id = self._get_interface()
            self.__ir_id = self.__ir_id._narrow(CORBA.InterfaceDef)
            self.__ir_id = self.__ir_id._get_id()
        else:
            self.__ir_id = ir_id
            
        self.__real_mod = None
        self.__real_class = None
        
        #create the POA class first...
        classname =  self.__ir_id.split(':')[1].split('/').pop()  #get interface name
        self.__real_mod = self.__ir_id.split(':')[1].split('/')[1] + "__POA"  #"IDL:alma/acspytest/PyTest:1.0" becomes "acspytest__POA"
        self.__real_mod = __import__(self.__real_mod, globals(), locals(), [classname]) #get module
        self.__real_class = self.__real_mod.__dict__.get(classname) #get class
        if self.__real_class is None:
            reload(self.__real_mod)
            self.__real_class = self.__real_mod.__dict__.get(classname) #get class

        #copy it's class locally thereby converting DynamicImplementation
        #into the POA object!
        self.__dict__ = _mergeClasses(self.__dict__, self.__real_class)
        
        temp_list = list(self.__class__.__bases__)
        try:
            #OK for subclasses...
            temp_list.insert(temp_list.index(DynamicImplementation), self.__real_class)
        except:
            #should really never be the case...
            temp_list.insert(0, self.__real_class)
        self.__class__.__bases__ = tuple(temp_list)
        
        #now that all the underlying infrastructure is in place, we can finally use
        #CORBA introspection to start adding methods!
        #get the interface repository.       
        ifr = interfaceRepository()
                                   
        #assume this can be found in a subclass as well.
        self.__interf = ifr.lookup_id(self._NP_RepositoryId)
        if self.__interf is None:
            print "Failed to find interface", self._NP_RepositoryId
        self.__interf = self.__interf._narrow(CORBA.InterfaceDef)
        self.__interf = self.__interf.describe_interface()

        #add methods 
        for method in self.__interf.operations:
            _createMethodImplementation(self, method.name)

        #add attributes
        for attribute in self.__interf.attributes:
            #read-only and read-write attributes need the _get_ method...
            _createMethodImplementation(self, "_get_" + attribute.name)
            #but only normal attributes have the _set_ method defined
            if attribute.mode == CORBA.ATTR_NORMAL:
                _createMethodImplementation(self, "_set_" + attribute.name)