kopia lustrzana https://gitlab.com/sane-project/backends
Porównaj commity
7 Commity
d3d230a9a0
...
de9f132419
Autor | SHA1 | Data |
---|---|---|
Ralph Little | de9f132419 | |
Ralph Little | 0f472aa205 | |
ThierryFR | 728ca40272 | |
ThierryFR | 113be50f6b | |
Guillaume Girol | a6d63a72ec | |
Ralph Little | 88ca2d07a1 | |
Ralph Little | 7b847a10db |
|
@ -6,7 +6,8 @@
|
|||
# Your editor may need a plugin for this configuration to take effect.
|
||||
# See http://editorconfig.org/#download for details.
|
||||
|
||||
root = true ; look no further
|
||||
; look no further
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
|
|
|
@ -2635,22 +2635,34 @@ sane_get_parameters(SANE_Handle handle, SANE_Parameters *params)
|
|||
if (params == NULL)
|
||||
DBG(1, "%s: params is NULL\n", __func__);
|
||||
|
||||
|
||||
/*
|
||||
* If sane_start was already called, then just retrieve the parameters
|
||||
* from the scanner data structure
|
||||
* If scanning then make sure that we acquire an image before we proceed
|
||||
* if we didn't before. It is unlikely that s->scanning can be true and we have
|
||||
* not acquired an image yet but let us be sure.
|
||||
*
|
||||
* Otherwise, we will generate parameters purely from the current settings
|
||||
* rather than anything we got from the current image.
|
||||
*
|
||||
*/
|
||||
if (s->scanning) {
|
||||
if (s->scanning)
|
||||
{
|
||||
DBG(5, "scan in progress, returning saved params structure\n");
|
||||
|
||||
if (s->acquirePage == 0)
|
||||
{
|
||||
SANE_Status status = get_next_image(s);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(1, "failed to acquire image for parameters.\n");
|
||||
return status;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* otherwise initialize the params structure */
|
||||
eds_init_parameters(s);
|
||||
}
|
||||
|
||||
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
|
||||
status = get_next_image(s);
|
||||
|
||||
// if size auto, update page size value
|
||||
if(s->val[OPT_ADF_CRP].w)
|
||||
{
|
||||
|
@ -2713,7 +2725,7 @@ sane_get_parameters(SANE_Handle handle, SANE_Parameters *params)
|
|||
print_params(s->params);
|
||||
|
||||
DBG(20, "s->params.line = %d s->params.bytes_per_line = %d s->params.pixels_per_line = %d \n", s->params.lines, s->params.bytes_per_line , s->params.pixels_per_line );
|
||||
return status;
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
|
||||
|
@ -3311,6 +3323,10 @@ sane_start(SANE_Handle handle)
|
|||
s->scanning = 1;
|
||||
s->dummy = 0;
|
||||
s->scanEnd = 0;
|
||||
|
||||
/* acquire the first image. */
|
||||
status = get_next_image(s);
|
||||
|
||||
end:
|
||||
if (status != SANE_STATUS_GOOD) {
|
||||
DBG(1, "%s: start failed: %s\n", __func__, sane_strstatus(status));
|
||||
|
@ -3603,10 +3619,12 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, SANE_Int *le
|
|||
// data is empty fin
|
||||
if (read == 0) {
|
||||
*length = 0;
|
||||
eds_ring_flush(s->current);
|
||||
eds_ring_destory(s->current);
|
||||
DBG(18, "returns EOF 2\n");
|
||||
return SANE_STATUS_EOF;
|
||||
|
||||
// This is silly: we already established above that there is data available.
|
||||
// eds_ring_flush(s->current);
|
||||
// eds_ring_destory(s->current);
|
||||
DBG(18, "Couldn't read anything from ring buffer: probably not enough capacity to receive.\n");
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
*length = read;
|
||||
|
||||
|
|
|
@ -1345,7 +1345,7 @@ sane_cancel(SANE_Handle h)
|
|||
}
|
||||
handler->scanner->work = SANE_FALSE;
|
||||
handler->cancel = SANE_TRUE;
|
||||
escl_scanner(handler->device, handler->scanner->scanJob, handler->result);
|
||||
escl_scanner(handler->device, handler->scanner->scanJob, handler->result, SANE_TRUE);
|
||||
free(handler->result);
|
||||
handler->result = NULL;
|
||||
free(handler->scanner->scanJob);
|
||||
|
@ -1566,6 +1566,7 @@ sane_start(SANE_Handle h)
|
|||
handler->decompress_scan_data = SANE_FALSE;
|
||||
handler->end_read = SANE_FALSE;
|
||||
if (handler->scanner->work == SANE_FALSE) {
|
||||
escl_reset_all_jobs(handler->device);
|
||||
SANE_Status st = escl_status(handler->device,
|
||||
handler->scanner->source,
|
||||
NULL,
|
||||
|
|
|
@ -248,7 +248,11 @@ SANE_Status escl_scan(capabilities_t *scanner,
|
|||
|
||||
void escl_scanner(const ESCL_Device *device,
|
||||
char *scanJob,
|
||||
char *result);
|
||||
char *result,
|
||||
SANE_Bool status);
|
||||
|
||||
SANE_Status escl_reset_all_jobs(ESCL_Device *device);
|
||||
|
||||
|
||||
typedef void CURL;
|
||||
|
||||
|
|
|
@ -44,7 +44,32 @@ write_callback(void __sane_unused__*str,
|
|||
* This function is called in the 'sane_cancel' function.
|
||||
*/
|
||||
void
|
||||
escl_scanner(const ESCL_Device *device, char *scanJob, char *result)
|
||||
escl_delete(const ESCL_Device *device, char *uri)
|
||||
{
|
||||
CURL *curl_handle = NULL;
|
||||
long answer = 0;
|
||||
|
||||
if (uri == NULL)
|
||||
return;
|
||||
curl_handle = curl_easy_init();
|
||||
if (curl_handle != NULL) {
|
||||
escl_curl_url(curl_handle, device, uri);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
if (curl_easy_perform(curl_handle) == CURLE_OK) {
|
||||
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &answer);
|
||||
return;
|
||||
}
|
||||
curl_easy_cleanup(curl_handle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn void escl_scanner(const ESCL_Device *device, char *result)
|
||||
* \brief Function that resets the scanner after each scan, using curl.
|
||||
* This function is called in the 'sane_cancel' function.
|
||||
*/
|
||||
void
|
||||
escl_scanner(const ESCL_Device *device, char *scanJob, char *result, SANE_Bool status)
|
||||
{
|
||||
CURL *curl_handle = NULL;
|
||||
const char *scan_jobs = "/eSCL/";
|
||||
|
@ -70,10 +95,15 @@ CURL_CALL:
|
|||
if (i >= 15) return;
|
||||
}
|
||||
curl_easy_cleanup(curl_handle);
|
||||
if (SANE_STATUS_GOOD != escl_status(device,
|
||||
PLATEN,
|
||||
NULL,
|
||||
NULL))
|
||||
goto CURL_CALL;
|
||||
char* end = strrchr(scan_cmd, '/');
|
||||
*end = 0;
|
||||
escl_delete(device, scan_cmd);
|
||||
if (status) {
|
||||
if (SANE_STATUS_GOOD != escl_status(device,
|
||||
PLATEN,
|
||||
NULL,
|
||||
NULL))
|
||||
goto CURL_CALL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libxml/parser.h>
|
||||
|
||||
|
@ -270,3 +271,135 @@ clean_data:
|
|||
}
|
||||
return (status);
|
||||
}
|
||||
|
||||
static void
|
||||
print_xml_job_finish(xmlNode *node,
|
||||
SANE_Status *job)
|
||||
{
|
||||
while (node) {
|
||||
if (node->type == XML_ELEMENT_NODE) {
|
||||
if (find_nodes_s(node)) {
|
||||
if (strcmp((const char *)node->name, "JobState") == 0) {
|
||||
const char *state = (const char *)xmlNodeGetContent(node);
|
||||
if (!strcmp(state, "Canceled")) {
|
||||
*job = SANE_STATUS_GOOD;
|
||||
DBG(10, "jobId Completed SANE_STATUS_GOOD\n");
|
||||
}
|
||||
else if (!strcmp(state, "Aborted")) {
|
||||
*job = SANE_STATUS_GOOD;
|
||||
DBG(10, "jobId Completed SANE_STATUS_GOOD\n");
|
||||
}
|
||||
else if (!strcmp(state, "Completed")) {
|
||||
*job = SANE_STATUS_GOOD;
|
||||
DBG(10, "jobId Completed SANE_STATUS_GOOD\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print_xml_job_finish(node->children, job);
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_xml_reset_all_jobs (xmlNode *node,
|
||||
ESCL_Device *device)
|
||||
{
|
||||
DBG(10, "print_xml_reset_all_jobs\n");
|
||||
SANE_Status status = SANE_STATUS_DEVICE_BUSY;
|
||||
while (node) {
|
||||
if (node->type == XML_ELEMENT_NODE) {
|
||||
if (find_nodes_s(node)) {
|
||||
if (strcmp((const char *)node->name, "JobUri") == 0) {
|
||||
DBG(10, "print_xml_reset_all_jobs: %s\n", node->name);
|
||||
if (device != NULL) {
|
||||
print_xml_job_finish (node, &status);
|
||||
if (status == SANE_STATUS_DEVICE_BUSY) {
|
||||
char *jobUri = (char *)xmlNodeGetContent(node);
|
||||
char *job = strrchr((const char *)jobUri, '/');
|
||||
char *scanj = NULL;
|
||||
if (job != NULL) {
|
||||
if (strstr(jobUri,"ScanJobs"))
|
||||
scanj = strdup("ScanJobs");
|
||||
else
|
||||
scanj = strdup("ScanJob");
|
||||
DBG(10, "print_xml_reset_all_jobs: %s/%s\n", scanj, job);
|
||||
escl_scanner(device, scanj, job, SANE_FALSE);
|
||||
free(scanj);
|
||||
}
|
||||
DBG(10, "print_xml_reset_all_jobs: sleep to finish the job\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print_xml_reset_all_jobs (node->children,
|
||||
device);
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn SANE_Status escl_reset_all_jobs (ESCL_Device *device, , char *scanJob)
|
||||
* \brief Function that forces the end of jobs, using curl.
|
||||
* This function is called in the 'sane_start' function.
|
||||
*
|
||||
* \return status (if everything is OK, status = SANE_STATUS_GOOD, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL)
|
||||
*/
|
||||
SANE_Status
|
||||
escl_reset_all_jobs(ESCL_Device *device)
|
||||
{
|
||||
CURL *curl_handle = NULL;
|
||||
xmlDoc *data = NULL;
|
||||
xmlNode *node = NULL;
|
||||
struct idle *var = NULL;
|
||||
const char *scanner_status = "/eSCL/ScannerStatus";
|
||||
SANE_Status status = SANE_STATUS_DEVICE_BUSY;
|
||||
|
||||
DBG(10, "escl_reset_all_jobs\n");
|
||||
if (device == NULL)
|
||||
return (SANE_STATUS_NO_MEM);
|
||||
DBG(10, "1 - escl_reset_all_jobs\n");
|
||||
var = (struct idle*)calloc(1, sizeof(struct idle));
|
||||
if (var == NULL)
|
||||
return (SANE_STATUS_NO_MEM);
|
||||
DBG(10, "2 - escl_reset_all_jobs\n");
|
||||
var->memory = malloc(1);
|
||||
var->size = 0;
|
||||
curl_handle = curl_easy_init();
|
||||
|
||||
escl_curl_url(curl_handle, device, scanner_status);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, memory_callback_s);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)var);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 3L);
|
||||
CURLcode res = curl_easy_perform(curl_handle);
|
||||
if (res != CURLE_OK) {
|
||||
DBG( 1, "The scanner didn't respond: %s\n", curl_easy_strerror(res));
|
||||
status = SANE_STATUS_INVAL;
|
||||
goto clean_data1;
|
||||
}
|
||||
DBG(10, "3 - escl_reset_all_jobs\n");
|
||||
DBG( 10, "eSCL : Status : %s.\n", var->memory);
|
||||
data = xmlReadMemory(var->memory, var->size, "file.xml", NULL, 0);
|
||||
if (data == NULL) {
|
||||
status = SANE_STATUS_NO_MEM;
|
||||
goto clean_data1;
|
||||
}
|
||||
node = xmlDocGetRootElement(data);
|
||||
if (node == NULL) {
|
||||
status = SANE_STATUS_NO_MEM;
|
||||
goto clean1;
|
||||
}
|
||||
print_xml_reset_all_jobs (node, device);
|
||||
status = SANE_STATUS_GOOD;
|
||||
clean1:
|
||||
xmlFreeDoc(data);
|
||||
clean_data1:
|
||||
xmlCleanupParser();
|
||||
xmlMemoryDump();
|
||||
curl_easy_cleanup(curl_handle);
|
||||
free(var->memory);
|
||||
free(var);
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -1771,6 +1771,10 @@ do_scan (Wire * w, int h, int data_fd)
|
|||
/* get more input data */
|
||||
|
||||
/* reserve 4 bytes to store the length of the data record: */
|
||||
|
||||
/* NOTE: it seems to me that we could dispense with the record if we read nothing from sane_read() */
|
||||
/* Consider an optimization whereby we add nothing to the ring buffer in this case. */
|
||||
/* I do need to check the semantics of this though. [RL] */
|
||||
i = reader;
|
||||
reader += 4;
|
||||
if (reader >= (int) buffer_size)
|
||||
|
|
Ładowanie…
Reference in New Issue