2008-10-25 Louis Lagendijk <llagendijk-guest at users.alioth.debian.org>

* Added configuration  file support for pixma backend
        Currently used only for configuration of network scanners.
merge-requests/1/head
Louis Lagendijk 2008-10-25 14:56:11 +00:00
rodzic 677e4e5dd5
commit 69c9248356
11 zmienionych plików z 158 dodań i 67 usunięć

Wyświetl plik

@ -1,3 +1,7 @@
2008-10-25 Louis Lagendijk <llagendijk-guest at users.alioth.debian.org>
* Added configuration file support for pixma backend
Currently used only for configuration of network scanners.
2008-10-22 Nicolas Martin <nicols-guest at users.alioth.debian.org>
* backend/pixma.c, backend/pixma_io_sanei.c, backend/pixma_mp150.c:
TPU scanning in 48 bits mode now works fine on MP970, with Xsane or

Wyświetl plik

@ -166,7 +166,7 @@ DISTFILES = Makefile.in saned.conf.in sane_strstatus.c stubs.c \
pixma.c pixma.h pixma_common.c pixma_common.h pixma_mp150.c pixma_mp730.c \
pixma_mp750.c pixma_sane_options.c pixma_sane_options.h pixma_io.h \
pixma_io_sanei.c pixma_rename.h pixma_imageclass.c \
pixma_bjnp.c pixma_bjnp.h pixma_bjnp_private.h \
pixma_bjnp.c pixma_bjnp.h pixma_bjnp_private.h pixma.conf.in\
plustek.c plustek.conf.in plustek-usbdevs.c plustek.h plustek-usb.c \
plustek-usb.h plustek-usbhw.c plustek-usbimg.c plustek-usbio.c \
plustek-usbmap.c plustek-usbscan.c plustek-usbshading.c plustek-usbcalfile.c \

Wyświetl plik

@ -64,6 +64,7 @@
# include "../include/sane/saneopts.h"
# include "../include/sane/sanei_thread.h"
# include "../include/sane/sanei_backend.h"
# include "../include/sane/sanei_config.h"
#ifdef NDEBUG
# define PDBG(x)
@ -121,7 +122,22 @@ static const char type_str[] = "multi-function peripheral";
static pixma_sane_t *first_scanner = NULL;
static const SANE_Device **dev_list = NULL;
static const char* conf_devices[MAX_CONF_DEVICES];
static SANE_Status config_attach_pixma(SANEI_Config * config, const char *devname)
{
int i;
UNUSED(config);
for (i=0; i < (MAX_CONF_DEVICES -1); i++)
{
if(conf_devices[i] == NULL)
{
conf_devices[i] = strdup(devname);
return SANE_STATUS_GOOD;
}
}
return SANE_STATUS_INVAL;
}
static SANE_Status
map_error (int error)
@ -191,7 +207,7 @@ find_scanners (void)
unsigned i, nscanners;
cleanup_device_list ();
nscanners = pixma_find_scanners ();
nscanners = pixma_find_scanners (conf_devices);
PDBG (pixma_dbg (3, "pixma_find_scanners() found %u devices\n", nscanners));
dev_list =
(const SANE_Device **) calloc (nscanners + 1, sizeof (*dev_list));
@ -988,7 +1004,8 @@ read_image (pixma_sane_t * ss, void *buf, unsigned size, int *readlen)
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
int status, myversion;
int status, myversion, i;
SANEI_Config config;
UNUSED (authorize);
@ -1000,6 +1017,18 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
sanei_thread_init ();
pixma_set_debug_level (DBG_LEVEL);
for (i = 0; i < MAX_CONF_DEVICES; i++)
conf_devices[i] = NULL;
config.count = 0;
config.descriptors = NULL;
config.values = NULL;
if (sanei_configure_attach(PIXMA_CONFIG_FILE, &config, config_attach_pixma) !=
SANE_STATUS_GOOD)
PDBG(pixma_dbg(2, "Could not read pixma configuration file: %s\n",
PIXMA_CONFIG_FILE));
status = pixma_init ();
if (status < 0)
{
@ -1041,7 +1070,7 @@ sane_open (SANE_String_Const name, SANE_Handle * h)
return SANE_STATUS_INVAL;
*h = NULL;
nscanners = pixma_find_scanners ();
nscanners = pixma_find_scanners (conf_devices);
if (nscanners == 0)
return SANE_STATUS_INVAL;
if (name[0] == '\0')

Wyświetl plik

@ -0,0 +1,14 @@
# pixma.conf configuration for the sane pixma backend
#
# define URI's of scanners (one per line)
# This is only used for network scanners.
# normally scanners will be detected by sending a broadcast
# if this does not work under your OS, or if the scanners
# are on a different subnet, configure your scanners URI here
#
# method must be bjnp
# port number can normally be left out, port 8612 is used as default
# Example:
# bjnp://myscanner.my.domain:8612
# bjnp://printer-1.pheasant.org
#

Wyświetl plik

@ -153,6 +153,8 @@ typedef u_int32_t uint32_t;
/**@}*/
/** @} end of API group */
#define PIXMA_CONFIG_FILE "pixma.conf"
#define MAX_CONF_DEVICES 15
struct pixma_t;
struct pixma_scan_ops_t;
@ -316,7 +318,7 @@ void pixma_set_debug_level (int level);
*
* \return The number of scanners found currently. The return value is
* guaranteed to be valid until the next call to pixma_find_scanners(). */
int pixma_find_scanners (void);
int pixma_find_scanners (const char **conf_devices);
/** Return the model name of the device \a devnr. */
const char *pixma_get_device_model (unsigned devnr);

Wyświetl plik

@ -54,38 +54,38 @@
#include <unistd.h>
#include <stdio.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#include <stdint.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/timeb.h>
#include <sys/timeb.h>
#endif
/*
* networking stuff
*/
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#include <netinet/in.h>
#endif
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <net/if.h>
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
#endif
#ifdef HAVE_SYS_SELSECT_H
#include <sys/select.h>
#endif
#include <errno.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#include <fcntl.h>
#endif
#include "pixma_bjnp_private.h"
#include "pixma_bjnp.h"
@ -522,7 +522,7 @@ parse_scanner_address (char *resp_buf, char *address, char *serial)
/* do reverse name lookup, if hostname can not be fouund return ip-address */
res = inet_aton (ip_address, &ip_addr);
myhost = gethostbyaddr ((void *)&ip_addr, sizeof (ip_addr), AF_INET);
myhost = gethostbyaddr ((void *) &ip_addr, sizeof (ip_addr), AF_INET);
if (myhost == NULL)
strcpy (address, ip_address);
@ -805,7 +805,7 @@ bjnp_write (int devno, const SANE_Byte * buf, size_t count)
if ((sent_bytes =
send (device[devno].fd, &bjnp_buf,
sizeof (struct BJNP_command) + count, 0)) <
sizeof (struct BJNP_command) + count, 0)) <
(ssize_t) (sizeof (struct BJNP_command) + count))
{
/* return result from write */
@ -850,7 +850,8 @@ bjnp_send_read_request (int devno)
sizeof (struct BJNP_command));
if ((sent_bytes =
send (device[devno].fd, &bjnp_buf, sizeof (struct BJNP_command), 0)) < 0)
send (device[devno].fd, &bjnp_buf, sizeof (struct BJNP_command),
0)) < 0)
{
/* return result from write */
terrno = errno;
@ -909,7 +910,8 @@ bjnp_recv_header (int devno)
if ((recv_bytes =
recv (fd, (char *) &resp_buf,
sizeof (struct BJNP_command), 0)) != sizeof (struct BJNP_command))
sizeof (struct BJNP_command),
0)) != sizeof (struct BJNP_command))
{
terrno = errno;
PDBG (pixma_dbg (LOG_CRIT,
@ -1043,10 +1045,10 @@ sanei_bjnp_attach (SANE_String_Const devname, SANE_Int * dn)
* TODO: implement scanning of ALL returned addressess
*/
result = gethostbyname(hostname);
result = gethostbyname (hostname);
if ((result == NULL) || result->h_addrtype != AF_INET)
{
PDBG (pixma_dbg (LOG_CRIT, "Cannot resolve hostname: %s", hostname));
PDBG (pixma_dbg (LOG_CRIT, "Cannot resolve hostname: %s\n", hostname));
return SANE_STATUS_INVAL;
}
if (port == 0)
@ -1054,7 +1056,9 @@ sanei_bjnp_attach (SANE_String_Const devname, SANE_Int * dn)
port = BJNP_PORT_SCAN;
}
addr_list = (struct in_addr *) *result->h_addr_list;
device[*dn].fd = -1;
addr_list = (struct in_addr *) *result->h_addr_list;
device[*dn].addr.sin_family = AF_INET;
device[*dn].addr.sin_port = htons (port);
device[*dn].addr.sin_addr = addr_list[0];
@ -1109,7 +1113,8 @@ sanei_bjnp_init (void)
* @return SANE_STATUS_GOOD - on success (even if no scanner was found)
*/
extern SANE_Status
sanei_bjnp_find_devices (SANE_Status (*attach_bjnp)
sanei_bjnp_find_devices (const char **conf_devices,
SANE_Status (*attach_bjnp)
(SANE_String_Const devname,
SANE_String_Const makemodel,
SANE_String_Const serial,
@ -1161,58 +1166,61 @@ sanei_bjnp_find_devices (SANE_Status (*attach_bjnp)
/* send broadcast packet to each suitable interface */
if ((interface->ifa_addr->sa_family != AF_INET) ||
(((struct sockaddr_in *)interface->ifa_addr)->sin_addr.s_addr == htonl (INADDR_LOOPBACK)))
{
/* not an IPv4 address */
(((struct sockaddr_in *) interface->ifa_addr)->sin_addr.s_addr ==
htonl (INADDR_LOOPBACK)))
{
/* not an IPv4 address */
PDBG (pixma_dbg (LOG_DEBUG, "%s is not a valid IPv4 interface, skipping...\n",
interface->ifa_name));
PDBG (pixma_dbg
(LOG_DEBUG, "%s is not a valid IPv4 interface, skipping...\n",
interface->ifa_name));
}
else
{
PDBG (pixma_dbg (LOG_INFO, "%s is IPv4 capable, sending broadcast..\n",
interface->ifa_name));
}
else
{
PDBG (pixma_dbg
(LOG_INFO, "%s is IPv4 capable, sending broadcast..\n",
interface->ifa_name));
if ((socket_fd[no_sockets] =
bjnp_send_broadcast (((struct sockaddr_in *) interface->ifa_broadaddr)->sin_addr,
cmd, sizeof (cmd))) != -1)
{
if (socket_fd[no_sockets] > last_socketfd)
{
/* track highest used socket for use in select */
if ((socket_fd[no_sockets] =
bjnp_send_broadcast (((struct sockaddr_in *) interface->
ifa_broadaddr)->sin_addr, cmd,
sizeof (cmd))) != -1)
{
if (socket_fd[no_sockets] > last_socketfd)
{
/* track highest used socket for use in select */
last_socketfd = socket_fd[no_sockets];
}
FD_SET (socket_fd[no_sockets], &fdset);
no_sockets++;
}
}
last_socketfd = socket_fd[no_sockets];
}
FD_SET (socket_fd[no_sockets], &fdset);
no_sockets++;
}
}
interface = interface->ifa_next;
}
freeifaddrs (interfaces);
#else
/* we have no easy way to find interfaces with their broadcast addresses, use global broadcast */
no_sockets = 0;
no_sockets = 0;
broadcast.s_addr = INADDR_BROADCAST;
if ((socket_fd[no_sockets] =
bjnp_send_broadcast (broadcast,
cmd, sizeof (cmd))) != -1)
bjnp_send_broadcast (broadcast, cmd, sizeof (cmd))) != -1)
{
if (socket_fd[no_sockets] > last_socketfd)
{
/* track highest used socket for use in select */
{
/* track highest used socket for use in select */
last_socketfd = socket_fd[no_sockets];
}
last_socketfd = socket_fd[no_sockets];
}
FD_SET (socket_fd[no_sockets], &fdset);
no_sockets++;
}
#endif
/* wait for up to 1 second for a UDP response */
timeout.tv_sec = 1;
@ -1278,7 +1286,6 @@ sanei_bjnp_find_devices (SANE_Status (*attach_bjnp)
* inform caller of found scanner
*/
attach_bjnp (uri, makemodel, serial, pixma_devices);
/* no longer required: sanei_bjnp_close(dev_no); */
num_scanners++;
}
}
@ -1292,6 +1299,38 @@ sanei_bjnp_find_devices (SANE_Status (*attach_bjnp)
for (i = 0; i < no_sockets; i++)
close (socket_fd[i]);
/* add pre-configures devices */
for (i = 0; conf_devices[i] != NULL; i++)
{
PDBG (pixma_dbg
(LOG_DEBUG, "Adding pre-configured scanner: %s\n",
conf_devices[i]));
/* Test scanner connection by attaching it and reading its IEEE1284 id */
if ((result = sanei_bjnp_attach (conf_devices[i], &dev_no)) != SANE_STATUS_GOOD)
{
PDBG (pixma_dbg
(LOG_NOTICE,
"Scanner at %s defined in configuration file, but can not open it\n",
uri));
}
else
{
if (get_scanner_id (dev_no, makemodel, IEEE1284_id) != 0)
{
PDBG (pixma_dbg
(LOG_CRIT,
"Cannot read scanner make & model: %s\n", uri));
return SANE_STATUS_INVAL;
}
/*
* inform caller of found scanner
*/
attach_bjnp (conf_devices[i], makemodel, serial, pixma_devices);
num_scanners++;
}
}
return SANE_STATUS_GOOD;
}
@ -1349,8 +1388,9 @@ void
sanei_bjnp_close (SANE_Int dn)
{
PDBG (pixma_dbg (LOG_INFO, "sanei_bjnp_close(%d):\n", dn));
device[dn].open = 0;
bjnp_finish_job (dn);
close(device[dn].fd);
device[dn].fd = -1;
}
/** Set the timeout for bulk and interrupt reads.

Wyświetl plik

@ -67,12 +67,15 @@ extern void sanei_bjnp_init (void);
*
* The function attach is called for every device which has been found.
*
* @param conf_devices lsit of pre-configures device URI's to attach
* @param attach attach function
* @param pixma_devices device informatio needed by attach function
*
* @return SANE_STATUS_GOOD - on success (even if no scanner was found)
*/
extern SANE_Status
sanei_bjnp_find_devices (SANE_Status (*attach_bjnp)
sanei_bjnp_find_devices (const char **conf_devices,
SANE_Status (*attach_bjnp)
(SANE_String_Const devname,
SANE_String_Const makemodel,
SANE_String_Const serial,

Wyświetl plik

@ -200,11 +200,8 @@ typedef enum bjnp_paper_status_e
typedef struct device_s
{
char open; /* device state open/closed */
int fd; /* file descriptor */
struct sockaddr_in addr;
char makemodel[BJNP_MODEL_MAX]; /* make & model reported by the scanner */
char IEEE1284_id[BJNP_IEEE1284_MAX]; /* IEEE1284 string reported by scanner */
int session_id; /* session id used in bjnp protocol for TCP packets */
uint32_t serial; /* sequence number of command */
int bjnp_timeout_sec; /* timeout (seconds) for next command */

Wyświetl plik

@ -1,4 +1,4 @@
/* SANE - Scanner Access Now Easy.
/** SANE - Scanner Access Now Easy.
Copyright (C) 2007-2008 Nicolas Martin, <nicols-guest at alioth dot debian dot org>
Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de>
@ -856,9 +856,9 @@ pixma_fill_gamma_table (double gamma, uint8_t * table, unsigned n)
}
int
pixma_find_scanners (void)
pixma_find_scanners (const char **conf_devices)
{
return pixma_collect_devices (pixma_devices);
return pixma_collect_devices (conf_devices, pixma_devices);
}
const char *

Wyświetl plik

@ -91,7 +91,8 @@ void pixma_io_cleanup (void);
* array of pixma_config_t which is terminated by setting
* pixma_config_t::name to \c NULL.
* \return Number of devices found */
unsigned pixma_collect_devices (const struct pixma_config_t *const
unsigned pixma_collect_devices (const char ** conf_devices,
const struct pixma_config_t *const
pixma_devices[]);
/** Get device configuration. */

Wyświetl plik

@ -325,7 +325,8 @@ pixma_io_cleanup (void)
}
unsigned
pixma_collect_devices (const struct pixma_config_t *const pixma_devices[])
pixma_collect_devices (const char **conf_devices,
const struct pixma_config_t *const pixma_devices[])
{
unsigned i, j;
struct scanner_info_t *si;
@ -350,7 +351,7 @@ pixma_collect_devices (const struct pixma_config_t *const pixma_devices[])
}
}
}
sanei_bjnp_find_devices(attach_bjnp, pixma_devices);
sanei_bjnp_find_devices(conf_devices, attach_bjnp, pixma_devices);
si = first_scanner;
while (j < nscanners)
{