int bb_is_paper_in_adf(struct ledm_session *ps) /* 0 = no paper in adf, 1 = paper in adf, -1 = error */ { char buf[1024]; int bytes_read; struct bb_ledm_session *pbb = ps->bb_session; if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK) { _BUG("unable to open channel HPMUD_S_LEDM_SCAN \n"); return -1; } if (http_write(pbb->http_handle, GET_SCANNER_STATUS, sizeof(GET_SCANNER_STATUS)-1, 10) != HTTP_R_OK) { _BUG("unable to get scanner status \n"); } read_http_payload(ps, buf, sizeof(buf), EXCEPTION_TIMEOUT, &bytes_read); http_close(pbb->http_handle); /* error, close http connection */ pbb->http_handle = 0; _DBG("bb_is_paper_in_adf .job_id=%d page_id=%d buf=%s \n", ps->job_id, ps->page_id, buf ); if(strstr(buf, ADF_LOADED)) return 1; if(strstr(buf, ADF_EMPTY)) { if (strstr(buf, SCANNER_BUSY_WITH_SCAN_JOB)) return 1; if (ps->currentInputSource ==IS_ADF_DUPLEX && ps->page_id % 2 == 1) return 1; else return 0; } else return -1; }
void _arch_irq_task_switch(void * _cpu_state) { if(run_queue) { spinlock_lock(&run_queue->spinlock); get_system_time(&run_queue->sched_time); struct kthread * c = run_queue_current(); struct kthread * n = run_queue_next(); spinlock_unlock(&run_queue->spinlock); _BUG_ON(!n); _BUG_ON(!c); if(stack_check(&(c->stack))<0) _BUG(); // TASK WE JUST PUT TO SLEEP BLEW ITS STACK! _switch(c,n,_cpu_state); // schedule next switch. _sched_next_task(NULL); } }
int kthread_init(const struct stack_struct *ss) { const int idle_task=0; const int boot_task=1; if((run_queue = kmalloc(sizeof *run_queue, GFP_KERNEL | GFP_ZERO))) { DEBUG_TRACE("%d = stack_check %x %x", stack_check(ss), ss->stack_base, ss->stack_size); spinlock_init(&run_queue->spinlock); run_queue->running = boot_task; // create an empty kthread for the boot-task! UGLY! run_queue->kthreads[boot_task] = _kmalloc_kthread(); if(run_queue->kthreads[boot_task]) { DEBUG_TRACE("%d = stack_check", stack_check(ss)); // store boot_stack info. run_queue->kthreads[boot_task]->stack = *ss; irq_itf irq; if(timer_open(&run_queue->timer, &irq, 0)==0) { DEBUG_TRACE(""); interrupt_controller_itf intc; if(interrupt_controller(&intc) == 0) { DEBUG_TRACE(""); INVOKE(intc, register_handler, irq); INVOKE(intc, unmask, irq); goto success; } } } } goto err; success: // start idle-task. if(_kthread_create(&run_queue->kthreads[idle_task], GFP_KERNEL, &_asm_idle_task, 0)==0) { DEBUG_TRACE(""); _BUG_ON(!run_queue->kthreads[idle_task]); // UGLY - yield to self! current task is first, and only runnable thread right now. // we NEED to do this to populate the empty kthread we allocated for ourselves earier kthread_yield(); return _sched_next_task(NULL); } err: _BUG(); return -1; }
static int cancel_job(struct ledm_session *ps) { struct bb_ledm_session *pbb = ps->bb_session; int len, stat=1, tmo=5/*EXCEPTION_TIMEOUT*/; char buf[2048]; int bytes_read; _DBG("cancel_job user_cancel=%d job_id=%d url=%s \n", ps->user_cancel, ps->job_id, ps->url); if (ps->job_id == 0 || ps->user_cancel == 0) { ps->job_id = 0; ps->page_id = 0; return 0 ; } if (http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK) { _BUG("unable to open http connection %s\n", ps->uri); goto bugout; } len = snprintf(buf, sizeof(buf), CANCEL_JOB_REQUEST, ps->url, strlen(CANCEL_JOB_DATA)); if (http_write(pbb->http_handle, buf, len, 1) != HTTP_R_OK) { _BUG("unable to cancel_job %s\n", ps->url); } len = snprintf(buf, sizeof(buf), CANCEL_JOB_DATA); if (http_write(pbb->http_handle, buf, len, 1) != HTTP_R_OK) { _BUG("unable to cancel_job %s\n", ps->url); } if (read_http_payload(ps, buf, sizeof(buf), tmo, &bytes_read)) goto bugout; stat=0; bugout: if (pbb->http_handle) { http_close(pbb->http_handle); pbb->http_handle = 0; } return stat; }; /* cancel_job */
static int _sched_next_task(struct timespec *now) { struct timespec ts; ts.seconds = 0; ts.nanoseconds = 1000000; if(INVOKE(run_queue->timer, oneshot, &ts)!=0) { _BUG(); return -1; } return 0; }
static int get_scanner_elements(struct ledm_session *ps, struct wscn_scan_elements *elements) { struct bb_ledm_session *pbb = ps->bb_session; int bytes_read = 0; int stat=1, tmo=10; char buf[8192]; if (http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK) { _BUG("unable to open http connection %s\n", ps->uri); goto bugout; } /* Write the xml payload. */ if (http_write(pbb->http_handle, GET_SCANNER_ELEMENTS, sizeof(GET_SCANNER_ELEMENTS)-1, tmo) != HTTP_R_OK) { _BUG("unable to get_scanner_elements %s\n", ps->uri); goto bugout; } /* Read http response. */ if (read_http_payload(ps, buf, sizeof(buf), tmo, &bytes_read)) goto bugout; _DBG("get_scanner_elements bytes_read=%d len=%d buf=%s\n", bytes_read, strlen(buf), buf); http_unchunk_data(buf); bytes_read=strlen(buf); _DBG("get_scanner_elements buf=%s\n", buf); parse_scan_elements(buf, bytes_read, elements); stat=0; bugout: if (pbb->http_handle) { http_close(pbb->http_handle); pbb->http_handle = 0; } return stat; } /* get_scanner_elements */
static void _exited_kthread() { spinlock_lock(&run_queue->spinlock); _BUG_ON(run_queue->running==0); // CANT QUIT IDLE TASK! struct kthread * c = run_queue_current(); if(c) { run_queue_remove(c); c->flags |= KTHREAD_JOINABLE; } spinlock_unlock(&run_queue->spinlock); kthread_yield(); _BUG(); _asm_idle_task(NULL); }
SANE_Status bb_start_scan(struct ledm_session *ps) { char buf[4096] = {0}; char buf1[1024]={0}; int len, bytes_read, paper_status; int i, timeout = 10 ; char szPage_ID[5] = {0}; char szJob_ID[5] = {0}; SANE_Status stat = SANE_STATUS_IO_ERROR; struct bb_ledm_session *pbb = ps->bb_session; ps->user_cancel = 0; _DBG("bb_start_scan() entering...job_id=%d\n", ps->job_id); if (ps->job_id == 0) { if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK) { _BUG("unable to open channel HPMUD_S_LEDM_SCAN \n"); goto bugout; } if (http_write(pbb->http_handle, GET_SCANNER_STATUS, sizeof(GET_SCANNER_STATUS)-1, timeout) != HTTP_R_OK) { _BUG("unable to GET_SCANNER_STATUS \n"); goto bugout; } read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read); if(!strstr(buf, SCANNER_IDLE)) { stat = SANE_STATUS_DEVICE_BUSY; goto bugout; } http_close(pbb->http_handle); pbb->http_handle = 0; if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK) { _BUG("unable to open channel HPMUD_S_LEDM_SCAN \n"); goto bugout; } len = snprintf(buf, sizeof(buf), CREATE_SCAN_JOB_REQUEST, ps->currentResolution,//<XResolution> ps->currentResolution,//<YResolution> (int) (ps->currentTlx / 5548.7133),//<XStart> (int) ((ps->currentBrx / 5548.7133) - (ps->currentTlx / 5548.7133)),//<Width> (int) (ps->currentTly / 5548.7133),//<YStart> (int) ((ps->currentBry / 5548.7133) - (ps->currentTly / 5548.7133)),//<Height> "Jpeg",//<Format> (! strcmp(ce_element[ps->currentScanMode], "Color8")) ? "Color" : (! strcmp(ce_element[ps->currentScanMode], "Gray8")) ? "Gray" : "Gray",//<ColorSpace> ((! strcmp(ce_element[ps->currentScanMode], "Color8")) || (! strcmp(ce_element[ps->currentScanMode], "Gray8"))) ? 8: 8,//<BitDepth> ps->currentInputSource == IS_PLATEN ? is_element[1] : is_element[2],//<InputSource> ps->currentInputSource == IS_PLATEN ? is_element[1] : is_element[2],//<InputSourceType> ps->currentInputSource != IS_ADF_DUPLEX ? "" : "<AdfOptions><AdfOption>Duplex</AdfOption></AdfOptions>", (int)ps->currentBrightness,//<Brightness> (int)ps->currentContrast);//<Contrast> len = len + strlen(ZERO_FOOTER); len = snprintf(buf1, sizeof(buf1), POST_HEADER, len); if (http_write(pbb->http_handle, buf1, strlen(buf1), timeout) != HTTP_R_OK) { //goto bugout; } if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK) { //goto bugout; } /* Write zero footer. */ if (http_write(pbb->http_handle, ZERO_FOOTER, sizeof(ZERO_FOOTER)-1, 1) != HTTP_R_OK) { //goto bugout; } memset(buf, 0, sizeof(buf)); /* Read response. */ if (read_http_payload(ps, buf, sizeof(buf), timeout, &bytes_read)) goto bugout; http_close(pbb->http_handle); pbb->http_handle = 0; char joblist[64]; char* jl=strstr(buf, "Location:"); if (!jl) goto bugout; jl=jl+10; int i=0; while(*jl != '\r') { joblist[i]=*jl; jl=jl+1; i++; } joblist[i]='\0'; strcpy(ps->url, joblist); char *c=ps->url; c=strstr(c, "JobList"); if (c) { c=c+8; int job_id=strtol(c, NULL, 10); itoa(job_id, szJob_ID,10); itoa(1, szPage_ID,10); ps->page_id = 1; ps->job_id = job_id; } } else { if (ps->currentInputSource == IS_PLATEN) { stat = SANE_STATUS_INVAL; goto bugout; } ps->page_id++; itoa(ps->job_id,szJob_ID,10); itoa(ps->page_id, szPage_ID,10); } _DBG("bb_start_scan() url=%s page_id=%d\n", ps->url, ps->page_id); memset(buf, 0, sizeof(buf)-1); if(http_open(ps->dd, HPMUD_S_LEDM_SCAN, &pbb->http_handle) != HTTP_R_OK) { _BUG("unable to open channel HPMUD_S_LEDM_SCAN \n"); goto bugout; } while(strstr(buf, READY_TO_UPLOAD) == NULL) { _DBG("bb_start_scan() ENTERING....buf=%s\n", buf); len = snprintf(buf, sizeof(buf), GET_SCAN_JOB_URL, ps->url); if (http_write(pbb->http_handle, buf, strlen(buf), 1) != HTTP_R_OK) { //goto bugout; break ; } if (read_http_payload (ps, buf, sizeof(buf), 5, &len) != HTTP_R_OK) { //goto bugout _DBG("bb_start_scan() read_http_payload FAILED len=%d buf=%s\n", len, buf); break; } //For a new scan, buf must contain <PreScanPage>. if (NULL == strstr(buf,PRESCANPAGE)) { //i.e Paper is not present in Scanner stat = SANE_STATUS_NO_DOCS; goto bugout; } if (strstr(buf,JOBSTATE_CANCELED) || strstr(buf, CANCELED_BY_DEVICE) || strstr(buf, CANCELED_BY_CLIENT)) { _DBG("bb_start_scan() SCAN CANCELLED\n"); stat = SANE_STATUS_GOOD; ps->user_cancel = 1; goto bugout; } if (strstr(buf, JOBSTATE_COMPLETED)) { stat = SANE_STATUS_GOOD; goto bugout; } usleep(500000);//0.5 sec delay }//end while() char *c = strstr(buf, "<BinaryURL>"); _DBG("bb_start_scan() BinaryURL=%s \n", c); if (!c) goto bugout; c +=11; char BinaryURL[30]; i = 0; while(*c != '<') { BinaryURL[i++] = *c ; c++; } BinaryURL[i] = '\0'; //_DBG("bb_start_scan() BinaryURL=%s\n", BinaryURL); len = snprintf(buf, sizeof(buf), GET_SCAN_JOB_URL, BinaryURL); if (http_write(pbb->http_handle, buf, strlen(buf), timeout) != HTTP_R_OK) { //goto bugout; } if (http_read_header(pbb->http_handle, buf, sizeof(buf), timeout, &len) != HTTP_R_OK) { //goto bugout; } if(strstr(buf, "HTTP/1.1 400 Bad Request")) http_read_header(pbb->http_handle, buf, sizeof(buf), timeout, &len); stat = SANE_STATUS_GOOD; bugout: if (stat && pbb->http_handle) { http_close(pbb->http_handle); /* error, close http connection */ pbb->http_handle = 0; } return stat; } /* bb_start_scan */