2006-05-08 20:05:42 +02:00
|
|
|
/*
|
|
|
|
* SANE.DS functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Shi Quan He <shiquan@cyberdude.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-05-08 20:05:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2007-03-14 19:10:03 +01:00
|
|
|
#include "wine/port.h"
|
2006-05-08 20:05:42 +02:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "sane_i.h"
|
|
|
|
#include "wine/debug.h"
|
2007-03-14 19:10:03 +01:00
|
|
|
#include "wine/library.h"
|
2006-05-08 20:05:42 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(twain);
|
|
|
|
|
2017-11-14 22:14:11 +01:00
|
|
|
DSMENTRYPROC SANE_dsmentry;
|
|
|
|
|
2007-07-02 19:42:13 +02:00
|
|
|
#ifdef SONAME_LIBSANE
|
2007-03-14 19:10:03 +01:00
|
|
|
|
2014-05-16 11:34:37 +02:00
|
|
|
HINSTANCE SANE_instance;
|
|
|
|
|
2007-03-14 19:10:03 +01:00
|
|
|
static void *libsane_handle;
|
|
|
|
|
|
|
|
static void close_libsane(void *h)
|
|
|
|
{
|
|
|
|
if (h)
|
|
|
|
wine_dlclose(h, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *open_libsane(void)
|
|
|
|
{
|
|
|
|
void *h;
|
|
|
|
|
|
|
|
h = wine_dlopen(SONAME_LIBSANE, RTLD_GLOBAL | RTLD_NOW, NULL, 0);
|
|
|
|
if (!h)
|
|
|
|
{
|
|
|
|
WARN("dlopen(%s) failed\n", SONAME_LIBSANE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LOAD_FUNCPTR(f) \
|
|
|
|
if((p##f = wine_dlsym(h, #f, NULL, 0)) == NULL) { \
|
|
|
|
close_libsane(h); \
|
|
|
|
ERR("Could not dlsym %s\n", #f); \
|
|
|
|
return NULL; \
|
|
|
|
}
|
|
|
|
|
|
|
|
LOAD_FUNCPTR(sane_init)
|
|
|
|
LOAD_FUNCPTR(sane_exit)
|
|
|
|
LOAD_FUNCPTR(sane_get_devices)
|
|
|
|
LOAD_FUNCPTR(sane_open)
|
|
|
|
LOAD_FUNCPTR(sane_close)
|
|
|
|
LOAD_FUNCPTR(sane_get_option_descriptor)
|
|
|
|
LOAD_FUNCPTR(sane_control_option)
|
|
|
|
LOAD_FUNCPTR(sane_get_parameters)
|
|
|
|
LOAD_FUNCPTR(sane_start)
|
|
|
|
LOAD_FUNCPTR(sane_read)
|
|
|
|
LOAD_FUNCPTR(sane_cancel)
|
|
|
|
LOAD_FUNCPTR(sane_set_io_mode)
|
|
|
|
LOAD_FUNCPTR(sane_get_select_fd)
|
|
|
|
LOAD_FUNCPTR(sane_strstatus)
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
2006-09-29 01:19:00 +02:00
|
|
|
TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
|
2006-05-08 20:05:42 +02:00
|
|
|
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH: {
|
|
|
|
SANE_Int version_code;
|
2007-03-14 19:10:03 +01:00
|
|
|
|
|
|
|
libsane_handle = open_libsane();
|
|
|
|
if (! libsane_handle)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-07-21 11:06:52 +02:00
|
|
|
psane_init (&version_code, NULL);
|
2006-05-08 20:05:42 +02:00
|
|
|
SANE_instance = hinstDLL;
|
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DLL_PROCESS_DETACH:
|
2013-04-30 17:25:29 +02:00
|
|
|
if (lpvReserved) break;
|
2006-06-02 22:03:01 +02:00
|
|
|
TRACE("calling sane_exit()\n");
|
2007-03-14 19:10:03 +01:00
|
|
|
psane_exit ();
|
|
|
|
close_libsane(libsane_handle);
|
2006-05-08 20:05:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TW_UINT16 SANE_GetIdentity( pTW_IDENTITY, pTW_IDENTITY);
|
|
|
|
static TW_UINT16 SANE_OpenDS( pTW_IDENTITY, pTW_IDENTITY);
|
2014-05-16 11:34:37 +02:00
|
|
|
|
|
|
|
#endif /* SONAME_LIBSANE */
|
2006-05-08 20:05:42 +02:00
|
|
|
|
2017-11-14 22:14:11 +01:00
|
|
|
static TW_UINT16 SANE_SetEntryPoint (pTW_IDENTITY pOrigin, TW_MEMREF pData);
|
|
|
|
|
2007-01-27 19:08:01 +01:00
|
|
|
static TW_UINT16 SANE_SourceControlHandler (
|
2006-05-08 20:05:42 +02:00
|
|
|
pTW_IDENTITY pOrigin,
|
|
|
|
TW_UINT16 DAT,
|
|
|
|
TW_UINT16 MSG,
|
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS;
|
|
|
|
|
|
|
|
switch (DAT)
|
|
|
|
{
|
|
|
|
case DAT_IDENTITY:
|
|
|
|
switch (MSG)
|
|
|
|
{
|
|
|
|
case MSG_CLOSEDS:
|
2007-07-02 19:42:13 +02:00
|
|
|
#ifdef SONAME_LIBSANE
|
2007-03-14 19:10:03 +01:00
|
|
|
psane_close (activeDS.deviceHandle);
|
2009-03-06 19:44:39 +01:00
|
|
|
#else
|
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
activeDS.twCC = TWCC_CAPUNSUPPORTED;
|
2006-05-08 20:05:42 +02:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case MSG_OPENDS:
|
2007-07-02 19:42:13 +02:00
|
|
|
#ifdef SONAME_LIBSANE
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = SANE_OpenDS( pOrigin, (pTW_IDENTITY)pData);
|
|
|
|
#else
|
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
activeDS.twCC = TWCC_CAPUNSUPPORTED;
|
2006-05-08 20:05:42 +02:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case MSG_GET:
|
2007-07-02 19:42:13 +02:00
|
|
|
#ifdef SONAME_LIBSANE
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = SANE_GetIdentity( pOrigin, (pTW_IDENTITY)pData);
|
|
|
|
#else
|
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
activeDS.twCC = TWCC_CAPUNSUPPORTED;
|
2006-05-08 20:05:42 +02:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DAT_CAPABILITY:
|
|
|
|
switch (MSG)
|
|
|
|
{
|
|
|
|
case MSG_GET:
|
|
|
|
twRC = SANE_CapabilityGet (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_GETCURRENT:
|
|
|
|
twRC = SANE_CapabilityGetCurrent (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_GETDEFAULT:
|
|
|
|
twRC = SANE_CapabilityGetDefault (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_QUERYSUPPORT:
|
|
|
|
twRC = SANE_CapabilityQuerySupport (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_RESET:
|
|
|
|
twRC = SANE_CapabilityReset (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_SET:
|
|
|
|
twRC = SANE_CapabilitySet (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2015-03-18 08:44:56 +01:00
|
|
|
FIXME("unrecognized operation triplet\n");
|
2006-05-08 20:05:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-11-14 22:14:11 +01:00
|
|
|
case DAT_ENTRYPOINT:
|
|
|
|
if (MSG == MSG_SET)
|
|
|
|
twRC = SANE_SetEntryPoint (pOrigin, pData);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
|
|
|
FIXME("unrecognized operation triplet\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
case DAT_EVENT:
|
|
|
|
if (MSG == MSG_PROCESSEVENT)
|
|
|
|
twRC = SANE_ProcessEvent (pOrigin, pData);
|
|
|
|
else
|
2009-03-06 19:44:39 +01:00
|
|
|
{
|
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
}
|
2006-05-08 20:05:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_PENDINGXFERS:
|
|
|
|
switch (MSG)
|
|
|
|
{
|
|
|
|
case MSG_ENDXFER:
|
|
|
|
twRC = SANE_PendingXfersEndXfer (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_GET:
|
|
|
|
twRC = SANE_PendingXfersGet (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_RESET:
|
|
|
|
twRC = SANE_PendingXfersReset (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
default:
|
2009-03-06 19:44:39 +01:00
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_SETUPMEMXFER:
|
|
|
|
if (MSG == MSG_GET)
|
|
|
|
twRC = SANE_SetupMemXferGet (pOrigin, pData);
|
|
|
|
else
|
2009-03-06 19:44:39 +01:00
|
|
|
{
|
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
}
|
2006-05-08 20:05:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_STATUS:
|
|
|
|
if (MSG == MSG_GET)
|
|
|
|
twRC = SANE_GetDSStatus (pOrigin, pData);
|
|
|
|
else
|
2009-03-06 19:44:39 +01:00
|
|
|
{
|
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
}
|
2006-05-08 20:05:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_USERINTERFACE:
|
|
|
|
switch (MSG)
|
|
|
|
{
|
|
|
|
case MSG_DISABLEDS:
|
|
|
|
twRC = SANE_DisableDSUserInterface (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_ENABLEDS:
|
|
|
|
twRC = SANE_EnableDSUserInterface (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_ENABLEDSUIONLY:
|
|
|
|
twRC = SANE_EnableDSUIOnly (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
default:
|
2009-03-06 19:44:39 +01:00
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_XFERGROUP:
|
|
|
|
switch (MSG)
|
|
|
|
{
|
|
|
|
case MSG_GET:
|
|
|
|
twRC = SANE_XferGroupGet (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_SET:
|
|
|
|
twRC = SANE_XferGroupSet (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
default:
|
2009-03-06 19:44:39 +01:00
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-03-06 19:44:50 +01:00
|
|
|
WARN("code unsupported: %d\n", DAT);
|
2009-03-06 19:44:39 +01:00
|
|
|
activeDS.twCC = TWCC_CAPUNSUPPORTED;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return twRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-02 15:25:29 +01:00
|
|
|
static TW_UINT16 SANE_ImageGroupHandler (
|
2006-05-08 20:05:42 +02:00
|
|
|
pTW_IDENTITY pOrigin,
|
|
|
|
TW_UINT16 DAT,
|
|
|
|
TW_UINT16 MSG,
|
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS;
|
|
|
|
|
|
|
|
switch (DAT)
|
|
|
|
{
|
|
|
|
case DAT_IMAGEINFO:
|
|
|
|
if (MSG == MSG_GET)
|
|
|
|
twRC = SANE_ImageInfoGet (pOrigin, pData);
|
|
|
|
else
|
2009-03-06 19:44:39 +01:00
|
|
|
{
|
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
}
|
2006-05-08 20:05:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_IMAGELAYOUT:
|
|
|
|
switch (MSG)
|
|
|
|
{
|
|
|
|
case MSG_GET:
|
|
|
|
twRC = SANE_ImageLayoutGet (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_GETDEFAULT:
|
|
|
|
twRC = SANE_ImageLayoutGetDefault (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_RESET:
|
|
|
|
twRC = SANE_ImageLayoutReset (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
case MSG_SET:
|
|
|
|
twRC = SANE_ImageLayoutSet (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
ERR("unrecognized operation triplet\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_IMAGEMEMXFER:
|
|
|
|
if (MSG == MSG_GET)
|
|
|
|
twRC = SANE_ImageMemXferGet (pOrigin, pData);
|
|
|
|
else
|
2009-03-06 19:44:39 +01:00
|
|
|
{
|
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
}
|
2006-05-08 20:05:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_IMAGENATIVEXFER:
|
|
|
|
if (MSG == MSG_GET)
|
|
|
|
twRC = SANE_ImageNativeXferGet (pOrigin, pData);
|
|
|
|
else
|
2009-03-06 19:44:39 +01:00
|
|
|
{
|
|
|
|
activeDS.twCC = TWCC_CAPBADOPERATION;
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
}
|
2006-05-08 20:05:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
twRC = TWRC_FAILURE;
|
2009-03-06 19:44:39 +01:00
|
|
|
activeDS.twCC = TWCC_CAPUNSUPPORTED;
|
2009-03-06 19:44:50 +01:00
|
|
|
WARN("unsupported DG type %d\n", DAT);
|
|
|
|
break;
|
2006-05-08 20:05:42 +02:00
|
|
|
}
|
|
|
|
return twRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Main entry point for the TWAIN library */
|
|
|
|
TW_UINT16 WINAPI
|
|
|
|
DS_Entry ( pTW_IDENTITY pOrigin,
|
|
|
|
TW_UINT32 DG,
|
|
|
|
TW_UINT16 DAT,
|
|
|
|
TW_UINT16 MSG,
|
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS; /* Return Code */
|
|
|
|
|
2009-01-06 00:09:48 +01:00
|
|
|
TRACE("(DG=%d DAT=%d MSG=%d)\n", DG, DAT, MSG);
|
2006-05-08 20:05:42 +02:00
|
|
|
|
|
|
|
switch (DG)
|
|
|
|
{
|
|
|
|
case DG_CONTROL:
|
|
|
|
twRC = SANE_SourceControlHandler (pOrigin,DAT,MSG,pData);
|
|
|
|
break;
|
|
|
|
case DG_IMAGE:
|
|
|
|
twRC = SANE_ImageGroupHandler (pOrigin,DAT,MSG,pData);
|
|
|
|
break;
|
|
|
|
case DG_AUDIO:
|
2009-03-06 19:44:44 +01:00
|
|
|
WARN("Audio group of controls not implemented yet.\n");
|
2009-03-06 19:44:39 +01:00
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
activeDS.twCC = TWCC_CAPUNSUPPORTED;
|
|
|
|
break;
|
2006-05-08 20:05:42 +02:00
|
|
|
default:
|
|
|
|
activeDS.twCC = TWCC_BADPROTOCOL;
|
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return twRC;
|
|
|
|
}
|
|
|
|
|
2017-11-14 22:14:11 +01:00
|
|
|
void SANE_Notify (TW_UINT16 message)
|
|
|
|
{
|
|
|
|
SANE_dsmentry (&activeDS.identity, &activeDS.appIdentity, DG_CONTROL, DAT_NULL, message, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DG_CONTROL/DAT_ENTRYPOINT/MSG_SET */
|
|
|
|
TW_UINT16 SANE_SetEntryPoint (pTW_IDENTITY pOrigin, TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
TW_ENTRYPOINT *entry = (TW_ENTRYPOINT*)pData;
|
|
|
|
|
|
|
|
SANE_dsmentry = entry->DSM_Entry;
|
|
|
|
|
|
|
|
return TWRC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-07-02 19:42:13 +02:00
|
|
|
#ifdef SONAME_LIBSANE
|
2006-05-08 20:05:42 +02:00
|
|
|
/* Sane returns device names that are longer than the 32 bytes allowed
|
|
|
|
by TWAIN. However, it colon separates them, and the last bit is
|
|
|
|
the most interesting. So we use the last bit, and add a signature
|
|
|
|
to ensure uniqueness */
|
|
|
|
static void copy_sane_short_name(const char *in, char *out, size_t outsize)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
int signature = 0;
|
|
|
|
|
|
|
|
if (strlen(in) <= outsize - 1)
|
|
|
|
{
|
|
|
|
strcpy(out, in);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p = in; *p; p++)
|
|
|
|
signature += *p;
|
|
|
|
|
|
|
|
p = strrchr(in, ':');
|
|
|
|
if (!p)
|
|
|
|
p = in;
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if (strlen(p) > outsize - 7 - 1)
|
|
|
|
p += strlen(p) - (outsize - 7 - 1);
|
|
|
|
|
|
|
|
strcpy(out, p);
|
|
|
|
sprintf(out + strlen(out), "(%04X)", signature % 0x10000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static const SANE_Device **sane_devlist;
|
|
|
|
|
|
|
|
static void
|
2006-08-18 20:57:46 +02:00
|
|
|
detect_sane_devices(void) {
|
2006-05-08 20:05:42 +02:00
|
|
|
if (sane_devlist && sane_devlist[0]) return;
|
|
|
|
TRACE("detecting sane...\n");
|
2007-03-14 19:10:03 +01:00
|
|
|
if (psane_get_devices (&sane_devlist, SANE_FALSE) != SANE_STATUS_GOOD)
|
2006-05-08 20:05:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TW_UINT16
|
|
|
|
SANE_GetIdentity( pTW_IDENTITY pOrigin, pTW_IDENTITY self) {
|
|
|
|
static int cursanedev = 0;
|
|
|
|
|
|
|
|
detect_sane_devices();
|
|
|
|
if (!sane_devlist[cursanedev])
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
self->ProtocolMajor = TWON_PROTOCOLMAJOR;
|
|
|
|
self->ProtocolMinor = TWON_PROTOCOLMINOR;
|
2017-11-14 22:14:11 +01:00
|
|
|
self->SupportedGroups = DG_CONTROL | DG_IMAGE | DF_DS2;
|
2006-05-08 20:05:42 +02:00
|
|
|
copy_sane_short_name(sane_devlist[cursanedev]->name, self->ProductName, sizeof(self->ProductName) - 1);
|
|
|
|
lstrcpynA (self->Manufacturer, sane_devlist[cursanedev]->vendor, sizeof(self->Manufacturer) - 1);
|
|
|
|
lstrcpynA (self->ProductFamily, sane_devlist[cursanedev]->model, sizeof(self->ProductFamily) - 1);
|
|
|
|
cursanedev++;
|
|
|
|
|
|
|
|
if (!sane_devlist[cursanedev] ||
|
|
|
|
!sane_devlist[cursanedev]->model ||
|
|
|
|
!sane_devlist[cursanedev]->vendor ||
|
|
|
|
!sane_devlist[cursanedev]->name
|
|
|
|
)
|
|
|
|
cursanedev = 0; /* wrap to begin */
|
|
|
|
return TWRC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TW_UINT16 SANE_OpenDS( pTW_IDENTITY pOrigin, pTW_IDENTITY self) {
|
|
|
|
SANE_Status status;
|
|
|
|
int i;
|
|
|
|
|
2017-11-14 22:14:11 +01:00
|
|
|
if (SANE_dsmentry == NULL)
|
|
|
|
{
|
|
|
|
static const WCHAR twain32W[] = {'t','w','a','i','n','_','3','2',0};
|
|
|
|
HMODULE moddsm = GetModuleHandleW(twain32W);
|
|
|
|
|
|
|
|
if (moddsm)
|
|
|
|
SANE_dsmentry = (void*)GetProcAddress(moddsm, "DSM_Entry");
|
|
|
|
|
|
|
|
if (!SANE_dsmentry)
|
|
|
|
{
|
|
|
|
ERR("can't find DSM entry point\n");
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
detect_sane_devices();
|
|
|
|
if (!sane_devlist[0]) {
|
|
|
|
ERR("No scanners? We should not get to OpenDS?\n");
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; sane_devlist[i] && sane_devlist[i]->model; i++) {
|
|
|
|
TW_STR32 name;
|
|
|
|
|
|
|
|
/* To make string as short as above */
|
|
|
|
lstrcpynA(name, sane_devlist[i]->vendor, sizeof(name)-1);
|
2011-06-16 18:40:39 +02:00
|
|
|
if (*self->Manufacturer && strcmp(name, self->Manufacturer))
|
2006-05-08 20:05:42 +02:00
|
|
|
continue;
|
|
|
|
lstrcpynA(name, sane_devlist[i]->model, sizeof(name)-1);
|
2011-06-16 18:40:39 +02:00
|
|
|
if (*self->ProductFamily && strcmp(name, self->ProductFamily))
|
2006-05-08 20:05:42 +02:00
|
|
|
continue;
|
|
|
|
copy_sane_short_name(sane_devlist[i]->name, name, sizeof(name) - 1);
|
2011-06-16 18:40:39 +02:00
|
|
|
if (*self->ProductName && strcmp(name, self->ProductName))
|
2006-05-08 20:05:42 +02:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!sane_devlist[i]) {
|
2009-03-02 23:47:47 +01:00
|
|
|
WARN("Scanner not found.\n");
|
2009-02-26 03:58:51 +01:00
|
|
|
return TWRC_FAILURE;
|
2006-05-08 20:05:42 +02:00
|
|
|
}
|
2007-03-14 19:10:03 +01:00
|
|
|
status = psane_open(sane_devlist[i]->name,&activeDS.deviceHandle);
|
2006-05-08 20:05:42 +02:00
|
|
|
if (status == SANE_STATUS_GOOD) {
|
2009-03-05 20:15:13 +01:00
|
|
|
activeDS.twCC = SANE_SaneSetDefaults();
|
|
|
|
if (activeDS.twCC == TWCC_SUCCESS) {
|
|
|
|
activeDS.currentState = 4;
|
2017-11-14 22:14:11 +01:00
|
|
|
activeDS.identity.Id = self->Id;
|
|
|
|
activeDS.appIdentity = *pOrigin;
|
2009-03-05 20:15:13 +01:00
|
|
|
return TWRC_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
psane_close(activeDS.deviceHandle);
|
2006-05-08 20:05:42 +02:00
|
|
|
}
|
2009-03-05 20:15:13 +01:00
|
|
|
else
|
|
|
|
ERR("sane_open(%s): %s\n", sane_devlist[i]->name, psane_strstatus (status));
|
2006-05-08 20:05:42 +02:00
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|