Пример #1
0
        /*
        def register_events_callback(self, event_type, callback):
        """
        Register a callback.

        :param DfuEvent callback:
        :return: None
        """
        if event_type not in self.callbacks:
            self.callbacks[event_type] = []

        self.callbacks[event_type].append(callback)
        */
        /*
        def unregister_events_callback(self, callback):
        """
        Unregister a callback.

        :param callback: # TODO: add documentation for callback
        :return: None
        """
        for event_type in self.callbacks.keys():
            if callback in self.callbacks[event_type]:
                self.callbacks[event_type].remove(callback)
        */
        /*
        def _send_event(self, event_type, **kwargs):
        """
        Method for sending events to registered callbacks.

        If callbacks throws exceptions event propagation will stop and this method be part of the track trace.

        :param DfuEvent event_type:
        :param args: Arguments to callback function
        :return:
        """
        if event_type in self.callbacks.keys():
            for callback in self.callbacks[event_type]:
                callback(**kwargs)
        */
        public void _send_event(DfuEvent event_type, int progress, bool done, String log_message)
        {
            /*
            Method for sending events to registered callbacks.

            If callbacks throws exceptions event propagation will stop and this method be part of the track trace.

            :param DfuEvent event_type:
            :param args: Arguments to callback function
            :return:
            */

            if (event_type == DfuEvent.PROGRESS_EVENT)
            {
                logger.update_progress(progress, false, "");
            }
            if (event_type == DfuEvent.ERROR_EVENT)
            {
                logger.error(log_message);
            }
            if (event_type == DfuEvent.TIMEOUT_EVENT)
            {
                logger.error(log_message);
            }
            /* TODO put in dictionary !?!!!
            if( event_type in self.callbacks.keys() )
            {
                foreach( var callback in callbacks[event_type] )
                {
                    callback(**kwargs);
                }
            }
            */
        }
Пример #2
0
 public void register_events_callback(DfuEvent event_type, generic_event_handler_del callback)
 {
     if (event_type == DfuEvent.PROGRESS_EVENT)
     {
         this.callback_update_progress = callback;
     }
     if (event_type == DfuEvent.ERROR_EVENT)
     {
         this.callback_error_event = callback;
     }
     if (event_type == DfuEvent.TIMEOUT_EVENT)
     {
         this.callback_timeout_event = callback;
     }
 }