Exemplo n.º 1
0
    def command_failed(self, command, reason):
        """
        This method is called when a client code throws an exception during
        a command processing.

        TODO: replace command dictionary with an object which implements
              ICommand interface.

        TODO: extract 'Success' and 'Failed' constants into common module.

        @param command: a dictionary which represents a command
        @param reason: an exception
        @return: None
        """
        LOG_ERR('Failed to process command "{0}". Reason: {1}.'.format(
            command, reason))
        if isinstance(reason, Exception):
            res = CommandResult('Failed', reason.message)
        elif hasattr(reason, 'value'):
            if isinstance(reason.value, CommandResult):
                res = CommandResult(reason.value.status, reason.value.result)
            elif isinstance(reason.value, Exception):
                res = CommandResult('Failed', reason.value.message)
            else:
                res = CommandResult('Failed', reason.value)
        else:
            res = CommandResult('Failed', 'Unhandled Exception')
        self.owner.send_report(command['id'], res)
Exemplo n.º 2
0
 def command_failed(self, command, reason):
     LOG_ERR('Failed to process command "{0}". Reason: {1}.'.format(
         command, reason))
     if isinstance(reason, Exception):
         res = CommandResult('Failed', reason.message)
     elif hasattr(reason, 'value'):
         if isinstance(reason.value, CommandResult):
             res = CommandResult(reason.value.status, reason.value.result)
         elif isinstance(reason.value, Exception):
             res = CommandResult('Failed', reason.value.message)
         else:
             res = CommandResult('Failed', reason.value)
     else:
         res = CommandRequest('Failed', 'Unhandled Exception')
     self.owner.send_report(command['id'], res)
Exemplo n.º 3
0
 def command_done(self, command, result):
     LOG_MSG(
         'The command "{0}" successfully processed. Result: {1}.'.format(
             command, result))
     if not isinstance(result, CommandResult):
         res = CommandResult('Success', result)
     else:
         res = result
     self.owner.send_report(command['id'], res)
Exemplo n.º 4
0
 def handle_notification_command_result(self, address, notification):
     """
     Run all callbacks attached to notification_received deferred.
     """
     log.msg('BinaryFactory.handle_notification_command_result')
     if address in self.hardware_address_map:
         device_id = self.hardware_address_map[address]
         if (device_id in self.pending_results) and (notification.command_id in self.pending_results[device_id]):
             deferred = self.pending_results[device_id].pop(notification.command_id)
             deferred.callback(CommandResult(notification.status, notification.result))
Exemplo n.º 5
0
    def command_done(self, command, result):
        """
        This method is called if client application successfully handled
        received command.
        If a command is handled then a notification will be send to the server.

        @param command: a dictionary which represents a received command
        @param result: a command object
        @return: None
        """
        LOG_MSG('The command "{0}" successfully processed. Result: {1}.'.format(command, result))
        if not isinstance(result, CommandResult):
            res = CommandResult('Success', result)
        else:
            res = result
        self.owner.send_report(command['id'], res)