kopia lustrzana https://gitlab.com/sane-project/backends
Merge branch 'escl-discovery' into 'master'
Solves the problem of HP device discovery. See merge request sane-project/backends!285merge-requests/213/head
commit
bac0c4abce
|
@ -37,13 +37,26 @@
|
||||||
static AvahiSimplePoll *simple_poll = NULL;
|
static AvahiSimplePoll *simple_poll = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiResolverEvent event, const char *name,
|
* \fn static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED
|
||||||
* const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void *userdata)
|
* AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol,
|
||||||
* \brief Callback function that will check if the selected scanner follows the escl protocol or not.
|
* AvahiResolverEvent event, const char *name,
|
||||||
|
* const char *type, const char *domain, const char *host_name,
|
||||||
|
* const AvahiAddress *address, uint16_t port,
|
||||||
|
* AvahiStringList *txt, AvahiLookupResultFlags flags,
|
||||||
|
* void *userdata)
|
||||||
|
* \brief Callback function that will check if the selected scanner follows the escl
|
||||||
|
* protocol or not.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiResolverEvent event, const char *name,
|
resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface,
|
||||||
const char __sane_unused__ *type, const char __sane_unused__ *domain, const char __sane_unused__ *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags __sane_unused__ flags, void __sane_unused__ *userdata)
|
AVAHI_GCC_UNUSED AvahiProtocol protocol,
|
||||||
|
AvahiResolverEvent event, const char *name,
|
||||||
|
const char __sane_unused__ *type,
|
||||||
|
const char __sane_unused__ *domain,
|
||||||
|
const char __sane_unused__ *host_name,
|
||||||
|
const AvahiAddress *address, uint16_t port, AvahiStringList *txt,
|
||||||
|
AvahiLookupResultFlags __sane_unused__ flags,
|
||||||
|
void __sane_unused__ *userdata)
|
||||||
{
|
{
|
||||||
char a[AVAHI_ADDRESS_STR_MAX], *t;
|
char a[AVAHI_ADDRESS_STR_MAX], *t;
|
||||||
assert(r);
|
assert(r);
|
||||||
|
@ -53,19 +66,26 @@ resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interfac
|
||||||
case AVAHI_RESOLVER_FOUND:
|
case AVAHI_RESOLVER_FOUND:
|
||||||
avahi_address_snprint(a, sizeof(a), address);
|
avahi_address_snprint(a, sizeof(a), address);
|
||||||
t = avahi_string_list_to_string(txt);
|
t = avahi_string_list_to_string(txt);
|
||||||
if (strstr(t, "\"rs=eSCL\""))
|
if (strstr(t, "\"rs=eSCL\"") || strstr(t, "\"rs=/eSCL\""))
|
||||||
escl_device_add(port, name, a, (char*)type);
|
escl_device_add(port, name, a, (char*)type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
|
* \fn static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface,
|
||||||
|
* AvahiProtocol protocol, AvahiBrowserEvent event, const char *name,
|
||||||
|
* const char *type, const char *domain,
|
||||||
* AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata)
|
* AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata)
|
||||||
* \brief Callback function that will browse tanks to 'avahi' the scanners connected in network.
|
* \brief Callback function that will browse tanks to 'avahi' the scanners
|
||||||
|
* connected in network.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain,
|
browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface,
|
||||||
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata)
|
AvahiProtocol protocol, AvahiBrowserEvent event,
|
||||||
|
const char *name, const char *type,
|
||||||
|
const char *domain,
|
||||||
|
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
|
||||||
|
void* userdata)
|
||||||
{
|
{
|
||||||
AvahiClient *c = userdata;
|
AvahiClient *c = userdata;
|
||||||
assert(b);
|
assert(b);
|
||||||
|
@ -74,7 +94,10 @@ browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol pr
|
||||||
avahi_simple_poll_quit(simple_poll);
|
avahi_simple_poll_quit(simple_poll);
|
||||||
return;
|
return;
|
||||||
case AVAHI_BROWSER_NEW:
|
case AVAHI_BROWSER_NEW:
|
||||||
if (!(avahi_service_resolver_new(c, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, c)))
|
if (!(avahi_service_resolver_new(c, interface, protocol, name,
|
||||||
|
type, domain,
|
||||||
|
AVAHI_PROTO_UNSPEC, 0,
|
||||||
|
resolve_callback, c)))
|
||||||
break;
|
break;
|
||||||
case AVAHI_BROWSER_REMOVE:
|
case AVAHI_BROWSER_REMOVE:
|
||||||
break;
|
break;
|
||||||
|
@ -87,12 +110,15 @@ browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol pr
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void *userdata)
|
* \fn static void client_callback(AvahiClient *c, AvahiClientState state,
|
||||||
* \brief Callback Function that quit if it doesn't find a connected scanner, possible thanks the "Hello Protocol".
|
* AVAHI_GCC_UNUSED void *userdata)
|
||||||
|
* \brief Callback Function that quit if it doesn't find a connected scanner,
|
||||||
|
* possible thanks the "Hello Protocol".
|
||||||
* --> Waiting for a answer by the scanner to continue the avahi process.
|
* --> Waiting for a answer by the scanner to continue the avahi process.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void *userdata)
|
client_callback(AvahiClient *c, AvahiClientState state,
|
||||||
|
AVAHI_GCC_UNUSED void *userdata)
|
||||||
{
|
{
|
||||||
assert(c);
|
assert(c);
|
||||||
if (state == AVAHI_CLIENT_FAILURE)
|
if (state == AVAHI_CLIENT_FAILURE)
|
||||||
|
@ -101,7 +127,8 @@ client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void *u
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn ESCL_Device *escl_devices(SANE_Status *status)
|
* \fn ESCL_Device *escl_devices(SANE_Status *status)
|
||||||
* \brief Function that calls all the avahi functions and then, recovers the connected eSCL devices.
|
* \brief Function that calls all the avahi functions and then, recovers the
|
||||||
|
* connected eSCL devices.
|
||||||
* This function is called in the 'sane_get_devices' function.
|
* This function is called in the 'sane_get_devices' function.
|
||||||
*
|
*
|
||||||
* \return NULL (the eSCL devices found)
|
* \return NULL (the eSCL devices found)
|
||||||
|
@ -119,19 +146,27 @@ escl_devices(SANE_Status *status)
|
||||||
*status = SANE_STATUS_INVAL;
|
*status = SANE_STATUS_INVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error);
|
client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0,
|
||||||
|
client_callback, NULL, &error);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error));
|
fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error));
|
||||||
*status = SANE_STATUS_INVAL;
|
*status = SANE_STATUS_INVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_uscan._tcp", NULL, 0, browse_callback, client))) {
|
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC,
|
||||||
fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client)));
|
AVAHI_PROTO_UNSPEC, "_uscan._tcp",
|
||||||
|
NULL, 0, browse_callback, client))) {
|
||||||
|
fprintf(stderr, "Failed to create service browser: %s\n",
|
||||||
|
avahi_strerror(avahi_client_errno(client)));
|
||||||
*status = SANE_STATUS_INVAL;
|
*status = SANE_STATUS_INVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_uscans._tcp", NULL, 0, browse_callback, client))) {
|
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC,
|
||||||
fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client)));
|
AVAHI_PROTO_UNSPEC,
|
||||||
|
"_uscans._tcp", NULL, 0,
|
||||||
|
browse_callback, client))) {
|
||||||
|
fprintf(stderr, "Failed to create service browser: %s\n",
|
||||||
|
avahi_strerror(avahi_client_errno(client)));
|
||||||
*status = SANE_STATUS_INVAL;
|
*status = SANE_STATUS_INVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue