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;
|
||||
|
||||
/**
|
||||
* \fn static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, 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.
|
||||
* \fn static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED
|
||||
* AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol,
|
||||
* 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
|
||||
resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, 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)
|
||||
resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface,
|
||||
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;
|
||||
assert(r);
|
||||
|
@ -53,19 +66,26 @@ resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interfac
|
|||
case AVAHI_RESOLVER_FOUND:
|
||||
avahi_address_snprint(a, sizeof(a), address);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \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)
|
||||
* \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
|
||||
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)
|
||||
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)
|
||||
{
|
||||
AvahiClient *c = userdata;
|
||||
assert(b);
|
||||
|
@ -74,7 +94,10 @@ browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol pr
|
|||
avahi_simple_poll_quit(simple_poll);
|
||||
return;
|
||||
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;
|
||||
case AVAHI_BROWSER_REMOVE:
|
||||
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)
|
||||
* \brief Callback Function that quit if it doesn't find a connected scanner, possible thanks the "Hello Protocol".
|
||||
* \fn static void client_callback(AvahiClient *c, AvahiClientState state,
|
||||
* 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.
|
||||
*/
|
||||
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);
|
||||
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)
|
||||
* \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.
|
||||
*
|
||||
* \return NULL (the eSCL devices found)
|
||||
|
@ -119,19 +146,27 @@ escl_devices(SANE_Status *status)
|
|||
*status = SANE_STATUS_INVAL;
|
||||
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) {
|
||||
fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error));
|
||||
*status = SANE_STATUS_INVAL;
|
||||
goto fail;
|
||||
}
|
||||
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, 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)));
|
||||
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC,
|
||||
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;
|
||||
goto fail;
|
||||
}
|
||||
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, 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)));
|
||||
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC,
|
||||
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;
|
||||
goto fail;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue