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.

148 lines
5.1 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CAction.h
  7. //
  8. // Description:
  9. // Header file for CAction class.
  10. //
  11. // The CAction is the base class for all the action classes. It is an
  12. // abstract class which encapsulates the concept of an action - something
  13. // that be committed or rolled back. See IMPORTANT NOTE in the comment above
  14. // the class declaration.
  15. //
  16. // Maintained By:
  17. // Vij Vasu (Vvasu) 03-MAR-2000
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20. // Make sure that this file is included only once per compile path.
  21. #pragma once
  22. //////////////////////////////////////////////////////////////////////////////
  23. // Include Files
  24. //////////////////////////////////////////////////////////////////////////////
  25. // For HRESULT, WCHAR, etc.
  26. #include <windef.h>
  27. //////////////////////////////////////////////////////////////////////////////
  28. //++
  29. //
  30. // class CAction
  31. //
  32. // Description:
  33. // The CAction is the base class for all the action classes. It is an
  34. // abstract class which encapsulates the concept of an action - something
  35. // that be committed or rolled back.
  36. //
  37. // Typically, any class that derives from this class would also implement
  38. // other methods that allow for specifying what action would be performed
  39. // by the Commit() method.
  40. //
  41. // IMPORTANT NOTE:
  42. // An object of this class cannot be a part of a transaction at this stage
  43. // because many of the resources typically used by these actions (the registry,
  44. // the SCM database, etc.) do not do not support transactions.
  45. //
  46. // However, a transaction-like behavior is required from each of these
  47. // actions. What is meant by transaction-like is that the commit and
  48. // rollback methods of objects of this class have to guarantee durability,
  49. // and consistency. While they need not be isolated, they should at least
  50. // try to be atomic (it may not always be possilbe to be atomic).
  51. //
  52. // If any action cannot guarantee that it is at least consistency and
  53. // durability (and preferably atomicity) during its commit, then it should
  54. // NOT derive from this class.
  55. //
  56. //--
  57. //////////////////////////////////////////////////////////////////////////////
  58. class CAction
  59. {
  60. public:
  61. //////////////////////////////////////////////////////////////////////////
  62. // Constructors and destructors
  63. //////////////////////////////////////////////////////////////////////////
  64. // Default constructor.
  65. CAction()
  66. : m_fCommitComplete( false )
  67. , m_fRollbackPossible( true )
  68. {}
  69. // Default virtual destructor.
  70. virtual
  71. ~CAction() {}
  72. //////////////////////////////////////////////////////////////////////////
  73. // Pure virtual functions
  74. //////////////////////////////////////////////////////////////////////////
  75. //
  76. // Commit this action. This method has to be durable and consistent. It shoud
  77. // try as far as possible to be atomic.
  78. // The implementation of this method checks to see if the action has been committed
  79. // and throws an exception if it already has been committed.
  80. //
  81. virtual void
  82. Commit();
  83. //
  84. // Rollback this action. Be careful about throwing exceptions from this method
  85. // as a stack unwind might be in progress when this method is called.
  86. // The implementation of this method checks to see if the action has been committed
  87. // and if it can be rolled back and throws an exception otherwise.
  88. //
  89. virtual void
  90. Rollback();
  91. // Returns the number of progress messages that this action will send.
  92. virtual UINT
  93. UiGetMaxProgressTicks() const throw() { return 0; }
  94. //////////////////////////////////////////////////////////////////////////
  95. // Public accessor methods
  96. //////////////////////////////////////////////////////////////////////////
  97. // Has this action been successfully committed.
  98. bool
  99. FIsCommitComplete() const throw() { return m_fCommitComplete; }
  100. // Can this action be rolled back.
  101. bool
  102. FIsRollbackPossible() const throw() { return m_fRollbackPossible; }
  103. protected:
  104. //////////////////////////////////////////////////////////////////////////
  105. // Protected accessor methods
  106. //////////////////////////////////////////////////////////////////////////
  107. // Set the commit status.
  108. void
  109. SetCommitCompleted( bool fComplete = true ) throw() { m_fCommitComplete = fComplete; }
  110. // Indicate if rollback is possible
  111. void
  112. SetRollbackPossible( bool fPossible = true ) throw() { m_fRollbackPossible = fPossible; }
  113. private:
  114. //////////////////////////////////////////////////////////////////////////
  115. // Private data
  116. //////////////////////////////////////////////////////////////////////////
  117. // Indicates if this action has been successfully committed or not.
  118. bool m_fCommitComplete;
  119. // Indicates if this action can be rolled back or not.
  120. bool m_fRollbackPossible;
  121. }; //*** class CAction