示例#1
0
    def handle_push_notification(self, namespace, payload, from_myself=False):
        # Handle the ONLINE push notification
        # Leave the rest to the specific implementation
        if namespace == ONLINE:
            old_online_status = self.online
            status = payload['online']['status']
            if status == 2:
                with self._state_lock:
                    self.online = False
            elif status == 1:
                with self._state_lock:
                    self.online = True
            else:
                l.error(
                    "Unknown online status has been reported from the device: %d"
                    % status)

            # If the online status changed, fire the corresponding event
            if old_online_status != self.online:
                evt = DeviceOnlineStatusEvent(self, self.online)
                self.fire_event(evt)
        else:
            self._handle_push_notification(namespace,
                                           payload,
                                           from_myself=from_myself)
示例#2
0
 def unregister_event_callback(self, callback):
     with self.__event_handlers_lock:
         if callback in self.__event_handlers:
             self.__event_handlers.remove(callback)
         else:
             l.debug("The callback you tried to unregister is not present.")
             pass
示例#3
0
 def register_event_callback(self, callback):
     with self.__event_handlers_lock:
         if callback not in self.__event_handlers:
             self.__event_handlers.append(callback)
         else:
             l.debug("The callback you tried to register is already present.")
             pass
示例#4
0
    def handle_push_notification(self, namespace, payload, from_myself=False):
        # Handle the ONLINE push notification
        # Leave the rest to the specific implementation
        if namespace == ONLINE:
            old_online_status = self.online
            status = int(payload['online']['status'])
            if status == 2:
                with self._state_lock:
                    self.online = False
            elif status == 1:
                with self._state_lock:
                    self.online = True
            else:
                l.error(
                    "Unknown online status has been reported from the device: %d"
                    % status)

            # If the online status changed, fire the corresponding event
            if old_online_status != self.online:
                evt = DeviceOnlineStatusEvent(self, self.online)
                self.fire_event(evt)
        elif namespace == BIND:
            data = payload['bind']
            evt = DeviceBindEvent(device=self, bind_data=data)
            self.fire_event(evt)
        elif namespace == UNBIND:
            # Let everybody know we are going down before doing anything
            evt = DeviceUnbindEvent(device=self)
            self.fire_event(evt)
            # Let's handle stat clearing and resource release
            self._handle_unbound()
        else:
            self._handle_push_notification(namespace,
                                           payload,
                                           from_myself=from_myself)
示例#5
0
 def fire_event(self, eventobj):
     for c in self.__event_handlers:
         try:
             c(eventobj)
         except:
             l.exception(
                 "Unhandled error occurred while executing the registered event-callback"
             )
示例#6
0
 def get_wifi_list(self):
     if WIFI_LIST in self.get_abilities():
         return self.execute_command("GET",
                                     WIFI_LIST, {},
                                     timeout=LONG_TIMEOUT)
     else:
         l.error("This device does not support the WIFI_LIST ability")
         return None
示例#7
0
 def get_debug(self):
     if DEBUG in self.get_abilities():
         return self.execute_command("GET", DEBUG, {})
     else:
         l.error("This device does not support the DEBUG ability")
         return None
示例#8
0
 def get_trace(self):
     if TRACE in self.get_abilities():
         return self.execute_command("GET", TRACE, {})
     else:
         l.error("This device does not support the TRACE ability")
         return None