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.

255 lines
8.5 KiB

  1. // scuExc.h -- Smart Card Utility EXCeption declaration
  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. #if !defined(SCU_EXCEPTION_H)
  8. #define SCU_EXCEPTION_H
  9. #include "DllSymDefn.h"
  10. namespace scu
  11. {
  12. // Exception is a virtual root class for exceptions and cannot be
  13. // instantiated directly. Rather, specializations of Exception are
  14. // defined by a facility and instantiated. Given a reference to an
  15. // instance of Exception, it's facility can be obtained by the
  16. // Facility member function. Specializations of the Exception class
  17. // are typically defined by the responsible facility using the
  18. // convenience template ExcTemplate.
  19. //
  20. // Each specialization of an exception typically has, but is not
  21. // required to have, a cause code that uniquely identifies the reason
  22. // for the exception within the facility it represents. Each
  23. // Exception does have an error code that is a generic version of the
  24. // cause code (if it exists). This error code could overlap error
  25. // codes of other facilities. The specialization implements Error
  26. // routine.
  27. class SCU_DLLAPI Exception
  28. {
  29. public:
  30. // Types
  31. enum FacilityCode
  32. {
  33. fcCCI,
  34. fcIOP,
  35. fcOS,
  36. fcSmartCard,
  37. fcPKI,
  38. };
  39. typedef unsigned long ErrorCode;
  40. // ErrorCode must be the largest integer that any facility
  41. // needs to translate their native codes into a generic
  42. // error code.
  43. // C'tors/D'tors
  44. virtual
  45. ~Exception() throw() = 0;
  46. // Operators
  47. // Operations
  48. virtual Exception *
  49. Clone() const = 0;
  50. virtual void
  51. Raise() const = 0;
  52. // Access
  53. virtual char const *
  54. Description() const;
  55. // Textual description of the exception.
  56. virtual ErrorCode
  57. Error() const throw() = 0;
  58. // generic code
  59. FacilityCode
  60. Facility() const throw();
  61. // Facility that threw the exception
  62. // Predicates
  63. protected:
  64. // Types
  65. // C'tors/D'tors
  66. explicit
  67. Exception(FacilityCode fc) throw();
  68. // Operators
  69. // Operations
  70. // Access
  71. // Predicates
  72. // Variables
  73. private:
  74. // Types
  75. // C'tors/D'tors
  76. // Operators
  77. // Operations
  78. // Access
  79. // Predicates
  80. // Variables
  81. FacilityCode m_fc;
  82. };
  83. // ExcTemplate is a convenience template to define new exceptions by
  84. // facility. To define a new specialization, add the facility to the
  85. // Exception class, then reference it when declaring the new
  86. // exception. E.g.
  87. //
  88. // typedef ExcTemplate<OS, DWORD> OsException;
  89. //
  90. // The helper routine AsErrorCode is defined as a template to convert
  91. // a cause code into a error code. The helper templates operator==
  92. // and operator!= are also defined. These as well as the class
  93. // methods can be overriden in the usual C++ fashion.
  94. template<Exception::FacilityCode FC, class CC>
  95. class ExcTemplate
  96. : public Exception
  97. {
  98. public:
  99. // Types
  100. typedef CC CauseCode;
  101. // C'tors/D'tors
  102. explicit
  103. ExcTemplate(CauseCode cc) throw();
  104. virtual
  105. ~ExcTemplate() throw();
  106. // Operations
  107. virtual Exception *
  108. Clone() const;
  109. virtual void
  110. Raise() const;
  111. // Access
  112. CauseCode
  113. Cause() const throw();
  114. // facility-specific code indicating the cause of the
  115. // exception. The value is unique to facility.
  116. virtual char const *
  117. Description() const;
  118. ErrorCode
  119. Error() const throw();
  120. // Predicates
  121. protected:
  122. // Types
  123. // C'tors/D'tors
  124. // Operators
  125. // Operations
  126. // Access
  127. // Predicates
  128. // Variables
  129. private:
  130. // Types
  131. // C'tors/D'tors
  132. // Operators
  133. // Operations
  134. // Access
  135. // Predicates
  136. // Variables
  137. CauseCode m_cc;
  138. };
  139. ///////////////////////// TEMPLATE METHODS //////////////////////////////
  140. /////////////////////////// PUBLIC /////////////////////////////////
  141. // Types
  142. // C'tors/D'tors
  143. template<Exception::FacilityCode FC, class CC>
  144. ExcTemplate<FC, CC>::ExcTemplate(CauseCode cc) throw()
  145. : Exception(FC),
  146. m_cc(cc)
  147. {}
  148. template<Exception::FacilityCode FC, class CC>
  149. ExcTemplate<FC, CC>::~ExcTemplate() throw()
  150. {}
  151. // Operators
  152. // Operations
  153. template<Exception::FacilityCode FC, class CC>
  154. scu::Exception *
  155. ExcTemplate<FC, CC>::Clone() const
  156. {
  157. return new ExcTemplate<FC, CC>(*this);
  158. }
  159. template<Exception::FacilityCode FC, class CC>
  160. void
  161. ExcTemplate<FC, CC>::Raise() const
  162. {
  163. throw *this;
  164. }
  165. // Access
  166. template<Exception::FacilityCode FC, class CC>
  167. typename ExcTemplate<FC, CC>::CauseCode
  168. ExcTemplate<FC, CC>::Cause() const throw()
  169. {
  170. return m_cc;
  171. }
  172. template<Exception::FacilityCode FC, class CC>
  173. char const *
  174. ExcTemplate<FC, CC>::Description() const
  175. {
  176. return Exception::Description();
  177. }
  178. template<Exception::FacilityCode FC, class CC>
  179. typename ExcTemplate<FC, CC>::ErrorCode
  180. ExcTemplate<FC, CC>::Error() const throw()
  181. {
  182. return AsErrorCode(Cause());
  183. }
  184. // Predicates
  185. // Static Variables
  186. /////////////////////////// PROTECTED /////////////////////////////////
  187. // C'tors/D'tors
  188. // Operators
  189. // Operations
  190. // Access
  191. // Predicates
  192. // Static Variables
  193. /////////////////////////// PRIVATE /////////////////////////////////
  194. // C'tors/D'tors
  195. // Operators
  196. // Operations
  197. // Access
  198. // Predicates
  199. // Static Variables
  200. /////////////////////////// HELPERS /////////////////////////////////
  201. template<class CC>
  202. Exception::ErrorCode
  203. AsErrorCode(typename CC cc) throw()
  204. {
  205. return cc;
  206. }
  207. } // namespace
  208. #endif // SCU_EXCEPTION_H