Browse code

sbc: adds call-duration to 'call-end' events

Raphael Coeffic authored on 27/05/2013 10:10:29
Showing 3 changed files
... ...
@@ -564,21 +564,21 @@ void SBCCallLeg::onRemoteDisappeared(const AmSipReply& reply)
564 564
 {
565 565
   CallLeg::onRemoteDisappeared(reply);
566 566
   if(a_leg)
567
-    SBCEventLog::instance()->logCallEnd(dlg,"reply");
567
+    SBCEventLog::instance()->logCallEnd(dlg,"reply",&call_connect_ts);
568 568
 }
569 569
 
570 570
 void SBCCallLeg::onBye(const AmSipRequest& req)
571 571
 {
572 572
   CallLeg::onBye(req);
573 573
   if(a_leg)
574
-    SBCEventLog::instance()->logCallEnd(req,getLocalTag(),"bye");
574
+    SBCEventLog::instance()->logCallEnd(req,getLocalTag(),"bye",&call_connect_ts);
575 575
 }
576 576
 
577 577
 void SBCCallLeg::onOtherBye(const AmSipRequest& req)
578 578
 {
579 579
   CallLeg::onOtherBye(req);
580 580
   if(a_leg)
581
-    SBCEventLog::instance()->logCallEnd(req,getLocalTag(),"bye");
581
+    SBCEventLog::instance()->logCallEnd(req,getLocalTag(),"bye",&call_connect_ts);
582 582
 }
583 583
 
584 584
 void SBCCallLeg::onDtmf(int event, int duration)
... ...
@@ -617,7 +617,7 @@ void SBCCallLeg::onControlCmd(string& cmd, AmArg& params) {
617 617
       // was for caller:
618 618
       DBG("teardown requested from control cmd\n");
619 619
       stopCall();
620
-      SBCEventLog::instance()->logCallEnd(dlg,"ctrl-cmd");
620
+      SBCEventLog::instance()->logCallEnd(dlg,"ctrl-cmd",&call_connect_ts);
621 621
       // FIXME: don't we want to relay the controll event as well?
622 622
     }
623 623
     else {
... ...
@@ -646,7 +646,7 @@ void SBCCallLeg::process(AmEvent* ev) {
646 646
           timer_id <= SBC_TIMER_ID_CALL_TIMERS_END) {
647 647
         DBG("timer %d timeout, stopping call\n", timer_id);
648 648
         stopCall();
649
-	SBCEventLog::instance()->logCallEnd(dlg,"timeout");
649
+	SBCEventLog::instance()->logCallEnd(dlg,"timeout",&call_connect_ts);
650 650
         ev->processed = true;
651 651
       }
652 652
     }
... ...
@@ -113,7 +113,8 @@ void _SBCEventLog::logCallStart(const AmBasicSipDialog* dlg, int code,
113 113
 
114 114
 void _SBCEventLog::logCallEnd(const AmSipRequest& req,
115 115
 			      const string& local_tag,
116
-			      const string& reason)
116
+			      const string& reason,
117
+			      struct timeval* tv)
117 118
 {
118 119
   AmArg end_event;
119 120
 
... ...
@@ -135,11 +136,21 @@ void _SBCEventLog::logCallEnd(const AmSipRequest& req,
135 136
   else
136 137
     end_event["to"] = req.to;
137 138
 
139
+  if(tv && tv->tv_sec) {
140
+    struct timeval call_len;
141
+    gettimeofday(&call_len,NULL);
142
+    timersub(&call_len,tv,&call_len);
143
+    double dlen = call_len.tv_sec;
144
+    dlen += (double)call_len.tv_usec / (double)1000000.0;
145
+    end_event["duration"] = dlen;
146
+  }
147
+
138 148
   logEvent(local_tag,"call-end",end_event);
139 149
 }
140 150
 
141 151
 void _SBCEventLog::logCallEnd(const AmBasicSipDialog* dlg,
142
-			      const string& reason)
152
+			      const string& reason,
153
+			      struct timeval* tv)
143 154
 {
144 155
   AmArg end_event;
145 156
 
... ...
@@ -160,5 +171,14 @@ void _SBCEventLog::logCallEnd(const AmBasicSipDialog* dlg,
160 171
   else
161 172
     end_event["from"] = dlg->getRemoteParty();
162 173
 
174
+  if(tv && tv->tv_sec) {
175
+    struct timeval call_len;
176
+    gettimeofday(&call_len,NULL);
177
+    timersub(&call_len,tv,&call_len);
178
+    double dlen = call_len.tv_sec;
179
+    dlen += (double)call_len.tv_usec / (double)1000000.0;
180
+    end_event["duration"] = dlen;
181
+  }
182
+
163 183
   logEvent(dlg->getLocalTag(),"call-end",end_event);
164 184
 }
... ...
@@ -40,10 +40,12 @@ public:
40 40
 
41 41
   void logCallEnd(const AmSipRequest& req,
42 42
 		  const string& local_tag,
43
-		  const string& reason);
43
+		  const string& reason,
44
+		  struct timeval* tv);
44 45
 
45 46
   void logCallEnd(const AmBasicSipDialog* dlg,
46
-		  const string& reason);
47
+		  const string& reason,
48
+		  struct timeval* tv);
47 49
 };
48 50
 
49 51
 typedef singleton<_SBCEventLog> SBCEventLog;