summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlade Diviney <mopriadevteam@gmail.com>2019-11-04 18:43:32 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-11-04 18:43:32 -0800
commit4f502a1a3fa549508935d530237983a9b283d00b (patch)
tree0bf19a11bda6667376eb288a25320cfa10664e73
parent38650e2845290a3dc0e5873608d17e6b84115c2e (diff)
parenta9074c1dac70ad053014cc5b9baabe3dc8f24fee (diff)
downloadBuiltInPrintService-temp_b_145570283.tar.gz
refactor to avoid compiler warningtemp_b_145570283
am: a9074c1dac Change-Id: I53e95355f87806b1671ea5d42d29937da04d0a5f
-rw-r--r--jni/lib/lib_wprint.c124
1 files changed, 54 insertions, 70 deletions
diff --git a/jni/lib/lib_wprint.c b/jni/lib/lib_wprint.c
index 508c47f..a30d74c 100644
--- a/jni/lib/lib_wprint.c
+++ b/jni/lib/lib_wprint.c
@@ -827,9 +827,9 @@ static void *_job_thread(void *param) {
// wait for the printer to be idle
if ((jq->status_ifc != NULL) && (jq->status_ifc->get_status != NULL)) {
int retry = 0;
- int loop = 1;
+ bool idle = false;
printer_state_dyn_t printer_state;
- do {
+ while (!idle) {
print_status_t status;
jq->status_ifc->get_status(jq->status_ifc, &printer_state);
status = printer_state.printer_status & ~PRINTER_IDLE_BIT;
@@ -838,79 +838,63 @@ static void *_job_thread(void *param) {
cb_param.certificate = jq->certificate;
cb_param.certificate_len = jq->certificate_len;
- switch (status) {
- case PRINT_STATUS_IDLE:
- printer_state.printer_status = PRINT_STATUS_IDLE;
- jq->blocked_reasons = 0;
- loop = 0;
- break;
- case PRINT_STATUS_UNKNOWN:
- if (printer_state.printer_reasons[0] == PRINT_STATUS_UNKNOWN) {
- LOGE("PRINTER STATUS UNKNOWN - Ln 747 libwprint.c");
- // no status available, break out and hope for the best
- printer_state.printer_status = PRINT_STATUS_IDLE;
- loop = 0;
- break;
- }
- case PRINT_STATUS_SVC_REQUEST:
- if ((printer_state.printer_reasons[0] == PRINT_STATUS_UNABLE_TO_CONNECT)
- || (printer_state.printer_reasons[0] == PRINT_STATUS_OFFLINE)) {
- if (_is_certificate_allowed(jq)) {
- LOGD("_job_thread: Received an Unable to Connect message");
- jq->blocked_reasons = BLOCKED_REASON_UNABLE_TO_CONNECT;
- } else {
- LOGD("_job_thread: Bad certificate");
- jq->blocked_reasons = BLOCKED_REASON_BAD_CERTIFICATE;
- }
- loop = 0;
+ // Presume we found an idle state
+ idle = true;
+ if (status == PRINT_STATUS_IDLE) {
+ printer_state.printer_status = PRINT_STATUS_IDLE;
+ jq->blocked_reasons = 0;
+ } else if (status == PRINT_STATUS_UNKNOWN
+ && printer_state.printer_reasons[0] == PRINT_STATUS_UNKNOWN) {
+ // no status available, break out and hope for the best
+ printer_state.printer_status = PRINT_STATUS_IDLE;
+ } else if (status == PRINT_STATUS_SVC_REQUEST
+ && ((printer_state.printer_reasons[0] == PRINT_STATUS_UNABLE_TO_CONNECT)
+ || (printer_state.printer_reasons[0] == PRINT_STATUS_OFFLINE))) {
+ if (_is_certificate_allowed(jq)) {
+ LOGD("%s: Received an Unable to Connect message", __func__);
+ jq->blocked_reasons = BLOCKED_REASON_UNABLE_TO_CONNECT;
+ } else {
+ LOGD("%s: Bad certificate", __func__);
+ jq->blocked_reasons = BLOCKED_REASON_BAD_CERTIFICATE;
+ }
+ } else if (printer_state.printer_status & PRINTER_IDLE_BIT) {
+ LOGD("%s: printer blocked but appears to be in an idle state. "
+ "Allowing job to proceed", __func__);
+ printer_state.printer_status = PRINT_STATUS_IDLE;
+ } else if (retry >= MAX_IDLE_WAIT) {
+ jq->blocked_reasons |= BLOCKED_REASONS_PRINTER_BUSY;
+ } else if (!jq->job_params.cancelled) {
+ // Printer still appears busy, so stay in loop, notify, and poll again.
+ idle = false;
+ int blocked_reasons = 0;
+ for (i = 0; i <= PRINT_STATUS_MAX_STATE; i++) {
+ if (printer_state.printer_reasons[i] == PRINT_STATUS_MAX_STATE) {
break;
}
- default:
- if (printer_state.printer_status & PRINTER_IDLE_BIT) {
- LOGD("printer blocked but appears to be in an idle state. "
- "Allowing job to proceed");
- printer_state.printer_status = PRINT_STATUS_IDLE;
- loop = 0;
- break;
- } else if (retry >= MAX_IDLE_WAIT) {
- jq->blocked_reasons |= BLOCKED_REASONS_PRINTER_BUSY;
- loop = 0;
- } else if (!jq->job_params.cancelled) {
- int blocked_reasons = 0;
- for (i = 0; i <= PRINT_STATUS_MAX_STATE; i++) {
- if (printer_state.printer_reasons[i] ==
- PRINT_STATUS_MAX_STATE) {
- break;
- }
- blocked_reasons |= (1 << printer_state.printer_reasons[i]);
- }
- if (blocked_reasons == 0) {
- blocked_reasons |= BLOCKED_REASONS_PRINTER_BUSY;
- }
+ blocked_reasons |= (1 << printer_state.printer_reasons[i]);
+ }
+ if (blocked_reasons == 0) {
+ blocked_reasons |= BLOCKED_REASONS_PRINTER_BUSY;
+ }
- if ((jq->job_state != JOB_STATE_BLOCKED) ||
- (jq->blocked_reasons != blocked_reasons)) {
- jq->job_state = JOB_STATE_BLOCKED;
- jq->blocked_reasons = blocked_reasons;
- if (jq->cb_fn) {
- cb_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);
- }
- }
- _unlock();
- sleep(1);
- _lock();
- retry++;
+ if ((jq->job_state != JOB_STATE_BLOCKED)
+ || (jq->blocked_reasons != blocked_reasons)) {
+ jq->job_state = JOB_STATE_BLOCKED;
+ jq->blocked_reasons = blocked_reasons;
+ if (jq->cb_fn) {
+ cb_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);
}
- break;
- }
- if (jq->job_params.cancelled) {
- loop = 0;
+ }
+ _unlock();
+ sleep(1);
+ _lock();
+ retry++;
}
- } while (loop);
+ }
if (jq->job_params.cancelled) {
job_result = CANCELLED;