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
13 namespace Monitor_Control
15 Windows_Multi_Instance_Monitor::Windows_Multi_Instance_Monitor (
16 const ACE_TCHAR
*wildcard_path
)
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
,
32 if (PDH_MORE_DATA
== static_cast<DWORD
> (this->status_
))
36 paths
= (ACE_LPSTR
) GlobalAlloc (GPTR
, paths_size
);
38 this->status_
= ACE_TEXT_PdhExpandCounterPath (wildcard_path
,
43 if (PDH_CSTATUS_VALID_DATA
!= static_cast<DWORD
> (this->status_
))
45 ACELIB_ERROR ((LM_ERROR
,
46 ACE_TEXT ("%s: PdhExpandCounterPath failed\n"),
50 ACE_LPSTR path
= paths
;
52 /// Create a regular Windows monitor for each path name.
55 Windows_Monitor
*instance
= new Windows_Monitor (path
);
56 this->instances_
.enqueue_tail (instance
);
57 path
+= ACE_OS::strlen (path
) + 1;
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)
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_
;
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) */