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.

125 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Abstract:
  4. Declaration of helper classes.
  5. Author:
  6. Souren Aghajanyan (sourenag) 24-Sep-2001
  7. Revision History:
  8. <alias> <date> <comments>
  9. --*/
  10. #pragma once
  11. #include "mem.h"
  12. #ifdef DEBUG
  13. inline void Assert(PCSTR pCondition)
  14. {
  15. MessageBoxA(NULL, pCondition, "Error", MB_OK);
  16. #ifdef _X86_
  17. __asm int 3
  18. #else
  19. DebugBreak();
  20. #endif
  21. }
  22. #undef ASSERT
  23. #define ASSERT(x) {if(!(x)){Assert(#x);}}
  24. #else
  25. #undef ASSERT
  26. #define ASSERT(x)
  27. #endif
  28. class CMutualExclusionObject
  29. {
  30. HANDLE m_hHandle;
  31. UINT m_SpinCount;
  32. public:
  33. CMutualExclusionObject(){
  34. m_hHandle = NULL;
  35. m_SpinCount = 0;
  36. }
  37. ~CMutualExclusionObject(){
  38. Close();
  39. }
  40. BOOL Open(PCWSTR pNameOfObject,
  41. BOOL bInitialOwnership,
  42. UINT SpinCount = 0);
  43. VOID Acquiry();
  44. VOID Release();
  45. VOID Close();
  46. };
  47. class CSharedMemory
  48. {
  49. HANDLE m_hHandle;
  50. PVOID m_ViewOfSection;
  51. public:
  52. CSharedMemory(){
  53. m_hHandle = NULL;
  54. m_ViewOfSection = NULL;
  55. }
  56. ~CSharedMemory(){
  57. Close();
  58. }
  59. BOOL Open(PCWSTR pNameOfObject, UINT uiInitialSizeOfMapView, IN BOOL * pAlreadyExist);
  60. PVOID GetMapOfView(){return m_ViewOfSection;}
  61. VOID Close();
  62. };
  63. class CBuffer
  64. {
  65. PVOID m_pvBuffer;
  66. UINT m_uiSize;
  67. UINT m_uiUsedSize;
  68. public:
  69. CBuffer() : m_pvBuffer(NULL), m_uiSize(0), m_uiUsedSize(0){};
  70. ~CBuffer(){
  71. if(m_pvBuffer){
  72. HeapFree (GetProcessHeap(), 0, m_pvBuffer); //FREE(m_pvBuffer);
  73. }
  74. }
  75. PVOID GetBuffer(){return m_pvBuffer;}
  76. UINT GetSize(){return m_uiUsedSize;}
  77. VOID Free()
  78. {
  79. m_uiUsedSize = 0;
  80. /*if m_uiSize > THRESHOLD then reallocate with THRESHOLD*/
  81. }
  82. PVOID Allocate(UINT uiSize);
  83. PVOID ReAllocate(UINT uiSize);
  84. BOOL PreAllocate(UINT uiSize);
  85. };
  86. class CSharedAccessFile
  87. {
  88. HANDLE m_hHandle;
  89. public:
  90. CSharedAccessFile() : m_hHandle(INVALID_HANDLE_VALUE){}
  91. ~CSharedAccessFile(){Close();}
  92. BOOL Open(PCWSTR pFilePath,
  93. BOOL SharedWriteAccess,
  94. BOOL CreateAlwaysNewIfPossible,
  95. BOOL bWriteThrough,
  96. BOOL * pbAlreadyOpened);
  97. VOID Close();
  98. BOOL Append(PVOID pBuffer, UINT Size);
  99. };