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.

107 lines
3.2 KiB

  1. //
  2. // MODULE: Stateless.
  3. //
  4. // PURPOSE: interface for CStateless class.
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Joe Mabel
  9. //
  10. // ORIGINAL DATE: 9-9-98
  11. //
  12. // NOTES: See CStateless.cpp for further information
  13. //
  14. // Version Date By Comments
  15. //--------------------------------------------------------------------
  16. // V3.0 9-9-98 JM
  17. //
  18. #if !defined(AFX_STATELESS_H__278584FB_47F9_11D2_95F2_00C04FC22ADD__INCLUDED_)
  19. #define AFX_STATELESS_H__278584FB_47F9_11D2_95F2_00C04FC22ADD__INCLUDED_
  20. #if _MSC_VER >= 1000
  21. #pragma once
  22. #endif // _MSC_VER >= 1000
  23. #include <windows.h>
  24. #include "apgtsstr.h"
  25. ////////////////////////////////////////////////////////////////////////////////////
  26. // CStateless
  27. /////////////////////////////////////////////////////////////////////////////////////
  28. class CStateless
  29. {
  30. private:
  31. HANDLE m_hMutex;
  32. DWORD m_TimeOutVal; // Time-out interval in milliseconds, after which we
  33. // log error & wait infinitely when waiting for m_hMutex.
  34. protected:
  35. CStateless(DWORD TimeOutVal = 60000);
  36. virtual ~CStateless();
  37. void Lock( LPCSTR srcFile, // Calling source file (__FILE__), used for logging.
  38. // LPCSTR, not LPCTSTR, because __FILE__ is a char*, not a TCHAR*
  39. int srcLine // Calling source line (__LINE__), used for logging.
  40. ) const;
  41. void Unlock() const;
  42. HANDLE GetMutexHandle() const; // provided only for the creation of a CMultiMutexObj.
  43. // >>> might be better to use private and friend than protected.
  44. };
  45. ////////////////////////////////////////////////////////////////////////////////////
  46. // CStatelessPublic
  47. // will be used when we can not inherit our class from CStateless,
  48. // but have to create member variable of CStatelessPublic to control
  49. // data access
  50. /////////////////////////////////////////////////////////////////////////////////////
  51. class CStatelessPublic : public CStateless
  52. {
  53. public:
  54. CStatelessPublic() : CStateless() {}
  55. ~CStatelessPublic() {}
  56. public:
  57. void Lock( LPCSTR srcFile,
  58. int srcLine
  59. ) const;
  60. void Unlock() const;
  61. HANDLE GetMutexHandle() const;
  62. };
  63. inline void CStatelessPublic::Lock(LPCSTR srcFile, int srcLine) const
  64. {
  65. CStateless::Lock(srcFile, srcLine);
  66. }
  67. inline void CStatelessPublic::Unlock() const
  68. {
  69. CStateless::Unlock();
  70. }
  71. inline HANDLE CStatelessPublic::GetMutexHandle() const
  72. {
  73. return CStateless::GetMutexHandle();
  74. }
  75. ////////////////////////////////////////////////////////////////////////////////////
  76. // CNameStateless
  77. /////////////////////////////////////////////////////////////////////////////////////
  78. class CNameStateless : public CStateless
  79. {
  80. CString m_strName;
  81. public:
  82. CNameStateless();
  83. CNameStateless(const CString& str);
  84. void Set(const CString& str);
  85. CString Get() const;
  86. };
  87. // these must be macros, because otherwise __FILE__ and __LINE__ won't indicate the
  88. // calling location. UNLOCKOBJECT is defined in case we ever need to determine if objects
  89. // are being unlocked and to provide a consistent look.
  90. #define LOCKOBJECT() Lock(__FILE__, __LINE__)
  91. #define UNLOCKOBJECT() Unlock()
  92. #endif // !defined(AFX_STATELESS_H__278584FB_47F9_11D2_95F2_00C04FC22ADD__INCLUDED_)