blob: ed1aee83af2170eceb44d15a019bb9a130325216 [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;
40
Alexandre Savard557a5742012-10-24 13:54:53 -040041public class SipCall
Alexandre Savard4a19d752012-09-19 13:19:24 -040042{
43 final static String TAG = "SipCall";
Alexandre Savard74c1cad2012-10-24 16:39:00 -040044 public static CallElementList mCallElementList = null;
Alexandre Savard7a46f542012-09-20 11:23:33 -040045 public CallInfo mCallInfo;
46
Alexandre Savard557a5742012-10-24 13:54:53 -040047 public static int CALL_STATE_INVALID = 0; // The call is not existent in SFLphone service
48 public static int CALL_STATE_NULL = 1; // Before any action performed
49 public static int CALL_STATE_CALLING = 2; // After INVITE is sent
50 public static int CALL_STATE_INCOMING = 3; // After INVITE is received
51 public static int CALL_STATE_EARLY = 4; // After response with To tag
52 public static int CALL_STATE_CONNECTING = 5; // After 2xx is sent/received
53 public static int CALL_STATE_CONFIRMED = 6; // After ACK is sent/received
54 public static int CALL_STATE_DISCONNECTED = 7; // Session is terminated
Alexandre Savard2b01c822012-09-20 15:00:37 -040055
Alexandre Savard557a5742012-10-24 13:54:53 -040056 public static int MEDIA_STATE_NONE = 0; // No media currently
57 public static int MEDIA_STATE_ACTIVE = 1; // Media is active
58 public static int MEDIA_STATE_LOCAL_HOLD = 2; // Media is put on hold bu user
59 public static int MEDIA_STATE_REMOTE_HOLD = 3; // Media is put on hold by peer
60 public static int MEDIA_STATE_ERROR = 4; // Media is in error state
Alexandre Savard2b01c822012-09-20 15:00:37 -040061
Alexandre Savard557a5742012-10-24 13:54:53 -040062 public static class CallInfo implements Parcelable
Alexandre Savard7a46f542012-09-20 11:23:33 -040063 {
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 = "";
Alexandre Savard557a5742012-10-24 13:54:53 -040069 public int mCallState = CALL_STATE_NULL;
70 public int mMediaState = MEDIA_STATE_NONE;
71
72 @Override
73 public int describeContents() {
74 return 0;
75 }
76
77 @Override
78 public void writeToParcel(Parcel out, int flags) {
79 ArrayList<String> list = new ArrayList<String>();
Alexandre Savard74c1cad2012-10-24 16:39:00 -040080
81 // Don't mess with this order!!!
Alexandre Savard557a5742012-10-24 13:54:53 -040082 list.add(mCallID);
83 list.add(mDisplayName);
84 list.add(mPhone);
85 list.add(mEmail);
86 list.add(mRemoteContact);
87
88 out.writeStringList(list);
89 out.writeInt(mCallState);
90 out.writeInt(mMediaState);
91 }
92
93 public static final Parcelable.Creator<CallInfo> CREATOR
94 = new Parcelable.Creator<CallInfo>() {
95 public CallInfo createFromParcel(Parcel in) {
96 return new CallInfo(in);
97 }
98
99 public CallInfo[] newArray(int size) {
100 return new CallInfo[size];
101 }
102 };
103
104 public CallInfo() {}
105
106 private CallInfo(Parcel in) {
107 ArrayList<String> list = in.createStringArrayList();
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400108
109 // Don't mess with this order!!!
Alexandre Savard557a5742012-10-24 13:54:53 -0400110 mCallID = list.get(0);
111 mDisplayName = list.get(1);
112 mPhone = list.get(2);
113 mEmail = list.get(3);
114 mRemoteContact = list.get(4);
115
116 mCallState = in.readInt();
117 mMediaState = in.readInt();
118 }
Alexandre Savard7a46f542012-09-20 11:23:33 -0400119 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400120
121 public SipCall()
122 {
Alexandre Savard7a46f542012-09-20 11:23:33 -0400123 mCallInfo = new CallInfo();
Alexandre Savard4a19d752012-09-19 13:19:24 -0400124 }
125
Alexandre Savard7a46f542012-09-20 11:23:33 -0400126 public SipCall(CallInfo info)
Alexandre Savard4a19d752012-09-19 13:19:24 -0400127 {
Alexandre Savard7a46f542012-09-20 11:23:33 -0400128 mCallInfo = info;
Alexandre Savard4a19d752012-09-19 13:19:24 -0400129 }
130
Alexandre Savarda1404652012-09-20 13:34:08 -0400131 public static void setCallElementList(CallElementList list)
132 {
133 mCallElementList = list;
134 }
135
Alexandre Savard23240c12012-09-19 18:23:44 -0400136 public void placeCall()
137 {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400138 if(mCallElementList != null)
139 mCallElementList.addCall(this);
Alexandre Savarda1404652012-09-20 13:34:08 -0400140 // mManager.callmanagerJNI.placeCall("IP2IP", "CALL1234", "192.168.40.35");
Alexandre Savard23240c12012-09-19 18:23:44 -0400141 }
142
Alexandre Savard4a19d752012-09-19 13:19:24 -0400143 public void answer()
144 {
145
146 }
147
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400148 public void hangup(ISipService service)
Alexandre Savard4a19d752012-09-19 13:19:24 -0400149 {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400150 Log.i(TAG, "Hangup call " + mCallInfo.mCallID);
151
152 if(mCallElementList != null)
153 mCallElementList.removeCall(this);
154
155 try {
156 service.hangUp(mCallInfo.mCallID);
157 } catch (RemoteException e) {
158 Log.e(TAG, "Cannot call service method", e);
159 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400160 }
Alexandre Savardaef9d802012-09-20 17:31:32 -0400161
162 public void addToConference()
163 {
164 Log.i(TAG, "Add call to conference");
165 }
166
167 public void sendTextMessage()
168 {
169 Log.i(TAG, "Send text message");
170 }
Alexandre Savard4a19d752012-09-19 13:19:24 -0400171}