blob: 2babf81290c6e50410069f9fe9098962ac634b4d [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
Alexandre Savard85936b92012-10-24 11:23:53 -040033import android.os.Parcelable;
Alexandre Savard557a5742012-10-24 13:54:53 -040034import android.os.Parcel;
Alexandre Savard74c1cad2012-10-24 16:39:00 -040035import android.os.RemoteException;
Alexandre Savard4a19d752012-09-19 13:19:24 -040036import android.util.Log;
37import java.util.ArrayList;
38
Alexandre Savard74c1cad2012-10-24 16:39:00 -040039import com.savoirfairelinux.sflphone.service.ISipService;
Alexandre Savard4f42ade2012-10-24 18:03:31 -040040import com.savoirfairelinux.sflphone.client.CallActivity;
Alexandre Savard74c1cad2012-10-24 16:39:00 -040041
Alexandre Savard557a5742012-10-24 13:54:53 -040042public class SipCall
Alexandre Savard4a19d752012-09-19 13:19:24 -040043{
44 final static String TAG = "SipCall";
Alexandre Savard74c1cad2012-10-24 16:39:00 -040045 public static CallElementList mCallElementList = null;
Alexandre Savard4f42ade2012-10-24 18:03:31 -040046 private static CallActivity mCallActivity = null;
Alexandre Savard7a46f542012-09-20 11:23:33 -040047 public CallInfo mCallInfo;
48
Alexandre Savard557a5742012-10-24 13:54:53 -040049 public static int CALL_STATE_INVALID = 0; // The call is not existent in SFLphone service
50 public static int CALL_STATE_NULL = 1; // Before any action performed
51 public static int CALL_STATE_CALLING = 2; // After INVITE is sent
52 public static int CALL_STATE_INCOMING = 3; // After INVITE is received
53 public static int CALL_STATE_EARLY = 4; // After response with To tag
54 public static int CALL_STATE_CONNECTING = 5; // After 2xx is sent/received
55 public static int CALL_STATE_CONFIRMED = 6; // After ACK is sent/received
56 public static int CALL_STATE_DISCONNECTED = 7; // Session is terminated
Alexandre Savard2b01c822012-09-20 15:00:37 -040057
Alexandre Savard557a5742012-10-24 13:54:53 -040058 public static int MEDIA_STATE_NONE = 0; // No media currently
59 public static int MEDIA_STATE_ACTIVE = 1; // Media is active
60 public static int MEDIA_STATE_LOCAL_HOLD = 2; // Media is put on hold bu user
61 public static int MEDIA_STATE_REMOTE_HOLD = 3; // Media is put on hold by peer
62 public static int MEDIA_STATE_ERROR = 4; // Media is in error state
Alexandre Savard2b01c822012-09-20 15:00:37 -040063
Alexandre Savard557a5742012-10-24 13:54:53 -040064 public static class CallInfo implements Parcelable
Alexandre Savard7a46f542012-09-20 11:23:33 -040065 {
Alexandre Savard2b01c822012-09-20 15:00:37 -040066 public String mCallID = "";
Alexandre Savard7a46f542012-09-20 11:23:33 -040067 public String mDisplayName = "";
68 public String mPhone = "";
69 public String mEmail = "";
Alexandre Savard2b01c822012-09-20 15:00:37 -040070 public String mRemoteContact = "";
Alexandre Savard557a5742012-10-24 13:54:53 -040071 public int mCallState = CALL_STATE_NULL;
72 public int mMediaState = MEDIA_STATE_NONE;
73
74 @Override
75 public int describeContents() {
76 return 0;
77 }
78
79 @Override
80 public void writeToParcel(Parcel out, int flags) {
81 ArrayList<String> list = new ArrayList<String>();
Alexandre Savard74c1cad2012-10-24 16:39:00 -040082
83 // Don't mess with this order!!!
Alexandre Savard557a5742012-10-24 13:54:53 -040084 list.add(mCallID);
85 list.add(mDisplayName);
86 list.add(mPhone);
87 list.add(mEmail);
88 list.add(mRemoteContact);
89
90 out.writeStringList(list);
91 out.writeInt(mCallState);
92 out.writeInt(mMediaState);
93 }
94
95 public static final Parcelable.Creator<CallInfo> CREATOR
96 = new Parcelable.Creator<CallInfo>() {
97 public CallInfo createFromParcel(Parcel in) {
98 return new CallInfo(in);
99 }
100
101 public CallInfo[] newArray(int size) {
102 return new CallInfo[size];
103 }
104 };
105
106 public CallInfo() {}
107
108 private CallInfo(Parcel in) {
109 ArrayList<String> list = in.createStringArrayList();
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400110
111 // Don't mess with this order!!!
Alexandre Savard557a5742012-10-24 13:54:53 -0400112 mCallID = list.get(0);
113 mDisplayName = list.get(1);
114 mPhone = list.get(2);
115 mEmail = list.get(3);
116 mRemoteContact = list.get(4);
117
118 mCallState = in.readInt();
119 mMediaState = in.readInt();
120 }
Alexandre Savard7a46f542012-09-20 11:23:33 -0400121 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400122
123 public SipCall()
124 {
Alexandre Savard7a46f542012-09-20 11:23:33 -0400125 mCallInfo = new CallInfo();
Alexandre Savard4a19d752012-09-19 13:19:24 -0400126 }
127
Alexandre Savard7a46f542012-09-20 11:23:33 -0400128 public SipCall(CallInfo info)
Alexandre Savard4a19d752012-09-19 13:19:24 -0400129 {
Alexandre Savard7a46f542012-09-20 11:23:33 -0400130 mCallInfo = info;
Alexandre Savard4a19d752012-09-19 13:19:24 -0400131 }
132
Alexandre Savarda1404652012-09-20 13:34:08 -0400133 public static void setCallElementList(CallElementList list)
134 {
135 mCallElementList = list;
136 }
137
Alexandre Savard23240c12012-09-19 18:23:44 -0400138 public void placeCall()
139 {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400140 if(mCallElementList != null)
141 mCallElementList.addCall(this);
Alexandre Savarda1404652012-09-20 13:34:08 -0400142 // mManager.callmanagerJNI.placeCall("IP2IP", "CALL1234", "192.168.40.35");
Alexandre Savard23240c12012-09-19 18:23:44 -0400143 }
144
Alexandre Savard4a19d752012-09-19 13:19:24 -0400145 public void answer()
146 {
147
148 }
149
Alexandre Savard4f42ade2012-10-24 18:03:31 -0400150 /**
151 * Perform hangup action without sending request to the service
152 */
153 public void hangup() {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400154 Log.i(TAG, "Hangup call " + mCallInfo.mCallID);
155
156 if(mCallElementList != null)
157 mCallElementList.removeCall(this);
158
Alexandre Savard4f42ade2012-10-24 18:03:31 -0400159 if(mCallActivity != null)
160 mCallActivity.finish();
161 }
162
163 /**
164 * Perform hangup action and send request to the service
165 */
166 public void notifyServiceHangup(ISipService service)
167 {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400168 try {
169 service.hangUp(mCallInfo.mCallID);
170 } catch (RemoteException e) {
171 Log.e(TAG, "Cannot call service method", e);
172 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400173 }
Alexandre Savardaef9d802012-09-20 17:31:32 -0400174
175 public void addToConference()
176 {
177 Log.i(TAG, "Add call to conference");
178 }
179
180 public void sendTextMessage()
181 {
182 Log.i(TAG, "Send text message");
183 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400184}