fire event when done ping

This commit is contained in:
Seven Du 2013-09-27 05:26:02 +08:00
parent 2af0cf891d
commit 17bd89c2a5
1 changed files with 18 additions and 1 deletions

View File

@ -92,6 +92,7 @@ SWITCH_STANDARD_APP(sonar_app)
int lost = 0;
int x;
int avg = 0, mdev = 0;
switch_event_t *event;
if (zstr(arg)) {
loops = 5;
@ -151,9 +152,25 @@ SWITCH_STANDARD_APP(sonar_app)
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
"SONAR: min:%d max:%d avg:%d mdev:%d sent:%d recv: %d lost:%d lost/send:%2.2f%%\n",
"Sonar Ping (in ms): min:%d max:%d avg:%d mdev:%d sent:%d recv: %d lost:%d lost/send:%2.2f%%\n",
min, max, avg, mdev, loops, received, lost, lost * 1.0 / loops);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "sonar::ping") == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_min", "%d", min);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_max", "%d", max);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_avg", "%d", avg);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_mdev", "%d", mdev);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_sent", "%d", loops);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_recv", "%d", received);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ping_lost", "%d", lost);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lost_rate", "%2.2f%%", lost * 1.0 / loops);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "destination_number",
switch_channel_get_variable(channel, "ping_destination_number"));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sonar_ping_ref",
switch_channel_get_variable(channel, "sonar_ping_ref"));
switch_event_fire(&event);
}
}
/* Macro expands to: switch_status_t mod_sonar_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */