Esempio n. 1
0
def handle_session_signal(*args, **kwds):
    if kwds['interface'] == 'com.hplip.Toolbox' and \
        kwds['member'] == 'Event':

        event = device.Event(*args)
        event.debug()

        if event.event_code > EVENT_MAX_EVENT:
            event.event_code = status.MapPJLErrorCode(event.event_code)

        # regular user/device status event
        log.debug("Received event notifier: %d" % event.event_code)

        if not event.send_via_pipe(w, 'toolbox ui'):
            sys.exit(1)
Esempio n. 2
0
def handle_event(event, more_args=None):
    #global polling_blocked
    #global request_queue

    # checking if any zombie child process exists. then cleaning same.
    try:
        os.waitpid(0, os.WNOHANG)
    except OSError:
        pass

    log.debug("Handling event...")

    if more_args is None:
        more_args = []

    event.debug()

    if event.event_code == EVENT_AUTO_CONFIGURE:
        handle_plugin_install()
        return

    if event.event_code == EVENT_DIAGNOSE_PRINTQUEUE:
        handle_printer_diagnose()
        return

    if event.device_uri and check_device(event.device_uri) != ERROR_SUCCESS:
        return

    # If event-code > 10001, its a PJL error code, so convert it
    if event.event_code > EVENT_MAX_EVENT:
        event.event_code = status.MapPJLErrorCode(event.event_code)

    # regular user/device status event
    if event.event_code < EVENT_MIN_USER_EVENT:
        pass

    elif EVENT_MIN_USER_EVENT <= event.event_code <= EVENT_MAX_USER_EVENT:

        if event.device_uri:
            #event.device_uri = event.device_uri.replace('hpfax:', 'hp:')
            dup_event = create_history(event)

            if event.event_code in (EVENT_DEVICE_STOP_POLLING,
                                    EVENT_START_MAINT_JOB,
                                    EVENT_START_COPY_JOB, EVENT_START_FAX_JOB,
                                    EVENT_START_PRINT_JOB):
                pass  # stop polling (increment counter)

            elif event.event_code in (
                    EVENT_DEVICE_START_POLLING,  # should this event force counter to 0?
                    EVENT_END_MAINT_JOB,
                    EVENT_END_COPY_JOB,
                    EVENT_END_FAX_JOB,
                    EVENT_END_PRINT_JOB,
                    EVENT_PRINT_FAILED_MISSING_PLUGIN,
                    EVENT_SCANNER_FAIL,
                    EVENT_END_SCAN_JOB,
                    EVENT_SCAN_FAILED_MISSING_PLUGIN,
                    EVENT_FAX_JOB_FAIL,
                    EVENT_FAX_JOB_CANCELED,
                    EVENT_FAX_FAILED_MISSING_PLUGIN,
                    EVENT_COPY_JOB_FAIL,
                    EVENT_COPY_JOB_CANCELED):
                pass  # start polling if counter <= 0
                # TODO: Do tools send END event if canceled or failed? Should they?
                # TODO: What to do if counter doesn't hit 0 after a period? Timeout?
                # TODO: Also, need to deal with the backoff setting (or it completely sep?)

        # Send to system tray icon if available
        if not dup_event:  # and event.event_code != STATUS_PRINTER_IDLE:
            send_event_to_systray_ui(event)

        # send EVENT_HISTORY_UPDATE signal to hp-toolbox
        send_toolbox_event(event, EVENT_HISTORY_UPDATE)

        if event.event_code in (EVENT_PRINT_FAILED_MISSING_PLUGIN,
                                EVENT_SCAN_FAILED_MISSING_PLUGIN,
                                EVENT_FAX_FAILED_MISSING_PLUGIN):
            handle_plugin_install()

    # Handle fax signals
    elif EVENT_FAX_MIN <= event.event_code <= EVENT_FAX_MAX and more_args:
        log.debug("Fax event")
        pipe_name = str(more_args[0])
        handle_fax_event(event, pipe_name)

    elif event.event_code == EVENT_USER_CONFIGURATION_CHANGED:
        # Sent if polling, hiding, etc. configuration has changed
        #    send_event_to_hpdio(event)
        send_event_to_systray_ui(event)

    elif event.event_code == EVENT_SYS_CONFIGURATION_CHANGED:  # Not implemented
        #send_event_to_hpdio(event)
        send_event_to_systray_ui(event)

    # Qt4 only
    elif event.event_code in (EVENT_DEVICE_UPDATE_REQUESTED, ):
        #EVENT_DEVICE_START_POLLING,  # ?  Who handles polling? hpssd? probably...
        #EVENT_DEVICE_STOP_POLLING):  # ?
        send_event_to_hpdio(event)

    # Qt4 only
    elif event.event_code in (EVENT_DEVICE_UPDATE_ACTIVE,
                              EVENT_DEVICE_UPDATE_INACTIVE):
        send_event_to_systray_ui(event)

    # Qt4 only
    elif event.event_code == EVENT_DEVICE_UPDATE_REPLY:
        bytes_written = int(more_args[1])
        handle_hpdio_event(event, bytes_written)

    # Qt4 only
    elif event.event_code == EVENT_CUPS_QUEUES_ADDED or event.event_code == EVENT_CUPS_QUEUES_REMOVED:
        send_event_to_systray_ui(event)
        send_toolbox_event(event, EVENT_HISTORY_UPDATE)

    # Qt4 only
    elif event.event_code == EVENT_SYSTEMTRAY_EXIT:
        send_event_to_hpdio(event)
        send_toolbox_event(event)
        send_event_to_systray_ui(event)
        log.debug("Exiting")
        main_loop.quit()

    elif event.event_code in (EVENT_DEVICE_START_POLLING,
                              EVENT_DEVICE_STOP_POLLING):
        pass

    else:
        log.error("Unhandled event: %d" % event.event_code)