blob: 7c8c6440ac7dc033bf529929d8718838f434873b [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
alision806e18e2013-06-21 15:30:17 -040057 public interface state {
58 int ACTIVE_ATTACHED = 0;
59 int ACTIVE_DETACHED = 1;
60 int ACTIVE_ATTACHED_REC = 2;
61 int ACTIVE_DETACHED_REC = 3;
62 int HOLD = 4;
63 int HOLD_REC = 5;
64 }
65
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050066 public void setCallState(String callID, int newState) {
67 if(id.contentEquals(callID))
68 mConfState = newState;
69 else {
70 getCallById(callID).setCallState(newState);
71 }
72 }
73
74 public void setCallState(String confID, String newState) {
75 if (newState.equals("ACTIVE_ATTACHED")) {
76 setCallState(confID, state.ACTIVE_ATTACHED);
77 } else if (newState.equals("ACTIVE_DETACHED")) {
78 setCallState(confID, state.ACTIVE_DETACHED);
79 } else if (newState.equals("ACTIVE_ATTACHED_REC")) {
80 setCallState(confID, state.ACTIVE_ATTACHED_REC);
81 } else if (newState.equals("ACTIVE_DETACHED_REC")) {
82 setCallState(confID, state.ACTIVE_DETACHED_REC);
83 } else if (newState.equals("HOLD")) {
84 setCallState(confID, state.HOLD);
85 } else if (newState.equals("HOLD_REC")) {
86 setCallState(confID, state.HOLD_REC);
87 }
88 }
89
alision806e18e2013-06-21 15:30:17 -040090 @Override
91 public int describeContents() {
92 return 0;
93 }
94
95 @Override
96 public void writeToParcel(Parcel out, int flags) {
alision806e18e2013-06-21 15:30:17 -040097 out.writeString(id);
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050098 out.writeInt(mConfState);
Alexandre Lision8162f4c2014-02-14 16:45:49 -050099 ArrayList<SipCall> normal_calls = new ArrayList<SipCall>();
100 ArrayList<SecureSipCall> secure_calls = new ArrayList<SecureSipCall>();
101
102 for(SipCall part : participants){
103 if(part instanceof SecureSipCall)
104 secure_calls.add((SecureSipCall) part);
105 else
106 normal_calls.add(part);
107 }
108 out.writeTypedList(secure_calls);
109 out.writeTypedList(normal_calls);
Alexandre Lisiond5686032013-10-29 11:09:21 -0400110 out.writeByte((byte) (recording ? 1 : 0));
111 out.writeTypedList(messages);
alision806e18e2013-06-21 15:30:17 -0400112 }
113
114 public static final Parcelable.Creator<Conference> CREATOR = new Parcelable.Creator<Conference>() {
115 public Conference createFromParcel(Parcel in) {
116 return new Conference(in);
117 }
118
119 public Conference[] newArray(int size) {
120 return new Conference[size];
121 }
122 };
123
Alexandre Lision96db8032014-01-17 16:43:51 -0500124
alision806e18e2013-06-21 15:30:17 -0400125 private Conference(Parcel in) {
alision806e18e2013-06-21 15:30:17 -0400126 participants = new ArrayList<SipCall>();
127 id = in.readString();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500128 mConfState = in.readInt();
Alexandre Lision8162f4c2014-02-14 16:45:49 -0500129 ArrayList<SecureSipCall> tmp = new ArrayList<SecureSipCall>();
130 in.readTypedList(tmp, SecureSipCall.CREATOR);
alision806e18e2013-06-21 15:30:17 -0400131 in.readTypedList(participants, SipCall.CREATOR);
Alexandre Lision8162f4c2014-02-14 16:45:49 -0500132 participants.addAll(tmp);
Alexandre Lisiond5686032013-10-29 11:09:21 -0400133 recording = in.readByte() == 1 ? true : false;
134 messages = new ArrayList<SipMessage>();
135 in.readTypedList(messages, SipMessage.CREATOR);
alision806e18e2013-06-21 15:30:17 -0400136 }
137
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500138 public Conference(SipCall call) {
139 this(DEFAULT_ID);
140 participants.add(call);
141 }
142
alision806e18e2013-06-21 15:30:17 -0400143 public Conference(String cID) {
144 id = cID;
145 participants = new ArrayList<SipCall>();
Alexandre Lisiond5545232013-10-29 11:24:02 -0400146 recording = false;
147 messages = new ArrayList<SipMessage>();
alision806e18e2013-06-21 15:30:17 -0400148 }
149
alisioncd8fb912013-06-28 14:43:51 -0400150 public Conference(Conference c) {
151 id = c.id;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500152 mConfState = c.mConfState;
alisioncd8fb912013-06-28 14:43:51 -0400153 participants = new ArrayList<SipCall>(c.participants);
154 recording = c.recording;
Alexandre Lisiond5545232013-10-29 11:24:02 -0400155 messages = new ArrayList<SipMessage>();
alisioncd8fb912013-06-28 14:43:51 -0400156 }
157
alision806e18e2013-06-21 15:30:17 -0400158 public String getId() {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400159 if(hasMultipleParticipants())
160 return id;
161 else
162 return participants.get(0).getCallId();
alision907bde72013-06-20 14:40:37 -0400163 }
alision806e18e2013-06-21 15:30:17 -0400164
alision907bde72013-06-20 14:40:37 -0400165 public String getState() {
alisioncd8fb912013-06-28 14:43:51 -0400166 if (participants.size() == 1) {
alisiondf1dac92013-06-27 17:35:53 -0400167 return participants.get(0).getCallStateString();
168 }
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500169 return getConferenceStateString();
alision907bde72013-06-20 14:40:37 -0400170 }
alision806e18e2013-06-21 15:30:17 -0400171
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500172 public String getConferenceStateString() {
173
174 String text_state;
175
176 switch (mConfState) {
177 case state.ACTIVE_ATTACHED:
178 text_state = "ACTIVE_ATTACHED";
179 break;
180 case state.ACTIVE_DETACHED:
181 text_state = "ACTIVE_DETACHED";
182 break;
183 case state.ACTIVE_ATTACHED_REC:
184 text_state = "ACTIVE_ATTACHED_REC";
185 break;
186 case state.ACTIVE_DETACHED_REC:
187 text_state = "ACTIVE_DETACHED_REC";
188 break;
189 case state.HOLD:
190 text_state = "HOLD";
191 break;
192 case state.HOLD_REC:
193 text_state = "HOLD_REC";
194 break;
195 default:
196 text_state = "NULL";
197 }
198
199 return text_state;
alision907bde72013-06-20 14:40:37 -0400200 }
alision806e18e2013-06-21 15:30:17 -0400201
alision907bde72013-06-20 14:40:37 -0400202 public ArrayList<SipCall> getParticipants() {
203 return participants;
204 }
alision806e18e2013-06-21 15:30:17 -0400205
206 public boolean contains(String callID) {
alisioncd8fb912013-06-28 14:43:51 -0400207 for (int i = 0; i < participants.size(); ++i) {
208 if (participants.get(i).getCallId().contentEquals(callID))
alision806e18e2013-06-21 15:30:17 -0400209 return true;
210 }
211 return false;
212 }
213
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500214 public SipCall getCallById(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 participants.get(i);
218 }
219 return null;
alision907bde72013-06-20 14:40:37 -0400220 }
Alexandre Lisiond5686032013-10-29 11:09:21 -0400221
alision465ceba2013-07-04 09:24:30 -0400222 /**
223 * Compare conferences based on confID/participants
224 */
225 @Override
226 public boolean equals(Object c) {
227 if (c instanceof Conference) {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400228 if (((Conference) c).id.contentEquals(id) && !id.contentEquals("-1")) {
alision465ceba2013-07-04 09:24:30 -0400229 return true;
230 } else {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400231 if (((Conference) c).id.contentEquals(id)) {
alision465ceba2013-07-04 09:24:30 -0400232 for (int i = 0; i < participants.size(); ++i) {
233 if (!((Conference) c).contains(participants.get(i).getCallId()))
234 return false;
235 }
236 return true;
237 }
238 }
239 }
240 return false;
241
242 }
alision907bde72013-06-20 14:40:37 -0400243
alisiondf1dac92013-06-27 17:35:53 -0400244 public boolean hasMultipleParticipants() {
245 return participants.size() > 1;
246 }
247
248 public boolean isOnHold() {
alisioncd8fb912013-06-28 14:43:51 -0400249 if (participants.size() == 1 && participants.get(0).isOnHold())
alisiondf1dac92013-06-27 17:35:53 -0400250 return true;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500251 return getConferenceStateString().contentEquals("HOLD");
alisiondf1dac92013-06-27 17:35:53 -0400252 }
253
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500254 public boolean isIncoming() {
255 if (participants.size() == 1 && participants.get(0).isIncoming())
256 return true;
257 return false;
258 }
259
260
alisiondf1dac92013-06-27 17:35:53 -0400261 public void setRecording(boolean b) {
262 recording = b;
263 }
264
265 public boolean isRecording() {
Alexandre Lision3874e552013-11-04 17:20:12 -0500266 return recording;
alisiondf1dac92013-06-27 17:35:53 -0400267 }
268
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500269
alisiondf1dac92013-06-27 17:35:53 -0400270 public boolean isOnGoing() {
alisioncd8fb912013-06-28 14:43:51 -0400271 if (participants.size() == 1 && participants.get(0).isOngoing())
alisiondf1dac92013-06-27 17:35:53 -0400272 return true;
alisioncd8fb912013-06-28 14:43:51 -0400273
alisiondf1dac92013-06-27 17:35:53 -0400274 if (participants.size() > 1)
275 return true;
alisioncd8fb912013-06-28 14:43:51 -0400276
alisiondf1dac92013-06-27 17:35:53 -0400277 return false;
278 }
279
Alexandre Lisiond5686032013-10-29 11:09:21 -0400280 public ArrayList<SipMessage> getMessages() {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500281 return messages;
Alexandre Lisiond5686032013-10-29 11:09:21 -0400282 }
283
Alexandre Lisiond5545232013-10-29 11:24:02 -0400284 public void addSipMessage(SipMessage sipMessage) {
285 messages.add(sipMessage);
286 }
287
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500288 public void addParticipant(SipCall part) {
289 participants.add(part);
290 }
291
alision907bde72013-06-20 14:40:37 -0400292}