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.

128 lines
3.0 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. HRESULT FinalConstruct() throw ();
  80. // Returns the entry for the RADIUS proxy counters.
  81. RadiusProxyEntry& getProxyEntry() throw ()
  82. { return stats->peProxy; }
  83. // Returns the entry for a give server, creating a new entry if necessary.
  84. // Returns NULL if no more room is available in the shared memory segment.
  85. RadiusRemoteServerEntry* getRemoteServerEntry(ULONG address) throw ();
  86. // Update the counters.
  87. void updateCounters(
  88. RadiusPortType port,
  89. RadiusEventType event,
  90. RadiusRemoteServerEntry* server,
  91. ULONG data
  92. ) throw ();
  93. protected:
  94. void lock() throw ()
  95. { WaitForSingleObject(mutex, INFINITE); }
  96. void unlock() throw ()
  97. { ReleaseMutex(mutex); }
  98. // Find an entry without creating a new one.
  99. RadiusRemoteServerEntry* findRemoteServer(ULONG address) throw ();
  100. private:
  101. RadiusProxyStatistics* stats;
  102. HANDLE mutex;
  103. SharedMemory data;
  104. DWORD nbyte; // Current size of the counter data.
  105. // Not implemented.
  106. ProxyCounters(ProxyCounters&);
  107. ProxyCounters& operator=(ProxyCounters&);
  108. };
  109. #endif // COUNTERS_H