def write(self, value):
        '''
        Overridden. 
        
        Calls the super implementation and sets the "current" readonly
        BACI double property to value.
        '''
        #call super
        DevIO.write(self, value)
        
        #get the REAL current property implementation if
        #write has not been called before
        if self.current_prop == None:
            #to access the readback property, it's necessary
            #to use this weird machination as the readbackObject
            #is a so-called private member of self.comp_ref
            self.current_prop = self.comp_ref.__dict__['__readbackObject']
            
        #now set the current's value
        self.current_prop.value.write(value)
        return
#-----------------------------------------------------------------------------
Exemple #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.
        '''
        TypelessProperty.__init__(self, name, charCompRef)
        self.monitors = []

        if devIORef == None:
            self.value = DevIO(self._get_default_value())
        else:
            self.value = devIORef
        return
 def __init__(self, comp_ref):
     '''
     Constructor
     
     Parameters:
         comp_ref - a reference to the component which is creating
         "us"
         
     Returns: Nothing
     
     Raises: Nothing
     '''
     #intialize the superclass providing a suitable default 
     #double value
     DevIO.__init__(self, 3.14)
     
     #save a copy of the component for later
     self.comp_ref = comp_ref
     
     #reference to the current property
     #no guarantee this has been created yet so we set it 
     #to None and get it on demand later
     self.current_prop = None
    def __init__(self, comp_ref):
        '''
        Constructor
        
        Parameters:
            comp_ref - a reference to the component which is creating
            "us"
            
        Returns: Nothing
        
        Raises: Nothing
        '''
        #intialize the superclass providing a suitable default
        #double value
        DevIO.__init__(self, 3.14)

        #save a copy of the component for later
        self.comp_ref = comp_ref

        #reference to the current property
        #no guarantee this has been created yet so we set it
        #to None and get it on demand later
        self.current_prop = None
    def write(self, value):
        '''
        Overridden. 
        
        Calls the super implementation and sets the "current" readonly
        BACI double property to value.
        '''
        #call super
        DevIO.write(self, value)

        #get the REAL current property implementation if
        #write has not been called before
        if self.current_prop == None:
            #to access the readback property, it's necessary
            #to use this weird machination as the readbackObject
            #is a so-called private member of self.comp_ref
            self.current_prop = self.comp_ref.__dict__['__readbackObject']

        #now set the current's value
        self.current_prop.value.write(value)
        return


#-----------------------------------------------------------------------------
Exemple #6
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.
        '''
        TypelessProperty.__init__(self, name, charCompRef)
        self.monitors=[]

        if devIORef==None:
            self.value = DevIO(self._get_default_value())
        else:
            self.value = devIORef
        return
 def __init__(self):
     DevIO.__init__(self, 3.14)
Exemple #8
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 #9
0
 def __init__(self, initVal=[ACS.SUBSYSSTATE_OFFLINE, ACS.SUBSYSSTATE_SHUTDOWN]):
     """
     """
     DevIO.__init__(self, initVal)
     return
Exemple #10
0
class GenericProperty(TypelessProperty):
    '''
    This intermediary class is used so certain methods in TypelessProperty-derived
    IDL interfaces do not have to be needlessly duplicated.
    '''

    #--------------------------------------------------------------------------
    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.
        '''
        TypelessProperty.__init__(self, name, charCompRef)
        self.monitors = []

        if devIORef == None:
            self.value = DevIO(self._get_default_value())
        else:
            self.value = devIORef
        return

    #--------------------------------------------------------------------------
    #--Helper methods to be overriden in subclasses----------------------------
    #--------------------------------------------------------------------------
    def coerceToPropertyType(self, value=None):
        '''
        This helper method MUST be overriden in subclasses. Basically it is used
        to coerce a stringified value of the property type to its correct type.
        
        '''
        del value  #to make pychecker happy
        self.getLogger().logCritical(
            "Looks like this method was never overriden in a subclass!")
        raise NO_IMPLEMENT()

    #--------------------------------------------------------------------------
    def getMonitorObject(self, scheduler, timeoutID):
        '''
        Helper method.
        '''
        del scheduler  #to make pychecker happy
        del timeoutID  #to make pychecker happy

        self.getLogger().logCritical(
            "Looks like this method was never overriden in a subclass!")
        raise NO_IMPLEMENT()

    #--------------------------------------------------------------------------
    #--From "P" properties-----------------------------------------------------
    #--------------------------------------------------------------------------
    def _get_default_timer_trigger(self):
        '''
        Implementation of the IDL attribute.

        readonly attribute TimeInterval default_timer_trigger;
        '''
        try:
            return long(
                float(self.getCDBDict()['default_timer_trig']) * 10000000.0)
        except:
            #warn them about CDB access
            self.getLogger().logInfo(
                "Some problem occurred when attempting to retrieve default timer trigger data from the ACS CDB"
            )
            print_exc()
            #return an acceptable default value instead... 0.1 seconds
            return 1000000L

    #--------------------------------------------------------------------------
    def _get_min_timer_trigger(self):
        '''
        Implementation of the IDL attribute.

        readonly attribute TimeInterval min_timer_trigger;
        '''
        try:
            return long(
                float(self.getCDBDict()['min_timer_trig']) * 10000000.0)
        except:
            #warn them about CDB access
            self.getLogger().logInfo(
                "Some problem occurred when attempting to retrieve minimum timer trigger data from the ACS CDB"
            )
            print_exc()
            #return an acceptable default value instead... 0.001 seconds
            return 10000L

    #--------------------------------------------------------------------------
    def _get_min_delta_trigger(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) min_delta_trigger;
        '''
        try:
            return self.coerceToPropertyType(
                str(self.getCDBDict()['min_delta_trig']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo(
                "Some problem occurred when attempting to retrieve data from the ACS CDB"
            )
            print_exc()
            #return an acceptable default value instead. It's up to the overriden
            #coerceToPropertyType method to decide what an acceptable default
            #value is!
            return self.coerceToPropertyType(str(0))

    #--------------------------------------------------------------------------
    def _get_default_value(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) default_value;
        '''
        try:
            return self.coerceToPropertyType(
                str(self.getCDBDict()['default_value']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo(
                "Some problem occurred when attempting to retrieve data from the ACS CDB"
            )
            print_exc()
            #return an acceptable default value instead. It's up to the overriden
            #coerceToPropertyType method to decide what an acceptable default
            #value is!
            return self.coerceToPropertyType(None)

    #--------------------------------------------------------------------------
    def _get_graph_min(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) graph_min;
        '''
        try:
            return self.coerceToPropertyType(
                str(self.getCDBDict()['graph_min']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo(
                "Some problem occurred when attempting to retrieve data from the ACS CDB"
            )
            print_exc()
            #return an acceptable default value instead.
            return self.coerceToPropertyType(str(0))

    #--------------------------------------------------------------------------
    def _get_graph_max(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) graph_max;
        '''
        try:
            return self.coerceToPropertyType(
                str(self.getCDBDict()['graph_max']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo(
                "Some problem occurred when attempting to retrieve data from the ACS CDB"
            )
            print_exc()
            #return an acceptable default value instead.
            return self.coerceToPropertyType(str(1000))

    #--------------------------------------------------------------------------
    def _get_min_step(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) min_step;
        '''
        try:
            return self.coerceToPropertyType(str(
                self.getCDBDict()['min_step']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo(
                "Some problem occurred when attempting to retrieve data from the ACS CDB"
            )
            print_exc()
            #return an acceptable default value instead. It's up to the overriden
            #coerceToPropertyType method to decide what an acceptable default
            #value is!
            return self.coerceToPropertyType(str(0))

    #--------------------------------------------------------------------------
    def get_sync(self):
        '''
        Implementation of the IDL method.

        stringSeq get_sync (out ACSErr::Completion c);
        '''
        try:
            #first just try to get the value from the DevIO...
            retVal = self.value.read()

            #in order to provide the same interface as the C++ DevIOs,
            #a Python DevIO is expected to pass back a list of value
            #and timestamp.  To preserve backward compatablity, if the
            #DevIO does not return a tuple, a timestamp will be generated
            #as before.
            if isinstance(retVal, tuple):
                ts = retVal[-1]
                retVal = retVal[0]
            else:
                ts = long(getTimeStamp().value)

            #succeeded! now just create a "no-error" completion
            compl = Completion(
                ts,  #unsigned long long timeStamp;
                0L,  #ACSErr::CompletionType type;
                0L,  #ACSErr::CompletionCode code;
                ())  #ErrorLinkedList  previousError;
        except Exception, e:
            self.getLogger().logAlert(
                "Some problem occurred when accessing the DevIO's read method")
            print_exc()
            #whoops...something failed. use the default value as a return
            #value instead. this is bad to do but get_sync does not throw
            #IDL exceptions!
            retVal = self._get_default_value()

            #let's see if it raised an ACS Error
            #System exception first...
            try:
                compl = CouldntAccessPropertyCompletionImpl(exception=e)
            except:
                #a native Python exception was raised...not much we can do
                #here
                compl = CouldntAccessPropertyCompletionImpl()

        return (retVal, compl)
Exemple #11
0
class GenericProperty(TypelessProperty):
    '''
    This intermediary class is used so certain methods in TypelessProperty-derived
    IDL interfaces do not have to be needlessly duplicated.
    '''
    #--------------------------------------------------------------------------
    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.
        '''
        TypelessProperty.__init__(self, name, charCompRef)
        self.monitors=[]

        if devIORef==None:
            self.value = DevIO(self._get_default_value())
        else:
            self.value = devIORef
        return
    #--------------------------------------------------------------------------
    #--Helper methods to be overriden in subclasses----------------------------
    #--------------------------------------------------------------------------
    def coerceToPropertyType(self, value=None):
        '''
        This helper method MUST be overriden in subclasses. Basically it is used
        to coerce a stringified value of the property type to its correct type.
        
        '''
        del value  #to make pychecker happy
        self.getLogger().logCritical("Looks like this method was never overriden in a subclass!")
        raise NO_IMPLEMENT()
    #--------------------------------------------------------------------------
    def getMonitorObject(self, scheduler, timeoutID):
        '''
        Helper method.
        '''
        del scheduler  #to make pychecker happy
        del timeoutID  #to make pychecker happy
        
        self.getLogger().logCritical("Looks like this method was never overriden in a subclass!")
        raise NO_IMPLEMENT()
    #--------------------------------------------------------------------------
    #--From "P" properties-----------------------------------------------------
    #--------------------------------------------------------------------------
    def _get_default_timer_trigger(self):
        '''
        Implementation of the IDL attribute.

        readonly attribute TimeInterval default_timer_trigger;
        '''
        try:
            return long(float(self.getCDBDict()['default_timer_trig']) * 10000000.0)
        except:
            #warn them about CDB access
            self.getLogger().logInfo("Some problem occurred when attempting to retrieve default timer trigger data from the ACS CDB")
            print_exc()
            #return an acceptable default value instead... 0.1 seconds
            return 1000000L
    #--------------------------------------------------------------------------
    def _get_min_timer_trigger(self):
        '''
        Implementation of the IDL attribute.

        readonly attribute TimeInterval min_timer_trigger;
        '''
        try:
            return long(float(self.getCDBDict()['min_timer_trig']) * 10000000.0)
        except:
            #warn them about CDB access
            self.getLogger().logInfo("Some problem occurred when attempting to retrieve minimum timer trigger data from the ACS CDB")
            print_exc()
            #return an acceptable default value instead... 0.001 seconds
            return 10000L
    #--------------------------------------------------------------------------
    def _get_min_delta_trigger(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) min_delta_trigger;
        '''
        try:
            return self.coerceToPropertyType(str(self.getCDBDict()['min_delta_trig']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo("Some problem occurred when attempting to retrieve data from the ACS CDB")
            print_exc()
            #return an acceptable default value instead. It's up to the overriden
            #coerceToPropertyType method to decide what an acceptable default
            #value is!
            return self.coerceToPropertyType(str(0))
    #--------------------------------------------------------------------------
    def _get_default_value(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) default_value;
        '''
        try:
            return self.coerceToPropertyType(str(self.getCDBDict()['default_value']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo("Some problem occurred when attempting to retrieve data from the ACS CDB")
            print_exc()
            #return an acceptable default value instead. It's up to the overriden
            #coerceToPropertyType method to decide what an acceptable default
            #value is!
            return self.coerceToPropertyType(None)
    #--------------------------------------------------------------------------
    def _get_graph_min(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) graph_min;
        '''
        try:
            return self.coerceToPropertyType(str(self.getCDBDict()['graph_min']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo("Some problem occurred when attempting to retrieve data from the ACS CDB")
            print_exc()
            #return an acceptable default value instead.
            return self.coerceToPropertyType(str(0))
    #--------------------------------------------------------------------------
    def _get_graph_max(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) graph_max;
        '''
        try:
            return self.coerceToPropertyType(str(self.getCDBDict()['graph_max']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo("Some problem occurred when attempting to retrieve data from the ACS CDB")
            print_exc()
            #return an acceptable default value instead.
            return self.coerceToPropertyType(str(1000))
    #--------------------------------------------------------------------------
    def _get_min_step(self):
        '''
        Implementation of the IDL attribute.
        
        readonly attribute (unknown type) min_step;
        '''
        try:
            return self.coerceToPropertyType(str(self.getCDBDict()['min_step']))
        except:
            #warn them about CDB access
            self.getLogger().logInfo("Some problem occurred when attempting to retrieve data from the ACS CDB")
            print_exc()
            #return an acceptable default value instead. It's up to the overriden
            #coerceToPropertyType method to decide what an acceptable default
            #value is!
            return self.coerceToPropertyType(str(0))
    #--------------------------------------------------------------------------
    def get_sync(self):
        '''
        Implementation of the IDL method.

        stringSeq get_sync (out ACSErr::Completion c);
        '''
        try:
            #first just try to get the value from the DevIO...
            retVal = self.value.read()

            #in order to provide the same interface as the C++ DevIOs,
            #a Python DevIO is expected to pass back a list of value
            #and timestamp.  To preserve backward compatablity, if the
            #DevIO does not return a tuple, a timestamp will be generated
            #as before.
            if isinstance(retVal,tuple):
                ts = retVal[-1]
                retVal = retVal[0]
            else:
                ts = long(getTimeStamp().value)

            #succeeded! now just create a "no-error" completion
            compl = Completion(ts,  #unsigned long long timeStamp;
                               0L,  #ACSErr::CompletionType type;
                               0L,  #ACSErr::CompletionCode code;
                               ())  #ErrorLinkedList  previousError;
        except Exception, e:
            self.getLogger().logAlert("Some problem occurred when accessing the DevIO's read method")
            print_exc()
            #whoops...something failed. use the default value as a return
            #value instead. this is bad to do but get_sync does not throw
            #IDL exceptions!
            retVal = self._get_default_value()

            #let's see if it raised an ACS Error
            #System exception first...
            try:
                compl = CouldntAccessPropertyCompletionImpl(exception=e)
            except:
                #a native Python exception was raised...not much we can do
                #here
                compl = CouldntAccessPropertyCompletionImpl()

                
        return (retVal, compl)
Exemple #12
0
 def __init__(self):
     DevIO.__init__(self, 0)
     return
Exemple #13
0
 def __init__(self, device):
     self.device = device
     DevIO.__init__(self, self.read())
Exemple #14
0
 def __init__(self, device):
     self.device = device
     DevIO.__init__(self, device.getPosition())
Exemple #15
0
 def __init__(self):
     DevIO.__init__(self, 0)
     return
 def __init__(self, device, value=0):
     DevIO.__init__(self, value)
Exemple #17
0
 def __init__(self,
              initVal=[ACS.SUBSYSSTATE_OFFLINE, ACS.SUBSYSSTATE_SHUTDOWN]):
     '''
     '''
     DevIO.__init__(self, initVal)
     return