Go to the documentation of this file.00001
00002
00003 #include "ace/Monitor_Control/Windows_Multi_Instance_Monitor.h"
00004
00005 #if defined (ACE_HAS_WIN32_PDH)
00006
00007 #include "ace/Log_Msg.h"
00008 #include "ace/SString.h"
00009 #include "ace/os_include/os_pdhmsg.h"
00010
00011 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00012
00013 namespace ACE
00014 {
00015 namespace Monitor_Control
00016 {
00017 Windows_Multi_Instance_Monitor::Windows_Multi_Instance_Monitor (
00018 const ACE_TCHAR *wildcard_path)
00019 : value_ (0.0)
00020 , instances_ (0)
00021 , n_instances_ (0)
00022 , status_ (ERROR_SUCCESS)
00023 {
00024
00025
00026
00027 DWORD paths_size = 4096;
00028 ACE_LPSTR paths = (ACE_LPSTR) GlobalAlloc (GPTR, paths_size);
00029
00030 this->status_ = ACE_TEXT_PdhExpandCounterPath (wildcard_path,
00031 paths,
00032 &paths_size);
00033
00034 if (PDH_MORE_DATA == static_cast<DWORD> (this->status_))
00035 {
00036 ++paths_size;
00037 GlobalFree (paths);
00038 paths = (ACE_LPSTR) GlobalAlloc (GPTR, paths_size);
00039
00040 this->status_ = ACE_TEXT_PdhExpandCounterPath (wildcard_path,
00041 paths,
00042 &paths_size);
00043 }
00044
00045 if (PDH_CSTATUS_VALID_DATA != static_cast<DWORD> (this->status_))
00046 {
00047 ACE_ERROR ((LM_ERROR,
00048 ACE_TEXT ("%s: PdhExpandCounterPath failed\n"),
00049 wildcard_path));
00050 }
00051
00052 ACE_LPSTR path = paths;
00053
00054
00055 while (*path != 0)
00056 {
00057 Windows_Monitor *instance = new Windows_Monitor (path);
00058 this->instances_.enqueue_tail (instance);
00059 path += ACE_OS::strlen (path) + 1;
00060 }
00061
00062 GlobalFree (paths);
00063 }
00064
00065 Windows_Multi_Instance_Monitor::~Windows_Multi_Instance_Monitor (void)
00066 {
00067 Windows_Monitor *instance = 0;
00068
00069
00070 while (this->instances_.dequeue_head (instance) == 0)
00071 {
00072 delete instance;
00073 }
00074 }
00075
00076 void
00077 Windows_Multi_Instance_Monitor::update_i (void)
00078 {
00079 Windows_Monitor **current_instance = 0;
00080
00081
00082 for (INSTANCES_ITERATOR i (this->instances_); !i.done (); i.advance ())
00083 {
00084 i.next (current_instance);
00085
00086 (*current_instance)->update_i ();
00087
00088 this->value_ += (*current_instance)->value_;
00089 }
00090 }
00091
00092 void
00093 Windows_Multi_Instance_Monitor::clear_impl (void)
00094 {
00095 Windows_Monitor **current_instance = 0;
00096
00097
00098 for (INSTANCES_ITERATOR i (this->instances_); !i.done (); i.advance ())
00099 {
00100 i.next (current_instance);
00101
00102 (*current_instance)->clear_impl ();
00103 }
00104 }
00105 }
00106 }
00107
00108 ACE_END_VERSIONED_NAMESPACE_DECL
00109
00110 #endif