Example #1
0
    def __init__(self, profile, spd, scd, prf, instanceName, refid, impl=None, idmListener=None):
        DomainComponent.__init__(self, profile, spd, scd, prf, instanceName, refid, impl)

        # NB: The model.Device class is not directly in the hierarchy, but any
        # concrete subclass should inherit from Device or one of its subclasses.
        model.Device._buildAPI(self)

        self.__adminState = CorbaAttribute(WeakBoundMethod(self._get_adminState),
                                           WeakBoundMethod(self._set_adminState))
        self.__adminState.changed.addListener(WeakBoundMethod(self.adminStateChanged))

        self.__operationalState = CorbaAttribute(WeakBoundMethod(self._get_operationalState))
        self.__operationalState.changed.addListener(WeakBoundMethod(self.operationalStateChanged))

        self.__usageState = CorbaAttribute(WeakBoundMethod(self._get_usageState))
        self.__usageState.changed.addListener(WeakBoundMethod(self.usageStateChanged))

        self.__idmListener = idmListener

        # If the domain IDM channel is available, listen for state changes.
        if self.__idmListener:
            # Only receive notifications for this device by filtering based on
            # the identifier.
            identifier = self._get_identifier()
            def matcher(deviceId, stateChangeFrom, stateChangeTo):
                return deviceId == identifier

            self.__idmListener.administrativeStateChanged.addListener(WeakBoundMethod(self.__adminStateChangeEvent), matcher)
            self.__idmListener.operationalStateChanged.addListener(WeakBoundMethod(self.__operationalStateChangeEvent), matcher)
            self.__idmListener.usageStateChanged.addListener(WeakBoundMethod(self.__usageStateChangeEvent), matcher)
Example #2
0
class DomainDevice(DomainComponent):
    @notification
    def adminStateChanged(self, oldState, newState):
        """
        The administrative state of this device changed from 'oldState' to
        'newState'.
        """
        pass

    @notification
    def usageStateChanged(self, oldState, newState):
        """
        The usage state of this device changed from 'oldState' to 'newState'.
        """
        pass

    @notification
    def operationalStateChanged(self, oldState, newState):
        """
        The operational state of this device changed from 'oldState' to
        'newState'.
        """
        pass

    @property
    def device_ref(self):
        warnings.warn('Device.device_ref is deprecated. Device reference is automatically typed.')
        return self.ref

    @property
    def loadabledevice_ref(self):
        warnings.warn('Device.loadabledevice_ref is deprecated. Device reference is automatically typed.')
        return self.ref._narrow(CF.LoadableDevice)

    @property
    def executabledevice_ref(self):
        warnings.warn('Device.loadabledevice_ref is deprecated. Device reference is automatically typed.')
        return self.ref._narrow(CF.ExecutableDevice)

    @property
    def aggregatedevice_ref(self):
        warnings.warn('Device.aggregatedevice_ref is deprecated. Device reference is automatically typed.')
        return self.ref._narrow(CF.AggregateDevice)

    def __init__(self, profile, spd, scd, prf, instanceName, refid, impl=None, idmListener=None):
        DomainComponent.__init__(self, profile, spd, scd, prf, instanceName, refid, impl)

        # NB: The model.Device class is not directly in the hierarchy, but any
        # concrete subclass should inherit from Device or one of its subclasses.
        model.Device._buildAPI(self)

        self.__adminState = CorbaAttribute(WeakBoundMethod(self._get_adminState),
                                           WeakBoundMethod(self._set_adminState))
        self.__adminState.changed.addListener(WeakBoundMethod(self.adminStateChanged))

        self.__operationalState = CorbaAttribute(WeakBoundMethod(self._get_operationalState))
        self.__operationalState.changed.addListener(WeakBoundMethod(self.operationalStateChanged))

        self.__usageState = CorbaAttribute(WeakBoundMethod(self._get_usageState))
        self.__usageState.changed.addListener(WeakBoundMethod(self.usageStateChanged))

        self.__idmListener = idmListener

        # If the domain IDM channel is available, listen for state changes.
        if self.__idmListener:
            # Only receive notifications for this device by filtering based on
            # the identifier.
            identifier = self._get_identifier()
            def matcher(deviceId, stateChangeFrom, stateChangeTo):
                return deviceId == identifier

            self.__idmListener.administrativeStateChanged.addListener(WeakBoundMethod(self.__adminStateChangeEvent), matcher)
            self.__idmListener.operationalStateChanged.addListener(WeakBoundMethod(self.__operationalStateChangeEvent), matcher)
            self.__idmListener.usageStateChanged.addListener(WeakBoundMethod(self.__usageStateChangeEvent), matcher)

    def updateReferences(self):
        warnings.warn('Device.updateReferences() is deprecated. Device references are handled automatically')

    def __get_adminState(self):
        """
        The administrative state of this device.
        """
        return self.__adminState.value

    def __set_adminState(self, state):
        self.__adminState.value = state

    adminState = property(__get_adminState, __set_adminState)

    @property
    def usageState(self):
        """
        The usage state of this device.
        """
        return self.__usageState.value

    @property
    def operationalState(self):
        """
        The operational state of this device.
        """
        return self.__operationalState.value

    def __adminStateChangeEvent(self, deviceId, stateChangeFrom, stateChangeTo):
        self.__adminState.update(stateChangeTo)

    def __operationalStateChangeEvent(self, deviceId, stateChangeFrom, stateChangeTo):
        self.__operationalState.update(stateChangeTo)

    def __usageStateChangeEvent(self, deviceId, stateChangeFrom, stateChangeTo):
        self.__usageState.update(stateChangeTo)

    def api(self):
        super(DomainDevice,self).api()
        print
        model.Device.api(self)