blob: 98036e92d27a9700900934400b6647b10b4b8baf [file] [log] [blame]
Alexandre Savard4a19d752012-09-19 13:19:24 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
Alexandre Savarda1404652012-09-20 13:34:08 -04004 * Author: Alexandre Savard <alexandre.savard@gmail.com>
Alexandre Savard4a19d752012-09-19 13:19:24 -04005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31package com.savoirfairelinux.sflphone.client;
32
33import android.util.Log;
34import java.util.ArrayList;
35
36public class SipCall
37{
38 final static String TAG = "SipCall";
Alexandre Savarda1404652012-09-20 13:34:08 -040039 private static ArrayList<SipCall> CallList = new ArrayList<SipCall>();
40 public static CallElementList mCallElementList;
Alexandre Savard7a46f542012-09-20 11:23:33 -040041 public CallInfo mCallInfo;
42
Alexandre Savard2b01c822012-09-20 15:00:37 -040043 public enum CallState {
44 INVALID, // The call is not existent in SFLphone service
45 NULL, // Before any action performed
46 CALLING, // After INVITE is sent
47 INCOMING, // After INVITE is received
48 EARLY, // After response with To tag
49 CONNECTING, // After 2xx is sent/received
50 CONFIRMED, // After ACK is sent/received
51 DISCONNECTED // Session is terminated
52 }
53
54 public enum MediaState {
55 NONE, // No media currently
56 ACTIVE, // Media is active
57 LOCAL_HOLD, // Media is put on hold bu user
58 REMOTE_HOLD, // Media is put on hold by peer
59 ERROR, // Media is in error state
60 }
61
Alexandre Savard7a46f542012-09-20 11:23:33 -040062 public static class CallInfo
63 {
Alexandre Savard2b01c822012-09-20 15:00:37 -040064 public String mCallID = "";
Alexandre Savard7a46f542012-09-20 11:23:33 -040065 public String mDisplayName = "";
66 public String mPhone = "";
67 public String mEmail = "";
Alexandre Savard2b01c822012-09-20 15:00:37 -040068 public String mRemoteContact = "";
69 public CallState mCallState = NULL;
70 public MediaState mMediaState = NONE;
Alexandre Savard7a46f542012-09-20 11:23:33 -040071 }
Alexandre Savard4a19d752012-09-19 13:19:24 -040072
73 public SipCall()
74 {
Alexandre Savard4a19d752012-09-19 13:19:24 -040075 CallList.add(this);
Alexandre Savard7a46f542012-09-20 11:23:33 -040076 mCallInfo = new CallInfo();
Alexandre Savard4a19d752012-09-19 13:19:24 -040077 }
78
Alexandre Savard7a46f542012-09-20 11:23:33 -040079 public SipCall(CallInfo info)
Alexandre Savard4a19d752012-09-19 13:19:24 -040080 {
Alexandre Savard4a19d752012-09-19 13:19:24 -040081 CallList.add(this);
Alexandre Savard7a46f542012-09-20 11:23:33 -040082 mCallInfo = info;
Alexandre Savard4a19d752012-09-19 13:19:24 -040083 }
84
85 protected void finalize() throws Throwable
86 {
Alexandre Savard7a46f542012-09-20 11:23:33 -040087 CallList.remove(this);
Alexandre Savard4a19d752012-09-19 13:19:24 -040088 }
89
Alexandre Savarda1404652012-09-20 13:34:08 -040090 public static void setCallElementList(CallElementList list)
91 {
92 mCallElementList = list;
93 }
94
Alexandre Savard7a46f542012-09-20 11:23:33 -040095 public static SipCall getCallInstance(CallInfo info)
Alexandre Savard4a19d752012-09-19 13:19:24 -040096 {
Alexandre Savard4a19d752012-09-19 13:19:24 -040097 if(CallList.isEmpty())
Alexandre Savard7a46f542012-09-20 11:23:33 -040098 return new SipCall(info);
Alexandre Savard4a19d752012-09-19 13:19:24 -040099
100 for(SipCall sipcall : CallList) {
Alexandre Savard7a46f542012-09-20 11:23:33 -0400101 if(sipcall.mCallInfo.mDisplayName.equals(info.mDisplayName)) {
102 if(sipcall.mCallInfo.mPhone.equals(info.mPhone)) {
103 return sipcall;
104 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400105 }
106 }
107
Alexandre Savard7a46f542012-09-20 11:23:33 -0400108 return new SipCall(info);
Alexandre Savard4a19d752012-09-19 13:19:24 -0400109 }
110
111 public static int getNbCalls()
112 {
113 return CallList.size();
114 }
115
Alexandre Savard23240c12012-09-19 18:23:44 -0400116 public void placeCall()
117 {
Alexandre Savarda1404652012-09-20 13:34:08 -0400118 mCallElementList.addCall(this);
119 // mManager.callmanagerJNI.placeCall("IP2IP", "CALL1234", "192.168.40.35");
Alexandre Savard23240c12012-09-19 18:23:44 -0400120 }
121
Alexandre Savard4a19d752012-09-19 13:19:24 -0400122 public void answer()
123 {
124
125 }
126
127 public void hangup()
128 {
Alexandre Savard6b7f4182012-09-20 14:10:42 -0400129 mCallElementList.removeCall(this);
130 CallList.remove(this);
Alexandre Savard2b01c822012-09-20 15:00:37 -0400131 // mManager.callmanagerJNI.hangup("IP2IP", "CALL1234", "192.168.40.35");
Alexandre Savard4a19d752012-09-19 13:19:24 -0400132 }
133}