From 17bd89c2a51b63ded453466ad76a6c4ceeebb627 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Fri, 27 Sep 2013 05:26:02 +0800 Subject: [PATCH] fire event when done ping --- src/mod/applications/mod_sonar/mod_sonar.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_sonar/mod_sonar.c b/src/mod/applications/mod_sonar/mod_sonar.c index 478702b118..f332f7cae2 100644 --- a/src/mod/applications/mod_sonar/mod_sonar.c +++ b/src/mod/applications/mod_sonar/mod_sonar.c @@ -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) */