1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_ctype.h"
4 #include "orbsvcs/Notify/MonitorControl/NotificationServiceMCC.h"
6 static const ACE_TCHAR
* monitor_ior
= 0;
7 static const char* shutdown_cmd
= "shutdown";
8 static const char* rm_consumer
= "remove_consumer";
9 static const char* rm_supplier
= "remove_supplier";
10 static const char* rm_consumeradmin
= "remove_consumeradmin";
11 static const char* rm_supplieradmin
= "remove_supplieradmin";
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("k:"));
19 while ((c
= get_opts ()) != -1)
24 monitor_ior
= get_opts
.opt_arg ();
28 ACE_ERROR_RETURN ((LM_ERROR
,
41 sorter (const void* a
, const void* b
)
43 const char* left
= *(reinterpret_cast<const char* const*> (a
));
44 const char* right
= *(reinterpret_cast<const char* const*> (b
));
45 return ACE_OS::strcmp (left
, right
);
49 process_command (CosNotification::NotificationServiceMonitorControl_ptr nsm
,
53 if (ACE_OS::strstr (buf
, command
) == buf
)
55 const char* name
= buf
+ ACE_OS::strlen (command
);
59 while (ACE_OS::ace_isspace (name
[i
]))
69 const char* start
= name
+ i
;
71 if (ACE_OS::strcmp (command
, shutdown_cmd
) == 0)
73 nsm
->shutdown_event_channel (start
);
75 else if (ACE_OS::strcmp (command
, rm_consumer
) == 0)
77 nsm
->remove_consumer (start
);
79 else if (ACE_OS::strcmp (command
, rm_supplier
) == 0)
81 nsm
->remove_supplier (start
);
83 else if (ACE_OS::strcmp (command
, rm_consumeradmin
) == 0)
85 nsm
->remove_consumeradmin (start
);
87 else if (ACE_OS::strcmp (command
, rm_supplieradmin
) == 0)
89 nsm
->remove_supplieradmin (start
);
92 catch (const CORBA::Exception
& ex
)
94 ACE_OS::strcat (buf
, ": ");
95 ex
._tao_print_exception (buf
);
106 ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
112 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
114 if (parse_args (argc
, argv
) != 0)
119 CORBA::Object_var obj
= orb
->string_to_object (
120 ACE_TEXT_ALWAYS_CHAR (monitor_ior
));
121 CosNotification::NotificationServiceMonitorControl_var nsm
=
122 CosNotification::NotificationServiceMonitorControl::_narrow (obj
.in ());
124 if (CORBA::is_nil (nsm
.in ()))
126 ACE_ERROR_RETURN ((LM_ERROR
,
127 "Unable to locate the "
128 "Notification Service Monitor\n"),
133 static const size_t lsize
= 1024;
138 ACE_OS::printf ("NotifyService> ");
139 ACE_OS::fflush (stdout
);
141 char line
[lsize
] = "";
142 char* rl
= ACE_OS::fgets (line
, lsize
, stdin
);
146 int len
= static_cast<int> (ACE_OS::strlen (line
));
148 for (int i
= 0; i
< len
&& ACE_OS::ace_isspace (rl
[0]); ++i
)
153 for (int i
= len
- 1; i
>= 0 && ACE_OS::ace_isspace (line
[i
]); --i
)
158 if (ACE_OS::strlen (rl
) == 0 || ACE_OS::strcmp (rl
, "!!") == 0)
160 ACE_OS::strcpy (line
, prev
);
164 ACE_OS::strcpy (prev
, line
);
171 ACE_DEBUG ((LM_DEBUG
, "\n"));
173 else if (ACE_OS::strlen (rl
) == 0)
176 else if (ACE_OS::strcmp (rl
, "quit") == 0)
180 else if (ACE_OS::strcmp (rl
, "help") == 0)
182 ACE_DEBUG ((LM_DEBUG
,
183 "names - Get a list of "
184 "currently available statistic names.\n"
185 "quit - Exit the monitor.\n"
186 "remove_consumer - Remove a consumer "
187 "with the given name.\n"
188 "remove_supplier - Remove a supplier "
189 "with the given name.\n"
190 "remove_consumeradmin - Remove a consumer "
191 "admin with the given name.\n"
192 "remove_supplieradmin - Remove a supplier "
193 "admin with the given name.\n"
194 "shutdown - Shut down an "
195 "event channel with the given name.\n"
196 "<statistic name> - Return the "
197 "information for the specified statistic.\n"));
199 else if (ACE_OS::strcmp (rl
, "names") == 0)
203 Monitor::NameList_var names
= nsm
->get_statistic_names ();
204 CORBA::ULong length
= names
->length ();
205 ACE_DEBUG ((LM_DEBUG
, "Statistic names\n"));
207 // It's much easier to read once it's sorted
208 const char** narray
= 0;
209 ACE_NEW_THROW_EX (narray
,
210 const char* [length
],
211 CORBA::NO_MEMORY ());
213 for (CORBA::ULong i
= 0; i
< length
; ++i
)
215 narray
[i
] = names
[i
].in ();
218 ACE_OS::qsort (narray
,
220 sizeof (const char*),
223 for (CORBA::ULong i
= 0; i
< length
; ++i
)
225 ACE_DEBUG ((LM_DEBUG
, " %s\n", narray
[i
]));
230 catch (const CORBA::Exception
& ex
)
232 ex
._tao_print_exception ("names: ");
237 if (process_command (nsm
.in (), rl
, shutdown_cmd
))
241 else if (process_command (nsm
.in (), rl
, rm_consumer
))
245 else if (process_command (nsm
.in (), rl
, rm_supplier
))
249 else if (process_command (nsm
.in (), rl
, rm_consumeradmin
))
253 else if (process_command (nsm
.in (), rl
, rm_supplieradmin
))
260 Monitor::Data_var data
=
261 nsm
->get_statistic (rl
);
262 ACE_DEBUG ((LM_DEBUG
, "%s => ", rl
));
264 if (data
->data_union
._d () == Monitor::DATA_NUMERIC
)
266 ACE_DEBUG ((LM_DEBUG
,
267 "Last: %g Average: %g\n",
268 data
->data_union
.num().dlist
[0].value
,
269 data
->data_union
.num().average
));
273 Monitor::NameList list
= data
->data_union
.list ();
274 CORBA::ULong
const length
= list
.length ();
276 for (CORBA::ULong i
= 0; i
< length
; ++i
)
278 ACE_DEBUG ((LM_DEBUG
, "%s ", list
[i
].in ()));
281 ACE_DEBUG ((LM_DEBUG
, "\n"));
284 catch (const CORBA::Exception
& ex
)
286 ACE_OS::strcat (rl
, ": ");
287 ex
._tao_print_exception (rl
);
294 catch (const CORBA::UserException
& ex
)
296 ex
._tao_print_exception ("Notification Service Monitor: ");
299 catch (const CORBA::Exception
& ex
)
301 ex
._tao_print_exception ("Notification Service Monitor: ");
306 ACE_ERROR ((LM_ERROR
,
307 "Notification Service Monitor: "
308 "unexpected exception type\n"));