1 #include "ace/OS_NS_unistd.h"
3 #include "ace/Monitor_Control/Monitor_Control.h"
5 #include "examples/Monitor/MC_Test_Utilities.h"
7 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
9 using namespace ACE_VERSIONED_NAMESPACE_NAME::ACE::Monitor_Control
;
11 /// Subclass of ACE_Task_Base, meaning that the override of
12 /// the svc() method below will run in a new thread when
13 /// activate() is called on a class instance.
14 class Monitor_Checker
: public ACE_Task_Base
19 /// Get an instance of the MC service singleton.
20 MC_ADMINMANAGER
* mgr
=
21 ACE_Dynamic_Service
<MC_ADMINMANAGER
>::instance ("MC_ADMINMANAGER");
23 /// Call on the administrator class to look up the desired monitors.
24 Monitor_Base
*bytes_monitor
=
25 mgr
->admin ().monitor_point ("OS/Network/BytesSent");
27 if (bytes_monitor
!= 0)
29 /// Query the monitor for its data every 2 seconds, and call the
30 /// appropriate display function.
31 for (int i
= 0; i
< 15; ++i
)
35 Monitor_Control_Types::Data
data (bytes_monitor
->type ());
36 bytes_monitor
->retrieve (data
);
37 MC_Test_Utilities::display_bytes_sent (data
);
40 bytes_monitor
->remove_ref ();
47 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */
50 ACE_TMAIN (int /* argc */, ACE_TCHAR
* /* argv */ [])
52 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
54 /// Set the timer for # of threads check at 2 sec.
55 Monitor_Base
*monitor
=
56 create_os_monitor
<BYTES_SENT_MONITOR
> (0, ACE_Time_Value (2));
58 /// Runs the reactor's event loop in a separate thread so the timer(s)
59 /// can run concurrently with the application.
60 START_PERIODIC_MONITORS
;
62 /// Run the monitor checker in a separate thread.
63 Monitor_Checker monitor_checker
;
64 monitor_checker
.activate ();
68 /// End the reactor's event loop, stopping the timer(s).
69 STOP_PERIODIC_MONITORS
;
71 monitor
->remove_ref ();
73 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */