tested maxdebit with linphone and corrected a few issues

This commit is contained in:
Radu Ioan Fericean
2012-08-16 15:55:43 +03:00
parent 74754d545f
commit 25d5584799
4 changed files with 10 additions and 3 deletions

View File

@@ -227,6 +227,7 @@ func startSessionManager(responder *timespans.Responder, loggerDb timespans.Stor
sm.Connect(&sessionmanager.SessionDelegate{connector, dp}, freeswitch_server, freeswitch_pass)
default:
timespans.Logger.Err(fmt.Sprintf("Cannot start session manger of type: %s!", sm_switch_type))
exitChan <- true
}
}

View File

@@ -23,7 +23,7 @@ logdb_name = cgrates # The name of the database to connect to.
[session_manager]
enabled = true
type = freeswitch
switch_type = freeswitch
debit_period = 10
rater = internal #address where to access rater. Can be internal, direct rater address or the address of a balancer
rpc_encoding = gob

View File

@@ -150,6 +150,7 @@ func (rsd *SessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
func (rsd *SessionDelegate) LoopAction(s *Session, cd *timespans.CallDescriptor) {
cc := &timespans.CallCost{}
cd.Amount = rsd.DebitPeriod.Seconds()
err := rsd.Connector.MaxDebit(*cd, cc)
if err != nil {
timespans.Logger.Err(fmt.Sprintf("Could not complete debit opperation: %v", err))
@@ -157,7 +158,11 @@ func (rsd *SessionDelegate) LoopAction(s *Session, cd *timespans.CallDescriptor)
s.sessionManager.DisconnectSession(s)
}
nbts := len(cc.Timespans)
remainingSeconds := cc.Timespans[nbts-1].TimeEnd.Sub(cc.Timespans[0].TimeStart).Seconds()
remainingSeconds := 0.0
timespans.Logger.Debug(fmt.Sprintf("MaxDebited and got this: %v", cc))
if nbts > 0 {
remainingSeconds = cc.Timespans[nbts-1].TimeEnd.Sub(cc.Timespans[0].TimeStart).Seconds()
}
if remainingSeconds == 0 || err != nil {
timespans.Logger.Info(fmt.Sprintf("No credit left: Disconnect %v", s))
s.Disconnect()

View File

@@ -410,8 +410,9 @@ func (cd *CallDescriptor) Debit() (cc *CallCost, err error) {
// by the GetMaxSessionTime method. The amount filed has to be filled in call descriptor.
func (cd *CallDescriptor) MaxDebit() (cc *CallCost, err error) {
remainingSeconds, err := cd.GetMaxSessionTime()
Logger.Debug(fmt.Sprintf("In MaxDebitd remaining seconds: %v", remainingSeconds))
if err != nil || remainingSeconds == 0 {
return nil, errors.New("no more credit")
return new(CallCost), errors.New("no more credit")
}
if remainingSeconds > 0 { // for postpaying client returns -1
rs, _ := time.ParseDuration(fmt.Sprintf("%vs", remainingSeconds))