Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
5.5 KiB

  1. /****************************g************************************************
  2. *
  3. * SampUSD.H
  4. *
  5. * Copyright (C) Microsoft Corporation 1996-1997
  6. * All rights reserved
  7. *
  8. ***************************************************************************/
  9. //#define WIN32_LEAN_AND_MEAN
  10. #include <windows.h>
  11. #pragma intrinsic(memcmp,memset)
  12. #include <objbase.h>
  13. #include "sti.h"
  14. #include "stierr.h"
  15. #include "stiusd.h"
  16. #if !defined(DLLEXPORT)
  17. #define DLLEXPORT __declspec( dllexport )
  18. #endif
  19. /*
  20. * Class IID's
  21. */
  22. #if defined( _WIN32 ) && !defined( _NO_COM)
  23. // This GUID must match that use in the .inf file for this device.
  24. DEFINE_GUID(GUID_NULL, 0L, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  25. // {61127F40-E1A5-11D0-B454-00A02438AD48}
  26. DEFINE_GUID(guidEventTimeChanged, 0x61127F40L, 0xE1A5, 0x11D0, 0xB4, 0x54, 0x00, 0xA0, 0x24, 0x38, 0xAD, 0x48);
  27. // {052ED270-28A3-11D1-ACAD-00A02438AD48}
  28. DEFINE_GUID(guidEventSizeChanged, 0x052ED270L, 0x28A3, 0x11D1, 0xAC, 0xAD, 0x00, 0xA0, 0x24, 0x38, 0xAD, 0x48);
  29. // {052ED270-28A3-11D1-ACAD-00A02438AD48}
  30. DEFINE_GUID(guidEventFirstLoaded, 0x052ED270L, 0x28A3, 0x11D3, 0xAC, 0xAD, 0x00, 0xA0, 0x24, 0x38, 0xAD, 0x48);
  31. // {C3A80960-28B1-11D1-ACAD-00A02438AD48}
  32. DEFINE_GUID(CLSID_SampUSDObj, 0xC3A80960L, 0x28B1, 0x11D1, 0xAC, 0xAD, 0x00, 0xA0, 0x24, 0x38, 0xAD, 0x48);
  33. #endif
  34. #define DATASEG_PERINSTANCE ".instance"
  35. #define DATASEG_SHARED ".shared"
  36. #define DATASEG_READONLY ".code"
  37. #define DATASEG_DEFAULT DATASEG_SHARED
  38. #pragma data_seg(DATASEG_PERINSTANCE)
  39. // Set the default data segment
  40. #pragma data_seg(DATASEG_DEFAULT)
  41. //
  42. // Module ref counting
  43. //
  44. extern UINT g_cRefThisDll;
  45. extern UINT g_cLocks;
  46. extern HINSTANCE g_hInst;
  47. extern BOOL DllInitializeCOM(void);
  48. extern BOOL DllUnInitializeCOM(void);
  49. extern void DllAddRef(void);
  50. extern void DllRelease(void);
  51. //
  52. // Auto critical section clss
  53. //
  54. class CRIT_SECT
  55. {
  56. public:
  57. void Lock() {EnterCriticalSection(&m_sec);}
  58. void Unlock() {LeaveCriticalSection(&m_sec);}
  59. CRIT_SECT() {InitializeCriticalSection(&m_sec);}
  60. ~CRIT_SECT() {DeleteCriticalSection(&m_sec);}
  61. CRITICAL_SECTION m_sec;
  62. };
  63. class TAKE_CRIT_SECT
  64. {
  65. private:
  66. CRIT_SECT& _syncres;
  67. public:
  68. inline TAKE_CRIT_SECT(CRIT_SECT& syncres) : _syncres(syncres) { _syncres.Lock(); }
  69. inline ~TAKE_CRIT_SECT() { _syncres.Unlock(); }
  70. };
  71. //
  72. // Base class for supporting non-delegating IUnknown for contained objects
  73. //
  74. struct INonDelegatingUnknown
  75. {
  76. // *** IUnknown-like methods ***
  77. STDMETHOD(NonDelegatingQueryInterface)( THIS_ REFIID riid, LPVOID * ppvObj) PURE;
  78. STDMETHOD_(ULONG,NonDelegatingAddRef)(THIS) PURE;
  79. STDMETHOD_(ULONG,NonDelegatingRelease)( THIS) PURE;
  80. };
  81. //
  82. // Class definition for object
  83. //
  84. class UsdSampDevice : public IStiUSD, public INonDelegatingUnknown
  85. {
  86. private:
  87. ULONG m_cRef;
  88. BOOL m_fValid;
  89. CRIT_SECT m_cs;
  90. LPUNKNOWN m_punkOuter;
  91. PSTIDEVICECONTROL m_pDcb;
  92. CHAR *m_pszDeviceNameA;
  93. HANDLE m_DeviceDataHandle;
  94. DWORD m_dwLastOperationError;
  95. DWORD m_dwAsync ;
  96. HANDLE m_hSignalEvent;
  97. HANDLE m_hShutdownEvent;
  98. HANDLE m_hThread;
  99. BOOL m_EventSignalState;
  100. FILETIME m_ftLastWriteTime;
  101. LARGE_INTEGER m_dwLastHugeSize;
  102. GUID m_guidLastEvent;
  103. BOOL inline IsValid(VOID) {
  104. return m_fValid;
  105. }
  106. public:
  107. // *** IUnknown-like methods ***
  108. STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, LPVOID * ppvObj);
  109. STDMETHODIMP_(ULONG) NonDelegatingAddRef();
  110. STDMETHODIMP_(ULONG) NonDelegatingRelease();
  111. // *** IUnknown methods ***
  112. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  113. STDMETHODIMP_(ULONG) AddRef( void);
  114. STDMETHODIMP_(ULONG) Release( void);
  115. /*** IStiUSD methods ***/
  116. STDMETHOD(Initialize) (THIS_ PSTIDEVICECONTROL pHelDcb,DWORD dwStiVersion,HKEY hParametersKey) ;
  117. STDMETHOD(GetCapabilities) (THIS_ PSTI_USD_CAPS pDevCaps) ;
  118. STDMETHOD(GetStatus) (THIS_ PSTI_DEVICE_STATUS pDevStatus) ;
  119. STDMETHOD(DeviceReset)(THIS ) ;
  120. STDMETHOD(Diagnostic)(THIS_ LPDIAG pBuffer) ;
  121. STDMETHOD(Escape)(THIS_ STI_RAW_CONTROL_CODE EscapeFunction,LPVOID lpInData,DWORD cbInDataSize,LPVOID pOutData,DWORD dwOutDataSize,LPDWORD pdwActualData) ;
  122. STDMETHOD(GetLastError) (THIS_ LPDWORD pdwLastDeviceError) ;
  123. STDMETHOD(LockDevice) (THIS ) ;
  124. STDMETHOD(UnLockDevice) (THIS ) ;
  125. STDMETHOD(RawReadData)(THIS_ LPVOID lpBuffer,LPDWORD lpdwNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  126. STDMETHOD(RawWriteData)(THIS_ LPVOID lpBuffer,DWORD nNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  127. STDMETHOD(RawReadCommand)(THIS_ LPVOID lpBuffer,LPDWORD lpdwNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  128. STDMETHOD(RawWriteCommand)(THIS_ LPVOID lpBuffer,DWORD nNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  129. STDMETHOD(SetNotificationHandle)(THIS_ HANDLE hEvent) ;
  130. STDMETHOD(GetNotificationData)(THIS_ LPSTINOTIFY lpNotify) ;
  131. STDMETHOD(GetLastErrorInfo) (THIS_ STI_ERROR_INFO *pLastErrorInfo);
  132. /**** ***/
  133. UsdSampDevice(LPUNKNOWN punkOuter);
  134. ~UsdSampDevice();
  135. VOID RunNotifications(VOID);
  136. BOOL IsChangeDetected(GUID *pguidEvent,BOOL fRefresh=TRUE);
  137. };
  138. typedef UsdSampDevice *PUsdSampDevice;
  139. //
  140. // Syncronization mechanisms
  141. //
  142. #define ENTERCRITICAL DllEnterCrit(void);
  143. #define LEAVECRITICAL DllLeaveCrit(void);