Call explicitly cancel.

merge-requests/213/head^2
thierry1970 2020-01-09 16:58:12 +01:00 zatwierdzone przez Thierry HUCHARD
rodzic 2c12635b23
commit 1b3f0c9bc0
1 zmienionych plików z 712 dodań i 711 usunięć

Wyświetl plik

@ -124,9 +124,9 @@ escl_add_in_list(ESCL_Device *current)
} }
current = escl_free_device(current); current = escl_free_device(current);
return (SANE_STATUS_NO_MEM); return (SANE_STATUS_NO_MEM);
} }
/** /**
* \fn SANE_Status escl_device_add(int port_nb, const char *model_name, char *ip_address, char *type) * \fn SANE_Status escl_device_add(int port_nb, const char *model_name, char *ip_address, char *type)
* \brief Function that browses my list ('for' loop) and returns the "escl_add_in_list" function to * \brief Function that browses my list ('for' loop) and returns the "escl_add_in_list" function to
* adds all the element needed to my list : * adds all the element needed to my list :
@ -134,9 +134,9 @@ escl_add_in_list(ESCL_Device *current)
* *
* \return escl_add_in_list(current) * \return escl_add_in_list(current)
*/ */
SANE_Status SANE_Status
escl_device_add(int port_nb, const char *model_name, char *ip_address, char *type) escl_device_add(int port_nb, const char *model_name, char *ip_address, char *type)
{ {
char tmp[PATH_MAX] = { 0 }; char tmp[PATH_MAX] = { 0 };
char *model = NULL; char *model = NULL;
ESCL_Device *current = NULL; ESCL_Device *current = NULL;
@ -161,18 +161,18 @@ escl_device_add(int port_nb, const char *model_name, char *ip_address, char *typ
current->ip_address = strdup(ip_address); current->ip_address = strdup(ip_address);
current->type = strdup(type); current->type = strdup(type);
return escl_add_in_list(current); return escl_add_in_list(current);
} }
/** /**
* \fn static inline size_t max_string_size(const SANE_String_Const strings[]) * \fn static inline size_t max_string_size(const SANE_String_Const strings[])
* \brief Function that browses the string ('for' loop) and counts the number of character in the string. * \brief Function that browses the string ('for' loop) and counts the number of character in the string.
* --> this allows to know the maximum size of the string. * --> this allows to know the maximum size of the string.
* *
* \return max_size + 1 (the size max) * \return max_size + 1 (the size max)
*/ */
static inline size_t static inline size_t
max_string_size(const SANE_String_Const strings[]) max_string_size(const SANE_String_Const strings[])
{ {
size_t max_size = 0; size_t max_size = 0;
int i = 0; int i = 0;
@ -182,9 +182,9 @@ max_string_size(const SANE_String_Const strings[])
max_size = size; max_size = size;
} }
return (max_size + 1); return (max_size + 1);
} }
/** /**
* \fn static SANE_Device *convertFromESCLDev(ESCL_Device *cdev) * \fn static SANE_Device *convertFromESCLDev(ESCL_Device *cdev)
* \brief Function that checks if the url of the received scanner is secured or not (http / https). * \brief Function that checks if the url of the received scanner is secured or not (http / https).
* --> if the url is not secured, our own url will be composed like "http://'ip':'port'". * --> if the url is not secured, our own url will be composed like "http://'ip':'port'".
@ -195,9 +195,9 @@ max_string_size(const SANE_String_Const strings[])
* *
* \return sdev (structure that contains the elements of the url) * \return sdev (structure that contains the elements of the url)
*/ */
static SANE_Device * static SANE_Device *
convertFromESCLDev(ESCL_Device *cdev) convertFromESCLDev(ESCL_Device *cdev)
{ {
char tmp[PATH_MAX] = { 0 }; char tmp[PATH_MAX] = { 0 };
SANE_Device *sdev = (SANE_Device*) calloc(1, sizeof(SANE_Device)); SANE_Device *sdev = (SANE_Device*) calloc(1, sizeof(SANE_Device));
if (!sdev) { if (!sdev) {
@ -231,18 +231,18 @@ convertFromESCLDev(ESCL_Device *cdev)
goto freevendor; goto freevendor;
} }
return (sdev); return (sdev);
freevendor: freevendor:
free((void*)sdev->vendor); free((void*)sdev->vendor);
freemodel: freemodel:
free((void*)sdev->model); free((void*)sdev->model);
freename: freename:
free((void*)sdev->name); free((void*)sdev->name);
freedev: freedev:
free((void*)sdev); free((void*)sdev);
return NULL; return NULL;
} }
/** /**
* \fn SANE_Status sane_init(SANE_Int *version_code, SANE_Auth_Callback authorize) * \fn SANE_Status sane_init(SANE_Int *version_code, SANE_Auth_Callback authorize)
* \brief Function that's called before any other SANE function ; it's the first SANE function called. * \brief Function that's called before any other SANE function ; it's the first SANE function called.
* --> this function checks the SANE config. and can check the authentication of the user if * --> this function checks the SANE config. and can check the authentication of the user if
@ -251,9 +251,9 @@ freedev:
* *
* \return SANE_STATUS_GOOD (everything is OK) * \return SANE_STATUS_GOOD (everything is OK)
*/ */
SANE_Status SANE_Status
sane_init(SANE_Int *version_code, SANE_Auth_Callback __sane_unused__ authorize) sane_init(SANE_Int *version_code, SANE_Auth_Callback __sane_unused__ authorize)
{ {
DBG_INIT(); DBG_INIT();
DBG (10, "escl sane_init\n"); DBG (10, "escl sane_init\n");
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status = SANE_STATUS_GOOD;
@ -263,18 +263,18 @@ sane_init(SANE_Int *version_code, SANE_Auth_Callback __sane_unused__ authorize)
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
return (status); return (status);
return (SANE_STATUS_GOOD); return (SANE_STATUS_GOOD);
} }
/** /**
* \fn void sane_exit(void) * \fn void sane_exit(void)
* \brief Function that must be called to terminate use of a backend. * \brief Function that must be called to terminate use of a backend.
* This function will first close all device handles that still might be open. * This function will first close all device handles that still might be open.
* --> by freeing all the elements of my list. * --> by freeing all the elements of my list.
* After this function, no function other than 'sane_init' may be called. * After this function, no function other than 'sane_init' may be called.
*/ */
void void
sane_exit(void) sane_exit(void)
{ {
DBG (10, "escl sane_exit\n"); DBG (10, "escl sane_exit\n");
ESCL_Device *next = NULL; ESCL_Device *next = NULL;
@ -288,9 +288,9 @@ sane_exit(void)
list_devices_primary = NULL; list_devices_primary = NULL;
devlist = NULL; devlist = NULL;
curl_global_cleanup(); curl_global_cleanup();
} }
/** /**
* \fn static SANE_Status attach_one_config(SANEI_Config *config, const char *line) * \fn static SANE_Status attach_one_config(SANEI_Config *config, const char *line)
* \brief Function that implements a configuration file to the user : * \brief Function that implements a configuration file to the user :
* if the user can't detect some devices, he will be able to force their detection with this config' file to use them. * if the user can't detect some devices, he will be able to force their detection with this config' file to use them.
@ -299,9 +299,9 @@ sane_exit(void)
* *
* \return escl_add_in_list(escl_device) if the parsing worked, SANE_STATUS_GOOD otherwise. * \return escl_add_in_list(escl_device) if the parsing worked, SANE_STATUS_GOOD otherwise.
*/ */
static SANE_Status static SANE_Status
attach_one_config(SANEI_Config __sane_unused__ *config, const char *line) attach_one_config(SANEI_Config __sane_unused__ *config, const char *line)
{ {
int port = 0; int port = 0;
SANE_Status status; SANE_Status status;
static ESCL_Device *escl_device = NULL; static ESCL_Device *escl_device = NULL;
@ -349,18 +349,18 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line)
if (status == SANE_STATUS_GOOD) if (status == SANE_STATUS_GOOD)
escl_device = NULL; escl_device = NULL;
return status; return status;
} }
/** /**
* \fn SANE_Status sane_get_devices(const SANE_Device ***device_list, SANE_Bool local_only) * \fn SANE_Status sane_get_devices(const SANE_Device ***device_list, SANE_Bool local_only)
* \brief Function that searches for connected devices and places them in our 'device_list'. ('for' loop) * \brief Function that searches for connected devices and places them in our 'device_list'. ('for' loop)
* If the attribute 'local_only' is worth SANE_FALSE, we only returns the connected devices locally. * If the attribute 'local_only' is worth SANE_FALSE, we only returns the connected devices locally.
* *
* \return SANE_STATUS_GOOD if devlist != NULL ; SANE_STATUS_NO_MEM otherwise. * \return SANE_STATUS_GOOD if devlist != NULL ; SANE_STATUS_NO_MEM otherwise.
*/ */
SANE_Status SANE_Status
sane_get_devices(const SANE_Device ***device_list, SANE_Bool local_only) sane_get_devices(const SANE_Device ***device_list, SANE_Bool local_only)
{ {
if (local_only) /* eSCL is a network-only protocol */ if (local_only) /* eSCL is a network-only protocol */
return (device_list ? SANE_STATUS_GOOD : SANE_STATUS_INVAL); return (device_list ? SANE_STATUS_GOOD : SANE_STATUS_INVAL);
@ -391,9 +391,9 @@ sane_get_devices(const SANE_Device ***device_list, SANE_Bool local_only)
devlist[i] = 0; devlist[i] = 0;
*device_list = devlist; *device_list = devlist;
return (devlist) ? SANE_STATUS_GOOD : SANE_STATUS_NO_MEM; return (devlist) ? SANE_STATUS_GOOD : SANE_STATUS_NO_MEM;
} }
/** /**
* \fn static SANE_Status init_options(SANE_String_Const name, escl_sane_t *s) * \fn static SANE_Status init_options(SANE_String_Const name, escl_sane_t *s)
* \brief Function thzt initializes all the needed options of the received scanner * \brief Function thzt initializes all the needed options of the received scanner
* (the resolution / the color / the margins) thanks to the informations received with * (the resolution / the color / the margins) thanks to the informations received with
@ -401,9 +401,9 @@ sane_get_devices(const SANE_Device ***device_list, SANE_Bool local_only)
* *
* \return status (if everything is OK, status = SANE_STATUS_GOOD) * \return status (if everything is OK, status = SANE_STATUS_GOOD)
*/ */
static SANE_Status static SANE_Status
init_options(SANE_String_Const name, escl_sane_t *s) init_options(SANE_String_Const name, escl_sane_t *s)
{ {
DBG (10, "escl init_options\n"); DBG (10, "escl init_options\n");
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status = SANE_STATUS_GOOD;
int i = 0; int i = 0;
@ -547,9 +547,9 @@ init_options(SANE_String_Const name, escl_sane_t *s)
else else
s->val[OPT_SCAN_SOURCE].s = strdup (s->scanner->Sources[0]); s->val[OPT_SCAN_SOURCE].s = strdup (s->scanner->Sources[0]);
return (status); return (status);
} }
/** /**
* \fn SANE_Status sane_open(SANE_String_Const name, SANE_Handle *h) * \fn SANE_Status sane_open(SANE_String_Const name, SANE_Handle *h)
* \brief Function that establishes a connection with the device named by 'name', * \brief Function that establishes a connection with the device named by 'name',
* and returns a 'handler' using 'SANE_Handle *h', representing it. * and returns a 'handler' using 'SANE_Handle *h', representing it.
@ -558,9 +558,9 @@ init_options(SANE_String_Const name, escl_sane_t *s)
* *
* \return status (if everything is OK, status = SANE_STATUS_GOOD, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL) * \return status (if everything is OK, status = SANE_STATUS_GOOD, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL)
*/ */
SANE_Status SANE_Status
sane_open(SANE_String_Const name, SANE_Handle *h) sane_open(SANE_String_Const name, SANE_Handle *h)
{ {
DBG (10, "escl sane_open\n"); DBG (10, "escl sane_open\n");
SANE_Status status; SANE_Status status;
escl_sane_t *handler = NULL; escl_sane_t *handler = NULL;
@ -599,17 +599,17 @@ sane_open(SANE_String_Const name, SANE_Handle *h)
handler->end_read = SANE_FALSE; handler->end_read = SANE_FALSE;
*h = handler; *h = handler;
return (status); return (status);
} }
/** /**
* \fn void sane_cancel(SANE_Handle h) * \fn void sane_cancel(SANE_Handle h)
* \brief Function that's used to, immediately or as quickly as possible, cancel the currently * \brief Function that's used to, immediately or as quickly as possible, cancel the currently
* pending operation of the device represented by 'SANE_Handle h'. * pending operation of the device represented by 'SANE_Handle h'.
* This functions calls the 'escl_scanner' functions, that resets the scan operations. * This functions calls the 'escl_scanner' functions, that resets the scan operations.
*/ */
void void
sane_cancel(SANE_Handle h) sane_cancel(SANE_Handle h)
{ {
DBG (10, "escl sane_cancel\n"); DBG (10, "escl sane_cancel\n");
escl_sane_t *handler = h; escl_sane_t *handler = h;
if (handler->scanner->tmp) if (handler->scanner->tmp)
@ -619,24 +619,24 @@ sane_cancel(SANE_Handle h)
} }
handler->cancel = SANE_TRUE; handler->cancel = SANE_TRUE;
escl_scanner(handler->name, handler->result); escl_scanner(handler->name, handler->result);
} }
/** /**
* \fn void sane_close(SANE_Handle h) * \fn void sane_close(SANE_Handle h)
* \brief Function that closes the communication with the device represented by 'SANE_Handle h'. * \brief Function that closes the communication with the device represented by 'SANE_Handle h'.
* This function must release the resources that were allocated to the opening of 'h'. * This function must release the resources that were allocated to the opening of 'h'.
*/ */
void void
sane_close(SANE_Handle h) sane_close(SANE_Handle h)
{ {
DBG (10, "escl sane_close\n"); DBG (10, "escl sane_close\n");
if (h != NULL) { if (h != NULL) {
free(h); free(h);
h = NULL; h = NULL;
} }
} }
/** /**
* \fn const SANE_Option_Descriptor *sane_get_option_descriptor(SANE_Handle h, SANE_Int n) * \fn const SANE_Option_Descriptor *sane_get_option_descriptor(SANE_Handle h, SANE_Int n)
* \brief Function that retrieves a descriptor from the n number option of the scanner * \brief Function that retrieves a descriptor from the n number option of the scanner
* represented by 'h'. * represented by 'h'.
@ -644,18 +644,18 @@ sane_close(SANE_Handle h)
* *
* \return s->opt + n * \return s->opt + n
*/ */
const SANE_Option_Descriptor * const SANE_Option_Descriptor *
sane_get_option_descriptor(SANE_Handle h, SANE_Int n) sane_get_option_descriptor(SANE_Handle h, SANE_Int n)
{ {
DBG (10, "escl sane_get_option_descriptor\n"); DBG (10, "escl sane_get_option_descriptor\n");
escl_sane_t *s = h; escl_sane_t *s = h;
if ((unsigned) n >= NUM_OPTIONS || n < 0) if ((unsigned) n >= NUM_OPTIONS || n < 0)
return (0); return (0);
return (&s->opt[n]); return (&s->opt[n]);
} }
/** /**
* \fn SANE_Status sane_control_option(SANE_Handle h, SANE_Int n, SANE_Action a, void *v, SANE_Int *i) * \fn SANE_Status sane_control_option(SANE_Handle h, SANE_Int n, SANE_Action a, void *v, SANE_Int *i)
* \brief Function that defines the actions to perform for the 'n' option of the machine, * \brief Function that defines the actions to perform for the 'n' option of the machine,
* represented by 'h', if the action is 'a'. * represented by 'h', if the action is 'a'.
@ -668,9 +668,9 @@ sane_get_option_descriptor(SANE_Handle h, SANE_Int n)
* *
* \return SANE_STATUS_GOOD if everything is OK, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL * \return SANE_STATUS_GOOD if everything is OK, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL
*/ */
SANE_Status SANE_Status
sane_control_option(SANE_Handle h, SANE_Int n, SANE_Action a, void *v, SANE_Int *i) sane_control_option(SANE_Handle h, SANE_Int n, SANE_Action a, void *v, SANE_Int *i)
{ {
DBG (10, "escl sane_control_option\n"); DBG (10, "escl sane_control_option\n");
escl_sane_t *handler = h; escl_sane_t *handler = h;
@ -735,18 +735,18 @@ sane_control_option(SANE_Handle h, SANE_Int n, SANE_Action a, void *v, SANE_Int
} }
} }
return (SANE_STATUS_GOOD); return (SANE_STATUS_GOOD);
} }
/** /**
* \fn SANE_Status sane_start(SANE_Handle h) * \fn SANE_Status sane_start(SANE_Handle h)
* \brief Function that initiates aquisition of an image from the device represented by handle 'h'. * \brief Function that initiates aquisition of an image from the device represented by handle 'h'.
* This function calls the "escl_newjob" function and the "escl_scan" function. * This function calls the "escl_newjob" function and the "escl_scan" function.
* *
* \return status (if everything is OK, status = SANE_STATUS_GOOD, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL) * \return status (if everything is OK, status = SANE_STATUS_GOOD, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL)
*/ */
SANE_Status SANE_Status
sane_start(SANE_Handle h) sane_start(SANE_Handle h)
{ {
DBG (10, "escl sane_start\n"); DBG (10, "escl sane_start\n");
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status = SANE_STATUS_GOOD;
escl_sane_t *handler = h; escl_sane_t *handler = h;
@ -843,6 +843,7 @@ sane_start(SANE_Handle h)
DBG(10, "2-Size Image [%dx%d|%dx%d]\n", 0, 0, w, he); DBG(10, "2-Size Image [%dx%d|%dx%d]\n", 0, 0, w, he);
if (handler->scanner->source > 0) if (handler->scanner->source > 0)
escl_scanner(handler->name, handler->result); escl_scanner(handler->name, handler->result);
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
return (status); return (status);
handler->ps.depth = 8; handler->ps.depth = 8;