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.

131 lines
3.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // counters.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // Declares the classes SharedMemory and ProxyCounters.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/16/2000 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #ifndef COUNTERS_H
  19. #define COUNTERS_H
  20. #if _MSC_VER >= 1000
  21. #pragma once
  22. #endif
  23. #include <iasinfo.h>
  24. ///////////////////////////////////////////////////////////////////////////////
  25. //
  26. // CLASS
  27. //
  28. // SharedMemory
  29. //
  30. // DESCRIPTION
  31. //
  32. // Simple wrapper around a shared memory segment.
  33. //
  34. ///////////////////////////////////////////////////////////////////////////////
  35. class SharedMemory
  36. {
  37. public:
  38. SharedMemory() throw ();
  39. ~SharedMemory() throw ()
  40. { close(); }
  41. // Open a shared memory segment and reserve (but not commit) the specified
  42. // number of bytes.
  43. bool open(PCWSTR name, DWORD reserve) throw ();
  44. // Close the mapping.
  45. void close() throw ();
  46. // Ensure that at least 'nbyte' bytes are committed. Returns 'true' if
  47. // successful.
  48. bool commit(DWORD nbyte) throw ();
  49. // Returns the base address of the segment.
  50. PVOID base() const throw ()
  51. { return view; }
  52. private:
  53. HANDLE fileMap;
  54. PVOID view;
  55. DWORD pageSize;
  56. DWORD reserved; // Number of pages reserved.
  57. DWORD committed; // Number of pages committed.
  58. // Not implemented.
  59. SharedMemory(SharedMemory&);
  60. SharedMemory& operator=(SharedMemory&);
  61. };
  62. ///////////////////////////////////////////////////////////////////////////////
  63. //
  64. // CLASS
  65. //
  66. // ProxyCounters
  67. //
  68. // DESCRIPTION
  69. //
  70. // Manages the PerfMon/SNMP counters for the RADIUS proxy.
  71. //
  72. ///////////////////////////////////////////////////////////////////////////////
  73. class ProxyCounters
  74. {
  75. public:
  76. ProxyCounters() throw ()
  77. : stats(NULL), mutex(NULL), nbyte(0)
  78. { }
  79. ~ProxyCounters() throw()
  80. {if (mutex) CloseHandle(mutex);}
  81. HRESULT FinalConstruct() throw ();
  82. // Returns the entry for the RADIUS proxy counters.
  83. RadiusProxyEntry& getProxyEntry() throw ()
  84. { return stats->peProxy; }
  85. // Returns the entry for a give server, creating a new entry if necessary.
  86. // Returns NULL if no more room is available in the shared memory segment.
  87. RadiusRemoteServerEntry* getRemoteServerEntry(ULONG address) throw ();
  88. // Update the counters.
  89. void updateCounters(
  90. RadiusPortType port,
  91. RadiusEventType event,
  92. RadiusRemoteServerEntry* server,
  93. ULONG data
  94. ) throw ();
  95. protected:
  96. void lock() throw ()
  97. { WaitForSingleObject(mutex, INFINITE); }
  98. void unlock() throw ()
  99. { ReleaseMutex(mutex); }
  100. // Find an entry without creating a new one.
  101. RadiusRemoteServerEntry* findRemoteServer(ULONG address) throw ();
  102. private:
  103. RadiusProxyStatistics* stats;
  104. HANDLE mutex;
  105. SharedMemory data;
  106. DWORD nbyte; // Current size of the counter data.
  107. // Not implemented.
  108. ProxyCounters(ProxyCounters&);
  109. ProxyCounters& operator=(ProxyCounters&);
  110. };
  111. #endif // COUNTERS_H