Added support for sanei_thread. Removed OS/2 specific code.

Added more debug messages.
merge-requests/1/head
Henning Geinitz 2003-10-29 10:45:33 +00:00
rodzic 741da182e2
commit c0340511f0
5 zmienionych plików z 84 dodań i 76 usunięć

Wyświetl plik

@ -345,6 +345,7 @@ libsane-mustek.la: ../sanei/sanei_config2.lo
libsane-mustek.la: ../sanei/sanei_constrain_value.lo libsane-mustek.la: ../sanei/sanei_constrain_value.lo
libsane-mustek.la: ../sanei/sanei_scsi.lo libsane-mustek.la: ../sanei/sanei_scsi.lo
libsane-mustek.la: ../sanei/sanei_ab306.lo libsane-mustek.la: ../sanei/sanei_ab306.lo
libsane-mustek.la: ../sanei/sanei_thread.lo
libsane-mustek_pp.la: ../sanei/sanei_constrain_value.lo libsane-mustek_pp.la: ../sanei/sanei_constrain_value.lo
libsane-mustek_pp.la: ../sanei/sanei_pa4s2.lo libsane-mustek_pp.la: ../sanei/sanei_pa4s2.lo
libsane-mustek_pp_ccd.la: ../sanei/sanei_constrain_value.lo libsane-mustek_pp_ccd.la: ../sanei/sanei_constrain_value.lo

Wyświetl plik

@ -46,7 +46,7 @@
/**************************************************************************/ /**************************************************************************/
/* Mustek backend version */ /* Mustek backend version */
#define BUILD 133 #define BUILD 134
/**************************************************************************/ /**************************************************************************/
#include "../include/sane/config.h" #include "../include/sane/config.h"
@ -63,16 +63,13 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h>
#include "../include/sane/sane.h" #include "../include/sane/sane.h"
#include "../include/sane/sanei.h" #include "../include/sane/sanei.h"
#include "../include/sane/saneopts.h" #include "../include/sane/saneopts.h"
#include "../include/sane/sanei_scsi.h" #include "../include/sane/sanei_scsi.h"
#include "../include/sane/sanei_ab306.h" #include "../include/sane/sanei_ab306.h"
#ifdef HAVE_OS2_H
#include "../include/sane/sanei_thread.h" #include "../include/sane/sanei_thread.h"
#endif
#define BACKEND_NAME mustek #define BACKEND_NAME mustek
#include "../include/sane/sanei_backend.h" #include "../include/sane/sanei_backend.h"
@ -2867,37 +2864,31 @@ do_stop (Mustek_Scanner * s)
/* ensure child knows it's time to stop: */ /* ensure child knows it's time to stop: */
DBG (5, "do_stop: terminating reader process\n"); DBG (5, "do_stop: terminating reader process\n");
kill (s->reader_pid, SIGTERM); sanei_thread_kill (s->reader_pid);
pid = waitpid (s->reader_pid, &exit_status, 0); pid = sanei_thread_waitpid (s->reader_pid, &exit_status);
if (pid < 0) if (pid < 0)
{ {
DBG (1, "do_stop: waitpid failed, already terminated? (%s)\n", DBG (1, "do_stop: sanei_thread_waitpid failed, already terminated? (%s)\n",
strerror (errno)); strerror (errno));
} }
else if (WIFEXITED (exit_status)) else
{ {
DBG (2, "do_stop: reader process terminated with status %s\n", DBG (2, "do_stop: reader process terminated with status %s\n",
sane_strstatus (WEXITSTATUS (exit_status))); sane_strstatus (exit_status));
if (status != SANE_STATUS_CANCELLED if (status != SANE_STATUS_CANCELLED
&& WEXITSTATUS (exit_status) != SANE_STATUS_GOOD) && exit_status != SANE_STATUS_GOOD)
status = WEXITSTATUS (exit_status); status = exit_status;
} }
else if (WIFSIGNALED (status))
{
DBG (2, "do_stop: reader process was terminated by signal %d\n",
WTERMSIG (exit_status));
if (WTERMSIG (exit_status) != 15)
status = SANE_STATUS_IO_ERROR;
}
else
DBG (1, "do_stop: reader process terminated by unknown reason\n");
s->reader_pid = 0; s->reader_pid = 0;
} }
if (s->fd >= 0) if (s->fd >= 0)
{ {
if (!sanei_thread_is_forked())
sanei_scsi_req_flush_all (); /* flush SCSI queue */
if (s->hw->flags & MUSTEK_FLAG_PRO) if (s->hw->flags & MUSTEK_FLAG_PRO)
{ {
if (s->total_bytes < s->params.lines * s->params.bytes_per_line) if (s->total_bytes < s->params.lines * s->params.bytes_per_line)
@ -2922,29 +2913,17 @@ do_stop (Mustek_Scanner * s)
DBG (5, "do_stop: waiting for scanner to be ready\n"); DBG (5, "do_stop: waiting for scanner to be ready\n");
dev_wait_ready (s); dev_wait_ready (s);
} }
do_eof (s);
DBG (5, "do_stop: closing scanner\n"); DBG (5, "do_stop: closing scanner\n");
dev_close (s); dev_close (s);
s->fd = -1; s->fd = -1;
} }
DBG (5, "do_stop: finished\n");
return status; return status;
} }
#ifdef HAVE_OS2_H
/*
* reader thread for OS/2: need a wrapper, because threads can have
* only one parameter.
*/
static void
os2_reader_process (void *data)
{
struct Mustek_Scanner *scanner = (struct Mustek_Scanner *) data;
DBG (1, "reader_process thread started\n");
reader_process (scanner, scanner->reader_fds);
}
#endif
/* Paragon I + II: Determine the CCD's distance between the primary color /* Paragon I + II: Determine the CCD's distance between the primary color
lines. */ lines. */
static SANE_Status static SANE_Status
@ -4712,21 +4691,24 @@ output_data (Mustek_Scanner * s, FILE * fp,
static RETSIGTYPE static RETSIGTYPE
sigterm_handler (int signal) sigterm_handler (int signal)
{ {
DBG (5, "sigterm_handler: started, signal is %d, starting sanei_scsi_req_flush_all()\n", signal); DBG (4, "sigterm_handler: started, signal is %d, starting sanei_scsi_req_flush_all()\n", signal);
sanei_scsi_req_flush_all (); /* flush SCSI queue */ sanei_scsi_req_flush_all (); /* flush SCSI queue */
DBG (5, "sigterm_handler: sanei_scsi_req_flush_all() finisheshed, _exiting()\n"); DBG (4, "sigterm_handler: sanei_scsi_req_flush_all() finisheshed, _exiting()\n");
_exit (SANE_STATUS_GOOD); _exit (SANE_STATUS_GOOD);
} }
static SANE_Int static SANE_Int
reader_process (Mustek_Scanner * s, SANE_Int fd) reader_process (void * data)
{ {
Mustek_Scanner * s = (Mustek_Scanner *) data;
SANE_Int lines_per_buffer, bpl; SANE_Int lines_per_buffer, bpl;
SANE_Byte *extra = 0, *ptr; SANE_Byte *extra = 0, *ptr;
sigset_t sigterm_set; sigset_t sigterm_set;
struct SIGACTION act; struct SIGACTION act;
SANE_Status status; SANE_Status status;
FILE *fp; FILE *fp;
int fd = s->reader_fds;
SANE_Int buffernumber = 0; SANE_Int buffernumber = 0;
SANE_Int buffer_count, max_buffers; SANE_Int buffer_count, max_buffers;
struct struct
@ -4742,13 +4724,34 @@ reader_process (Mustek_Scanner * s, SANE_Int fd)
} }
bstat[2]; bstat[2];
DBG (3, "reader_process: started\n");
if (sanei_thread_is_forked())
{
DBG (4, "reader_process: using fork ()\n");
close (s->pipe);
s->pipe = -1;
}
else
{
DBG (4, "reader_process: using threads\n");
}
if (sanei_thread_is_forked())
{
/* ignore SIGTERM while writing SCSI commands */
sigemptyset (&sigterm_set);
sigaddset (&sigterm_set, SIGTERM);
/* call our sigterm handler to clean up ongoing SCSI requests */
memset (&act, 0, sizeof (act));
act.sa_handler = sigterm_handler;
sigaction (SIGTERM, &act, 0);
}
if (disable_double_buffering) if (disable_double_buffering)
DBG (3, "reader_process: disable_double_buffering is set, this may be " DBG (3, "reader_process: disable_double_buffering is set, this may be "
"slow\n"); "slow\n");
sigemptyset (&sigterm_set);
sigaddset (&sigterm_set, SIGTERM);
fp = fdopen (fd, "w"); fp = fdopen (fd, "w");
if (!fp) if (!fp)
return SANE_STATUS_IO_ERROR; return SANE_STATUS_IO_ERROR;
@ -4831,10 +4834,6 @@ reader_process (Mustek_Scanner * s, SANE_Int fd)
} }
} }
memset (&act, 0, sizeof (act));
act.sa_handler = sigterm_handler;
sigaction (SIGTERM, &act, 0);
if (s->hw->flags & MUSTEK_FLAG_N) if (s->hw->flags & MUSTEK_FLAG_N)
{ {
/* reacquire port access rights (lost because of fork()): */ /* reacquire port access rights (lost because of fork()): */
@ -5043,6 +5042,8 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
DBG_INIT (); DBG_INIT ();
sanei_thread_init ();
#ifdef DBG_LEVEL #ifdef DBG_LEVEL
debug_level = DBG_LEVEL; debug_level = DBG_LEVEL;
#else #else
@ -5424,6 +5425,7 @@ sane_exit (void)
devlist = 0; devlist = 0;
first_dev = 0; first_dev = 0;
sanei_ab306_exit (); /* may have to do some cleanup */ sanei_ab306_exit (); /* may have to do some cleanup */
DBG (5, "sane_exit: finished\n");
} }
SANE_Status SANE_Status
@ -5555,6 +5557,7 @@ sane_close (SANE_Handle handle)
first_handle = s->next; first_handle = s->next;
free (handle); free (handle);
handle = 0; handle = 0;
DBG (5, "sane_close: finished\n");
} }
const SANE_Option_Descriptor * const SANE_Option_Descriptor *
@ -6072,6 +6075,7 @@ sane_start (SANE_Handle handle)
Mustek_Scanner *s = handle; Mustek_Scanner *s = handle;
SANE_Status status; SANE_Status status;
int fds[2]; int fds[2];
struct SIGACTION act;
if (!s) if (!s)
{ {
@ -6374,38 +6378,33 @@ sane_start (SANE_Handle handle)
s->line = 0; s->line = 0;
/* don't call any SIGTERM or SIGCHLD handlers
this is to stop xsane and other frontends from calling
its quit handlers */
memset (&act, 0, sizeof (act));
sigaction (SIGTERM, &act, 0);
sigaction (SIGCHLD, &act, 0);
if (pipe (fds) < 0) if (pipe (fds) < 0)
return SANE_STATUS_IO_ERROR; return SANE_STATUS_IO_ERROR;
#ifndef HAVE_OS2_H
s->reader_pid = fork ();
#else
/* create reader routine as new process or thread */
s->reader_fds = fds[1]; s->reader_fds = fds[1];
s->reader_pid = sanei_thread_begin (os2_reader_process, (void *) s);
#endif /* create reader routine as new process or thread */
if (s->reader_pid == 0) s->reader_pid = sanei_thread_begin (reader_process, (void *) s);
if (s->reader_pid < 0)
{ {
SANE_Int status; DBG (1, "sane_start: sanei_thread_begin failed (%s)\n", strerror(errno));
sigset_t ignore_set; return SANE_STATUS_NO_MEM;
struct SIGACTION act;
close (fds[0]);
sigfillset (&ignore_set);
sigdelset (&ignore_set, SIGTERM);
sigprocmask (SIG_SETMASK, &ignore_set, 0);
memset (&act, 0, sizeof (act));
sigaction (SIGTERM, &act, 0);
status = reader_process (s, fds[1]);
/* don't use exit() since that would run the atexit() handlers... */
_exit (status);
} }
#ifndef HAVE_OS2_H
close (fds[1]); if (sanei_thread_is_forked ())
#endif {
close (s->reader_fds);
s->reader_fds = -1;
}
s->pipe = fds[0]; s->pipe = fds[0];
return SANE_STATUS_GOOD; return SANE_STATUS_GOOD;
@ -6545,7 +6544,7 @@ sane_cancel (SANE_Handle handle)
s->cancelled = SANE_TRUE; s->cancelled = SANE_TRUE;
do_stop (handle); do_stop (handle);
} }
DBG (4, "sane_cancel finished\n"); DBG (5, "sane_cancel: finished\n");
} }
SANE_Status SANE_Status

Wyświetl plik

@ -269,9 +269,7 @@ typedef struct Mustek_Scanner
SANE_Int resolution_code; SANE_Int resolution_code;
int fd; /* SCSI filedescriptor */ int fd; /* SCSI filedescriptor */
pid_t reader_pid; /* process id of reader */ pid_t reader_pid; /* process id of reader */
#ifdef HAVE_OS2_H
int reader_fds; /* OS/2: pipe write handler for reader */ int reader_fds; /* OS/2: pipe write handler for reader */
#endif
int pipe; /* pipe to reader process */ int pipe; /* pipe to reader process */
long start_time; /* at this time the scan started */ long start_time; /* at this time the scan started */
SANE_Word total_bytes; /* bytes transmitted by sane_read */ SANE_Word total_bytes; /* bytes transmitted by sane_read */

Wyświetl plik

@ -9,7 +9,7 @@
; ;
:backend "mustek" ; name of backend :backend "mustek" ; name of backend
:version "1.0-133" ; version of backend :version "1.0-134" ; version of backend
:manpage "sane-mustek" ; name of manpage (if it exists) :manpage "sane-mustek" ; name of manpage (if it exists)
:url "http://www.meier-geinitz.de/sane/mustek-backend/" :url "http://www.meier-geinitz.de/sane/mustek-backend/"
:comment "Most Mustek SCSI scanners are supported by this backend. For USB scanners, look at the mustek_usb backend." :comment "Most Mustek SCSI scanners are supported by this backend. For USB scanners, look at the mustek_usb backend."

Wyświetl plik

@ -1,5 +1,15 @@
CHANGES for the SANE Mustek backend CHANGES for the SANE Mustek backend
2003-10-29
* Released Mustek backend 1.0-134
2003-10-29
* Added support for sanei_thread.
* Removed OS/2 specific code.
2003-10-15
* Added more debug messages.
2003-09-21 2003-09-21
* Released Mustek backend 1.0-133 * Released Mustek backend 1.0-133