kopia lustrzana https://gitlab.com/sane-project/backends
Switched backend over to sanei_thread usage, to make it work at least with OS/2.
rodzic
bd9dda41c7
commit
463debf80f
|
@ -1,6 +1,6 @@
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
/* sane - Scanner Access Now Easy.
|
/* sane - Scanner Access Now Easy.
|
||||||
coolscan.c , version 0.4.3
|
coolscan.c , version 0.4.4
|
||||||
|
|
||||||
This file is part of the SANE package.
|
This file is part of the SANE package.
|
||||||
|
|
||||||
|
@ -81,7 +81,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "sane/sane.h"
|
#include "sane/sane.h"
|
||||||
|
@ -89,6 +88,7 @@
|
||||||
#include "sane/saneopts.h"
|
#include "sane/saneopts.h"
|
||||||
#include "sane/sanei_scsi.h"
|
#include "sane/sanei_scsi.h"
|
||||||
#include "sane/sanei_debug.h"
|
#include "sane/sanei_debug.h"
|
||||||
|
#include "sane/sanei_thread.h"
|
||||||
|
|
||||||
#include "sane/sanei_config.h"
|
#include "sane/sanei_config.h"
|
||||||
#define COOLSCAN_CONFIG_FILE "coolscan.conf"
|
#define COOLSCAN_CONFIG_FILE "coolscan.conf"
|
||||||
|
@ -1986,21 +1986,6 @@ static const SANE_Range shift_range =
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
static const SANE_Range percentage_range =
|
|
||||||
{
|
|
||||||
-100 << SANE_FIXED_SCALE_SHIFT, /* minimum */
|
|
||||||
100 << SANE_FIXED_SCALE_SHIFT, /* maximum */
|
|
||||||
1 << SANE_FIXED_SCALE_SHIFT /* quantization */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static const SANE_Range percentage_range_100 =
|
|
||||||
{
|
|
||||||
0 << SANE_FIXED_SCALE_SHIFT, /* minimum */
|
|
||||||
100 << SANE_FIXED_SCALE_SHIFT, /* maximum */
|
|
||||||
1 << SANE_FIXED_SCALE_SHIFT /* quantization */
|
|
||||||
};
|
|
||||||
|
|
||||||
static int num_devices;
|
static int num_devices;
|
||||||
static Coolscan_t *first_dev;
|
static Coolscan_t *first_dev;
|
||||||
|
|
||||||
|
@ -2049,8 +2034,9 @@ do_cancel (Coolscan_t * scanner)
|
||||||
DBG (10, "do_cancel: kill reader_process\n");
|
DBG (10, "do_cancel: kill reader_process\n");
|
||||||
|
|
||||||
/* ensure child knows it's time to stop: */
|
/* ensure child knows it's time to stop: */
|
||||||
kill (scanner->reader_pid, SIGTERM);
|
sanei_thread_kill (scanner->reader_pid);
|
||||||
while (wait (&exit_status) != scanner->reader_pid);
|
while (sanei_thread_waitpid(scanner->reader_pid, &exit_status) !=
|
||||||
|
scanner->reader_pid );
|
||||||
scanner->reader_pid = 0;
|
scanner->reader_pid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2545,7 +2531,7 @@ static int RGBIfix1(unsigned char* rgbimat,unsigned char* orgbimat,
|
||||||
#endif
|
#endif
|
||||||
/* This function is executed as a child process. */
|
/* This function is executed as a child process. */
|
||||||
static int
|
static int
|
||||||
reader_process (Coolscan_t * scanner, int pipe_fd)
|
reader_process (void *data )
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -2554,19 +2540,35 @@ reader_process (Coolscan_t * scanner, int pipe_fd)
|
||||||
unsigned int data_to_read;
|
unsigned int data_to_read;
|
||||||
unsigned int data_to_write;
|
unsigned int data_to_write;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
sigset_t sigterm_set;
|
sigset_t sigterm_set, ignore_set;
|
||||||
struct SIGACTION act;
|
struct SIGACTION act;
|
||||||
unsigned int bpl, linesPerBuf, lineOffset;
|
unsigned int bpl, linesPerBuf, lineOffset;
|
||||||
unsigned char r_data, g_data, b_data;
|
unsigned char r_data, g_data, b_data;
|
||||||
unsigned int j, line;
|
unsigned int j, line;
|
||||||
|
Coolscan_t * scanner = (Coolscan_t*)data;
|
||||||
|
|
||||||
DBG (10, "reader_process started\n");
|
if (sanei_thread_is_forked ())
|
||||||
|
{
|
||||||
|
DBG (10, "reader_process started (forked)\n");
|
||||||
|
close (scanner->pipe);
|
||||||
|
scanner->pipe = -1;
|
||||||
|
|
||||||
|
sigfillset ( &ignore_set );
|
||||||
|
sigdelset ( &ignore_set, SIGTERM );
|
||||||
|
sigprocmask( SIG_SETMASK, &ignore_set, 0 );
|
||||||
|
|
||||||
|
memset (&act, 0, sizeof (act));
|
||||||
|
sigaction (SIGTERM, &act, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DBG (10, "reader_process started (as thread)\n");
|
||||||
|
}
|
||||||
|
|
||||||
sigemptyset (&sigterm_set);
|
sigemptyset (&sigterm_set);
|
||||||
sigaddset (&sigterm_set, SIGTERM);
|
sigaddset (&sigterm_set, SIGTERM);
|
||||||
|
|
||||||
fp = fdopen (pipe_fd, "w");
|
fp = fdopen ( scanner->reader_fds, "w");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
DBG (1, "reader_process: couldn't open pipe!\n");
|
DBG (1, "reader_process: couldn't open pipe!\n");
|
||||||
|
@ -3236,6 +3238,8 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
|
||||||
authorize = authorize;
|
authorize = authorize;
|
||||||
|
|
||||||
DBG_INIT ();
|
DBG_INIT ();
|
||||||
|
sanei_thread_init ();
|
||||||
|
|
||||||
DBG (10, "sane_init\n");
|
DBG (10, "sane_init\n");
|
||||||
if (version_code)
|
if (version_code)
|
||||||
*version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 0);
|
*version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 0);
|
||||||
|
@ -4078,27 +4082,21 @@ sane_start (SANE_Handle handle)
|
||||||
return SANE_STATUS_IO_ERROR;
|
return SANE_STATUS_IO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner->reader_pid = fork ();
|
scanner->pipe = fds[0];
|
||||||
if (scanner->reader_pid == 0)
|
scanner->reader_fds = fds[1];
|
||||||
|
scanner->reader_pid = sanei_thread_begin( reader_process, (void*)scanner );
|
||||||
|
if (scanner->reader_pid < 0)
|
||||||
{
|
{
|
||||||
/* reader_pid = 0 ===> child process */
|
DBG (1, "sane_start: sanei_thread_begin failed (%s)\n",
|
||||||
sigset_t ignore_set;
|
strerror (errno));
|
||||||
struct SIGACTION act;
|
return SANE_STATUS_NO_MEM;
|
||||||
|
}
|
||||||
close (fds[0]);
|
|
||||||
|
if (sanei_thread_is_forked ())
|
||||||
sigfillset (&ignore_set);
|
{
|
||||||
sigdelset (&ignore_set, SIGTERM);
|
close (scanner->reader_fds);
|
||||||
sigprocmask (SIG_SETMASK, &ignore_set, 0);
|
scanner->reader_fds = -1;
|
||||||
|
|
||||||
memset (&act, 0, sizeof (act));
|
|
||||||
sigaction (SIGTERM, &act, 0);
|
|
||||||
|
|
||||||
/* don't use exit() since that would run the atexit() handlers... */
|
|
||||||
_exit (reader_process (scanner, fds[1]));
|
|
||||||
}
|
}
|
||||||
close (fds[1]);
|
|
||||||
scanner->pipe = fds[0];
|
|
||||||
|
|
||||||
return SANE_STATUS_GOOD;
|
return SANE_STATUS_GOOD;
|
||||||
}
|
}
|
||||||
|
@ -4149,8 +4147,8 @@ sane_cancel (SANE_Handle handle)
|
||||||
|
|
||||||
if (s->reader_pid > 0)
|
if (s->reader_pid > 0)
|
||||||
{
|
{
|
||||||
kill (s->reader_pid, SIGTERM);
|
sanei_thread_kill ( s->reader_pid );
|
||||||
waitpid (s->reader_pid, 0, 0);
|
sanei_thread_waitpid( s->reader_pid, NULL );
|
||||||
s->reader_pid = 0;
|
s->reader_pid = 0;
|
||||||
}
|
}
|
||||||
swap_res (s);
|
swap_res (s);
|
||||||
|
|
|
@ -123,6 +123,7 @@ typedef struct Coolscan
|
||||||
SANE_Option_Descriptor opt[NUM_OPTIONS];
|
SANE_Option_Descriptor opt[NUM_OPTIONS];
|
||||||
|
|
||||||
pid_t reader_pid;
|
pid_t reader_pid;
|
||||||
|
int reader_fds;
|
||||||
int pipe;
|
int pipe;
|
||||||
int scanning;
|
int scanning;
|
||||||
/*--------------------------*/
|
/*--------------------------*/
|
||||||
|
|
Ładowanie…
Reference in New Issue