merge-requests/1/head
Henning Geinitz 2003-10-17 09:44:20 +00:00
rodzic 4bf0aa0851
commit d63c6321a6
1 zmienionych plików z 68 dodań i 59 usunięć

Wyświetl plik

@ -272,7 +272,7 @@ init_options (Test_Device * test_device)
{ {
SANE_Option_Descriptor *od; SANE_Option_Descriptor *od;
DBG (2, "init_options: test_device=%p\n", (void*)test_device); DBG (2, "init_options: test_device=%p\n", (void *) test_device);
/* opt_num_opts */ /* opt_num_opts */
od = &test_device->opt[opt_num_opts]; od = &test_device->opt[opt_num_opts];
@ -1225,7 +1225,7 @@ reader_process (Test_Device * test_device, SANE_Int fd)
size_t buffer_size = 0, write_count = 0; size_t buffer_size = 0, write_count = 0;
DBG (2, "(child) reader_process: test_device=%p, fd=%d\n", DBG (2, "(child) reader_process: test_device=%p, fd=%d\n",
(void*)test_device, fd); (void *) test_device, fd);
bytes_total = test_device->lines * test_device->bytes_per_line; bytes_total = test_device->lines * test_device->bytes_per_line;
status = init_picture_buffer (test_device, &buffer, &buffer_size); status = init_picture_buffer (test_device, &buffer, &buffer_size);
@ -1272,7 +1272,8 @@ reader_process (Test_Device * test_device, SANE_Int fd)
/* /*
* this code either runs in child or thread context... * this code either runs in child or thread context...
*/ */
static int reader_task(void *data) static int
reader_task (void *data)
{ {
SANE_Status status; SANE_Status status;
sigset_t ignore_set; sigset_t ignore_set;
@ -1280,13 +1281,16 @@ static int reader_task(void *data)
struct Test_Device *test_device = (struct Test_Device *) data; struct Test_Device *test_device = (struct Test_Device *) data;
DBG (2, "reader_task started\n"); DBG (2, "reader_task started\n");
if( sanei_thread_is_forked()) { if (sanei_thread_is_forked ())
DBG( 3, "reader_task started (forked)\n" ); {
close( test_device->pipe ); DBG (3, "reader_task started (forked)\n");
close (test_device->pipe);
test_device->pipe = -1; test_device->pipe = -1;
} else { }
DBG( 3, "reader_task started (as thread)\n" ); else
{
DBG (3, "reader_task started (as thread)\n");
} }
/* block SIGPIPE */ /* block SIGPIPE */
@ -1296,10 +1300,10 @@ static int reader_task(void *data)
memset (&act, 0, sizeof (act)); memset (&act, 0, sizeof (act));
sigaction (SIGTERM, &act, 0); sigaction (SIGTERM, &act, 0);
status = reader_process (test_device, test_device->reader_fds ); status = reader_process (test_device, test_device->reader_fds);
DBG (2, "(child) reader_task: reader_process finished (%s)\n", DBG (2, "(child) reader_task: reader_process finished (%s)\n",
sane_strstatus (status)); sane_strstatus (status));
return (int)status; return (int) status;
} }
static SANE_Status static SANE_Status
@ -1307,7 +1311,7 @@ finish_pass (Test_Device * test_device)
{ {
SANE_Status return_status = SANE_STATUS_GOOD; SANE_Status return_status = SANE_STATUS_GOOD;
DBG (2, "finish_pass: test_device=%p\n", (void*)test_device); DBG (2, "finish_pass: test_device=%p\n", (void *) test_device);
test_device->scanning = SANE_FALSE; test_device->scanning = SANE_FALSE;
if (test_device->pipe > 0) if (test_device->pipe > 0)
{ {
@ -1324,12 +1328,15 @@ finish_pass (Test_Device * test_device)
DBG (2, "finish_pass: terminating reader process %d\n", DBG (2, "finish_pass: terminating reader process %d\n",
test_device->reader_pid); test_device->reader_pid);
sanei_thread_kill (test_device->reader_pid); sanei_thread_kill (test_device->reader_pid);
pid = sanei_thread_waitpid (test_device->reader_pid, &status ); pid = sanei_thread_waitpid (test_device->reader_pid, &status);
if (pid < 0) if (pid < 0)
{ {
DBG (1, "finish_pass: sanei_thread_waitpid failed, already terminated? (%s)\n", DBG (1,
"finish_pass: sanei_thread_waitpid failed, already terminated? (%s)\n",
strerror (errno)); strerror (errno));
} else { }
else
{
DBG (2, "finish_pass: reader process terminated with status: %s\n", DBG (2, "finish_pass: reader process terminated with status: %s\n",
sane_strstatus (status)); sane_strstatus (status));
} }
@ -1412,15 +1419,15 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
SANE_Int num; SANE_Int num;
DBG_INIT (); DBG_INIT ();
sanei_thread_init(); sanei_thread_init ();
test_device = 0; test_device = 0;
previous_device = 0; previous_device = 0;
DBG (2, "sane_init: version_code= %p, authorize=%p\n", (void*)version_code, DBG (2, "sane_init: version_code= %p, authorize=%p\n",
(void*)authorize); (void *) version_code, (void *) authorize);
DBG (1, "sane_init: SANE test backend version %d.%d.%d from %s\n", DBG (1, "sane_init: SANE test backend version %d.%d.%d from %s\n", V_MAJOR,
V_MAJOR, V_MINOR, BUILD, PACKAGE_STRING); V_MINOR, BUILD, PACKAGE_STRING);
if (version_code) if (version_code)
*version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, BUILD); *version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, BUILD);
@ -1640,7 +1647,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
{ {
DBG (2, "sane_get_devices: device_list=%p, local_only=%d\n", DBG (2, "sane_get_devices: device_list=%p, local_only=%d\n",
(void*)device_list, local_only); (void *) device_list, local_only);
if (!inited) if (!inited)
{ {
DBG (1, "sane_get_devices: not inited, call sane_init() first\n"); DBG (1, "sane_get_devices: not inited, call sane_init() first\n");
@ -1663,7 +1670,7 @@ sane_open (SANE_String_Const devicename, SANE_Handle * handle)
SANE_Status status; SANE_Status status;
DBG (2, "sane_open: devicename = \"%s\", handle=%p\n", DBG (2, "sane_open: devicename = \"%s\", handle=%p\n",
devicename, (void*)handle); devicename, (void *) handle);
if (!inited) if (!inited)
{ {
DBG (1, "sane_open: not inited, call sane_init() first\n"); DBG (1, "sane_open: not inited, call sane_init() first\n");
@ -1700,7 +1707,7 @@ sane_open (SANE_String_Const devicename, SANE_Handle * handle)
return SANE_STATUS_DEVICE_BUSY; return SANE_STATUS_DEVICE_BUSY;
} }
DBG (2, "sane_open: opening device `%s', handle = %p\n", test_device->name, DBG (2, "sane_open: opening device `%s', handle = %p\n", test_device->name,
(void*)test_device); (void *) test_device);
test_device->open = SANE_TRUE; test_device->open = SANE_TRUE;
*handle = test_device; *handle = test_device;
@ -1723,7 +1730,7 @@ sane_close (SANE_Handle handle)
{ {
Test_Device *test_device = handle; Test_Device *test_device = handle;
DBG (2, "sane_close: handle=%p\n", (void*)handle); DBG (2, "sane_close: handle=%p\n", (void *) handle);
if (!inited) if (!inited)
{ {
DBG (1, "sane_close: not inited, call sane_init() first\n"); DBG (1, "sane_close: not inited, call sane_init() first\n");
@ -1732,12 +1739,12 @@ sane_close (SANE_Handle handle)
if (!check_handle (handle)) if (!check_handle (handle))
{ {
DBG (1, "sane_close: handle %p unknown\n", (void*)handle); DBG (1, "sane_close: handle %p unknown\n", (void *) handle);
return; return;
} }
if (!test_device->open) if (!test_device->open)
{ {
DBG (1, "sane_close: handle %p not open\n", (void*)handle); DBG (1, "sane_close: handle %p not open\n", (void *) handle);
return; return;
} }
test_device->open = SANE_FALSE; test_device->open = SANE_FALSE;
@ -1750,7 +1757,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
Test_Device *test_device = handle; Test_Device *test_device = handle;
DBG (4, "sane_get_option_descriptor: handle=%p, option = %d\n", DBG (4, "sane_get_option_descriptor: handle=%p, option = %d\n",
(void*)handle, option); (void *) handle, option);
if (!inited) if (!inited)
{ {
DBG (1, "sane_get_option_descriptor: not inited, call sane_init() " DBG (1, "sane_get_option_descriptor: not inited, call sane_init() "
@ -1761,7 +1768,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
if (!check_handle (handle)) if (!check_handle (handle))
{ {
DBG (1, "sane_get_option_descriptor: handle %p unknown\n", DBG (1, "sane_get_option_descriptor: handle %p unknown\n",
(void*)handle); (void *) handle);
return 0; return 0;
} }
if (!test_device->open) if (!test_device->open)
@ -1788,7 +1795,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
SANE_Status status; SANE_Status status;
DBG (4, "sane_control_option: handle=%p, opt=%d, act=%d, val=%p, info=%p\n", DBG (4, "sane_control_option: handle=%p, opt=%d, act=%d, val=%p, info=%p\n",
(void*)handle, option, action, (void*)value, (void*)info); (void *) handle, option, action, (void *) value, (void *) info);
if (!inited) if (!inited)
{ {
DBG (1, "sane_control_option: not inited, call sane_init() first\n"); DBG (1, "sane_control_option: not inited, call sane_init() first\n");
@ -1797,7 +1804,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
if (!check_handle (handle)) if (!check_handle (handle))
{ {
DBG (1, "sane_control_option: handle %p unknown\n", (void*)handle); DBG (1, "sane_control_option: handle %p unknown\n", (void *) handle);
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
} }
if (!test_device->open) if (!test_device->open)
@ -2013,7 +2020,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
memcpy (test_device->val[option].wa, value, memcpy (test_device->val[option].wa, value,
test_device->opt[option].size); test_device->opt[option].size);
DBG (4, "sane_control_option: set option %d (%s) to %p\n", DBG (4, "sane_control_option: set option %d (%s) to %p\n",
option, test_device->opt[option].name, (void *)value); option, test_device->opt[option].name, (void *) value);
break; break;
/* options with side-effects */ /* options with side-effects */
case opt_print_options: case opt_print_options:
@ -2270,7 +2277,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
SANE_Int channels = 1; SANE_Int channels = 1;
DBG (2, "sane_get_parameters: handle=%p, params=%p\n", DBG (2, "sane_get_parameters: handle=%p, params=%p\n",
(void*)handle, (void*)params); (void *) handle, (void *) params);
if (!inited) if (!inited)
{ {
DBG (1, "sane_get_parameters: not inited, call sane_init() first\n"); DBG (1, "sane_get_parameters: not inited, call sane_init() first\n");
@ -2278,12 +2285,12 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
} }
if (!check_handle (handle)) if (!check_handle (handle))
{ {
DBG (1, "sane_get_parameters: handle %p unknown\n", (void*)handle); DBG (1, "sane_get_parameters: handle %p unknown\n", (void *) handle);
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
} }
if (!test_device->open) if (!test_device->open)
{ {
DBG (1, "sane_get_parameters: handle %p not open\n", (void*)handle); DBG (1, "sane_get_parameters: handle %p not open\n", (void *) handle);
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
} }
@ -2479,17 +2486,19 @@ sane_start (SANE_Handle handle)
/* create reader routine as new process or thread */ /* create reader routine as new process or thread */
test_device->pipe = pipe_descriptor[0]; test_device->pipe = pipe_descriptor[0];
test_device->reader_fds = pipe_descriptor[1]; test_device->reader_fds = pipe_descriptor[1];
test_device->reader_pid = sanei_thread_begin(reader_task,(void*)test_device); test_device->reader_pid =
sanei_thread_begin (reader_task, (void *) test_device);
if (test_device->reader_pid < 0) if (test_device->reader_pid < 0)
{ {
DBG (1, "sane_start: sanei_thread_begin failed (%s)\n", strerror(errno)); DBG (1, "sane_start: sanei_thread_begin failed (%s)\n",
strerror (errno));
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
} }
if( sanei_thread_is_forked()) if (sanei_thread_is_forked ())
{ {
close( test_device->reader_fds ); close (test_device->reader_fds);
test_device->reader_fds = -1; test_device->reader_fds = -1;
} }
@ -2509,7 +2518,7 @@ sane_read (SANE_Handle handle, SANE_Byte * data,
DBG (4, "sane_read: handle=%p, data=%p, max_length = %d, length=%p\n", DBG (4, "sane_read: handle=%p, data=%p, max_length = %d, length=%p\n",
handle, data, max_length, (void*)length); handle, data, max_length, (void *) length);
if (!inited) if (!inited)
{ {
DBG (1, "sane_read: not inited, call sane_init() first\n"); DBG (1, "sane_read: not inited, call sane_init() first\n");