From 8362c9dfa00fd078842b96ea887e800b3638f87b Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 15 May 2012 16:22:58 +0300 Subject: [PATCH] start fs decoupling --- data/test_activation_periods.json | 8 ++++---- sessionmanager/{event.go => fsevent.go} | 14 ++++++++++---- sessionmanager/{event_test.go => fsevent_test.go} | 0 sessionmanager/session.go | 3 ++- sessionmanager/sessionmanager.go | 8 ++++---- timespans/calldesc.go | 9 ++++----- 6 files changed, 24 insertions(+), 18 deletions(-) rename sessionmanager/{event.go => fsevent.go} (80%) rename sessionmanager/{event_test.go => fsevent_test.go} (100%) diff --git a/data/test_activation_periods.json b/data/test_activation_periods.json index dcd9c824b..ee42cf1fe 100644 --- a/data/test_activation_periods.json +++ b/data/test_activation_periods.json @@ -1,5 +1,5 @@ [ -{"TOR": 0,"CstmId":"vdf","Subject":"rif","DestinationPrefix":"0256", "ActivationPeriods": [ +{"TOR": "0","CstmId":"vdf","Subject":"rif","DestinationPrefix":"0256", "ActivationPeriods": [ {"ActivationTime": "2012-01-01T00:00:00Z", "Intervals": [ {"BillingUnit":1,"ConnectFee":0,"Month":0,"MonthDay":0,"Ponder":0,"Price":0.2,"StartTime":"","EndTime":"18:00:00","WeekDays":[1,2,3,4,5]}, {"BillingUnit":1,"ConnectFee":0,"Month":0,"MonthDay":0,"Ponder":0,"Price":0.1,"StartTime":"18:00:00","EndTime":"","WeekDays":[1,2,3,4,5]}, @@ -8,7 +8,7 @@ } ] }, -{"TOR": 0,"CstmId":"vdf","Subject":"rif","DestinationPrefix":"0257", "ActivationPeriods": [ +{"TOR": "0","CstmId":"vdf","Subject":"rif","DestinationPrefix":"0257", "ActivationPeriods": [ {"ActivationTime": "2012-01-01T00:00:00Z", "Intervals": [ {"BillingUnit":1,"ConnectFee":0,"Month":0,"MonthDay":0,"Ponder":0,"Price":0.1,"StartTime":"18:00:00","EndTime":"","WeekDays":[1,2,3,4,5]}, {"BillingUnit":1,"ConnectFee":0,"Month":0,"MonthDay":0,"Ponder":0,"Price":0.2,"StartTime":"","EndTime":"18:00:00","WeekDays":[1,2,3,4,5]}, @@ -23,14 +23,14 @@ } ] }, -{"TOR": 0,"CstmId":"vdf","Subject":"rif","DestinationPrefix":"0723", "ActivationPeriods": [ +{"TOR": "0","CstmId":"vdf","Subject":"rif","DestinationPrefix":"0723", "ActivationPeriods": [ {"ActivationTime": "2012-01-01T00:00:00Z", "Intervals": [ {"BillingUnit":60,"ConnectFee":0,"Month":0,"MonthDay":0,"Ponder":0,"Price":1,"StartTime":"","EndTime":""} ] } ] }, -{"TOR": 0,"CstmId":"vdf","Subject":"minutosu","DestinationPrefix":"0723", "ActivationPeriods": [ +{"TOR": "0","CstmId":"vdf","Subject":"minutosu","DestinationPrefix":"0723", "ActivationPeriods": [ {"ActivationTime": "2012-01-01T00:00:00Z", "Intervals": [ {"BillingUnit":60,"ConnectFee":0,"Month":0,"MonthDay":0,"Ponder":0,"Price":1,"StartTime":"","EndTime":""} ] diff --git a/sessionmanager/event.go b/sessionmanager/fsevent.go similarity index 80% rename from sessionmanager/event.go rename to sessionmanager/fsevent.go index cf2a88404..5e7a2506e 100644 --- a/sessionmanager/event.go +++ b/sessionmanager/fsevent.go @@ -36,11 +36,17 @@ var ( const ( // Freswitch event proprities names CALL_DIRECTION = "Call-Direction" - SUBJECT = "variable_sip_full_from" - DESTINATION = "variable_sip_full_to" - UUID = "Unique-ID" - CSTMID = "Caller-Dialplan" + ORIG_ID = "variable_sip_call_id" //- originator_id - match cdrs + SUBJECT = "variable_cgr_subject" + DESTINATION = "variable_cgr_destination" + TOR = "variable_cgr_tor" + UUID = "Unique-ID" // -Unique ID for this call leg + CSTMID = "variable_cgr_cstmid" START_TIME = "Event-Date-GMT" + NAME = "Event-Name" + HEARTBEAT = "HEARTBEAT" + ANSWER = "CHANNEL_ANSWER" + HANGUP = "CHANNEL_HANGUP_COMPLETE" ) // Creates a new event from a bod of text containing the key value proprieties. diff --git a/sessionmanager/event_test.go b/sessionmanager/fsevent_test.go similarity index 100% rename from sessionmanager/event_test.go rename to sessionmanager/fsevent_test.go diff --git a/sessionmanager/session.go b/sessionmanager/session.go index 5742c6f96..bfe895c4e 100644 --- a/sessionmanager/session.go +++ b/sessionmanager/session.go @@ -42,7 +42,8 @@ func NewSession(ev *Event, ed SessionDelegate) (s *Session) { log.Print("Error parsing answer event start time, using time.Now!") startTime = time.Now() } - cd := ×pans.CallDescriptor{CstmId: ev.Fields[CSTMID], + cd := ×pans.CallDescriptor{TOR: ev.Fields[TOR], + CstmId: ev.Fields[CSTMID], Subject: ev.Fields[SUBJECT], DestinationPrefix: ev.Fields[DESTINATION], TimeStart: startTime} diff --git a/sessionmanager/sessionmanager.go b/sessionmanager/sessionmanager.go index 118ddb7ad..371637ae7 100644 --- a/sessionmanager/sessionmanager.go +++ b/sessionmanager/sessionmanager.go @@ -63,12 +63,12 @@ func (sm *SessionManager) readNextEvent() (ev *Event) { log.Print("Could not read from freeswitch connection!") } ev = NewEvent(body) - switch ev.Fields["Event-Name"] { - case "HEARTBEAT": + switch ev.Fields[NAME] { + case HEARTBEAT: sm.OnHeartBeat(ev) - case "CHANNEL_ANSWER": + case ANSWER: sm.OnChannelAnswer(ev) - case "CHANNEL_HANGUP_COMPLETE": + case HANGUP: sm.OnChannelHangupComplete(ev) default: sm.OnOther(ev) diff --git a/timespans/calldesc.go b/timespans/calldesc.go index a9041e845..bf22b7984 100644 --- a/timespans/calldesc.go +++ b/timespans/calldesc.go @@ -51,7 +51,7 @@ func round(val float64, prec int) float64 { The input stucture that contains call information. */ type CallDescriptor struct { - TOR int + TOR string CstmId, Subject, DestinationPrefix string TimeStart, TimeEnd time.Time Amount float64 @@ -228,10 +228,9 @@ func (cd *CallDescriptor) GetCost() (*CallCost, error) { The output structure that will be returned with the call cost information. */ type CallCost struct { - TOR int - CstmId, Subject, DestinationPrefix string - Cost, ConnectFee float64 - Timespans []*TimeSpan + TOR, CstmId, Subject, DestinationPrefix string + Cost, ConnectFee float64 + Timespans []*TimeSpan } /*