Source code of Windows XP (NT5)
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.

114 lines
2.9 KiB

  1. // IOPLock.h: interface for the CIOPLock class.
  2. //
  3. // There is a CIOPLock object associated with each card object. The card object passes in its reader
  4. // name to the CIOPLock object in order to create the mutex by name.
  5. //
  6. //////////////////////////////////////////////////////////////////////
  7. #if !defined(AFX_IOPLOCK_H__EB8BCE22_0ED2_11D3_A585_00104BD32DA8__INCLUDED_)
  8. #define AFX_IOPLOCK_H__EB8BCE22_0ED2_11D3_A585_00104BD32DA8__INCLUDED_
  9. #if _MSC_VER > 1000
  10. #pragma once
  11. #endif // _MSC_VER > 1000
  12. #include <memory> // for std::auto_ptr
  13. #include <windows.h>
  14. #include <winscard.h>
  15. #include <scuOsVersion.h>
  16. #include "DllSymDefn.h"
  17. // Define when target OS is anything but W2K series. On non-W2K
  18. // platforms, the smart card Resource Manager will hang other
  19. // processes when another process using the RM dies suddenly without
  20. // cleaning up.
  21. #if !SLBSCU_WIN2K_SERIES
  22. #define SLBIOP_RM_HANG_AT_PROCESS_DEATH
  23. #endif
  24. namespace iop
  25. {
  26. class CSmartCard;
  27. // Instantiate the templates so they will be properly accessible
  28. // as data members to the exported class CIOPLock in the DLL. See
  29. // MSDN Knowledge Base Article Q168958 for more information.
  30. #pragma warning(push)
  31. // Non-standard extension used: 'extern' before template explicit
  32. // instantiation
  33. #pragma warning(disable : 4231)
  34. // Synchronization objects used to guard against the Resource
  35. // Manager hanging when a process dies. Only used in non-W2K MS
  36. // environments since the RM doesn't have that attribute in W2K+.
  37. class RMHangProcDeathSynchObjects
  38. {
  39. public:
  40. enum
  41. {
  42. cMaxMutexNameLength = MAX_PATH,
  43. };
  44. RMHangProcDeathSynchObjects(SECURITY_ATTRIBUTES *psa,
  45. LPCTSTR lpMutexName);
  46. ~RMHangProcDeathSynchObjects();
  47. CRITICAL_SECTION *
  48. CriticalSection();
  49. HANDLE
  50. Mutex() const;
  51. private:
  52. CRITICAL_SECTION m_cs;
  53. HANDLE m_hMutex;
  54. };
  55. IOPDLL_EXPIMP_TEMPLATE template class IOPDLL_API std::auto_ptr<RMHangProcDeathSynchObjects>;
  56. #pragma warning(pop)
  57. class IOPDLL_API CIOPLock
  58. {
  59. public:
  60. explicit CIOPLock(const char *szReaderName);
  61. virtual ~CIOPLock();
  62. CRITICAL_SECTION *CriticalSection();
  63. HANDLE MutexHandle();
  64. CSmartCard *SmartCard() {return m_pSmartCard;};
  65. void IncrementRefCount() {m_iRefCount++;};
  66. void DecrementRefCount() {if(m_iRefCount) m_iRefCount--;};
  67. long RefCount() {return m_iRefCount;};
  68. void RegisterWriteEvent();
  69. void Init(CSmartCard *pSmartCard);
  70. private:
  71. // CIOPLock can not be copied due to CRITICAL_SECTION member, so
  72. // copy member routines are declared private and not defined.
  73. CIOPLock(CIOPLock const &rhs);
  74. CIOPLock &
  75. operator=(CIOPLock const &rhs);
  76. unsigned long m_iRefCount;
  77. std::auto_ptr<RMHangProcDeathSynchObjects> m_apRMHangProcDeathSynchObjects;
  78. CSmartCard *m_pSmartCard;
  79. };
  80. } // namespace iop
  81. #endif // !defined(AFX_IOPLOCK_H__EB8BCE22_0ED2_11D3_A585_00104BD32DA8__INCLUDED_)