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.

100 lines
2.9 KiB

  1. // HSCardCtx.cpp -- Handle Smart Card Context wrapper class implementation
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #include <scuOsExc.h>
  8. #include "HSCardCtx.h"
  9. /////////////////////////// HELPER /////////////////////////////////
  10. /////////////////////////// LOCAL VAR /////////////////////////////////
  11. namespace
  12. {
  13. SCARDCONTEXT const sccNil = 0;
  14. } // namespace
  15. /////////////////////////// PUBLIC /////////////////////////////////
  16. // Types
  17. // C'tors/D'tors
  18. HSCardContext::HSCardContext()
  19. : m_scc(sccNil)
  20. {
  21. }
  22. HSCardContext::~HSCardContext()
  23. {
  24. if (m_scc)
  25. {
  26. try
  27. {
  28. Release();
  29. }
  30. catch (...) // destructors should not throw exceptions
  31. {
  32. }
  33. }
  34. }
  35. // Operators
  36. // Operations
  37. void
  38. HSCardContext::Establish(DWORD dwScope)
  39. {
  40. DWORD dwErrorCode = SCardEstablishContext(dwScope, NULL, NULL,
  41. &m_scc);
  42. if (SCARD_S_SUCCESS != dwErrorCode)
  43. throw scu::OsException(dwErrorCode);
  44. }
  45. void
  46. HSCardContext::Release()
  47. {
  48. if (m_scc)
  49. {
  50. SCARDCONTEXT old = m_scc;
  51. m_scc = sccNil;
  52. DWORD dwErrorCode = SCardReleaseContext(old);
  53. if (SCARD_S_SUCCESS != dwErrorCode)
  54. throw scu::OsException(dwErrorCode);
  55. }
  56. }
  57. // Access
  58. SCARDCONTEXT
  59. HSCardContext::AsSCARDCONTEXT() const
  60. {
  61. return m_scc;
  62. }
  63. // Predicates
  64. // Static Variables
  65. /////////////////////////// PROTECTED /////////////////////////////////
  66. // C'tors/D'tors
  67. // Operators
  68. // Operations
  69. // Access
  70. // Predicates
  71. // Static Variables
  72. /////////////////////////// PRIVATE /////////////////////////////////
  73. // C'tors/D'tors
  74. // Operators
  75. // Operations
  76. // Access
  77. // Predicates
  78. // Static Variables