ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dsm_ctrl.c
Go to the documentation of this file.
00001 /*
00002  * TWAIN32 Source Manager
00003  *
00004  * Copyright 2000 Corel Corporation
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 //#include "config.h"
00022 
00023 #include <stdlib.h>
00024 #include <stdarg.h>
00025 
00026 #define NONAMELESSUNION
00027 #define NONAMELESSSTRUCT
00028 #include "windef.h"
00029 #include "winbase.h"
00030 #include "twain.h"
00031 #include "twain_i.h"
00032 #include "wine/debug.h"
00033 
00034 WINE_DEFAULT_DEBUG_CHANNEL(twain);
00035 
00036 /* DG_CONTROL/DAT_IDENTITY/MSG_CLOSEDS */
00037 TW_UINT16 TWAIN_CloseDS (pTW_IDENTITY pOrigin, TW_MEMREF pData)
00038 {
00039 #ifndef HAVE_SANE
00040     DSM_twCC = TWCC_NODS;
00041     return TWRC_FAILURE;
00042 #else
00043     TW_UINT16 twRC = TWRC_SUCCESS;
00044     pTW_IDENTITY pIdentity = (pTW_IDENTITY) pData;
00045     activeDS *currentDS = NULL, *prevDS = NULL;
00046 
00047     TRACE ("DG_CONTROL/DAT_IDENTITY/MSG_CLOSEDS\n");
00048 
00049     for (currentDS = activeSources; currentDS; currentDS = currentDS->next)
00050     {
00051         if (currentDS->identity.Id == pIdentity->Id)
00052             break;
00053         prevDS = currentDS;
00054     }
00055     if (currentDS)
00056     {
00057         /* Only valid to close a data source if it is in state 4 */
00058         if (currentDS->currentState == 4)
00059         {
00060             sane_close (currentDS->deviceHandle);
00061             /* remove the data source from active data source list */
00062             if (prevDS)
00063                 prevDS->next = currentDS->next;
00064             else
00065                 activeSources = currentDS->next;
00066             HeapFree (GetProcessHeap(), 0, currentDS);
00067             twRC = TWRC_SUCCESS;
00068             DSM_twCC = TWCC_SUCCESS;
00069         }
00070         else
00071         {
00072             twRC = TWRC_FAILURE;
00073             DSM_twCC = TWCC_SEQERROR;
00074         }
00075     }
00076     else
00077     {
00078         twRC = TWRC_FAILURE;
00079         DSM_twCC = TWCC_NODS;
00080     }
00081 
00082     return twRC;
00083 #endif
00084 }
00085 
00086 /* DG_CONTROL/DAT_IDENTITY/MSG_GETDEFAULT */
00087 TW_UINT16 TWAIN_IdentityGetDefault (pTW_IDENTITY pOrigin, TW_MEMREF pData)
00088 {
00089 #ifndef HAVE_SANE
00090     DSM_twCC = TWCC_NODS;
00091     return TWRC_FAILURE;
00092 #else
00093     TW_UINT16 twRC = TWRC_SUCCESS;
00094     pTW_IDENTITY pSourceIdentity = (pTW_IDENTITY) pData;
00095 
00096     TRACE("DG_CONTROL/DAT_IDENTITY/MSG_GETDEFAULT\n");
00097 
00098     if (!device_list)
00099     {
00100         if ((sane_get_devices (&device_list, SANE_FALSE) != SANE_STATUS_GOOD))
00101         {
00102             DSM_twCC = TWCC_NODS;
00103             return TWRC_FAILURE;
00104         }
00105     }
00106 
00107     /* FIXME: the default device is not necessarily the first device.  *
00108      * Users should be able to choose the default device               */
00109     if (device_list && device_list[0])
00110     {
00111         pSourceIdentity->Id = DSM_sourceId ++;
00112         strcpy (pSourceIdentity->ProductName, device_list[0]->name);
00113         strcpy (pSourceIdentity->Manufacturer, device_list[0]->vendor);
00114         strcpy (pSourceIdentity->ProductFamily, device_list[0]->model);
00115         pSourceIdentity->ProtocolMajor = TWON_PROTOCOLMAJOR;
00116         pSourceIdentity->ProtocolMinor = TWON_PROTOCOLMINOR;
00117 
00118         twRC = TWRC_SUCCESS;
00119         DSM_twCC = TWCC_SUCCESS;
00120     }
00121     else
00122     {
00123         twRC = TWRC_FAILURE;
00124         DSM_twCC = TWCC_NODS;
00125     }
00126 
00127     return twRC;
00128 #endif
00129 }
00130 
00131 /* DG_CONTROL/DAT_IDENTITY/MSG_GETFIRST */
00132 TW_UINT16 TWAIN_IdentityGetFirst (pTW_IDENTITY pOrigin, TW_MEMREF pData)
00133 {
00134 #ifndef HAVE_SANE
00135     DSM_twCC = TWCC_NODS;
00136     return TWRC_FAILURE;
00137 #else
00138     TW_UINT16 twRC = TWRC_SUCCESS;
00139     pTW_IDENTITY pSourceIdentity;/* = (pTW_IDENTITY) pData;*/
00140     SANE_Status status;
00141 
00142     TRACE ("DG_CONTROL/DAT_IDENTITY/MSG_GETFIRST\n");
00143 
00144     status = sane_get_devices (&device_list, SANE_FALSE);
00145     if (status == SANE_STATUS_GOOD)
00146     {
00147         if (device_list[0])
00148         {
00149             pSourceIdentity->Id = DSM_sourceId ++;
00150             strcpy (pSourceIdentity->ProductName, device_list[0]->name);
00151             strcpy (pSourceIdentity->Manufacturer, device_list[0]->vendor);
00152             strcpy (pSourceIdentity->ProductFamily, device_list[0]->model);
00153             pSourceIdentity->ProtocolMajor = TWON_PROTOCOLMAJOR;
00154             pSourceIdentity->ProtocolMinor = TWON_PROTOCOLMINOR;
00155         }
00156         DSM_currentDevice = 1;
00157         twRC = TWRC_SUCCESS;
00158         DSM_twCC = TWCC_SUCCESS;
00159     }
00160     else if (status == SANE_STATUS_NO_MEM)
00161     {
00162         twRC = TWRC_FAILURE;
00163         DSM_twCC = TWCC_LOWMEMORY;
00164     }
00165     else
00166     {
00167         WARN("sane_get_devices() failed: %s\n", sane_strstatus (status));
00168         twRC = TWRC_FAILURE;
00169         DSM_twCC = TWCC_NODS;
00170     }
00171 
00172     return twRC;
00173 #endif
00174 }
00175 
00176 /* DG_CONTROL/DAT_IDENTITY/MSG_GETNEXT */
00177 TW_UINT16 TWAIN_IdentityGetNext (pTW_IDENTITY pOrigin, TW_MEMREF pData)
00178 {
00179 #ifndef HAVE_SANE
00180     DSM_twCC = TWCC_SUCCESS;
00181     return TWRC_ENDOFLIST;
00182 #else
00183     TW_UINT16 twRC = TWRC_SUCCESS;
00184     pTW_IDENTITY pSourceIdentity = (pTW_IDENTITY) pData;
00185 
00186     TRACE("DG_CONTROL/DAT_IDENTITY/MSG_GETNEXT\n");
00187 
00188     if (device_list && device_list[DSM_currentDevice])
00189     {
00190         pSourceIdentity->Id = DSM_sourceId ++;
00191         strcpy (pSourceIdentity->ProductName, device_list[DSM_currentDevice]->name);
00192         strcpy (pSourceIdentity->Manufacturer, device_list[DSM_currentDevice]->vendor);
00193         strcpy (pSourceIdentity->ProductFamily, device_list[DSM_currentDevice]->model);
00194         pSourceIdentity->ProtocolMajor = TWON_PROTOCOLMAJOR;
00195         pSourceIdentity->ProtocolMinor = TWON_PROTOCOLMINOR;
00196         DSM_currentDevice ++;
00197 
00198         twRC = TWRC_SUCCESS;
00199         DSM_twCC = TWCC_SUCCESS;
00200     }
00201     else
00202     {
00203         DSM_twCC = TWCC_SUCCESS;
00204         twRC = TWRC_ENDOFLIST;
00205     }
00206 
00207     return twRC;
00208 #endif
00209 }
00210 
00211 /* DG_CONTROL/DAT_IDENTITY/MSG_OPENDS */
00212 TW_UINT16 TWAIN_OpenDS (pTW_IDENTITY pOrigin, TW_MEMREF pData)
00213 {
00214 #ifndef HAVE_SANE
00215     DSM_twCC = TWCC_NODS;
00216     return TWRC_FAILURE;
00217 #else
00218     TW_UINT16 twRC = TWRC_SUCCESS, i = 0;
00219     pTW_IDENTITY pIdentity = (pTW_IDENTITY) pData;
00220     activeDS *newSource;
00221     SANE_Status status;
00222 
00223     TRACE("DG_CONTROL/DAT_IDENTITY/MSG_OPENDS\n");
00224 
00225     if (DSM_currentState != 3)
00226     {
00227         DSM_twCC = TWCC_SEQERROR;
00228         return TWRC_FAILURE;
00229     }
00230 
00231     if (!device_list &&
00232        (sane_get_devices (&device_list, SANE_FALSE) != SANE_STATUS_GOOD))
00233     {
00234         DSM_twCC = TWCC_NODS;
00235         return TWRC_FAILURE;
00236     }
00237 
00238     if (pIdentity->ProductName[0] != '\0')
00239     {
00240         /* Make sure the source to be open exists in the device list */
00241         for (i = 0; device_list[i]; i ++)
00242         {
00243             if (strcmp (device_list[i]->name, pIdentity->ProductName) == 0)
00244                 break;
00245         }
00246     }
00247 
00248     if (device_list[i])
00249     {
00250         /* the source is found in the device list */
00251         newSource = HeapAlloc (GetProcessHeap(), 0, sizeof (activeDS));
00252         if (newSource)
00253         {
00254             status = sane_open(device_list[i]->name,&newSource->deviceHandle);
00255             if (status == SANE_STATUS_GOOD)
00256             {
00257                 /* Assign name and id for the opened data source */
00258                 strcpy (pIdentity->ProductName, device_list[i]->name);
00259                 pIdentity->Id = DSM_sourceId ++;
00260                 /* add the data source to an internal active source list */
00261                 newSource->next = activeSources;
00262                 newSource->identity.Id = pIdentity->Id;
00263                 strcpy (newSource->identity.ProductName, pIdentity->ProductName);
00264                 newSource->currentState = 4; /*transition into state 4*/
00265                 newSource->twCC = TWCC_SUCCESS;
00266                 activeSources = newSource;
00267                 twRC = TWRC_SUCCESS;
00268                 DSM_twCC = TWCC_SUCCESS;
00269             }
00270             else
00271             {
00272                 twRC = TWRC_FAILURE;
00273                 DSM_twCC = TWCC_OPERATIONERROR;
00274             }
00275         }
00276         else
00277         {
00278             twRC = TWRC_FAILURE;
00279             DSM_twCC = TWCC_LOWMEMORY;
00280         }
00281     }
00282     else
00283     {
00284         twRC = TWRC_FAILURE;
00285         DSM_twCC = TWCC_NODS;
00286     }
00287 
00288     return twRC;
00289 #endif
00290 }
00291 
00292 /* DG_CONTROL/DAT_IDENTITY/MSG_USERSELECT */
00293 TW_UINT16 TWAIN_UserSelect (pTW_IDENTITY pOrigin, TW_MEMREF pData)
00294 {
00295 #ifndef HAVE_SANE
00296     return TWRC_SUCCESS;
00297 #else
00298     TW_UINT16 twRC = TWRC_SUCCESS;
00299 
00300     TRACE("DG_CONTROL/DAT_IDENTITY/MSG_USERSELECT\n");
00301 
00302     /* FIXME: we should replace xscanimage with our own  User Select UI */
00303     system("xscanimage");
00304 
00305     DSM_twCC = TWCC_SUCCESS;
00306     return twRC;
00307 #endif
00308 }
00309 
00310 /* DG_CONTROL/DAT_PARENT/MSG_CLOSEDSM */
00311 TW_UINT16 TWAIN_CloseDSM (pTW_IDENTITY pOrigin, TW_MEMREF pData)
00312 {
00313 #ifndef HAVE_SANE
00314     return TWRC_FAILURE;
00315 #else
00316     TW_UINT16 twRC = TWRC_SUCCESS;
00317     activeDS *currentDS = activeSources, *nextDS;
00318 
00319     TRACE("DG_CONTROL/DAT_PARENT/MSG_CLOSEDSM\n");
00320 
00321     if (DSM_currentState == 3)
00322     {
00323         sane_exit ();
00324         DSM_initialized = FALSE;
00325         DSM_parentHWND = 0;
00326         DSM_currentState = 2;
00327 
00328         /* If there are data sources still open, close them now. */
00329         while (currentDS != NULL)
00330         {
00331             nextDS = currentDS->next;
00332             sane_close (currentDS->deviceHandle);
00333             HeapFree (GetProcessHeap(), 0, currentDS);
00334             currentDS = nextDS;
00335         }
00336         activeSources = NULL;
00337         DSM_twCC = TWCC_SUCCESS;
00338         twRC = TWRC_SUCCESS;
00339     }
00340     else
00341     {
00342         DSM_twCC = TWCC_SEQERROR;
00343         twRC = TWRC_FAILURE;
00344     }
00345 
00346     return twRC;
00347 #endif
00348 }
00349 
00350 /* DG_CONTROL/DAT_PARENT/MSG_OPENDSM */
00351 TW_UINT16 TWAIN_OpenDSM (pTW_IDENTITY pOrigin, TW_MEMREF pData)
00352 {
00353 #ifndef HAVE_SANE
00354     return TWRC_FAILURE;
00355 #else
00356     TW_UINT16 twRC = TWRC_SUCCESS;
00357     SANE_Status status;
00358     SANE_Int version_code;
00359 
00360     TRACE("DG_CONTROL/DAT_PARENT/MSG_OPENDSM\n");
00361 
00362     if (DSM_currentState == 2)
00363     {
00364         if (!DSM_initialized)
00365         {
00366             DSM_initialized = TRUE;
00367             status = sane_init (&version_code, NULL);
00368             device_list = NULL;
00369             DSM_currentDevice = 0;
00370             DSM_sourceId = 0;
00371         }
00372         DSM_parentHWND = *(TW_HANDLE*)pData;
00373         DSM_currentState = 3; /* transition to state 3 */
00374         DSM_twCC = TWCC_SUCCESS;
00375         twRC = TWRC_SUCCESS;
00376     }
00377     else
00378     {
00379         /* operation invoked in invalid state */
00380         DSM_twCC = TWCC_SEQERROR;
00381         twRC = TWRC_FAILURE;
00382     }
00383 
00384     return twRC;
00385 #endif
00386 }
00387 
00388 /* DG_CONTROL/DAT_STATUS/MSG_GET */
00389 TW_UINT16 TWAIN_GetDSMStatus (pTW_IDENTITY pOrigin, TW_MEMREF pData)
00390 {
00391     pTW_STATUS pSourceStatus = (pTW_STATUS) pData;
00392 
00393     TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
00394 
00395     pSourceStatus->ConditionCode = DSM_twCC;
00396     DSM_twCC = TWCC_SUCCESS;  /* clear the condition code */
00397 
00398     return TWRC_SUCCESS;
00399 }

Generated on Sat May 26 2012 04:25:10 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.