~ubuntu-branches/ubuntu/saucy/resiprocate/saucy-proposed

« back to all changes in this revision

Viewing changes to b2bua/B2BCallManager.cxx

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2012-05-17 19:29:59 UTC
  • Revision ID: package-import@ubuntu.com-20120517192959-vv00m77isztdy64q
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
#include <syslog.h>
 
4
 
 
5
#include "B2BCallManager.hxx"
 
6
#include "Logging.hxx"
 
7
 
 
8
using namespace b2bua;
 
9
using namespace resip;
 
10
using namespace std;
 
11
 
 
12
B2BCallManager::B2BCallManager(resip::DialogUsageManager& dum, AuthorizationManager *authorizationManager, CDRHandler& cdrHandler) : dum(dum), authorizationManager(authorizationManager), cdrHandler(cdrHandler) {
 
13
  stopping = false;
 
14
  mustStopCalls = false;
 
15
}
 
16
 
 
17
B2BCallManager::~B2BCallManager() {
 
18
}
 
19
 
 
20
void B2BCallManager::setAuthorizationManager(AuthorizationManager *authorizationManager) {
 
21
  this->authorizationManager = authorizationManager;
 
22
}
 
23
 
 
24
TaskManager::TaskResult B2BCallManager::doTaskProcessing() {
 
25
  time_t now;
 
26
 
 
27
  if(mustStopCalls) {
 
28
    B2BUA_LOG_NOTICE("notifying calls to stop");
 
29
    list<B2BCall *>::iterator call = calls.begin();
 
30
    while(call != calls.end()) {
 
31
      (*call)->onStopping();
 
32
      call++;
 
33
    }
 
34
    mustStopCalls = false;
 
35
  }
 
36
 
 
37
  time(&now);
 
38
  list<B2BCall *>::iterator i = calls.begin();
 
39
  while(i != calls.end()) {
 
40
    (*i)->checkProgress(now, stopping);
 
41
    if((*i)->isComplete()) {
 
42
      B2BCall *call = *i;
 
43
      i++;
 
44
      calls.remove(call);
 
45
      delete call;
 
46
    } else
 
47
      i++;
 
48
  }
 
49
  if(stopping && calls.begin() == calls.end()) {
 
50
    B2BUA_LOG_NOTICE("no (more) calls in progress");
 
51
    return TaskManager::TaskComplete;
 
52
  }
 
53
  return TaskManager::TaskNotComplete;
 
54
}
 
55
 
 
56
void B2BCallManager::stop() {
 
57
  stopping = true;
 
58
  mustStopCalls = true;
 
59
}
 
60
 
 
61
bool B2BCallManager::isStopping() {
 
62
  return stopping;
 
63
}
 
64
 
 
65
void B2BCallManager::onNewCall(MyAppDialog *aLegDialog, const resip::NameAddr& sourceAddr, const resip::Uri& destinationAddr, const resip::Data& authRealm, const resip::Data& authUser, const resip::Data& authPassword, const resip::Data& srcIp, const resip::Data& contextId, const resip::Data& accountId, const resip::Data& baseIp, const resip::Data& controlId) {
 
66
 
 
67
  B2BCall *call = new B2BCall(cdrHandler, dum, *authorizationManager, aLegDialog, sourceAddr, destinationAddr, authRealm, authUser, authPassword, srcIp, contextId, accountId, baseIp, controlId);
 
68
 
 
69
  calls.push_back(call);
 
70
 
 
71
}
 
72
 
 
73
void B2BCallManager::logStats() {
 
74
  int preDial = 0, dialing = 0, connected = 0, finishing = 0, unknown = 0;
 
75
  list<B2BCall *>::iterator call = calls.begin();
 
76
  while(call != calls.end()) {
 
77
    switch((*call)->getStatus()) {
 
78
    case B2BCall::PreDial:
 
79
      preDial++;
 
80
      break;
 
81
    case B2BCall::Dialing:
 
82
      dialing++;
 
83
      break;
 
84
    case B2BCall::Connected:
 
85
      connected++;
 
86
      break;
 
87
    case B2BCall::Finishing:
 
88
      finishing++;
 
89
      break;
 
90
    default:
 
91
      unknown++;
 
92
      break;
 
93
    }
 
94
    call++;
 
95
  }
 
96
  B2BUA_LOG_NOTICE("call info: preDial = %d, dialing = %d, connected = %d, finishing = %d, unknown = %d, total = %d", preDial, dialing, connected, finishing, unknown, (preDial + dialing + connected + finishing + unknown));
 
97
}
 
98
 
 
99
/* ====================================================================
 
100
 *
 
101
 * Copyright 2012 Daniel Pocock.  All rights reserved.
 
102
 *
 
103
 * Redistribution and use in source and binary forms, with or without
 
104
 * modification, are permitted provided that the following conditions
 
105
 * are met:
 
106
 *
 
107
 * 1. Redistributions of source code must retain the above copyright
 
108
 *    notice, this list of conditions and the following disclaimer.
 
109
 *
 
110
 * 2. Redistributions in binary form must reproduce the above copyright
 
111
 *    notice, this list of conditions and the following disclaimer in
 
112
 *    the documentation and/or other materials provided with the
 
113
 *    distribution.
 
114
 *
 
115
 * 3. Neither the name of the author(s) nor the names of any contributors
 
116
 *    may be used to endorse or promote products derived from this software
 
117
 *    without specific prior written permission.
 
118
 *
 
119
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
 
120
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
121
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
122
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
 
123
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
124
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
125
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
126
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
127
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
128
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
129
 * SUCH DAMAGE.
 
130
 *
 
131
 * ====================================================================
 
132
 *
 
133
 *
 
134
 */
 
135