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)
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)