Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / ace / Monitor_Control / Windows_Multi_Instance_Monitor.cpp
blob8a38444b76a5075dbb04e81acff05aadc435345f
1 #include "ace/Monitor_Control/Windows_Multi_Instance_Monitor.h"
3 #if defined (ACE_HAS_WIN32_PDH)
5 #include "ace/Log_Category.h"
6 #include "ace/SString.h"
7 #include "ace/os_include/os_pdhmsg.h"
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 namespace ACE
13 namespace Monitor_Control
15 Windows_Multi_Instance_Monitor::Windows_Multi_Instance_Monitor (
16 const ACE_TCHAR *wildcard_path)
17 : value_ (0.0)
18 , instances_ (0)
19 , n_instances_ (0)
20 , status_ (ERROR_SUCCESS)
22 /// Create a string which is a concatentation of the path
23 /// name of each 'instance' we need to monitor.
25 DWORD paths_size = 4096;
26 ACE_LPSTR paths = (ACE_LPSTR) GlobalAlloc (GPTR, paths_size);
28 this->status_ = ACE_TEXT_PdhExpandCounterPath (wildcard_path,
29 paths,
30 &paths_size);
32 if (PDH_MORE_DATA == static_cast<DWORD> (this->status_))
34 ++paths_size;
35 GlobalFree (paths);
36 paths = (ACE_LPSTR) GlobalAlloc (GPTR, paths_size);
38 this->status_ = ACE_TEXT_PdhExpandCounterPath (wildcard_path,
39 paths,
40 &paths_size);
43 if (PDH_CSTATUS_VALID_DATA != static_cast<DWORD> (this->status_))
45 ACELIB_ERROR ((LM_ERROR,
46 ACE_TEXT ("%s: PdhExpandCounterPath failed\n"),
47 wildcard_path));
50 ACE_LPSTR path = paths;
52 /// Create a regular Windows monitor for each path name.
53 while (*path != 0)
55 Windows_Monitor *instance = new Windows_Monitor (path);
56 this->instances_.enqueue_tail (instance);
57 path += ACE_OS::strlen (path) + 1;
60 GlobalFree (paths);
63 Windows_Multi_Instance_Monitor::~Windows_Multi_Instance_Monitor ()
65 Windows_Monitor *instance = 0;
67 /// Destroy the single instance monitors created in the constructor.
68 while (this->instances_.dequeue_head (instance) == 0)
70 delete instance;
74 void
75 Windows_Multi_Instance_Monitor::update_i ()
77 Windows_Monitor **current_instance = 0;
79 /// Sum the values of each single instance monitor.
80 for (INSTANCES_ITERATOR i (this->instances_); !i.done (); i.advance ())
82 i.next (current_instance);
84 (*current_instance)->update_i ();
86 this->value_ += (*current_instance)->value_;
90 void
91 Windows_Multi_Instance_Monitor::clear_impl ()
93 Windows_Monitor **current_instance = 0;
95 /// Sum the values of each single instance monitor.
96 for (INSTANCES_ITERATOR i (this->instances_); !i.done (); i.advance ())
98 i.next (current_instance);
100 (*current_instance)->clear_impl ();
106 ACE_END_VERSIONED_NAMESPACE_DECL
108 #endif /* defined (ACE_HAS_WIN32_PDH) */