diff options
author | Saurabh Chauhan <mopriadevteam@gmail.com> | 2024-03-06 08:10:54 +0000 |
---|---|---|
committer | Saurabh Chauhan <mopriadevteam@gmail.com> | 2024-03-06 08:10:54 +0000 |
commit | 0135ff95ece85e484fe703f141c2aceea0f78571 (patch) | |
tree | 0eb713b82816e7347cc478a297d71ee21f29a2f4 | |
parent | 31c722524ee6f9f29ff6b50e31928446935f0e98 (diff) | |
download | BuiltInPrintService-0135ff95ece85e484fe703f141c2aceea0f78571.tar.gz |
Fixed initial blocking conditions when job-id
is not generated.
Blocked conditions like "Out of Paper" are not reported for some
printers when the print job is at the initial stage.
Test: Empty paper tray on the printer > Print a doc > Observe
Out of Paper notification in mobile.
Signed-off-by: Saurabh Chauhan <mopriadevteam@gmail.com>
Change-Id: Ibe20a5ffea66eff5b4eaf9ab9480d82f5e85c82e
-rw-r--r-- | jni/include/wprint_status_types.h | 2 | ||||
-rw-r--r-- | jni/ipphelper/ippstatus_monitor.c | 3 | ||||
-rwxr-xr-x | jni/lib/lib_wprint.c | 79 |
3 files changed, 46 insertions, 38 deletions
diff --git a/jni/include/wprint_status_types.h b/jni/include/wprint_status_types.h index b1449bc..4dd0ed6 100644 --- a/jni/include/wprint_status_types.h +++ b/jni/include/wprint_status_types.h @@ -209,6 +209,8 @@ typedef struct printer_state_dyn_s { // all current print status events print_status_t printer_reasons[PRINT_STATUS_MAX_STATE + 1]; + + int job_id; } printer_state_dyn_t; typedef enum { diff --git a/jni/ipphelper/ippstatus_monitor.c b/jni/ipphelper/ippstatus_monitor.c index 2a19976..c54d623 100644 --- a/jni/ipphelper/ippstatus_monitor.c +++ b/jni/ipphelper/ippstatus_monitor.c @@ -209,9 +209,11 @@ static void _start(const ifc_status_monitor_t *this_p, last_status.printer_status = PRINT_STATUS_UNKNOWN; last_status.printer_reasons[0] = PRINT_STATUS_INITIALIZING; + last_status.job_id = 0; curr_status.printer_status = PRINT_STATUS_UNKNOWN; curr_status.printer_reasons[0] = PRINT_STATUS_INITIALIZING; + curr_status.job_id = 0; // send out the first callback if (status_cb != NULL) { @@ -263,6 +265,7 @@ static void _start(const ifc_status_monitor_t *this_p, } else { while (!monitor->stop_monitor) { pthread_mutex_lock(&monitor->mutex); + curr_status.job_id = job_id; _get_status(this_p, &curr_status); pthread_mutex_unlock(&monitor->mutex); if ((status_cb != NULL) && diff --git a/jni/lib/lib_wprint.c b/jni/lib/lib_wprint.c index fc3cfb5..db7f3cb 100755 --- a/jni/lib/lib_wprint.c +++ b/jni/lib/lib_wprint.c @@ -523,6 +523,20 @@ static int _stop_status_thread(_job_queue_t *jq) { } /* + * Helper function to send job status callbacks to wprintJNI + */ +static void _send_status_callback(_job_queue_t *jq, wprint_job_callback_params_t cb_param, + int state, unsigned int blocked_reasons, int job_done_result) { + if (jq->cb_fn) { + cb_param.id = WPRINT_CB_PARAM_JOB_STATE; + cb_param.param.state = state; + cb_param.blocked_reasons = blocked_reasons; + cb_param.job_done_result = job_done_result; + jq->cb_fn(jq->job_handle, (void *) &cb_param); + } +} + +/* * Handles a new status message from the printer. Based on the status of wprint and the printer, * this function will start/end a job, send another page, or return blocking errors. */ @@ -573,11 +587,24 @@ static void _job_status_callback(const printer_state_dyn_t *new_status, } break; + case PRINT_STATUS_PRINTING: + // print job is unblocked but job-id is not generated + if (new_status->job_id == -1) { + sem_post(&_job_start_wait_sem); + _lock(); + if ((jq->job_state != JOB_STATE_RUNNING) || + (jq->blocked_reasons != blocked_reasons)) { + jq->job_state = JOB_STATE_RUNNING; + jq->blocked_reasons = blocked_reasons; + _send_status_callback(jq, cb_param, JOB_RUNNING, jq->blocked_reasons, OK); + } + _unlock(); + } + break; + /* all is well, handled in job status */ case PRINT_STATUS_CANCELLED: /* all is well, handled in job status */ - case PRINT_STATUS_PRINTING: - /* all is well, handled in job status */ case PRINT_STATUS_UNABLE_TO_CONNECT: break; @@ -589,6 +616,10 @@ static void _job_status_callback(const printer_state_dyn_t *new_status, if ((jq->job_state != JOB_STATE_BLOCKED) || (jq->blocked_reasons != blocked_reasons)) { jq->job_state = JOB_STATE_BLOCKED; jq->blocked_reasons = blocked_reasons; + // print job is blocked at the initial stage and job-id is not generated + if (new_status->job_id == -1) { + _send_status_callback(jq, cb_param, JOB_BLOCKED, blocked_reasons, OK); + } } _unlock(); break; @@ -637,26 +668,14 @@ static void _print_job_state_callback(const job_state_dyn_t *new_state, void *pa _lock(); if (jq->job_state != JOB_STATE_RUNNING) { jq->job_state = JOB_STATE_RUNNING; - if (jq->cb_fn) { - cb_param.id = WPRINT_CB_PARAM_JOB_STATE; - cb_param.param.state = JOB_RUNNING; - cb_param.job_done_result = OK; - jq->cb_fn(jq->job_handle, (void *) &cb_param); - } + _send_status_callback(jq, cb_param, JOB_RUNNING, 0, OK); } _unlock(); break; case IPP_JOB_STATE_PROCESSING_STOPPED: if (jq->job_state == JOB_STATE_BLOCKED) { - if (jq->cb_fn) { - cb_param.id = WPRINT_CB_PARAM_JOB_STATE; - cb_param.param.state = JOB_BLOCKED; - cb_param.blocked_reasons = jq->blocked_reasons; - cb_param.job_done_result = OK; - - jq->cb_fn(jq->job_handle, (void *) &cb_param); - } + _send_status_callback(jq, cb_param, JOB_BLOCKED, jq->blocked_reasons, OK); } break; @@ -920,14 +939,7 @@ static void *_job_thread(void *param) { || (jq->blocked_reasons != blocked_reasons)) { jq->job_state = JOB_STATE_BLOCKED; jq->blocked_reasons = blocked_reasons; - if (jq->cb_fn) { - cb_param.id = WPRINT_CB_PARAM_JOB_STATE; - cb_param.param.state = JOB_BLOCKED; - cb_param.blocked_reasons = blocked_reasons; - cb_param.job_done_result = OK; - - jq->cb_fn(jq->job_handle, (void *) &cb_param); - } + _send_status_callback(jq, cb_param, JOB_BLOCKED, blocked_reasons, OK); } _unlock(); sleep(1); @@ -964,13 +976,8 @@ static void *_job_thread(void *param) { /* call the plugin's start_job method, if no other job is running use callback to notify the client */ - if ((job_result == OK) && jq->cb_fn) { - cb_param.id = WPRINT_CB_PARAM_JOB_STATE; - cb_param.param.state = JOB_RUNNING; - cb_param.blocked_reasons = 0; - cb_param.job_done_result = OK; - - jq->cb_fn(job_handle, (void *) &cb_param); + if (job_result == OK) { + _send_status_callback(jq, cb_param, JOB_RUNNING, 0, OK); } memcpy(&printer_caps, &g_printer_caps, sizeof(printer_capabilities_t)); @@ -1246,6 +1253,7 @@ static void *_job_thread(void *param) { } if ((jq->print_ifc != NULL) && (jq->print_ifc->end_job) && (strcmp(jq->job_params.print_format, PRINT_FORMAT_PDF) != 0)) { + _unlock(); int end_job_result = jq->print_ifc->end_job(jq->print_ifc); if (job_result == OK) { if (end_job_result == ERROR) { @@ -1254,6 +1262,7 @@ static void *_job_thread(void *param) { job_result = CANCELLED; } } + _lock(); } } @@ -1355,13 +1364,7 @@ static void *_job_thread(void *param) { } // end of job callback - if (jq->cb_fn) { - cb_param.id = WPRINT_CB_PARAM_JOB_STATE; - cb_param.param.state = JOB_DONE; - cb_param.blocked_reasons = jq->blocked_reasons; - cb_param.job_done_result = job_result; - jq->cb_fn(job_handle, (void *) &cb_param); - } + _send_status_callback(jq, cb_param, JOB_DONE, jq->blocked_reasons, job_result); if (jq->print_ifc != NULL) { jq->print_ifc->destroy(jq->print_ifc); |