def consumer_set(self, sample):
        """
        Called from a channel wishing to write this property's data.

        If there is a device set callback defined, it is called.  If
        the callback is called it is the callback's responsiblity to
        set the data in the channel (by calling producer_set()).  If
        the device wishes to reject the value of the set, it must
        raise an exception.


        If no callback is defined, the value is simply set on the
        channel as long as it passes type checking.
        """
        if not self.perms_mask & DPROP_PERM_SET:
            raise DevicePropertyPermError, "set permission denied"

        sample = ChannelSource._type_remap_and_check(self, self.type, sample)

        self.__rlock.acquire()
        try:
            if self.device_set_cb is not None:
                # Exceptions are propagated upward:
                self.device_set_cb(sample)
            else:
                self.__sample = sample
        finally:
            self.__rlock.release()
    def consumer_set(self, sample):
        """
        Called from a channel wishing to write this property's data.

        If there is a device set callback defined, it is called.  If
        the callback is called it is the callback's responsiblity to
        set the data in the channel (by calling producer_set()).  If
        the device wishes to reject the value of the set, it must
        raise an exception.

        If no callback is defined, the value is simply set on the
        channel as long as it passes type checking.

        Return: Returns True if the set was performed by the
        channel_source rather than the driver and the Channel needs to
        generate an event.
        """
        if not self.perms_mask & DPROP_PERM_SET:
            raise DevicePropertyPermError, "set permission denied"

        sample = ChannelSource._type_remap_and_check(self, self.type, sample)
        retval = False

        self.__rlock.acquire()
        try:
            if self.device_set_cb is not None:
                # Exceptions are propagated upward:
                self.device_set_cb(sample)
            else:
                self.__sample = sample
                retval = True
        finally:
            self.__rlock.release()

        return retval
 def producer_set(self, sample):
     """\
     Update the current sample object.
     
     This function should only be called by a logging object.
     """
     self.type = ChannelSource._type_remap(self, type(sample.value))
     self.__sample = sample
 def producer_set(self, sample):
     """\
     Update the current sample object.
     
     This function should only be called by a logging object.
     """
     self.type = ChannelSource._type_remap(self, type(sample.value))
     self.__sample = sample
    def __init__(self,
                 name,
                 type,
                 initial=Sample(timestamp=0, value=0),
                 perms_mask=DPROP_PERM_NONE,
                 options=DPROP_OPT_NONE,
                 set_cb=lambda s: None,
                 refresh_cb=lambda: None):
        """
        Create a DevicePropertyItem.

        Keyword arguments:
        * **name:** the name of the device property
        * **type:** a type constructor to create the item from a string
        * **initial:** the initial Sample object used to populate the channel
        * **permissions:** a mask of permissions (constants DPROP_PERM_*)
        * **options:** a mask of options (constants DPROP_OPT_*)
        * **set_cb:** function called with sample argument for a set request
        * **refresh_cb:** function called when this property should be updated

        """

        if not isinstance(name, str):
            raise ValueError, "Channel name must be a string"
        if name.find('.') >= 0:
            raise ValueError("Channel name may not contain a dot (%s)" % name)
        if not callable(type):
            raise ValueError, "type must be callable"
        if not isinstance(initial, Sample):
            raise ValueError, "initial value must be Sample object instance"
        if not isinstance(initial.value, type):
            raise ValueError, \
                "(%s): cannot create, sample type/property type mis-match ('%s' != '%s')" % \
                    (name, repr(BUILTIN_TYPE(initial.value)), repr(type))
        if not isinstance(perms_mask, int) or perms_mask >= DPROP_PERM_MAX:
            raise ValueError, "invalid permissions mask"
        if not isinstance(options, int) or options >= DPROP_OPT_MAX:
            raise ValueError, "invalid options mask"
        if set_cb is not None and not callable(set_cb):
            raise ValueError, "set_cb must be callable"
        if not callable(refresh_cb):
            raise ValueError, "refresh_cb must be callable"

        # attributes of this property:
        self.name = name
        self.type = ChannelSource._type_remap(self, type)
        self.perms_mask = perms_mask
        self.options = options
        self.device_set_cb = set_cb
        self.device_refresh_cb = refresh_cb
        self.__rlock = threading.RLock()

        # the current sample for this channel:
        self.__sample = initial
    def __init__(self, initial=Sample(timestamp=0, value=0)):
        """\
        Create a ChannelSourceLogger; it implements the ChannelSource
        interface.
        """

        # channel meta-information
        self.type = ChannelSource._type_remap(self, type(initial.value))
        self.perms_mask = PERM_GET
        self.options = OPT_NONE

    	# the current sample for this channel:
    	self.__sample = initial
    def __init__(self, initial=Sample(timestamp=0, value=0)):
        """\
        Create a ChannelSourceLogger; it implements the ChannelSource
        interface.
        """

        # channel meta-information
        self.type = ChannelSource._type_remap(self, type(initial.value))
        self.perms_mask = PERM_GET
        self.options = OPT_NONE

        # the current sample for this channel:
        self.__sample = initial
 def producer_set(self, sample):
     """
     Update the current sample object.
     
     This function should only be called by a DeviceProperties object.
     """
     sample = ChannelSource._type_remap_and_check(self, self.type, sample)
     self.__rlock.acquire()
     try:
         if sample.timestamp == 0 and self.options & DPROP_OPT_AUTOTIMESTAMP:
             sample.timestamp = time.time()
         self.__sample = copy(sample)
     finally:
         self.__rlock.release()
    def __init__(self, name, type, initial=Sample(timestamp=0, value=0),
                    perms_mask=DPROP_PERM_NONE,
                    options=DPROP_OPT_NONE,
                    set_cb=lambda s: None, refresh_cb=lambda: None):
        """
        Create a DevicePropertyItem.

        Keyword arguments:
        * **name:** the name of the device property
        * **type:** a type constructor to create the item from a string
        * **initial:** the initial Sample object used to populate the channel
        * **permissions:** a mask of permissions (constants DPROP_PERM_*)
        * **options:** a mask of options (constants DPROP_OPT_*)
        * **set_cb:** function called with sample argument for a set request
        * **refresh_cb:** function called when this property should be updated

        """

        if not isinstance(name, str):
            raise ValueError, "Channel name must be a string"
        if name.find('.') >= 0:
            raise ValueError("Channel name may not contain a dot (%s)" % name)
        if not callable(type):
            raise ValueError, "type must be callable"
        if not isinstance(initial, Sample):
            raise ValueError, "initial value must be Sample object instance"
        if not isinstance(initial.value, type):
            raise ValueError, \
                "(%s): cannot create, sample type/property type mis-match ('%s' != '%s')" % \
                    (name, repr(BUILTIN_TYPE(initial.value)), repr(type))
        if not isinstance(perms_mask, int) or perms_mask >= DPROP_PERM_MAX:
            raise ValueError, "invalid permissions mask"
        if not isinstance(options, int) or options >= DPROP_OPT_MAX:
            raise ValueError, "invalid options mask"
        if set_cb is not None and not callable(set_cb):
            raise ValueError, "set_cb must be callable"
        if not callable(refresh_cb):
            raise ValueError, "refresh_cb must be callable"

        # attributes of this property:
        self.name = name
        self.type = ChannelSource._type_remap(self, type)
        self.perms_mask = perms_mask
        self.options = options
        self.device_set_cb = set_cb
        self.device_refresh_cb = refresh_cb
        self.__rlock = threading.RLock()

        # the current sample for this channel:
        self.__sample = initial
 def producer_set(self, sample):
     """
     Update the current sample object.
     
     This function should only be called by a DeviceProperties object.
     """
     sample = ChannelSource._type_remap_and_check(self, self.type, sample)
     self.__rlock.acquire()
     try:
         if sample.timestamp == 0 and self.options & DPROP_OPT_AUTOTIMESTAMP:
             sample.timestamp = digitime.time()
         self.__sample = copy(sample)
     finally:
         self.__rlock.release()