def _cov_check(self, new_value): if new_value != self._old_value: cov = ChangeOfValueEvent(self, self._old_value, new_value, time.time()) self._old_value = new_value self.event_generate(cov) #trigger the event using the Mixin class. return
def __init__(self): self._running = 0 self.driver = None self.mac_address = None self.discovery_mode = 'None' CompositeNode.__init__(self) AutoDiscoveredNode.__init__(self) EventProducerMixin.__init__(self) self.device_map = {} #keyed by mac address of clients; value=Child node self._out_q = [] #request queue self._out_q_cv = threading.Condition() self._mutex = threading.Lock() #prevent multiple access to outbound commands self._registered_clients = {} self.transceiver_state = TransceiverState[0] self.cov = ChangeOfValueEvent(self, None, self.transceiver_state) self.debug = debug self.timeout = 10 #seconds self.who_is_interval = 10 #seconds self.default_discovered_protocol_module = None # @todo # initailize this through configuration self.default_discovered_protocol_module = feu self.transceiver_state = 0 self.relay_node = '/interfaces/relay1' #this is temporary, should be None self.active_devices = {} self.status = None
def _trigger_cov(self): try: v = self.get() except: v = ETimeout() cov = ChangeOfValueEvent(self, self._last_value, v, time.time()) self.event_generate(cov) self._last_value = v
def event_subscribe(self, *args): EventProducerMixin.event_subscribe(self, *args) self.old_value = self.get() # generate initial event self.event_generate( ChangeOfValueEvent(self, self.old_value, self.old_value, time.time())) self.cache.add_callback((self.group_id, self.addr), self._trigger_cov)
def prune(self, force=False): CompositeNode.prune(self, force) new_value = ENoSuchNode(self._pruned_url) self._value = new_value cov = ChangeOfValueEvent(self, self._old_value, new_value, time.time()) self._old_value = new_value self.event_generate(cov) return
def event_subscribe(self, *args): EventProducerMixin.event_subscribe(self, *args) try: self._last_value = self.get() except: self._last_value = None # generate initial event self.event_generate(ChangeOfValueEvent(self, self._last_value, self._last_value, time.time()))
def trigger_cov(self): if not self.event_class_consumer_count: return v = self.get() if v != self._last_value: cov = ChangeOfValueEvent(self, self._last_value, v, time.time()) self.event_generate(cov) self.old_value = v return
def update(self, data): self.__cv.acquire() try: self._old_value = self._value self._value = data.get('relayState1') self._last_update = uptime.secs() self.__cv.notifyAll() self.event_generate(ChangeOfValueEvent(self, self._old_value, self._value, time.time())) finally: self.__cv.release()
def _set(self, value): self._value_lock.acquire() self._value_condition.acquire() try: old = self.__value self.__value = value self._value_condition.notifyAll() finally: self._value_lock.release() self._value_condition.release() if old != value: self.event_generate(ChangeOfValueEvent(self, old, value))
def _cov_event_callback(self, point_data_object): try: new_value = { 'value': point_data_object.value, 'status': point_data_object.state & 1 } cov = ChangeOfValueEvent(self, self._old_value, new_value, time.time()) self._old_value = new_value self.event_generate(cov) # - trigger the event. This is on # the line handler thread. except: msglog.exception() return
def _cov_event_callback(self, point_data_object): try: new_value = point_data_object.value self._value = new_value self._state = point_data_object.state cov = ChangeOfValueEvent(self, self._old_value, new_value, time.time()) self._old_value = new_value self.event_generate(cov) # - trigger the event. This is on the # line handler thread. if self.__status: # Update the _status child handle value too: self.__status._cov_event_callback(point_data_object) except: msglog.exception() return
def __init__(self, mac_address=None): self.running = 0 self._children_have_been_discovered = 0 Port.__init__(self) AutoDiscoveredNode.__init__(self) EventProducerMixin.__init__(self) if mac_address: self.mac_address = mac_address else: self.mac_address = REQUIRED self.in_range = None self.debug = debug self.transceiver_state = TransceiverState[0] self.cov = ChangeOfValueEvent(self, None, self.transceiver_state) self.from_discovery = 0 # 1: remote xcvr assoc'd with this node was discovered by Aerocomm Protocol code self.from_config = 0 # 1: remote xcvr assocd with this node was specified in config recvd from Client App
def update_cache(self): self.updated(True) fwstatus = self.fw_node.get() netstatus = int(bool(self.net_node.get())) value = {"net": netstatus, "framework": fwstatus} if self._cached_result: previous = self._cached_result.value if value == previous: return changes = self._cached_result.changes + 1 else: changes = 1 previous = None self._cached_result = Result(value, self.refreshed(), 1, changes) event = ChangeOfValueEvent(self, previous, value, time.time()) self.event_generate(event) self.state_changed(True)
class GetViaCOV(EventConsumerAbstract): def __init__(self, source_node, timeout=960): EventConsumerAbstract.__init__(self) self.__node = as_internal_node(source_node) self.__cond = Condition() self.__event = None self.__sched = None #scheduled action to unsubscribe the point self.__timeout = timeout #number of seconds to maintain subscription self._event_received = False return def get_event(self, **keywords): if self.__node._pruned_url: try: self.__node = as_internal_node(self.__node._pruned_url) except ENoSuchName, e: raise ENoSuchNode(self.__node._pruned_url) self.__cond.acquire() try: if self.__event is None: self.__node.event_subscribe(self, ChangeOfValueEvent) #@todo add a way to get subscription started without blocking - ie return a value of None - based on keyword? do_not_wait = keywords.get('do_not_wait', None) if do_not_wait: #create a dummy event and put None in the value and return that self.__event = ChangeOfValueEvent(self.__node, None, None) else: self.__cond.wait() #block until the value shows up elif not self._event_received: #if event not nil and no event received it means 'do_not_wait' was used on first call do_not_wait = keywords.get('do_not_wait', None) if not do_not_wait: self.__cond.wait( ) #if do_not_wait was used on last call, now we wait for cov if self.__sched: sched = self.__sched.reset( ) #if it's too late to reschedule, this returns None if sched is None: #too late self.__sched.cancel() #try to cancel it self.__sched = sched if self.__sched is None: #first time or after expiration self.__sched = scheduler.after(self.__timeout, self.unsubscribe) return self.__event finally: self.__cond.release()
def event_subscribe(self, *args): result = EventProducerMixin.event_subscribe(self, *args) # @note: COV model REQUIRES generating an initial event. self.event_generate( ChangeOfValueEvent(self, self.get(), self.get(), time.time())) return result
def notify(self): value = self.get() if value != self.lastvalue: event = ChangeOfValueEvent(self, self.lastvalue, value) self.event_generate(event) self.lastvalue = value
def __dispatch_cov(self, last_result, result): cov = ChangeOfValueEvent(self, last_result, result, result.timestamp) return self.__dispatcher.dispatch(cov)
def event_subscribe(self, *args): super(LightPoint, self).event_subscribe(self, *args) self._old_value = self.get() # generate initial event self.event_generate(ChangeOfValueEvent(self, self._old_value, self._old_value, time.time()))
def _trigger_cov(self, old_value, new_value, t): cov = ChangeOfValueEvent(self, old_value, new_value, t) self.event_generate(cov) return
def _trigger_cov(self, old_value, new_value, timestamp=None): if not timestamp: timestamp = time.time() cov = ChangeOfValueEvent(self, old_value, new_value, timestamp) self.event_generate(cov)
def _trigger_cov(self, new_value, old_value): if new_value != old_value: # prevent needless events for unchanging value cov_event = ChangeOfValueEvent(self, old_value, \ new_value, time.time()) self.event_generate(cov_event)
def event_subscribe(self, *args): result = EventProducerMixin.event_subscribe(self, *args) event = ChangeOfValueEvent(self, self.get(), self.get(), time.time()) self.event_generate(event) return result
def _trigger_cov(self, old_value): cov = ChangeOfValueEvent(self, old_value, self._cached_result.value, time.time()) self.event_generate(cov)