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.

207 lines
5.3 KiB

  1. // CntrFinder.cpp -- ContainerFinder 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 "stdafx.h"
  8. #include <string>
  9. #include <scuOsExc.h>
  10. #include <scuCast.h>
  11. #include "CntrFinder.h"
  12. using namespace std;
  13. using namespace scu;
  14. using namespace cci;
  15. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  16. namespace
  17. {
  18. // Predicate helper functor (function object) returning true iff
  19. // the container object's name matches the pattern.
  20. class ContainerMatcher
  21. : public unary_function<string, bool>
  22. {
  23. public:
  24. explicit
  25. ContainerMatcher(string const &rsPattern)
  26. : m_sPattern(rsPattern)
  27. {}
  28. bool
  29. operator()(CContainer &rcntr) const
  30. {
  31. return CSpec::Equiv(m_sPattern, rcntr->Name());
  32. }
  33. private:
  34. string const m_sPattern;
  35. };
  36. CContainer
  37. FindOnCard(HCardContext &rhcardctx,
  38. string const &rsContainer)
  39. {
  40. Secured<HCardContext> shcardctx(rhcardctx);
  41. vector<CContainer> vcContainers(shcardctx->Card()->EnumContainers());
  42. vector<CContainer>::const_iterator
  43. ci(find_if(vcContainers.begin(),
  44. vcContainers.end(),
  45. ContainerMatcher(rsContainer)));
  46. CContainer hcntr;
  47. if (vcContainers.end() != ci)
  48. hcntr = *ci;
  49. return hcntr;
  50. }
  51. } // namespace
  52. /////////////////////////// PUBLIC HELPER /////////////////////////////////
  53. /////////////////////////// PUBLIC /////////////////////////////////
  54. // Types
  55. // C'tors/D'tors
  56. ContainerFinder::ContainerFinder(DialogDisplayMode ddm,
  57. HWND hwnd,
  58. CString const &rsDialogTitle)
  59. : CardFinder(ddm, hwnd, rsDialogTitle),
  60. m_hcntr()
  61. {}
  62. ContainerFinder::~ContainerFinder()
  63. {}
  64. // Operators
  65. // Operations
  66. HContainer
  67. ContainerFinder::Find(CSpec const &rcsContainer)
  68. {
  69. DoFind(rcsContainer);
  70. return ContainerFound();
  71. }
  72. HAdaptiveContainerKey
  73. ContainerFinder::MakeAdaptiveContainerKey()
  74. {
  75. return HAdaptiveContainerKey(new
  76. AdaptiveContainerKey(CardFound(),
  77. CardSpec().CardId()));
  78. }
  79. // Access
  80. // Predicates
  81. // Static Variables
  82. /////////////////////////// PROTECTED /////////////////////////////////
  83. // C'tors/D'tors
  84. // Operators
  85. // Operations
  86. void
  87. ContainerFinder::ContainerFound(HContainer hcntr)
  88. {
  89. m_hcntr = hcntr;
  90. }
  91. void
  92. ContainerFinder::DoDisconnect()
  93. {
  94. ContainerFound(0);
  95. CardFinder::DoDisconnect();
  96. }
  97. // Access
  98. HContainer
  99. ContainerFinder::ContainerFound() const
  100. {
  101. return m_hcntr;
  102. }
  103. // Predicates
  104. bool
  105. ContainerFinder::DoIsValid()
  106. {
  107. ContainerFound(HContainer(0));
  108. if (CardFinder::DoIsValid())
  109. {
  110. AdaptiveContainerKey Key(CardFound(),
  111. CardSpec().CardId());
  112. CContainer hccntr(FindOnCard(Key.CardContext(),
  113. Key.ContainerName()));
  114. if(hccntr)
  115. {
  116. HContainer hcntr = Container::MakeContainer(CardSpec(),
  117. hccntr);
  118. ContainerFound(hcntr);
  119. }
  120. }
  121. if (!ContainerFound())
  122. throw scu::OsException(NTE_BAD_KEYSET);
  123. return true;
  124. }
  125. void
  126. ContainerFinder::DoOnError()
  127. {
  128. CardFinder::DoOnError();
  129. scu::Exception const *pexc = Exception();
  130. if (pexc && (DialogDisplayMode::ddmNever != DisplayMode()))
  131. {
  132. switch (pexc->Facility())
  133. {
  134. case scu::Exception::fcOS:
  135. {
  136. scu::OsException const *pOsExc =
  137. DownCast<scu::OsException const *>(pexc);
  138. if (NTE_BAD_KEYSET == pOsExc->Cause())
  139. {
  140. YNPrompt(IDS_CONTAINER_NOT_FOUND);
  141. ClearException();
  142. }
  143. }
  144. break;
  145. default:
  146. break;
  147. }
  148. }
  149. }
  150. // Static Variables
  151. /////////////////////////// PRIVATE /////////////////////////////////
  152. // C'tors/D'tors
  153. // Operators
  154. // Operations
  155. // Access
  156. // Predicates
  157. // Static Variables