Twain_DSM  1.0
dsm.h
Go to the documentation of this file.
1 /***************************************************************************
2  * TWAIN Data Source Manager version 2.1
3  * Manages image acquisition data sources used by a machine.
4  * Copyright © 2007 TWAIN Working Group:
5  * Adobe Systems Incorporated,AnyDoc Software Inc., Eastman Kodak Company,
6  * Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
7  * Ricoh Corporation, and Xerox Corporation.
8  * All rights reserved.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  * Contact the TWAIN Working Group by emailing the Technical Subcommittee at
25  * twainwg@twain.org or mailing us at 13090 Hwy 9, Suite 3, Boulder Creek, CA 95006.
26  *
27  ***************************************************************************/
28 
37 #ifndef __DSM_H__
38 #define __DSM_H__
39 
40 
54 #define TWNDSM_CMP_VISUALCPP 0x1001
55 #define TWNDSM_CMP_GNUGPP 0x1002
56 
57 
58 
62 #define TWNDSM_OS_WINDOWS 0x2001
63 #define TWNDSM_OS_MACOSX 0x2002
64 #define TWNDSM_OS_LINUX 0x2003
65 
66 
67 
77 #ifndef TWNDSM_CMP
78 
96  // GNU g++
97  #if defined(__GNUC__)
98  #define TWNDSM_CMP TWNDSM_CMP_GNUGPP
99  #define TWNDSM_CMP_VERSION __GNUC__
100  #if defined(__APPLE__)
101  #define TWNDSM_OS TWNDSM_OS_MACOSX
102  #else
103  #define TWNDSM_OS TWNDSM_OS_LINUX
104  #endif
105  #if defined(__x86_64__) || defined(__LP64__)
106  #define TWNDSM_OS_64BIT 1
107  #else
108  #define TWNDSM_OS_32BIT 1
109  #endif
110 
111  // Visual Studio C++
112  #elif defined(_MSC_VER)
113  #define TWNDSM_CMP TWNDSM_CMP_VISUALCPP
114  #define TWNDSM_CMP_VERSION _MSC_VER
115  #define TWNDSM_OS TWNDSM_OS_WINDOWS
116  #if defined(_M_X64) || defined(_M_IA64)
117  #define TWNDSM_OS_64BIT 1
118  #else
119  #define TWNDSM_OS_32BIT 1
120  #endif
121 
122  // ruh-roh...
123  #else
124  Sorry, we do not recognize this system...
125  #endif
126 #endif
127 
128 
129 
133 #if (TWNDSM_CMP == TWNDSM_CMP_VISUALCPP)
134  #ifndef WIN32_LEAN_AND_MEAN
135  #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
136  #endif
137  #include <windows.h>
138  #include <direct.h>
139  #include <share.h>
140 
141 #elif (TWNDSM_CMP == TWNDSM_CMP_GNUGPP)
142  #include <dirent.h>
143  #include <dlfcn.h>
144  #include <unistd.h>
145  #include <errno.h>
146  #include <stdarg.h>
147  #include <time.h>
148  #include <sys/syscall.h>
149  #include <sys/time.h>
150  #define gettid() syscall(SYS_gettid)
151 
152 #else
153  #error Sorry, we do not recognize this system...
154 #endif
155 
156 // End @defgroup Enviroment
158 
159 
163 #include "resource.h"
164 
165 
166 
170 #include <stdio.h>
171 #include <assert.h>
172 #include <string.h>
173 #include <sys/stat.h>
174 #include <sys/types.h>
175 #include <stdlib.h>
176 
180 #ifndef __in
181  #define __in
182  #define __out
183  #define __in_opt
184 #endif
185 
186 
187 
191 #include "twain.h"
192 
193 
254 #if (TWNDSM_CMP == TWNDSM_CMP_VISUALCPP)
255 
256  // Define TW_IDENTITY.Id
257  #define TWID_T TW_UINT32
258  #define TWIDDEST_T TW_UINT32
259 
260  // For 64-bit systems we work the same as on Linux/MacOSX...
261  #if TWNDSM_OS_64BIT
262  #define LOADLIBRARY(lib,hook,DSID) LoadLibrary(lib)
263  #define UNLOADLIBRARY(hmodule,unhook,DSID) FreeLibrary((HMODULE)hmodule)
264 
265  // For 32-bit systems we use a hooking mechanism to help 1.x
266  // drivers find the new TWAINDSM.DLL...
267  #else
268  HMODULE InstallTwain32DllHooks
269  (
270  const char* const _lib,
271  const bool _hook,
272  const TWID_T _DSID
273  );
274  BOOL UninstallTwain32DllHooks
275  (
276  const HMODULE _hmodule,
277  const bool _unhook,
278  const TWID_T _DSID
279  );
280  #define LOADLIBRARY(lib,hook,DSID) InstallTwain32DllHooks(lib,hook,DSID)
281  #define UNLOADLIBRARY(hmodule,unhook,DSID) UninstallTwain32DllHooks((HMODULE)hmodule,unhook,DSID)
282  #endif
283 
284  #define DllExport __declspec( dllexport )
285  #define NCHARS(s) sizeof(s)/sizeof(s[0])
286  #define PATH_SEPERATOR '\\'
287 
288  #define LOADFUNCTION(lib, func) GetProcAddress((HMODULE)lib, func)
289  #define READ _read
290  #define CLOSE _close
291  #if (TWNDSM_CMP_VERSION >= 1400)
292  #define SNPRINTF _snprintf_s
293  #else
294  #define SNPRINTF _snprintf
295  #endif
296  #define UNLINK _unlink
297  #define STRNICMP _strnicmp
298  #define DSMENTRY TW_UINT16 FAR PASCAL
299  #define GETTHREADID ::GetCurrentThreadId
300  #define FOPEN(pf, name, mode) pf = _fsopen(name, mode, _SH_DENYNO)
301  #ifndef kTWAIN_DS_DIR
302  #if TWNDSM_OS_64BIT
303  #define kTWAIN_DS_DIR "twain_64"
304  #else
305  #define kTWAIN_DS_DIR "twain_32"
306  #endif
307  #endif
308 
309 #elif (TWNDSM_CMP == TWNDSM_CMP_GNUGPP)
310  #define DllExport
311  #define NCHARS(s) sizeof(s)/sizeof(s[0])
312  #define PATH_SEPERATOR '/'
313 #if (TWNDSM_OS == TWNDSM_OS_MACOSX)
314  #define LOADLIBRARY(lib,hook,DSID) \
315  CFBundleCreate(0, CFURLCreateWithFileSystemPath(0, CFStringCreateWithCStringNoCopy(0, _pPath, kCFStringEncodingUTF8, 0), kCFURLPOSIXPathStyle, TRUE))
316  #define UNLOADLIBRARY(lib,unhook,DSID) 0; CFRelease((CFBundleRef)(lib))
317 #else
318  #define LOADLIBRARY(lib,hook,DSID) dlopen(lib, RTLD_LAZY)
319  #define UNLOADLIBRARY(lib,unhook,DSID) dlclose(lib)
320 #endif
321  #define LOADFUNCTION(lib, func) dlsym(lib, func)
322  #define READ read
323  #define CLOSE close
324  #define SNPRINTF snprintf
325  #define UNLINK unlink
326  #define STRNICMP strncasecmp
327  #define GETTHREADID gettid
328  #define FOPEN(pf,name,mode) pf = fopen(name,mode)
329  #ifndef kTWAIN_DS_DIR
330  #if (TWNDSM_OS == TWNDSM_OS_MACOSX)
331  #define kTWAIN_DS_DIR "/Library/Image Capture/TWAIN Data Sources"
332  #else
333  #define kTWAIN_DS_DIR "/usr/local/lib/twain"
334  #endif
335  #endif
336  typedef unsigned int UINT;
337  typedef void* HINSTANCE;
338  typedef void* HWND;
339  #define DSMENTRY FAR PASCAL TW_UINT16
340 
341  #if (TWNDSM_OS == TWNDSM_OS_MACOSX)
342  #if TWNDSM_OS_64BIT
343  #define TWID_T unsigned long long
344  #define TWIDDEST_T TW_MEMREF
345  #else
346  #define TWID_T unsigned long
347  #define TWIDDEST_T TW_MEMREF
348  #endif
349  #else
350  #define TWID_T TW_UINT32
351  #define TWIDDEST_T TW_UINT32
352  #endif
353 
354 
355  #if !defined(TRUE)
356  #define FALSE 0
357  #define TRUE 1
358  #endif
359 
360 #else
361  #error Sorry, we do not recognize this system...
362 #endif
363 
364 
365 
400 #if (TWNDSM_CMP == TWNDSM_CMP_VISUALCPP) && (TWNDSM_CMP_VERSION >= 1400)
401  #define SSTRCPY(d,z,s) strncpy_s(d,z,s,_TRUNCATE)
402  #define SSTRCAT(d,z,s) strncat_s(d,z,s,_TRUNCATE)
403  #define SSTRNCPY(d,z,s,m) strncpy_s(d,z,s,m)
404  #define SGETENV(d,z,n) ::GetEnvironmentVariable(n,d,z)
405  inline int SSNPRINTF(char *d, const size_t z, const size_t c, const char* const f,...)
406  {
407  int result;
408  va_list valist;
409  va_start(valist,f);
410  result = _vsnprintf_s(d,z,c,f,valist);
411  va_end(valist);
412  return result;
413  }
414 
415 
420 #elif __APPLE__
421  #define SSTRCPY(d,z,s) strlcpy(d,s,z)
422  #define SSTRCAT(d,z,s) strcat(d,s)
423  #define SSTRNCPY(d,z,s,m) strncpy(d,s,m)
424  #define SGETENV(d,z,n) strcpy(d,getenv(n)?getenv(n):"")
425  inline int SSNPRINTF(char *d, const size_t, const size_t c, const char* const f,...)
426  {
427  int result;
428  va_list valist;
429  va_start(valist,f);
430  #if (TWNDSM_CMP == TWNDSM_CMP_VISUALCPP)
431  result = _vsnprintf(d,c,f,valist);
432  #elif (TWNDSM_CMP == TWNDSM_CMP_GNUGPP)
433  result = vsnprintf(d,c,f,valist);
434  #else
435  #error Sorry, we do not recognize this system...
436  #endif
437  va_end(valist);
438  return result;
439  }
440 
441 
446 #else
447  #define SSTRCPY(d,z,s) strcpy(d,s)
448  #define SSTRCAT(d,z,s) strcat(d,s)
449  #define SSTRNCPY(d,z,s,m) strncpy(d,s,m)
450  #define SGETENV(d,z,n) strcpy(d,getenv(n)?getenv(n):"")
451  inline int SSNPRINTF(char *d, const size_t, const size_t c, const char* const f,...)
452  {
453  int result;
454  va_list valist;
455  va_start(valist,f);
456  #if (TWNDSM_CMP == TWNDSM_CMP_VISUALCPP)
457  result = _vsnprintf(d,c,f,valist);
458  #elif (TWNDSM_CMP == TWNDSM_CMP_GNUGPP)
459  result = vsnprintf(d,c,f,valist);
460  #else
461  #error Sorry, we do not recognize this system...
462  #endif
463  va_end(valist);
464  return result;
465  }
466 #endif
467 // End @defgroup StringFunctions
469 
470 // End @defgroup CrossPlatformFunc
472 
473 
474 
485 #define kLOGINFO 0,__FILE__,__LINE__
486 
490 #define kLOGERR 1,__FILE__,__LINE__
491 
496 #define kLOG(a) if (g_ptwndsmlog) g_ptwndsmlog->Log a
497 
498 // End @defgroup Logging
500 
501 
507 #if (TWNDSM_CMP == TWNDSM_CMP_VISUALCPP)
508  #define kPANIC(msg) ::MessageBox(NULL,msg,"TWAIN Data Source Manager",MB_OK);
509 #elif (TWNDSM_CMP == TWNDSM_CMP_GNUGPP)
510  #define kPANIC(msg) fprintf(stderr,"TWAIN Data Source Manager: %s\r\n",msg);
511 #else
512  #error Sorry, we do not recognize this system...
513 #endif
514 
515 
521 #define MAX_NUM_DS 50
522 
523 
530 typedef enum
531 {
534  dsmState_Open = 3
536 
541 void* DSM_LoadFunction(void* _pHandle, const char* _pszSymbol);
542 
551 class CTwnDsmLogImpl;
553 {
554  public:
555 
559  CTwnDsmLog();
560 
564  ~CTwnDsmLog();
565 
575  void Log(const int _doassert,
576  const char* const _file,
577  const int _line,
578  const char* const _format,
579  ...);
580 
585  void Indent(int nChange);
586 
587  private:
588 
593 };
594 extern CTwnDsmLog *g_ptwndsmlog;
595 
596 
597 
608 class CTwnDsmAppsImpl;
610 {
611  public:
612 
616  CTwnDsmApps();
617 
621  ~CTwnDsmApps();
622 
630  TW_UINT16 AddApp(TW_IDENTITY *_pAppId,
631  TW_MEMREF _MemRef);
632 
639  TW_UINT16 RemoveApp(TW_IDENTITY *_pAppId);
640 
647  TW_INT16 LoadDS(TW_IDENTITY *_pAppId,
648  TWID_T _DsId);
649 
655  void UnloadDS(TW_IDENTITY *_pAppId,
656  TWID_T _DsId);
657 
663  TW_BOOL AppValidateId(TW_IDENTITY *_pAppId);
664 
671  TW_BOOL AppValidateIds(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDSId);
672 
681 
688  TW_UINT16 AppGetConditionCode(TW_IDENTITY *_pAppId);
689 
695  void AppSetConditionCode(TW_IDENTITY *_pAppId,
696  TW_UINT16 _conditioncode);
697 
703 
710 
716  void *AppHwnd(TW_IDENTITY *_pAppId);
717 
725  TWID_T AppGetNumDs(TW_IDENTITY *_pAppId);
726 
732  void AppWakeup(TW_IDENTITY *_pAppId);
733 
741  TWID_T _DsId);
742 
749  DSENTRYPROC DsGetEntryProc(TW_IDENTITY *_pAppId,
750  TWID_T _DsId);
751 
760  char *DsGetPath(TW_IDENTITY *_pAppId,
761  TWID_T _DsId);
762 
771  TWID_T _DsId);
772 
779  TW_BOOL DsCallbackIsWaiting(TW_IDENTITY *_pAppId,
780  TWID_T _DsId);
781 
790  void DsCallbackSetWaiting(TW_IDENTITY *_pAppId,
791  TWID_T _DsId,
792  TW_BOOL _Waiting);
793 
800  TW_BOOL DsIsProcessingMessage(TW_IDENTITY *_pAppId,
801  TWID_T _DsId);
802 
810  void DsSetProcessingMessage(TW_IDENTITY *_pAppId,
811  TWID_T _DsId,
812  TW_BOOL _Processing);
813 
820  TW_BOOL DsIsAppProcessingCallback(TW_IDENTITY *_pAppId,
821  TWID_T _DsId);
822 
831  TWID_T _DsId,
832  TW_BOOL _Processing);
833 
838  TWID_T AppGetNumApp();
839 
840  private:
841 
846 };
847 
848 
849 
860 class CTwnDsm
861 {
862  //
863  // All of our public functions go here...
864  //
865  public:
866 
870  CTwnDsm();
871 
875  ~CTwnDsm();
876 
890  TW_UINT16 DSM_Entry(TW_IDENTITY *_pOrigin,
891  TW_IDENTITY *_pDest,
892  TW_UINT32 _DG,
893  TW_UINT16 _DAT,
894  TW_UINT16 _MSG,
895  TW_MEMREF _pData);
896 
897  #if (TWNDSM_CMP == TWNDSM_CMP_VISUALCPP)
898 
908  BOOL CALLBACK SelectDlgProc(HWND _hWnd,
909  UINT _Message,
910  WPARAM _wParam,
911  LPARAM _lParam);
912  #elif (TWNDSM_CMP == TWNDSM_CMP_GNUGPP)
913  // We don't have one of these...
914  #else
915  #error Sorry, we do not recognize this system...
916  #endif
917 
923 
924 
925  //
926  // All of our private functions go here...
927  //
928  private:
929 
937  TW_INT16 DSM_Null(TW_IDENTITY *_pAppId,
938  TW_IDENTITY *_pDsId,
939  TW_UINT16 _MSG);
940 
949  TW_INT16 DSM_Status(TW_IDENTITY *_pAppId,
950  TW_UINT16 _MSG,
951  TW_STATUS *_pStatus);
952 
960  TW_INT16 DSM_Parent(TW_IDENTITY *_pAppId,
961  TW_UINT16 _MSG,
962  TW_MEMREF _MemRef);
963 
971  TW_INT16 DSM_Identity(TW_IDENTITY *_pAppId,
972  TW_UINT16 _MSG,
973  TW_IDENTITY *_pDsId);
974 
986  TW_INT16 DSM_TwunkIdentity(TW_IDENTITY *_pAppId,
987  TW_UINT16 _MSG,
988  TW_TWUNKIDENTITY *_pTwunkId);
989 
997  TW_INT16 DSM_Entrypoint(TW_IDENTITY *_pAppId,
998  TW_UINT16 _MSG,
999  TW_ENTRYPOINT *_pEntrypoint);
1000 
1009  TW_INT16 DSM_Callback(TW_IDENTITY *_pAppId,
1010  TW_IDENTITY *_pDsId,
1011  TW_UINT16 _MSG,
1012  TW_CALLBACK *_pData);
1013 
1022  TW_INT16 DSM_Callback2(TW_IDENTITY *_pAppId,
1023  TW_IDENTITY *_pDsId,
1024  TW_UINT16 _MSG,
1025  TW_CALLBACK2 *_pData);
1026 
1035  TW_INT16 OpenDS(TW_IDENTITY *_pAppId,
1036  TW_IDENTITY *_pDsId);
1037 
1044  TW_INT16 CloseDS(TW_IDENTITY *_pAppId,
1045  TW_IDENTITY *_pDsId);
1046 
1053  TW_INT16 DSM_SelectDS(TW_IDENTITY *_pAppId,
1054  TW_IDENTITY *_pDsId);
1055 
1062  TW_INT16 DSM_SetDefaultDS(TW_IDENTITY *_pAppId,
1063  TW_IDENTITY *_pDsId);
1064 
1073  TW_INT16 GetDSFromProductName(TW_IDENTITY *_pAppId,
1074  TW_IDENTITY *_pDsId);
1075 
1082  TW_INT16 DSM_GetFirst(TW_IDENTITY *_pAppId,
1083  TW_IDENTITY *_pDsId);
1084 
1092  TW_INT16 DSM_GetNext(TW_IDENTITY *_pAppId,
1093  TW_IDENTITY *_pDsId);
1094 
1104  TW_INT16 GetMatchingDefault(TW_IDENTITY *_pAppId,
1105  TW_IDENTITY *_pDsId);
1106 
1115  TW_INT16 GetIdentity(TW_IDENTITY *_pAppId,
1116  TW_IDENTITY *_pDsId);
1117 
1128  bool printTripletsInfo(const TW_IDENTITY *_pOrigin,
1129  const TW_IDENTITY *_pDest,
1130  const TW_UINT32 _DG,
1131  const TW_UINT16 _DAT,
1132  const TW_UINT16 _MSG,
1133  const TW_MEMREF _pData);
1134 
1143  void printResults(const TW_UINT32 _DG,
1144  const TW_UINT16 _DAT,
1145  const TW_UINT16 _MSG,
1146  const TW_MEMREF _pData,
1147  const TW_UINT16 _RC);
1148 
1155  void StringFromMsg(char *_szMsg,
1156  const int _nChars,
1157  const TW_UINT16 _MSG);
1158 
1165  void StringFromDat(char *_szDat,
1166  const int _nChars,
1167  const TW_UINT16 _DAT);
1168 
1175  void StringFromDg(char *_szDg,
1176  const int _nChars,
1177  const TW_UINT32 _DG);
1178 
1185  void StringFromCap(char *_szCap,
1186  const int _nChars,
1187  const TW_UINT16 _Cap);
1188 
1195  void StringFromConType(char *_szConType,
1196  const int _nChars,
1197  const TW_UINT16 _ConType);
1198 
1205  void StringFromRC(char *_szRc,
1206  const int _nChars,
1207  const TW_UINT16 _rc);
1208 
1215  void StringFromConditionCode(char *_szCondCode,
1216  const int _nChars,
1217  const TW_UINT16 _cc);
1218 
1219 
1220  //
1221  // All of our attributes should be private. Encapsulation
1222  // is a good thing... :)
1223  //
1224  private:
1225 
1226  /*
1227  ** If you add a class in future, declare it here and not
1228  ** in the pod, or the memset we do on pod will ruin your
1229  ** day...
1230  */
1231 
1236  struct _pod
1237  {
1242 
1248  char m_DefaultDSPath[FILENAME_MAX];
1249 
1253  TWID_T m_nextDsId;
1254 
1260 
1266  } pod;
1267 };
1268 
1269 
1270 #endif // __DSM_H__
CTwnDsm::SelectDlgProc
BOOL CALLBACK SelectDlgProc(HWND _hWnd, UINT _Message, WPARAM _wParam, LPARAM _lParam)
Selection dialog, for apps that don't want to do GetFirst GetNext.
Definition: dsm.cpp:1517
CTwnDsmApps::AppSetConditionCode
void AppSetConditionCode(TW_IDENTITY *_pAppId, TW_UINT16 _conditioncode)
Set the condition code.
Definition: apps.cpp:647
CTwnDsmLog
Our logging class.
Definition: dsm.h:553
CTwnDsmAppsImpl
Impl Class to hold list of connected applications.
Definition: apps.cpp:241
CTwnDsmApps::DsSetProcessingMessage
void DsSetProcessingMessage(TW_IDENTITY *_pAppId, TWID_T _DsId, TW_BOOL _Processing)
Set the ProcessingMessage flag.
Definition: apps.cpp:958
CTwnDsmApps::DsGetPath
char * DsGetPath(TW_IDENTITY *_pAppId, TWID_T _DsId)
Get a pointer to the driver file path and name, which is guaranteed to be unique, even if the Product...
Definition: apps.cpp:834
CTwnDsmApps::AddApp
TW_UINT16 AddApp(TW_IDENTITY *_pAppId, TW_MEMREF _MemRef)
Add an application.
Definition: apps.cpp:364
CTwnDsmApps::m_ptwndsmappsimpl
CTwnDsmAppsImpl * m_ptwndsmappsimpl
The implementation pointer helps with encapulation.
Definition: dsm.h:845
CTwnDsm::_pod
We use a pod system because it help prevents us from making dumb initialization mistakes.
Definition: dsm.h:1237
CTwnDsmApps::AppValidateId
TW_BOOL AppValidateId(TW_IDENTITY *_pAppId)
Validate that an id is in range...
Definition: apps.cpp:541
CTwnDsm::_pod::m_pSelectDlgDsId
TW_IDENTITY * m_pSelectDlgDsId
The DS ID we end up with from SelectDlgProc.
Definition: dsm.h:1259
CTwnDsmLogImpl
Our implementation class where we hide our attributes...
Definition: log.cpp:67
CTwnDsm::DSM_Parent
TW_INT16 DSM_Parent(TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_MEMREF _MemRef)
Initializes or closes the DSM.
Definition: dsm.cpp:726
CTwnDsmApps::DsGetIdentity
TW_IDENTITY * DsGetIdentity(TW_IDENTITY *_pAppId, TWID_T _DsId)
Get a pointer to the identity of the specified driver...
Definition: apps.cpp:785
CTwnDsm::DSM_Identity
TW_INT16 DSM_Identity(TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_IDENTITY *_pDsId)
Source operations.
Definition: dsm.cpp:772
DSM_LoadFunction
void * DSM_LoadFunction(void *_pHandle, const char *_pszSymbol)
This function wraps the function loading calls.
Definition: dsm.cpp:3892
CTwnDsmLog::Log
void Log(const int _doassert, const char *const _file, const int _line, const char *const _format,...)
The logging function.
Definition: log.cpp:173
CTwnDsm::DSM_Status
TW_INT16 DSM_Status(TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_STATUS *_pStatus)
Returns the current DSM status.
Definition: dsm.cpp:696
CTwnDsm::printTripletsInfo
bool printTripletsInfo(const TW_IDENTITY *_pOrigin, const TW_IDENTITY *_pDest, const TW_UINT32 _DG, const TW_UINT16 _DAT, const TW_UINT16 _MSG, const TW_MEMREF _pData)
prints to stdout information about the triplets.
Definition: dsm.cpp:2328
CTwnDsm::_pod::m_nextDsId
TWID_T m_nextDsId
The next id to test for GetFirst/GetNext...
Definition: dsm.h:1253
CTwnDsmApps::DsCallbackSetWaiting
void DsCallbackSetWaiting(TW_IDENTITY *_pAppId, TWID_T _DsId, TW_BOOL _Waiting)
Set the callback flag for the driver to TRUE if the callback needs to have its callback called,...
Definition: apps.cpp:909
TW_TWUNKIDENTITY
Definition: twain.h:2094
CTwnDsm::_pod::m_DefaultDSPath
char m_DefaultDSPath[FILENAME_MAX]
The path to the default DS.
Definition: dsm.h:1248
g_ptwndsmlog
CTwnDsmLog * g_ptwndsmlog
The logging object, only access through macros.
Definition: dsm.cpp:70
CTwnDsmApps::RemoveApp
TW_UINT16 RemoveApp(TW_IDENTITY *_pAppId)
Remove an application.
Definition: apps.cpp:465
CTwnDsm::StringFromDg
void StringFromDg(char *_szDg, const int _nChars, const TW_UINT32 _DG)
Translates the _DG passed in into a string and returns it.
Definition: dsm.cpp:2560
CTwnDsm::_pod::m_pSelectDlgAppId
TW_IDENTITY * m_pSelectDlgAppId
The Application ID we're using inside of SelectDlgProc.
Definition: dsm.h:1265
TW_IDENTITY
Definition: twain.h:443
TW_ENTRYPOINT
Definition: twain.h:2221
CTwnDsm::StringFromConditionCode
void StringFromConditionCode(char *_szCondCode, const int _nChars, const TW_UINT16 _cc)
Translates the Condition Code passed in into a string and returns it.
Definition: dsm.cpp:3615
TW_CALLBACK
Definition: twain.h:297
dsmState_PreSession
@ dsmState_PreSession
Source Manager not loaded.
Definition: dsm.h:532
CTwnDsmApps::DsCallbackIsWaiting
TW_BOOL DsCallbackIsWaiting(TW_IDENTITY *_pAppId, TWID_T _DsId)
Test if the driver has a callback pending for attention...
Definition: apps.cpp:885
CTwnDsm::~CTwnDsm
~CTwnDsm()
Our CTwnDsm destructor...
Definition: dsm.cpp:428
TW_CALLBACK2
Definition: twain.h:308
CTwnDsm::DSM_Callback2
TW_INT16 DSM_Callback2(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId, TW_UINT16 _MSG, TW_CALLBACK2 *_pData)
Register application's callback.
Definition: dsm.cpp:1055
CTwnDsm::DSM_SetDefaultDS
TW_INT16 DSM_SetDefaultDS(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId)
Set the default source.
Definition: dsm.cpp:1955
CTwnDsm::CTwnDsm
CTwnDsm()
Our CTwnDsm constructor...
Definition: dsm.cpp:395
CTwnDsmApps::DsIsProcessingMessage
TW_BOOL DsIsProcessingMessage(TW_IDENTITY *_pAppId, TWID_T _DsId)
Check if the DS is still processing last message.
Definition: apps.cpp:934
CTwnDsmApps::AppValidateIds
TW_BOOL AppValidateIds(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDSId)
Validate that the App ID and DS ID are in range...
Definition: apps.cpp:561
CTwnDsmApps::AppGetConditionCode
TW_UINT16 AppGetConditionCode(TW_IDENTITY *_pAppId)
Get the condition code, then reset it internally to TWCC_SUCCESS, so you can only get it once,...
Definition: apps.cpp:619
CTwnDsmApps::DsIsAppProcessingCallback
TW_BOOL DsIsAppProcessingCallback(TW_IDENTITY *_pAppId, TWID_T _DsId)
Check if the App is still processing last callback.
Definition: apps.cpp:982
CTwnDsm::DSM_Entrypoint
TW_INT16 DSM_Entrypoint(TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_ENTRYPOINT *_pEntrypoint)
Gets entry points.
Definition: dsm.cpp:893
CTwnDsmApps::LoadDS
TW_INT16 LoadDS(TW_IDENTITY *_pAppId, TWID_T _DsId)
Loads a DS from disk and adds it to a global list of DS's.
Definition: apps.cpp:1380
CTwnDsm::printResults
void printResults(const TW_UINT32 _DG, const TW_UINT16 _DAT, const TW_UINT16 _MSG, const TW_MEMREF _pData, const TW_UINT16 _RC)
prints to stdout information about result of processing the triplets.
Definition: dsm.cpp:2402
CTwnDsm::StringFromRC
void StringFromRC(char *_szRc, const int _nChars, const TW_UINT16 _rc)
Translates the rc passed in into a string and returns it.
Definition: dsm.cpp:3525
CTwnDsmLog::CTwnDsmLog
CTwnDsmLog()
The CTwnDsmLog constructor.
Definition: log.cpp:106
CTwnDsm::DSM_Null
TW_INT16 DSM_Null(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId, TW_UINT16 _MSG)
Handles DAT_NULL calls from DS for Application.
Definition: dsm.cpp:2453
dsmState_Open
@ dsmState_Open
Source Manager is open.
Definition: dsm.h:534
CTwnDsm::GetIdentity
TW_INT16 GetIdentity(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId)
Return back the tw_identity of the current source.
CTwnDsmLog::~CTwnDsmLog
~CTwnDsmLog()
The CTwnDsmLog destructor.
Definition: log.cpp:139
CTwnDsmApps::AppGetNumDs
TWID_T AppGetNumDs(TW_IDENTITY *_pAppId)
Get the number of drivers we found as the result of a successful call to LoadDS with _boolKeepOpen se...
Definition: apps.cpp:762
CTwnDsm::DSM_GetFirst
TW_INT16 DSM_GetFirst(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId)
Copies the applications first available source into _pDsId.
Definition: dsm.cpp:2113
CTwnDsm::OpenDS
TW_INT16 OpenDS(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId)
Opens the Data Source specified by pDSIdentity.
Definition: dsm.cpp:1134
CTwnDsmApps::DsGetEntryProc
DSENTRYPROC DsGetEntryProc(TW_IDENTITY *_pAppId, TWID_T _DsId)
Get a pointer to the DS_Entry function of the specified driver...
Definition: apps.cpp:809
CTwnDsmApps::DsCallback2Get
TW_CALLBACK2 * DsCallback2Get(TW_IDENTITY *_pAppId, TWID_T _DsId)
Get a pointer to TW_CALLBACK structure for the specified driver...
Definition: apps.cpp:860
CTwnDsm::StringFromMsg
void StringFromMsg(char *_szMsg, const int _nChars, const TW_UINT16 _MSG)
Translates the _MSG passed in into a string and returns it.
Definition: dsm.cpp:2749
CTwnDsmApps::~CTwnDsmApps
~CTwnDsmApps()
The CTwnDsmApps destructor.
Definition: apps.cpp:328
CTwnDsm::DSM_GetNext
TW_INT16 DSM_GetNext(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId)
Copies the applications next available source into _pDsId.
Definition: dsm.cpp:2158
CTwnDsmApps::UnloadDS
void UnloadDS(TW_IDENTITY *_pAppId, TWID_T _DsId)
Unloads a DS and frees all its resources...
Definition: apps.cpp:1853
CTwnDsmApps::DsSetAppProcessingCallback
void DsSetAppProcessingCallback(TW_IDENTITY *_pAppId, TWID_T _DsId, TW_BOOL _Processing)
Set the AppProcessingCallback flag.
Definition: apps.cpp:1005
CTwnDsm::CloseDS
TW_INT16 CloseDS(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId)
Closes the Data Source specified by pDSIdentity.
Definition: dsm.cpp:1348
CTwnDsm::DSM_Callback
TW_INT16 DSM_Callback(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId, TW_UINT16 _MSG, TW_CALLBACK *_pData)
Register application's callback.
Definition: dsm.cpp:973
CTwnDsm::DSMGetState
DSM_State DSMGetState()
Get the state of the DSM by checking the state of all applications.
Definition: dsm.cpp:683
CTwnDsmApps::AppHwnd
void * AppHwnd(TW_IDENTITY *_pAppId)
Get the hwnd sent in with the call to MSG_OPENDSM.
Definition: apps.cpp:740
CTwnDsm::GetMatchingDefault
TW_INT16 GetMatchingDefault(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId)
This routine will check if the current default source matches the applications supported groups.
Definition: dsm.cpp:2199
CTwnDsm::StringFromConType
void StringFromConType(char *_szConType, const int _nChars, const TW_UINT16 _ConType)
Translates the _ConType and _hContainer passed in into a string and returns it.
Definition: dsm.cpp:3580
CTwnDsm::DSM_Entry
TW_UINT16 DSM_Entry(TW_IDENTITY *_pOrigin, TW_IDENTITY *_pDest, TW_UINT32 _DG, TW_UINT16 _DAT, TW_UINT16 _MSG, TW_MEMREF _pData)
The guts of the DSM_Entry, the resource management portion resides in a our DSM_Entry entry point,...
Definition: dsm.cpp:447
CTwnDsmApps::AppGetNumApp
TWID_T AppGetNumApp()
Get number of allocated App slots (Last valid App ID +1)
Definition: apps.cpp:729
CTwnDsmApps::AppWakeup
void AppWakeup(TW_IDENTITY *_pAppId)
Poke the application to wake it up when sending a DAT_NULL message to it...
Definition: apps.cpp:1893
CTwnDsm::_pod::m_ptwndsmapps
CTwnDsmApps * m_ptwndsmapps
The class takes care of our list of applications and drivers.
Definition: dsm.h:1241
CTwnDsmLog::Indent
void Indent(int nChange)
Indent the logging to help with seeing recursive calls param[in] nChange Either +1 or -1.
Definition: log.cpp:302
CTwnDsmApps::AppGetState
DSM_State AppGetState()
Get the state of the DSM for all applications.
Definition: apps.cpp:688
CTwnDsmLog::m_ptwndsmlogimpl
CTwnDsmLogImpl * m_ptwndsmlogimpl
The implementation pointer helps with encapulation.
Definition: dsm.h:592
CTwnDsm::GetDSFromProductName
TW_INT16 GetDSFromProductName(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId)
Goes through the applications supported data sources looking for one that has the exact same name as ...
Definition: dsm.cpp:2072
CTwnDsm::StringFromDat
void StringFromDat(char *_szDat, const int _nChars, const TW_UINT16 _DAT)
Translates the _DAT passed in into a string and returns it.
Definition: dsm.cpp:2589
CTwnDsmApps::CTwnDsmApps
CTwnDsmApps()
The CTwnDsmApps constructor.
Definition: apps.cpp:314
TW_STATUS
Definition: twain.h:587
CTwnDsm::DSM_SelectDS
TW_INT16 DSM_SelectDS(TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId)
Displays the source select dialog and sets the default source.
Definition: dsm.cpp:1800
CTwnDsm::StringFromCap
void StringFromCap(char *_szCap, const int _nChars, const TW_UINT16 _Cap)
Translates the _Cap passed in into a string and returns it.
Definition: dsm.cpp:2924
DSM_State
DSM_State
Possible States of the DSM.
Definition: dsm.h:531
CTwnDsm::DSM_TwunkIdentity
TW_INT16 DSM_TwunkIdentity(TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_TWUNKIDENTITY *_pTwunkId)
This routine will return the path to a DS.
Definition: dsm.cpp:843
CTwnDsm
This is the main class for the Data Source Manager.
Definition: dsm.h:861
dsmState_Loaded
@ dsmState_Loaded
Source Manager is loaded, but not open.
Definition: dsm.h:533
CTwnDsm::pod
struct CTwnDsm::_pod pod
Pieces of Data for the DSM class.
CTwnDsmApps::AppGetIdentity
TW_IDENTITY * AppGetIdentity(TW_IDENTITY *_pAppId)
Return a pointer to the application's identity.
Definition: apps.cpp:598
CTwnDsmApps
Class to hold list of connected applications.
Definition: dsm.h:610