blob: 57581ba6bf5e3875bdbbdced0537b723e60ff492 [file] [log] [blame]
Alexandre Lisiona8b78722013-12-13 10:18:33 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisiona8b78722013-12-13 10:18:33 -05003 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
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
Alexandre Lision064e1e02013-10-01 16:18:42 -040032package org.sflphone.model;
alision907bde72013-06-20 14:40:37 -040033
34import java.util.ArrayList;
35
alision806e18e2013-06-21 15:30:17 -040036import android.os.Parcel;
37import android.os.Parcelable;
38
39public class Conference implements Parcelable {
40
41 private String id;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050042 private int mConfState;
alision907bde72013-06-20 14:40:37 -040043 private ArrayList<SipCall> participants;
alisiondf1dac92013-06-27 17:35:53 -040044 private boolean recording;
Alexandre Lisiond5686032013-10-29 11:09:21 -040045 private ArrayList<SipMessage> messages;
alision806e18e2013-06-21 15:30:17 -040046
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050047 public static String DEFAULT_ID = "-1";
48
49 public boolean isRinging() {
50 return participants.get(0).isRinging();
51 }
52
Alexandre Lision96db8032014-01-17 16:43:51 -050053 public void removeParticipant(SipCall toRemove) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050054 participants.remove(toRemove);
55 }
56
Alexandre Lisione1b7f162014-02-26 16:45:32 -050057 public boolean useSecureLayer() {
58 for(SipCall call : participants){
59 if(call.getAccount().useSecureLayer())
60 return true;
61 }
62 return false;
63 }
64
alision806e18e2013-06-21 15:30:17 -040065 public interface state {
66 int ACTIVE_ATTACHED = 0;
67 int ACTIVE_DETACHED = 1;
68 int ACTIVE_ATTACHED_REC = 2;
69 int ACTIVE_DETACHED_REC = 3;
70 int HOLD = 4;
71 int HOLD_REC = 5;
72 }
73
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050074 public void setCallState(String callID, int newState) {
75 if(id.contentEquals(callID))
76 mConfState = newState;
77 else {
78 getCallById(callID).setCallState(newState);
79 }
80 }
81
82 public void setCallState(String confID, String newState) {
83 if (newState.equals("ACTIVE_ATTACHED")) {
84 setCallState(confID, state.ACTIVE_ATTACHED);
85 } else if (newState.equals("ACTIVE_DETACHED")) {
86 setCallState(confID, state.ACTIVE_DETACHED);
87 } else if (newState.equals("ACTIVE_ATTACHED_REC")) {
88 setCallState(confID, state.ACTIVE_ATTACHED_REC);
89 } else if (newState.equals("ACTIVE_DETACHED_REC")) {
90 setCallState(confID, state.ACTIVE_DETACHED_REC);
91 } else if (newState.equals("HOLD")) {
92 setCallState(confID, state.HOLD);
93 } else if (newState.equals("HOLD_REC")) {
94 setCallState(confID, state.HOLD_REC);
95 }
96 }
97
alision806e18e2013-06-21 15:30:17 -040098 @Override
99 public int describeContents() {
100 return 0;
101 }
102
103 @Override
104 public void writeToParcel(Parcel out, int flags) {
alision806e18e2013-06-21 15:30:17 -0400105 out.writeString(id);
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500106 out.writeInt(mConfState);
Alexandre Lision8162f4c2014-02-14 16:45:49 -0500107 ArrayList<SipCall> normal_calls = new ArrayList<SipCall>();
108 ArrayList<SecureSipCall> secure_calls = new ArrayList<SecureSipCall>();
109
110 for(SipCall part : participants){
111 if(part instanceof SecureSipCall)
112 secure_calls.add((SecureSipCall) part);
113 else
114 normal_calls.add(part);
115 }
116 out.writeTypedList(secure_calls);
117 out.writeTypedList(normal_calls);
Alexandre Lisiond5686032013-10-29 11:09:21 -0400118 out.writeByte((byte) (recording ? 1 : 0));
119 out.writeTypedList(messages);
alision806e18e2013-06-21 15:30:17 -0400120 }
121
122 public static final Parcelable.Creator<Conference> CREATOR = new Parcelable.Creator<Conference>() {
123 public Conference createFromParcel(Parcel in) {
124 return new Conference(in);
125 }
126
127 public Conference[] newArray(int size) {
128 return new Conference[size];
129 }
130 };
131
Alexandre Lision96db8032014-01-17 16:43:51 -0500132
alision806e18e2013-06-21 15:30:17 -0400133 private Conference(Parcel in) {
alision806e18e2013-06-21 15:30:17 -0400134 participants = new ArrayList<SipCall>();
135 id = in.readString();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500136 mConfState = in.readInt();
Alexandre Lision8162f4c2014-02-14 16:45:49 -0500137 ArrayList<SecureSipCall> tmp = new ArrayList<SecureSipCall>();
138 in.readTypedList(tmp, SecureSipCall.CREATOR);
alision806e18e2013-06-21 15:30:17 -0400139 in.readTypedList(participants, SipCall.CREATOR);
Alexandre Lision8162f4c2014-02-14 16:45:49 -0500140 participants.addAll(tmp);
Alexandre Lisiond5686032013-10-29 11:09:21 -0400141 recording = in.readByte() == 1 ? true : false;
142 messages = new ArrayList<SipMessage>();
143 in.readTypedList(messages, SipMessage.CREATOR);
alision806e18e2013-06-21 15:30:17 -0400144 }
145
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500146 public Conference(SipCall call) {
147 this(DEFAULT_ID);
148 participants.add(call);
149 }
150
alision806e18e2013-06-21 15:30:17 -0400151 public Conference(String cID) {
152 id = cID;
153 participants = new ArrayList<SipCall>();
Alexandre Lisiond5545232013-10-29 11:24:02 -0400154 recording = false;
155 messages = new ArrayList<SipMessage>();
alision806e18e2013-06-21 15:30:17 -0400156 }
157
alisioncd8fb912013-06-28 14:43:51 -0400158 public Conference(Conference c) {
159 id = c.id;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500160 mConfState = c.mConfState;
alisioncd8fb912013-06-28 14:43:51 -0400161 participants = new ArrayList<SipCall>(c.participants);
162 recording = c.recording;
Alexandre Lisiond5545232013-10-29 11:24:02 -0400163 messages = new ArrayList<SipMessage>();
alisioncd8fb912013-06-28 14:43:51 -0400164 }
165
alision806e18e2013-06-21 15:30:17 -0400166 public String getId() {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400167 if(hasMultipleParticipants())
168 return id;
169 else
170 return participants.get(0).getCallId();
alision907bde72013-06-20 14:40:37 -0400171 }
alision806e18e2013-06-21 15:30:17 -0400172
alision907bde72013-06-20 14:40:37 -0400173 public String getState() {
alisioncd8fb912013-06-28 14:43:51 -0400174 if (participants.size() == 1) {
alisiondf1dac92013-06-27 17:35:53 -0400175 return participants.get(0).getCallStateString();
176 }
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500177 return getConferenceStateString();
alision907bde72013-06-20 14:40:37 -0400178 }
alision806e18e2013-06-21 15:30:17 -0400179
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500180 public String getConferenceStateString() {
181
182 String text_state;
183
184 switch (mConfState) {
185 case state.ACTIVE_ATTACHED:
186 text_state = "ACTIVE_ATTACHED";
187 break;
188 case state.ACTIVE_DETACHED:
189 text_state = "ACTIVE_DETACHED";
190 break;
191 case state.ACTIVE_ATTACHED_REC:
192 text_state = "ACTIVE_ATTACHED_REC";
193 break;
194 case state.ACTIVE_DETACHED_REC:
195 text_state = "ACTIVE_DETACHED_REC";
196 break;
197 case state.HOLD:
198 text_state = "HOLD";
199 break;
200 case state.HOLD_REC:
201 text_state = "HOLD_REC";
202 break;
203 default:
204 text_state = "NULL";
205 }
206
207 return text_state;
alision907bde72013-06-20 14:40:37 -0400208 }
alision806e18e2013-06-21 15:30:17 -0400209
alision907bde72013-06-20 14:40:37 -0400210 public ArrayList<SipCall> getParticipants() {
211 return participants;
212 }
alision806e18e2013-06-21 15:30:17 -0400213
214 public boolean contains(String callID) {
alisioncd8fb912013-06-28 14:43:51 -0400215 for (int i = 0; i < participants.size(); ++i) {
216 if (participants.get(i).getCallId().contentEquals(callID))
alision806e18e2013-06-21 15:30:17 -0400217 return true;
218 }
219 return false;
220 }
221
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500222 public SipCall getCallById(String callID) {
alisioncd8fb912013-06-28 14:43:51 -0400223 for (int i = 0; i < participants.size(); ++i) {
224 if (participants.get(i).getCallId().contentEquals(callID))
alision806e18e2013-06-21 15:30:17 -0400225 return participants.get(i);
226 }
227 return null;
alision907bde72013-06-20 14:40:37 -0400228 }
Alexandre Lisiond5686032013-10-29 11:09:21 -0400229
alision465ceba2013-07-04 09:24:30 -0400230 /**
231 * Compare conferences based on confID/participants
232 */
233 @Override
234 public boolean equals(Object c) {
235 if (c instanceof Conference) {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400236 if (((Conference) c).id.contentEquals(id) && !id.contentEquals("-1")) {
alision465ceba2013-07-04 09:24:30 -0400237 return true;
238 } else {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400239 if (((Conference) c).id.contentEquals(id)) {
alision465ceba2013-07-04 09:24:30 -0400240 for (int i = 0; i < participants.size(); ++i) {
241 if (!((Conference) c).contains(participants.get(i).getCallId()))
242 return false;
243 }
244 return true;
245 }
246 }
247 }
248 return false;
249
250 }
alision907bde72013-06-20 14:40:37 -0400251
alisiondf1dac92013-06-27 17:35:53 -0400252 public boolean hasMultipleParticipants() {
253 return participants.size() > 1;
254 }
255
256 public boolean isOnHold() {
alisioncd8fb912013-06-28 14:43:51 -0400257 if (participants.size() == 1 && participants.get(0).isOnHold())
alisiondf1dac92013-06-27 17:35:53 -0400258 return true;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500259 return getConferenceStateString().contentEquals("HOLD");
alisiondf1dac92013-06-27 17:35:53 -0400260 }
261
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500262 public boolean isIncoming() {
263 if (participants.size() == 1 && participants.get(0).isIncoming())
264 return true;
265 return false;
266 }
267
268
alisiondf1dac92013-06-27 17:35:53 -0400269 public void setRecording(boolean b) {
270 recording = b;
271 }
272
273 public boolean isRecording() {
Alexandre Lision3874e552013-11-04 17:20:12 -0500274 return recording;
alisiondf1dac92013-06-27 17:35:53 -0400275 }
276
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500277
alisiondf1dac92013-06-27 17:35:53 -0400278 public boolean isOnGoing() {
alisioncd8fb912013-06-28 14:43:51 -0400279 if (participants.size() == 1 && participants.get(0).isOngoing())
alisiondf1dac92013-06-27 17:35:53 -0400280 return true;
alisioncd8fb912013-06-28 14:43:51 -0400281
alisiondf1dac92013-06-27 17:35:53 -0400282 if (participants.size() > 1)
283 return true;
alisioncd8fb912013-06-28 14:43:51 -0400284
alisiondf1dac92013-06-27 17:35:53 -0400285 return false;
286 }
287
Alexandre Lisiond5686032013-10-29 11:09:21 -0400288 public ArrayList<SipMessage> getMessages() {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500289 return messages;
Alexandre Lisiond5686032013-10-29 11:09:21 -0400290 }
291
Alexandre Lisiond5545232013-10-29 11:24:02 -0400292 public void addSipMessage(SipMessage sipMessage) {
293 messages.add(sipMessage);
294 }
295
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500296 public void addParticipant(SipCall part) {
297 participants.add(part);
298 }
299
alision907bde72013-06-20 14:40:37 -0400300}