blob: 2e60e8f93a6e99aab3265483597a7ff22c09a7b9 [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);
alision806e18e2013-06-21 15:30:17 -040099 out.writeTypedList(participants);
Alexandre Lisiond5686032013-10-29 11:09:21 -0400100 out.writeByte((byte) (recording ? 1 : 0));
101 out.writeTypedList(messages);
alision806e18e2013-06-21 15:30:17 -0400102 }
103
104 public static final Parcelable.Creator<Conference> CREATOR = new Parcelable.Creator<Conference>() {
105 public Conference createFromParcel(Parcel in) {
106 return new Conference(in);
107 }
108
109 public Conference[] newArray(int size) {
110 return new Conference[size];
111 }
112 };
113
Alexandre Lision96db8032014-01-17 16:43:51 -0500114
alision806e18e2013-06-21 15:30:17 -0400115 private Conference(Parcel in) {
alision806e18e2013-06-21 15:30:17 -0400116 participants = new ArrayList<SipCall>();
117 id = in.readString();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500118 mConfState = in.readInt();
alision806e18e2013-06-21 15:30:17 -0400119 in.readTypedList(participants, SipCall.CREATOR);
Alexandre Lisiond5686032013-10-29 11:09:21 -0400120 recording = in.readByte() == 1 ? true : false;
121 messages = new ArrayList<SipMessage>();
122 in.readTypedList(messages, SipMessage.CREATOR);
alision806e18e2013-06-21 15:30:17 -0400123 }
124
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500125 public Conference(SipCall call) {
126 this(DEFAULT_ID);
127 participants.add(call);
128 }
129
alision806e18e2013-06-21 15:30:17 -0400130 public Conference(String cID) {
131 id = cID;
132 participants = new ArrayList<SipCall>();
Alexandre Lisiond5545232013-10-29 11:24:02 -0400133 recording = false;
134 messages = new ArrayList<SipMessage>();
alision806e18e2013-06-21 15:30:17 -0400135 }
136
alisioncd8fb912013-06-28 14:43:51 -0400137 public Conference(Conference c) {
138 id = c.id;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500139 mConfState = c.mConfState;
alisioncd8fb912013-06-28 14:43:51 -0400140 participants = new ArrayList<SipCall>(c.participants);
141 recording = c.recording;
Alexandre Lisiond5545232013-10-29 11:24:02 -0400142 messages = new ArrayList<SipMessage>();
alisioncd8fb912013-06-28 14:43:51 -0400143 }
144
alision806e18e2013-06-21 15:30:17 -0400145 public String getId() {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400146 if(hasMultipleParticipants())
147 return id;
148 else
149 return participants.get(0).getCallId();
alision907bde72013-06-20 14:40:37 -0400150 }
alision806e18e2013-06-21 15:30:17 -0400151
alision907bde72013-06-20 14:40:37 -0400152 public String getState() {
alisioncd8fb912013-06-28 14:43:51 -0400153 if (participants.size() == 1) {
alisiondf1dac92013-06-27 17:35:53 -0400154 return participants.get(0).getCallStateString();
155 }
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500156 return getConferenceStateString();
alision907bde72013-06-20 14:40:37 -0400157 }
alision806e18e2013-06-21 15:30:17 -0400158
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500159 public String getConferenceStateString() {
160
161 String text_state;
162
163 switch (mConfState) {
164 case state.ACTIVE_ATTACHED:
165 text_state = "ACTIVE_ATTACHED";
166 break;
167 case state.ACTIVE_DETACHED:
168 text_state = "ACTIVE_DETACHED";
169 break;
170 case state.ACTIVE_ATTACHED_REC:
171 text_state = "ACTIVE_ATTACHED_REC";
172 break;
173 case state.ACTIVE_DETACHED_REC:
174 text_state = "ACTIVE_DETACHED_REC";
175 break;
176 case state.HOLD:
177 text_state = "HOLD";
178 break;
179 case state.HOLD_REC:
180 text_state = "HOLD_REC";
181 break;
182 default:
183 text_state = "NULL";
184 }
185
186 return text_state;
alision907bde72013-06-20 14:40:37 -0400187 }
alision806e18e2013-06-21 15:30:17 -0400188
alision907bde72013-06-20 14:40:37 -0400189 public ArrayList<SipCall> getParticipants() {
190 return participants;
191 }
alision806e18e2013-06-21 15:30:17 -0400192
193 public boolean contains(String callID) {
alisioncd8fb912013-06-28 14:43:51 -0400194 for (int i = 0; i < participants.size(); ++i) {
195 if (participants.get(i).getCallId().contentEquals(callID))
alision806e18e2013-06-21 15:30:17 -0400196 return true;
197 }
198 return false;
199 }
200
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500201 public SipCall getCallById(String callID) {
alisioncd8fb912013-06-28 14:43:51 -0400202 for (int i = 0; i < participants.size(); ++i) {
203 if (participants.get(i).getCallId().contentEquals(callID))
alision806e18e2013-06-21 15:30:17 -0400204 return participants.get(i);
205 }
206 return null;
alision907bde72013-06-20 14:40:37 -0400207 }
Alexandre Lisiond5686032013-10-29 11:09:21 -0400208
alision465ceba2013-07-04 09:24:30 -0400209 /**
210 * Compare conferences based on confID/participants
211 */
212 @Override
213 public boolean equals(Object c) {
214 if (c instanceof Conference) {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400215 if (((Conference) c).id.contentEquals(id) && !id.contentEquals("-1")) {
alision465ceba2013-07-04 09:24:30 -0400216 return true;
217 } else {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400218 if (((Conference) c).id.contentEquals(id)) {
alision465ceba2013-07-04 09:24:30 -0400219 for (int i = 0; i < participants.size(); ++i) {
220 if (!((Conference) c).contains(participants.get(i).getCallId()))
221 return false;
222 }
223 return true;
224 }
225 }
226 }
227 return false;
228
229 }
alision907bde72013-06-20 14:40:37 -0400230
alisiondf1dac92013-06-27 17:35:53 -0400231 public boolean hasMultipleParticipants() {
232 return participants.size() > 1;
233 }
234
235 public boolean isOnHold() {
alisioncd8fb912013-06-28 14:43:51 -0400236 if (participants.size() == 1 && participants.get(0).isOnHold())
alisiondf1dac92013-06-27 17:35:53 -0400237 return true;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500238 return getConferenceStateString().contentEquals("HOLD");
alisiondf1dac92013-06-27 17:35:53 -0400239 }
240
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500241 public boolean isIncoming() {
242 if (participants.size() == 1 && participants.get(0).isIncoming())
243 return true;
244 return false;
245 }
246
247
alisiondf1dac92013-06-27 17:35:53 -0400248 public void setRecording(boolean b) {
249 recording = b;
250 }
251
252 public boolean isRecording() {
Alexandre Lision3874e552013-11-04 17:20:12 -0500253 return recording;
alisiondf1dac92013-06-27 17:35:53 -0400254 }
255
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500256
alisiondf1dac92013-06-27 17:35:53 -0400257 public boolean isOnGoing() {
alisioncd8fb912013-06-28 14:43:51 -0400258 if (participants.size() == 1 && participants.get(0).isOngoing())
alisiondf1dac92013-06-27 17:35:53 -0400259 return true;
alisioncd8fb912013-06-28 14:43:51 -0400260
alisiondf1dac92013-06-27 17:35:53 -0400261 if (participants.size() > 1)
262 return true;
alisioncd8fb912013-06-28 14:43:51 -0400263
alisiondf1dac92013-06-27 17:35:53 -0400264 return false;
265 }
266
Alexandre Lisiond5686032013-10-29 11:09:21 -0400267 public ArrayList<SipMessage> getMessages() {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500268 return messages;
Alexandre Lisiond5686032013-10-29 11:09:21 -0400269 }
270
Alexandre Lisiond5545232013-10-29 11:24:02 -0400271 public void addSipMessage(SipMessage sipMessage) {
272 messages.add(sipMessage);
273 }
274
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500275 public void addParticipant(SipCall part) {
276 participants.add(part);
277 }
278
alision907bde72013-06-20 14:40:37 -0400279}