Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 4 | * Author: Alexandre Savard <alexandre.savard@gmail.com> |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 5 | * |
| 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 | */ |
| 31 | package com.savoirfairelinux.sflphone.client; |
| 32 | |
| 33 | import android.util.Log; |
| 34 | import java.util.ArrayList; |
| 35 | |
| 36 | public class SipCall |
| 37 | { |
| 38 | final static String TAG = "SipCall"; |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 39 | private static ArrayList<SipCall> CallList = new ArrayList<SipCall>(); |
| 40 | public static CallElementList mCallElementList; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 41 | public CallInfo mCallInfo; |
| 42 | |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 43 | 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 Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 62 | public static class CallInfo |
| 63 | { |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 64 | public String mCallID = ""; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 65 | public String mDisplayName = ""; |
| 66 | public String mPhone = ""; |
| 67 | public String mEmail = ""; |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 68 | public String mRemoteContact = ""; |
Alexandre Savard | 3143399 | 2012-09-20 15:19:49 -0400 | [diff] [blame] | 69 | public CallState mCallState = CallState.NULL; |
| 70 | public MediaState mMediaState = MediaState.NONE; |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 71 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 72 | |
| 73 | public SipCall() |
| 74 | { |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 75 | CallList.add(this); |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 76 | mCallInfo = new CallInfo(); |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 79 | public SipCall(CallInfo info) |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 80 | { |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 81 | CallList.add(this); |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 82 | mCallInfo = info; |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | protected void finalize() throws Throwable |
| 86 | { |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 87 | CallList.remove(this); |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 88 | } |
| 89 | |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 90 | public static void setCallElementList(CallElementList list) |
| 91 | { |
| 92 | mCallElementList = list; |
| 93 | } |
| 94 | |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 95 | public static SipCall getCallInstance(CallInfo info) |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 96 | { |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 97 | if(CallList.isEmpty()) |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 98 | return new SipCall(info); |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 99 | |
| 100 | for(SipCall sipcall : CallList) { |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 101 | if(sipcall.mCallInfo.mDisplayName.equals(info.mDisplayName)) { |
| 102 | if(sipcall.mCallInfo.mPhone.equals(info.mPhone)) { |
| 103 | return sipcall; |
| 104 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
Alexandre Savard | 7a46f54 | 2012-09-20 11:23:33 -0400 | [diff] [blame] | 108 | return new SipCall(info); |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | public static int getNbCalls() |
| 112 | { |
| 113 | return CallList.size(); |
| 114 | } |
| 115 | |
Alexandre Savard | 23240c1 | 2012-09-19 18:23:44 -0400 | [diff] [blame] | 116 | public void placeCall() |
| 117 | { |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 118 | mCallElementList.addCall(this); |
| 119 | // mManager.callmanagerJNI.placeCall("IP2IP", "CALL1234", "192.168.40.35"); |
Alexandre Savard | 23240c1 | 2012-09-19 18:23:44 -0400 | [diff] [blame] | 120 | } |
| 121 | |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 122 | public void answer() |
| 123 | { |
| 124 | |
| 125 | } |
| 126 | |
| 127 | public void hangup() |
| 128 | { |
Alexandre Savard | 6b7f418 | 2012-09-20 14:10:42 -0400 | [diff] [blame] | 129 | mCallElementList.removeCall(this); |
| 130 | CallList.remove(this); |
Alexandre Savard | 2b01c82 | 2012-09-20 15:00:37 -0400 | [diff] [blame] | 131 | // mManager.callmanagerJNI.hangup("IP2IP", "CALL1234", "192.168.40.35"); |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 132 | } |
Alexandre Savard | aef9d80 | 2012-09-20 17:31:32 -0400 | [diff] [blame] | 133 | |
| 134 | public void addToConference() |
| 135 | { |
| 136 | Log.i(TAG, "Add call to conference"); |
| 137 | } |
| 138 | |
| 139 | public void sendTextMessage() |
| 140 | { |
| 141 | Log.i(TAG, "Send text message"); |
| 142 | } |
Alexandre Savard | 4a19d75 | 2012-09-19 13:19:24 -0400 | [diff] [blame] | 143 | } |