1 #include "ace/streams.h"
2 #include "ace/OS_NS_unistd.h"
3 #include "ace/Get_Opt.h"
5 #include "tao/Strategies/advanced_resource.h"
6 #include "tao/Monitor/Monitor.h"
8 const ACE_TCHAR
*monitor_ior
= ACE_TEXT ("file://monitor.ior");
9 ::Monitor::NameList
* monitor_point
= 0;
10 bool mp_clear
= false;
12 ACE_Time_Value sleep_time
= ACE_Time_Value (1);
13 const ACE_TCHAR
* filter
= ACE_TEXT ("");
16 parse_args (int argc
, ACE_TCHAR
*argv
[])
18 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:p:ci:s:f:"));
21 while ((c
= get_opts ()) != -1)
25 filter
= get_opts
.opt_arg ();
28 monitor_ior
= get_opts
.opt_arg ();
32 if (monitor_point
== 0)
34 ACE_NEW_THROW_EX (monitor_point
,
39 monitor_point
->length (monitor_point
->length () + 1);
40 (*monitor_point
)[monitor_point
->length () - 1] =
41 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
48 n_iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
51 sleep_time
.set(ACE_OS::atoi (get_opts
.opt_arg ()), 0);
55 ACE_ERROR_RETURN ((LM_ERROR
,
68 // Indicates successful parsing of the command line
74 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
78 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
80 if (parse_args (argc
, argv
) != 0)
85 /// Get the MC object reference that the client has exposed.
86 CORBA::Object_var obj
=
87 orb
->string_to_object (monitor_ior
);
89 if (CORBA::is_nil (obj
.in ()))
91 ACE_ERROR_RETURN ((LM_ERROR
,
92 "Monitor client - string_to_object failed\n"),
96 Monitor::MC_var monitor
= Monitor::MC::_narrow (obj
.in ());
98 if (CORBA::is_nil (monitor
.in ()))
100 ACE_ERROR_RETURN ((LM_ERROR
,
101 "Monitor client - narrow failed\n"),
105 if (monitor_point
!= 0)
107 /// Access the monitor's value a few times and watch it grow.
108 for (int i
= 0; i
< n_iterations
; ++i
)
110 Monitor::DataList_var data
;
114 data
= monitor
->get_and_clear_statistics (*monitor_point
);
118 data
= monitor
->get_statistics (*monitor_point
);
121 for (CORBA::ULong index
= 0; index
< data
->length (); ++index
)
123 ACE_DEBUG ((LM_DEBUG
, "MP <%C>:\n", data
[index
].itemname
.in ()));
124 Monitor::Data dlist
= data
[index
];
126 if (dlist
.data_union
._d() == Monitor::DATA_TEXT
)
128 for (CORBA::ULong valueindex
= 0;
129 valueindex
< dlist
.data_union
.num().dlist
.length ();
132 Monitor::DataValue d
= dlist
.data_union
.num().dlist
[valueindex
];
133 ACE_DEBUG ((LM_DEBUG
, "\t value <%A>:\n", d
.value
));
138 ACE_OS::sleep (sleep_time
);
143 Monitor::NameList_var list
= monitor
->get_statistic_names (ACE_TEXT_ALWAYS_CHAR (filter
));
145 for (CORBA::ULong index
= 0; index
< list
->length (); ++index
)
147 ACE_DEBUG ((LM_DEBUG
, "MP: <%C>\n", list
[index
].in ()));
153 catch (const CORBA::Exception
&ex
)
155 ex
._tao_print_exception ("Monitor_client: Exception caught:");