Twain_DSM
1.0
|
We want to use secure string functions whenever possible, if g++ every includes a set I think it would be excellent to switch over to it, but at least with Windows using them we stand a better chance of finding boo-boos... More...
Modules | |
logging defines and functions | |
These functions are insecure, but everybody has them, so we don't need an else/error section like we use everywhere else... | |
Classes | |
class | CTwnDsmLog |
Our logging class. More... | |
class | CTwnDsmApps |
Class to hold list of connected applications. More... | |
class | CTwnDsm |
This is the main class for the Data Source Manager. More... | |
struct | CTwnDsm::_pod |
We use a pod system because it help prevents us from making dumb initialization mistakes. More... | |
Macros | |
#define | SSTRCPY(d, z, s) strncpy_s(d,z,s,_TRUNCATE) |
Secure String copy. More... | |
#define | SSTRCAT(d, z, s) strncat_s(d,z,s,_TRUNCATE) |
Secure String catinate. More... | |
#define | SSTRNCPY(d, z, s, m) strncpy_s(d,z,s,m) |
Secure String n copy. More... | |
#define | SGETENV(d, z, n) ::GetEnvironmentVariable(n,d,z) |
Secure Get enviroment varable. More... | |
#define | kLOGINFO 0,__FILE__,__LINE__ |
write info messages to LogFile. | |
#define | kLOGERR 1,__FILE__,__LINE__ |
write error messages to LogFile. | |
#define | kLOG(a) if (g_ptwndsmlog) g_ptwndsmlog->Log a |
Define to write messages to LogFile. More... | |
#define | kPANIC(msg) ::MessageBox(NULL,msg,"TWAIN Data Source Manager",MB_OK); |
Display message to user. More... | |
#define | MAX_NUM_DS 50 |
Maximum number of Data Sources that can be opened under one application. More... | |
Enumerations | |
enum | DSM_State { dsmState_PreSession = 1, dsmState_Loaded = 2, dsmState_Open = 3 } |
Possible States of the DSM. More... | |
Functions | |
int | SSNPRINTF (char *d, const size_t z, const size_t c, const char *const f,...) |
void * | DSM_LoadFunction (void *_pHandle, const char *_pszSymbol) |
This function wraps the function loading calls. More... | |
CTwnDsmLog::CTwnDsmLog () | |
The CTwnDsmLog constructor. More... | |
CTwnDsmLog::~CTwnDsmLog () | |
The CTwnDsmLog destructor. More... | |
void | CTwnDsmLog::Log (const int _doassert, const char *const _file, const int _line, const char *const _format,...) |
The logging function. More... | |
void | CTwnDsmLog::Indent (int nChange) |
Indent the logging to help with seeing recursive calls param[in] nChange Either +1 or -1. | |
CTwnDsmApps::CTwnDsmApps () | |
The CTwnDsmApps constructor. More... | |
CTwnDsmApps::~CTwnDsmApps () | |
The CTwnDsmApps destructor. More... | |
TW_UINT16 | CTwnDsmApps::AddApp (TW_IDENTITY *_pAppId, TW_MEMREF _MemRef) |
Add an application. More... | |
TW_UINT16 | CTwnDsmApps::RemoveApp (TW_IDENTITY *_pAppId) |
Remove an application. More... | |
TW_INT16 | CTwnDsmApps::LoadDS (TW_IDENTITY *_pAppId, TWID_T _DsId) |
Loads a DS from disk and adds it to a global list of DS's. More... | |
void | CTwnDsmApps::UnloadDS (TW_IDENTITY *_pAppId, TWID_T _DsId) |
Unloads a DS and frees all its resources... More... | |
TW_BOOL | CTwnDsmApps::AppValidateId (TW_IDENTITY *_pAppId) |
Validate that an id is in range... More... | |
TW_BOOL | CTwnDsmApps::AppValidateIds (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDSId) |
Validate that the App ID and DS ID are in range... More... | |
TW_IDENTITY * | CTwnDsmApps::AppGetIdentity (TW_IDENTITY *_pAppId) |
Return a pointer to the application's identity. More... | |
TW_UINT16 | CTwnDsmApps::AppGetConditionCode (TW_IDENTITY *_pAppId) |
Get the condition code, then reset it internally to TWCC_SUCCESS, so you can only get it once, per the specification... More... | |
void | CTwnDsmApps::AppSetConditionCode (TW_IDENTITY *_pAppId, TW_UINT16 _conditioncode) |
Set the condition code. More... | |
DSM_State | CTwnDsmApps::AppGetState () |
Get the state of the DSM for all applications. More... | |
DSM_State | CTwnDsmApps::AppGetState (TW_IDENTITY *_pAppId) |
Get the state of the DSM for the specified application. More... | |
void * | CTwnDsmApps::AppHwnd (TW_IDENTITY *_pAppId) |
Get the hwnd sent in with the call to MSG_OPENDSM. More... | |
TWID_T | CTwnDsmApps::AppGetNumDs (TW_IDENTITY *_pAppId) |
Get the number of drivers we found as the result of a successful call to LoadDS with _boolKeepOpen set to false (meaning that we were just browsing)... More... | |
void | CTwnDsmApps::AppWakeup (TW_IDENTITY *_pAppId) |
Poke the application to wake it up when sending a DAT_NULL message to it... More... | |
TW_IDENTITY * | CTwnDsmApps::DsGetIdentity (TW_IDENTITY *_pAppId, TWID_T _DsId) |
Get a pointer to the identity of the specified driver... More... | |
DSENTRYPROC | CTwnDsmApps::DsGetEntryProc (TW_IDENTITY *_pAppId, TWID_T _DsId) |
Get a pointer to the DS_Entry function of the specified driver... More... | |
char * | CTwnDsmApps::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 ProductName's aren't for some horrible reason... More... | |
TW_CALLBACK2 * | CTwnDsmApps::DsCallback2Get (TW_IDENTITY *_pAppId, TWID_T _DsId) |
Get a pointer to TW_CALLBACK structure for the specified driver... More... | |
TW_BOOL | CTwnDsmApps::DsCallbackIsWaiting (TW_IDENTITY *_pAppId, TWID_T _DsId) |
Test if the driver has a callback pending for attention... More... | |
void | CTwnDsmApps::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, and set it to FALSE after the call has been made... More... | |
TW_BOOL | CTwnDsmApps::DsIsProcessingMessage (TW_IDENTITY *_pAppId, TWID_T _DsId) |
Check if the DS is still processing last message. More... | |
void | CTwnDsmApps::DsSetProcessingMessage (TW_IDENTITY *_pAppId, TWID_T _DsId, TW_BOOL _Processing) |
Set the ProcessingMessage flag. More... | |
TW_BOOL | CTwnDsmApps::DsIsAppProcessingCallback (TW_IDENTITY *_pAppId, TWID_T _DsId) |
Check if the App is still processing last callback. More... | |
void | CTwnDsmApps::DsSetAppProcessingCallback (TW_IDENTITY *_pAppId, TWID_T _DsId, TW_BOOL _Processing) |
Set the AppProcessingCallback flag. More... | |
TWID_T | CTwnDsmApps::AppGetNumApp () |
Get number of allocated App slots (Last valid App ID +1) More... | |
CTwnDsm::CTwnDsm () | |
Our CTwnDsm constructor... | |
CTwnDsm::~CTwnDsm () | |
Our CTwnDsm destructor... | |
TW_UINT16 | CTwnDsm::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, which isn't a part of this class. More... | |
BOOL CALLBACK | CTwnDsm::SelectDlgProc (HWND _hWnd, UINT _Message, WPARAM _wParam, LPARAM _lParam) |
Selection dialog, for apps that don't want to do GetFirst GetNext. More... | |
DSM_State | CTwnDsm::DSMGetState () |
Get the state of the DSM by checking the state of all applications. More... | |
TW_INT16 | CTwnDsm::DSM_Null (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId, TW_UINT16 _MSG) |
Handles DAT_NULL calls from DS for Application. More... | |
TW_INT16 | CTwnDsm::DSM_Status (TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_STATUS *_pStatus) |
Returns the current DSM status. More... | |
TW_INT16 | CTwnDsm::DSM_Parent (TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_MEMREF _MemRef) |
Initializes or closes the DSM. More... | |
TW_INT16 | CTwnDsm::DSM_Identity (TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_IDENTITY *_pDsId) |
Source operations. More... | |
TW_INT16 | CTwnDsm::DSM_TwunkIdentity (TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_TWUNKIDENTITY *_pTwunkId) |
This routine will return the path to a DS. More... | |
TW_INT16 | CTwnDsm::DSM_Entrypoint (TW_IDENTITY *_pAppId, TW_UINT16 _MSG, TW_ENTRYPOINT *_pEntrypoint) |
Gets entry points. More... | |
TW_INT16 | CTwnDsm::DSM_Callback (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId, TW_UINT16 _MSG, TW_CALLBACK *_pData) |
Register application's callback. More... | |
TW_INT16 | CTwnDsm::DSM_Callback2 (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId, TW_UINT16 _MSG, TW_CALLBACK2 *_pData) |
Register application's callback. More... | |
TW_INT16 | CTwnDsm::OpenDS (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId) |
Opens the Data Source specified by pDSIdentity. More... | |
TW_INT16 | CTwnDsm::CloseDS (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId) |
Closes the Data Source specified by pDSIdentity. More... | |
TW_INT16 | CTwnDsm::DSM_SelectDS (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId) |
Displays the source select dialog and sets the default source. More... | |
TW_INT16 | CTwnDsm::DSM_SetDefaultDS (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId) |
Set the default source. More... | |
TW_INT16 | CTwnDsm::GetDSFromProductName (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId) |
Goes through the applications supported data sources looking for one that has the exact same name as product name in the passed in identity. More... | |
TW_INT16 | CTwnDsm::DSM_GetFirst (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId) |
Copies the applications first available source into _pDsId. More... | |
TW_INT16 | CTwnDsm::DSM_GetNext (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId) |
Copies the applications next available source into _pDsId. More... | |
TW_INT16 | CTwnDsm::GetMatchingDefault (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId) |
This routine will check if the current default source matches the applications supported groups. More... | |
TW_INT16 | CTwnDsm::GetIdentity (TW_IDENTITY *_pAppId, TW_IDENTITY *_pDsId) |
Return back the tw_identity of the current source. More... | |
bool | CTwnDsm::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. More... | |
void | CTwnDsm::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. More... | |
void | CTwnDsm::StringFromMsg (char *_szMsg, const int _nChars, const TW_UINT16 _MSG) |
Translates the _MSG passed in into a string and returns it. More... | |
void | CTwnDsm::StringFromDat (char *_szDat, const int _nChars, const TW_UINT16 _DAT) |
Translates the _DAT passed in into a string and returns it. More... | |
void | CTwnDsm::StringFromDg (char *_szDg, const int _nChars, const TW_UINT32 _DG) |
Translates the _DG passed in into a string and returns it. More... | |
void | CTwnDsm::StringFromCap (char *_szCap, const int _nChars, const TW_UINT16 _Cap) |
Translates the _Cap passed in into a string and returns it. More... | |
void | CTwnDsm::StringFromConType (char *_szConType, const int _nChars, const TW_UINT16 _ConType) |
Translates the _ConType and _hContainer passed in into a string and returns it. More... | |
void | CTwnDsm::StringFromRC (char *_szRc, const int _nChars, const TW_UINT16 _rc) |
Translates the rc passed in into a string and returns it. More... | |
void | CTwnDsm::StringFromConditionCode (char *_szCondCode, const int _nChars, const TW_UINT16 _cc) |
Translates the Condition Code passed in into a string and returns it. More... | |
Variables | |
CTwnDsmLogImpl * | CTwnDsmLog::m_ptwndsmlogimpl |
The implementation pointer helps with encapulation. | |
CTwnDsmLog * | g_ptwndsmlog |
The logging object, only access through macros. | |
CTwnDsmAppsImpl * | CTwnDsmApps::m_ptwndsmappsimpl |
The implementation pointer helps with encapulation. | |
CTwnDsmApps * | CTwnDsm::_pod::m_ptwndsmapps |
The class takes care of our list of applications and drivers. | |
char | CTwnDsm::_pod::m_DefaultDSPath [FILENAME_MAX] |
The path to the default DS. More... | |
TWID_T | CTwnDsm::_pod::m_nextDsId |
The next id to test for GetFirst/GetNext... | |
TW_IDENTITY * | CTwnDsm::_pod::m_pSelectDlgDsId |
The DS ID we end up with from SelectDlgProc. More... | |
TW_IDENTITY * | CTwnDsm::_pod::m_pSelectDlgAppId |
The Application ID we're using inside of SelectDlgProc. More... | |
struct CTwnDsm::_pod | CTwnDsm::pod |
Pieces of Data for the DSM class. | |
We want to use secure string functions whenever possible, if g++ every includes a set I think it would be excellent to switch over to it, but at least with Windows using them we stand a better chance of finding boo-boos...
#define kLOG | ( | a | ) | if (g_ptwndsmlog) g_ptwndsmlog->Log a |
#define kPANIC | ( | msg | ) | ::MessageBox(NULL,msg,"TWAIN Data Source Manager",MB_OK); |
#define MAX_NUM_DS 50 |
#define SGETENV | ( | d, | |
z, | |||
n | |||
) | ::GetEnvironmentVariable(n,d,z) |
#define SSTRCAT | ( | d, | |
z, | |||
s | |||
) | strncat_s(d,z,s,_TRUNCATE) |
#define SSTRCPY | ( | d, | |
z, | |||
s | |||
) | strncpy_s(d,z,s,_TRUNCATE) |
#define SSTRNCPY | ( | d, | |
z, | |||
s, | |||
m | |||
) | strncpy_s(d,z,s,m) |
enum DSM_State |
Possible States of the DSM.
The three possible states of the Data Source Manager. We don't want to know about the other states, because that would add needless complexity.
Enumerator | |
---|---|
dsmState_PreSession | Source Manager not loaded. |
dsmState_Loaded | Source Manager is loaded, but not open. |
dsmState_Open | Source Manager is open. |
TW_UINT16 CTwnDsmApps::AddApp | ( | TW_IDENTITY * | _pAppId, |
TW_MEMREF | _MemRef | ||
) |
Add an application.
This supports MSG_OPENDSM.
[out] | _pAppId | Origin of message |
[in] | _MemRef | the HWND on Window, null otherwise |
Attempt to add an application to our list. Truth be told we only expect an application to do this once, but for legacy's sake we support the ability to do it more than once, but the Application has to provide a unique ProductName in its Identity. If an Application really has to support multiple drivers, then it's recommended that it do this through seperate processes, since their is no guarantee that any two drivers will operator correctly in the same process...
Definition at line 364 of file apps.cpp.
Referenced by CTwnDsm::DSM_Parent().
TW_UINT16 CTwnDsmApps::AppGetConditionCode | ( | TW_IDENTITY * | _pAppId | ) |
Get the condition code, then reset it internally to TWCC_SUCCESS, so you can only get it once, per the specification...
Return the condition code and clear it internally.
[in] | _pAppId | id of app, or NULL if we have no apps |
Every open application maintains its own conditioncode, which is going to be used in state 3. In state 4 and higher the condition code is coming from the driver. In state 2 there is no condition code, so we have to use a value that is global to this instance of the DSM. The code is cleared internally, per the specification...
Definition at line 619 of file apps.cpp.
References CTwnDsmApps::AppValidateId(), CTwnDsmAppsImpl::m_AppInfo, and CTwnDsmApps::m_ptwndsmappsimpl.
Referenced by CTwnDsm::DSM_Status().
TW_IDENTITY * CTwnDsmApps::AppGetIdentity | ( | TW_IDENTITY * | _pAppId | ) |
Return a pointer to the application's identity.
Validate an application's identity.
Yeah, I know, this sorta violates encapsulation, but we do not want to get silly about this...
[in] | _pAppId | id of identity to get |
Make sure we're dealing with good data...
Definition at line 598 of file apps.cpp.
References CTwnDsmApps::AppValidateId(), CTwnDsmAppsImpl::m_AppInfo, and CTwnDsmApps::m_ptwndsmappsimpl.
TWID_T CTwnDsmApps::AppGetNumApp | ( | ) |
TWID_T CTwnDsmApps::AppGetNumDs | ( | TW_IDENTITY * | _pAppId | ) |
Get the number of drivers we found as the result of a successful call to LoadDS with _boolKeepOpen set to false (meaning that we were just browsing)...
Get the number of drivers found.
[in] | _pAppId | id of app |
When LoadDS() is called during AddApp() we browse for drivers and keep the identity for each one we find. This just tells us how many we found...
Definition at line 762 of file apps.cpp.
Referenced by CTwnDsm::DSM_GetFirst(), CTwnDsm::DSM_GetNext(), CTwnDsm::GetMatchingDefault(), and CTwnDsm::SelectDlgProc().
DSM_State CTwnDsmApps::AppGetState | ( | ) |
Get the state of the DSM for all applications.
Definition at line 688 of file apps.cpp.
References dsmState_PreSession.
Referenced by CTwnDsm::DSMGetState().
DSM_State CTwnDsmApps::AppGetState | ( | TW_IDENTITY * | _pAppId | ) |
Get the state of the DSM for the specified application.
Get our current state.
[in] | _pAppId | id of app |
There are really only two states that the DSM can occupy, state 2 where it's loaded, but hasn't had a MSG_OPENDSM done for the specified application identity. And state 3, where a MSG_OPENDSM has been successfully performed...
Definition at line 710 of file apps.cpp.
References CTwnDsmApps::AppValidateId(), CTwnDsmAppsImpl::m_AppInfo, and CTwnDsmApps::m_ptwndsmappsimpl.
void * CTwnDsmApps::AppHwnd | ( | TW_IDENTITY * | _pAppId | ) |
Get the hwnd sent in with the call to MSG_OPENDSM.
Get our hwnd.
[in] | _pAppId | id of app |
Windows needs this to help center the user select window...
Definition at line 740 of file apps.cpp.
References CTwnDsmApps::AppValidateId(), CTwnDsmAppsImpl::m_AppInfo, and CTwnDsmApps::m_ptwndsmappsimpl.
Referenced by CTwnDsm::SelectDlgProc().
void CTwnDsmApps::AppSetConditionCode | ( | TW_IDENTITY * | _pAppId, |
TW_UINT16 | _conditioncode | ||
) |
Set the condition code.
[in] | _pAppId | id of app, or NULL if we have no apps |
[in] | _conditioncode | the code to use |
Definition at line 647 of file apps.cpp.
References CTwnDsmAppsImpl::AppSetConditionCode(), and CTwnDsmApps::m_ptwndsmappsimpl.
Referenced by CTwnDsm::CloseDS(), CTwnDsm::DSM_Callback(), CTwnDsm::DSM_Callback2(), CTwnDsm::DSM_Entry(), CTwnDsm::DSM_Entrypoint(), CTwnDsm::DSM_GetFirst(), CTwnDsm::DSM_GetNext(), CTwnDsm::DSM_Null(), CTwnDsm::DSM_Parent(), CTwnDsm::DSM_SelectDS(), CTwnDsm::DSM_SetDefaultDS(), CTwnDsm::DSM_Status(), CTwnDsm::GetMatchingDefault(), and CTwnDsm::OpenDS().
TW_BOOL CTwnDsmApps::AppValidateId | ( | TW_IDENTITY * | _pAppId | ) |
Validate that an id is in range...
Validate an application's identity.
[in] | _pAppId | id of App to test |
Make sure we're dealing with good data...
Definition at line 541 of file apps.cpp.
Referenced by CTwnDsmApps::AppGetConditionCode(), CTwnDsmApps::AppGetIdentity(), CTwnDsmApps::AppGetState(), CTwnDsmApps::AppHwnd(), CTwnDsmApps::AppValidateIds(), CTwnDsmApps::AppWakeup(), CTwnDsm::DSM_GetFirst(), CTwnDsm::DSM_GetNext(), and CTwnDsm::GetMatchingDefault().
TW_BOOL CTwnDsmApps::AppValidateIds | ( | TW_IDENTITY * | _pAppId, |
TW_IDENTITY * | _pDSId | ||
) |
Validate that the App ID and DS ID are in range...
Validate an application's identity and its DS identity.
[in] | _pAppId | id of App to test |
[in] | _pDSId | id of DS to test |
Make sure we're dealing with good data...
Definition at line 561 of file apps.cpp.
References CTwnDsmApps::AppValidateId(), kLOG, and kLOGERR.
Referenced by CTwnDsm::DSM_Callback(), CTwnDsm::DSM_Callback2(), CTwnDsm::DSM_Entry(), and CTwnDsm::DSM_Null().
void CTwnDsmApps::AppWakeup | ( | TW_IDENTITY * | _pAppId | ) |
Poke the application to wake it up when sending a DAT_NULL message to it...
Wakeup an application.
[in] | _pAppId | id of app |
We need this in Windows when we send DAT_NULL to an application, otherwise it'll sit there like a lump on a bog until an event comes along to wake it up so it can process the message.
Definition at line 1893 of file apps.cpp.
References CTwnDsmApps::AppValidateId(), CTwnDsmAppsImpl::m_AppInfo, and CTwnDsmApps::m_ptwndsmappsimpl.
|
private |
Closes the Data Source specified by pDSIdentity.
[in] | _pAppId | Origin of message |
[in] | _pDsId | TW_IDENTITY structure |
Definition at line 1348 of file dsm.cpp.
References CTwnDsmApps::AppSetConditionCode(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
CTwnDsmApps::CTwnDsmApps | ( | ) |
The CTwnDsmApps constructor.
The constructor, where we create our implementation object...
Definition at line 314 of file apps.cpp.
References kLOG, kLOGERR, and CTwnDsmApps::m_ptwndsmappsimpl.
CTwnDsmLog::CTwnDsmLog | ( | ) |
The CTwnDsmLog constructor.
The constructor for our class.
This is where we see if we have a file in the TWAINDSM_LOG environment variable. If so, then we'll log stuff. If not, then we'll log nothing. TWAINDSM_LOGMODE selects how we open the file. The default value is "w+", which means it's wiped out each time a new session is started. Setting this environmental to "a+" will cause the log information to be appended to an existing file (a new one will still be created if needed...
Definition at line 106 of file log.cpp.
References kLOGENV, kLOGMODEENV, kPANIC, CTwnDsmLogImpl::_pod::m_logmode, CTwnDsmLogImpl::_pod::m_logpath, CTwnDsmLogImpl::_pod::m_message, CTwnDsmLog::m_ptwndsmlogimpl, NCHARS, CTwnDsmLogImpl::pod, SGETENV, SSTRCPY, and TWNDSM_MAX_MSG.
TW_CALLBACK2 * CTwnDsmApps::DsCallback2Get | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId | ||
) |
Get a pointer to TW_CALLBACK structure for the specified driver...
Get a point to the TW_CALLBACK2 for the specified driver.
reason...
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
This is optional for drivers on Windows. On Linux it's the only way to use DAT_NULL to let an Application know about messages going from the Driver to the Application
Definition at line 860 of file apps.cpp.
Referenced by CTwnDsm::DSM_Callback(), CTwnDsm::DSM_Callback2(), and CTwnDsm::DSM_Null().
TW_BOOL CTwnDsmApps::DsCallbackIsWaiting | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId | ||
) |
Test if the driver has a callback pending for attention...
Check if a callback is waiting.
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
This allows the DSM to help a driver get its message to an application...
Definition at line 885 of file apps.cpp.
Referenced by CTwnDsm::DSM_Entry().
void CTwnDsmApps::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, and set it to FALSE after the call has been made...
Set the callback flag.
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
[in] | _Waiting | the new state for the waiting flag |
This is how we know when we have something for the Application...
DSENTRYPROC CTwnDsmApps::DsGetEntryProc | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId | ||
) |
Get a pointer to the DS_Entry function of the specified driver...
Get the DS_Entry function for the specified driver.
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
Every driver has to have one of these...
TW_IDENTITY * CTwnDsmApps::DsGetIdentity | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId | ||
) |
Get a pointer to the identity of the specified driver...
Get the identity for the specified driver.
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
When LoadDS() is called during AddApp() we browse for drivers and keep the identity for each one we find. This just tells us how many we found...
Definition at line 785 of file apps.cpp.
Referenced by CTwnDsm::DSM_GetFirst(), CTwnDsm::DSM_GetNext(), and CTwnDsm::SelectDlgProc().
char * CTwnDsmApps::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 ProductName's aren't for some horrible reason...
Get the full path and filename for the specified driver.
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
We use this to uniquely identify each driver, since the ProductName is not guaranteed to be unique, though it should be...
Definition at line 834 of file apps.cpp.
Referenced by CTwnDsm::SelectDlgProc().
TW_BOOL CTwnDsmApps::DsIsAppProcessingCallback | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId | ||
) |
Check if the App is still processing last callback.
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
This allows the DSM to prevent the app from calling the DS with a
message before it returns from recieving the last callback.
TW_BOOL CTwnDsmApps::DsIsProcessingMessage | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId | ||
) |
Check if the DS is still processing last message.
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
This allows the DSM to prevent DS from recieving a new message when they have not finished the current
|
private |
Register application's callback.
[in] | _pAppId | Origin of message |
[in] | _pDsId | TW_IDENTITY structure |
[in] | _MSG | message id: MSG_xxxx valid = MSG_REGISTER_CALLBACK |
[in] | _pData | pointer to a callback struct |
Definition at line 973 of file dsm.cpp.
References CTwnDsmApps::AppSetConditionCode(), CTwnDsmApps::AppValidateIds(), CTwnDsmApps::DsCallback2Get(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
|
private |
Register application's callback.
[in] | _pAppId | Origin of message |
[in] | _pDsId | TW_IDENTITY structure |
[in] | _MSG | message id: MSG_xxxx valid = MSG_REGISTER_CALLBACK |
[in] | _pData | pointer to a callback2 struct |
Definition at line 1055 of file dsm.cpp.
References CTwnDsmApps::AppSetConditionCode(), CTwnDsmApps::AppValidateIds(), CTwnDsmApps::DsCallback2Get(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
TW_UINT16 CTwnDsm::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, which isn't a part of this class.
Hopefully it's not confusing that they have the same name...
[in] | _pOrigin | Origin of message in this case a DS |
[in] | _pDest | destination of message in this case an App |
[in] | _DG | message id: DG_xxxx |
[in] | _DAT | message id: DAT_xxxx |
[in] | _MSG | message id: MSG_xxxx |
[in] | _pData | the Data |
Definition at line 447 of file dsm.cpp.
References CTwnDsmApps::AppSetConditionCode(), CTwnDsmApps::AppValidateIds(), CTwnDsmApps::DsCallbackIsWaiting(), kLOG, kLOGINFO, CTwnDsm::_pod::m_ptwndsmapps, CTwnDsm::pod, and CTwnDsm::printTripletsInfo().
Referenced by DSM_Entry(), and CTwnDsm::DSM_Entrypoint().
|
private |
Gets entry points.
[in] | _pAppId | Origin of message |
[in] | _MSG | message id: MSG_xxxx |
[out] | _pEntrypoint | TW_IDENTITY structure |
Definition at line 893 of file dsm.cpp.
References CTwnDsmApps::AppSetConditionCode(), CTwnDsm::DSM_Entry(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
|
private |
Copies the applications first available source into _pDsId.
[in] | _pAppId | The origin identity structure |
[out] | _pDsId | the identity structure to copy data into |
Definition at line 2113 of file dsm.cpp.
References CTwnDsmApps::AppGetNumDs(), CTwnDsmApps::AppSetConditionCode(), CTwnDsmApps::AppValidateId(), CTwnDsmApps::DsGetIdentity(), kLOG, kLOGERR, CTwnDsm::_pod::m_nextDsId, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
|
private |
Copies the applications next available source into _pDsId.
A call to DSM_GetFirst must have been made at least once before calling this function.
[in] | _pAppId | The origin identity structure |
[out] | _pDsId | the identity structure to copy data into |
Definition at line 2158 of file dsm.cpp.
References CTwnDsmApps::AppGetNumDs(), CTwnDsmApps::AppSetConditionCode(), CTwnDsmApps::AppValidateId(), CTwnDsmApps::DsGetIdentity(), kLOG, kLOGERR, CTwnDsm::_pod::m_nextDsId, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
|
private |
Source operations.
[in] | _pAppId | Origin of message |
[in] | _MSG | message id: MSG_xxxx |
[in] | _pDsId | TW_IDENTITY structure |
void* DSM_LoadFunction | ( | void * | _pHandle, |
const char * | _pszSymbol | ||
) |
This function wraps the function loading calls.
Linux has a special way to check dlsym failures.
Definition at line 3892 of file dsm.cpp.
References kLOG, kLOGERR, and LOADFUNCTION.
|
private |
Handles DAT_NULL calls from DS for Application.
[in] | _pAppId | Origin of message |
[in] | _pDsId | TW_IDENTITY structure |
[in] | _MSG | message id: MSG_xxxx |
Definition at line 2453 of file dsm.cpp.
References CTwnDsmApps::AppSetConditionCode(), CTwnDsmApps::AppValidateIds(), CTwnDsmApps::DsCallback2Get(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
|
private |
Initializes or closes the DSM.
[in] | _pAppId | Orgin of message |
[in] | _MSG | message id: MSG_xxxx |
[in] | _MemRef | for Windows during MSG_OPENDSM it is HWND, null otherwise |
Definition at line 726 of file dsm.cpp.
References CTwnDsmApps::AddApp(), CTwnDsmApps::AppSetConditionCode(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, CTwnDsm::pod, and CTwnDsmApps::RemoveApp().
|
private |
Displays the source select dialog and sets the default source.
[in] | _pAppId | Origin of message |
[in,out] | _pDsId | TW_IDENTITY structure |
Definition at line 1800 of file dsm.cpp.
References CTwnDsmApps::AppSetConditionCode(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
|
private |
Set the default source.
[in] | _pAppId | Origin of message |
[in] | _pDsId | TW_IDENTITY structure |
Definition at line 1955 of file dsm.cpp.
References CTwnDsmApps::AppSetConditionCode(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
|
private |
Returns the current DSM status.
Resets pod.m_ConditionCode to TWCC_SUCCESS per the specification.
[in] | _pAppId | Orgin of message |
[in] | _MSG | message id: MSG_xxxx |
[out] | _pStatus | TW_STATUS structure |
Definition at line 696 of file dsm.cpp.
References CTwnDsmApps::AppGetConditionCode(), CTwnDsmApps::AppSetConditionCode(), CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
|
private |
This routine will return the path to a DS.
This is here for backwards compatibility. DAT_TWUNKIDENTITY is undocumented. It was used by the Twunking layer. Some old applications use it to get the path to the DS. We need to continue to support it.
[in] | _pAppId | Origin of message |
[in] | _MSG | message id: MSG_GET |
[in,out] | _pTwunkId | TW_TWUNKIDENTITY structure with a valid TW_IDENTITY, returns path |
DSM_State CTwnDsm::DSMGetState | ( | ) |
Get the state of the DSM by checking the state of all applications.
Definition at line 683 of file dsm.cpp.
References CTwnDsmApps::AppGetState(), CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
Referenced by DllMain(), and DSM_Entry().
void CTwnDsmApps::DsSetAppProcessingCallback | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId, | ||
TW_BOOL | _Processing | ||
) |
Set the AppProcessingCallback flag.
This is how we know the App is not done processing the previous callback
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
[in] | _Processing | the new state for the processing flag |
This is how we know the App is not done processing the previous callback
void CTwnDsmApps::DsSetProcessingMessage | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId, | ||
TW_BOOL | _Processing | ||
) |
Set the ProcessingMessage flag.
This is how we know the DS is not done processing the previous message
[in] | _pAppId | id of app |
[in] | _DsId | numeric id of driver |
[in] | _Processing | the new state for the processing flag |
This is how we know the DS is not done processing the previous message
|
private |
Goes through the applications supported data sources looking for one that has the exact same name as product name in the passed in identity.
Will update the _pDsId structure to match the name.
[in] | _pAppId | Origin of message |
[in,out] | _pDsId | TW_IDENTITY structure |
|
private |
Return back the tw_identity of the current source.
In state 3 this will be the default source. In state 4 this will be the currently opened source.
[in] | _pAppId | The application identity |
[in,out] | _pDsId | A pointer reference that will be set to point to the current identity. |
|
private |
This routine will check if the current default source matches the applications supported groups.
If it does it will copy it into the default Source's identity (_pDsId), otherwise this routine will search for a source that does match the app's supported groups and copy it into _pDsId.
[in] | _pAppId | The application identity |
[in,out] | _pDsId | A pointer reference that will be set to point to the default identity. |
Definition at line 2199 of file dsm.cpp.
References CTwnDsmApps::AppGetNumDs(), CTwnDsmApps::AppSetConditionCode(), CTwnDsmApps::AppValidateId(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
TW_INT16 CTwnDsmApps::LoadDS | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId | ||
) |
Loads a DS from disk and adds it to a global list of DS's.
Load a specific driver.
[in] | _pAppId | Origin of message |
[in] | _DsId | the source index of the library to open |
This is the interface function that's called by CTwnDsm
void CTwnDsmLog::Log | ( | const int | _doassert, |
const char *const | _file, | ||
const int | _line, | ||
const char *const | _format, | ||
... | |||
) |
The logging function.
Logging function.
This should only be access through the kLOG macro...
[in] | _doassert | decides if we assert or not |
[in] | _file | the source file of the message |
[in] | _line | the source line of the message |
[in] | _format | the format of the message (same as sprintf) |
[in] | ... | arguments to the format of the message |
We provide a timestamp from hours to milliseconds, which can be used to help with performance, and to detect large, unexpected idle times. The filename and line number in the source code is provided. GetLastError or errno may offer a hint about a problem with a system call, but be careful, since it's not cleared and so it may report a message that has nothing to do with the current calls, or anything going on in the DSM. The id of the thread that called us is useful for finding problems with unsafe use, or use that crosses thread boundaries in a bad way (like on Windows, when one has to stay in the same thread as the HWND if the DAT_NULL messages are going to work)...
Definition at line 173 of file log.cpp.
References FOPEN, GETTHREADID, CTwnDsmLogImpl::_pod::m_logmode, CTwnDsmLogImpl::_pod::m_logpath, CTwnDsmLogImpl::_pod::m_message, CTwnDsmLogImpl::_pod::m_nIndent, CTwnDsmLogImpl::_pod::m_plog, CTwnDsmLog::m_ptwndsmlogimpl, CTwnDsmLogImpl::pod, SNPRINTF, TWNDSM_CMP_VERSION, and TWNDSM_MAX_MSG.
|
private |
Opens the Data Source specified by pDSIdentity.
pDSIdentity must be valid, but if a null name and id is 0 then open default.
[in] | _pAppId | Origin of message |
[in] | _pDsId | TW_IDENTITY structure |
Definition at line 1134 of file dsm.cpp.
References CTwnDsmApps::AppSetConditionCode(), kLOG, kLOGERR, CTwnDsm::_pod::m_ptwndsmapps, and CTwnDsm::pod.
|
private |
prints to stdout information about result of processing the triplets.
[in] | _DG | the Data Group |
[in] | _DAT | the Data Argument Type |
[in] | _MSG | the Message |
[in] | _pData | the Data |
[in] | _RC | the Return Code after |
Definition at line 2402 of file dsm.cpp.
References NCHARS, SSTRCAT, CTwnDsm::StringFromConType(), and CTwnDsm::StringFromRC().
|
private |
prints to stdout information about the triplets.
[in] | _pOrigin | the Orgin to print the Product Name |
[in] | _pDest | the Destination to print the Product Name |
[in] | _DG | the Data Group |
[in] | _DAT | the Data Argument Type |
[in] | _MSG | the Message |
[in] | _pData | the Data |
Definition at line 2328 of file dsm.cpp.
References g_ptwndsmlog, CTwnDsmLog::Indent(), kLOG, kLOGINFO, NCHARS, SSTRCAT, CTwnDsm::StringFromCap(), CTwnDsm::StringFromConType(), CTwnDsm::StringFromDat(), CTwnDsm::StringFromDg(), and CTwnDsm::StringFromMsg().
Referenced by CTwnDsm::DSM_Entry().
TW_UINT16 CTwnDsmApps::RemoveApp | ( | TW_IDENTITY * | _pAppId | ) |
Remove an application.
This supports MSG_CLOSEDSM.
[in] | _pAppId | Origin of message |
Attempt to remove an application to our list.
Definition at line 465 of file apps.cpp.
Referenced by CTwnDsm::DSM_Parent().
BOOL CTwnDsm::SelectDlgProc | ( | HWND | _hWnd, |
UINT | _Message, | ||
WPARAM | _wParam, | ||
LPARAM | _lParam | ||
) |
Selection dialog, for apps that don't want to do GetFirst GetNext.
This is only public because of the way that dialogs are implemented.
[in] | _hWnd | Window handle of the dialog |
[in] | _Message | message |
[in] | _wParam | wparam |
[in] | _lParam | lparam |
Definition at line 1517 of file dsm.cpp.
References CTwnDsmApps::AppGetNumDs(), CTwnDsmApps::AppHwnd(), TwLocalize::Cancel, TwLocalize::CharSet, CTwnDsmApps::DsGetIdentity(), CTwnDsmApps::DsGetPath(), EnumChildProc(), TwLocalize::LangId, TwLocalize::Language, CTwnDsm::_pod::m_DefaultDSPath, CTwnDsm::_pod::m_pSelectDlgAppId, CTwnDsm::_pod::m_pSelectDlgDsId, CTwnDsm::_pod::m_ptwndsmapps, MAX_NUM_DS, CTwnDsm::pod, s_twlocalize, TwLocalize::Select, TwLocalize::Sources, and TwLocalize::Title.
Referenced by SelectDlgProc().
|
private |
Translates the _Cap passed in into a string and returns it.
[out] | _szCap | string to copy into |
[in] | _nChars | max chars in _szCap |
[in] | _Cap | the TWAIN Capability to translate |
Definition at line 2924 of file dsm.cpp.
Referenced by CTwnDsm::printTripletsInfo().
|
private |
|
private |
Translates the _ConType and _hContainer passed in into a string and returns it.
[out] | _szConType | string to copy into |
[in] | _nChars | max chars in _szCap |
[in] | _ConType | the TWAIN Container Type to translate |
Definition at line 3580 of file dsm.cpp.
Referenced by CTwnDsm::printResults(), and CTwnDsm::printTripletsInfo().
|
private |
Translates the _DAT passed in into a string and returns it.
[out] | _szDat | string to copy into |
[in] | _nChars | max chars in _szDat |
[in] | _DAT | the TWAIN data argument type to translate |
Definition at line 2589 of file dsm.cpp.
Referenced by CTwnDsm::printTripletsInfo().
|
private |
Translates the _DG passed in into a string and returns it.
[out] | _szDg | string to copy into |
[in] | _nChars | max chars in _szDg |
[in] | _DG | the TWAIN data group to translate |
Definition at line 2560 of file dsm.cpp.
Referenced by CTwnDsm::printTripletsInfo().
|
private |
Translates the _MSG passed in into a string and returns it.
[out] | _szMsg | string to copy into |
[in] | _nChars | max chars in _szMsg |
[in] | _MSG | the TWAIN message to translate |
Definition at line 2749 of file dsm.cpp.
Referenced by CTwnDsm::printTripletsInfo().
|
private |
Translates the rc passed in into a string and returns it.
[out] | _szRc | string to copy into |
[in] | _nChars | max chars in szRc |
[in] | _rc | the TWAIN Return Code to translate |
Definition at line 3525 of file dsm.cpp.
Referenced by CTwnDsm::printResults().
void CTwnDsmApps::UnloadDS | ( | TW_IDENTITY * | _pAppId, |
TWID_T | _DsId | ||
) |
Unloads a DS and frees all its resources...
Unload a specific driver.
[in] | _pAppId | Origin of message |
[in] | _DsId | the source index |
I don't care if the called sends this function a bouquet of pink bunnies, I think that close type functions shouldn't fail (unless, of course they're doing something vital, in which case that vital activity shouldn't be in the close function in the first place – so there)...
CTwnDsmApps::~CTwnDsmApps | ( | ) |
The CTwnDsmApps destructor.
The destructor, where we destroy our implementation object...
Definition at line 328 of file apps.cpp.
References CTwnDsmApps::m_ptwndsmappsimpl.
CTwnDsmLog::~CTwnDsmLog | ( | ) |
The CTwnDsmLog destructor.
The destructor for our class.
Make sure the log is closed, free the buffer and destroy our implementation class...
Definition at line 139 of file log.cpp.
References CTwnDsmLogImpl::_pod::m_message, CTwnDsmLogImpl::_pod::m_plog, CTwnDsmLog::m_ptwndsmlogimpl, and CTwnDsmLogImpl::pod.
char CTwnDsm::_pod::m_DefaultDSPath[FILENAME_MAX] |
The path to the default DS.
The Default DS is identified when the DSM is opened. A new Default is saved if SelectDlg is used. So this value will be compared against DsGetPath()...
Definition at line 1248 of file dsm.h.
Referenced by CTwnDsm::SelectDlgProc().
TW_IDENTITY* CTwnDsm::_pod::m_pSelectDlgAppId |
The Application ID we're using inside of SelectDlgProc.
This is only used on the Windows platform.
Definition at line 1265 of file dsm.h.
Referenced by CTwnDsm::SelectDlgProc().
TW_IDENTITY* CTwnDsm::_pod::m_pSelectDlgDsId |
The DS ID we end up with from SelectDlgProc.
This is only used on the Windows platform.
Definition at line 1259 of file dsm.h.
Referenced by CTwnDsm::SelectDlgProc().