Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 3 | * |
| 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 Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 32 | package org.sflphone.model; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 33 | |
| 34 | import java.util.ArrayList; |
| 35 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 36 | import android.os.Parcel; |
| 37 | import android.os.Parcelable; |
| 38 | |
| 39 | public class Conference implements Parcelable { |
| 40 | |
| 41 | private String id; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 42 | private int mConfState; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 43 | private ArrayList<SipCall> participants; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 44 | private boolean recording; |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 45 | private ArrayList<SipMessage> messages; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 46 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 47 | public static String DEFAULT_ID = "-1"; |
| 48 | |
| 49 | public boolean isRinging() { |
| 50 | return participants.get(0).isRinging(); |
| 51 | } |
| 52 | |
Alexandre Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 53 | public void removeParticipant(SipCall toRemove) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 54 | participants.remove(toRemove); |
| 55 | } |
| 56 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 57 | 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 Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 66 | 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 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 90 | @Override |
| 91 | public int describeContents() { |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public void writeToParcel(Parcel out, int flags) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 97 | out.writeString(id); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 98 | out.writeInt(mConfState); |
Alexandre Lision | 8162f4c | 2014-02-14 16:45:49 -0500 | [diff] [blame] | 99 | 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 Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 110 | out.writeByte((byte) (recording ? 1 : 0)); |
| 111 | out.writeTypedList(messages); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 112 | } |
| 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 Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 124 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 125 | private Conference(Parcel in) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 126 | participants = new ArrayList<SipCall>(); |
| 127 | id = in.readString(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 128 | mConfState = in.readInt(); |
Alexandre Lision | 8162f4c | 2014-02-14 16:45:49 -0500 | [diff] [blame] | 129 | ArrayList<SecureSipCall> tmp = new ArrayList<SecureSipCall>(); |
| 130 | in.readTypedList(tmp, SecureSipCall.CREATOR); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 131 | in.readTypedList(participants, SipCall.CREATOR); |
Alexandre Lision | 8162f4c | 2014-02-14 16:45:49 -0500 | [diff] [blame] | 132 | participants.addAll(tmp); |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 133 | recording = in.readByte() == 1 ? true : false; |
| 134 | messages = new ArrayList<SipMessage>(); |
| 135 | in.readTypedList(messages, SipMessage.CREATOR); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 138 | public Conference(SipCall call) { |
| 139 | this(DEFAULT_ID); |
| 140 | participants.add(call); |
| 141 | } |
| 142 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 143 | public Conference(String cID) { |
| 144 | id = cID; |
| 145 | participants = new ArrayList<SipCall>(); |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 146 | recording = false; |
| 147 | messages = new ArrayList<SipMessage>(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 148 | } |
| 149 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 150 | public Conference(Conference c) { |
| 151 | id = c.id; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 152 | mConfState = c.mConfState; |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 153 | participants = new ArrayList<SipCall>(c.participants); |
| 154 | recording = c.recording; |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 155 | messages = new ArrayList<SipMessage>(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 156 | } |
| 157 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 158 | public String getId() { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 159 | if(hasMultipleParticipants()) |
| 160 | return id; |
| 161 | else |
| 162 | return participants.get(0).getCallId(); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 163 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 164 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 165 | public String getState() { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 166 | if (participants.size() == 1) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 167 | return participants.get(0).getCallStateString(); |
| 168 | } |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 169 | return getConferenceStateString(); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 170 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 171 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 172 | 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; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 200 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 201 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 202 | public ArrayList<SipCall> getParticipants() { |
| 203 | return participants; |
| 204 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 205 | |
| 206 | public boolean contains(String callID) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 207 | for (int i = 0; i < participants.size(); ++i) { |
| 208 | if (participants.get(i).getCallId().contentEquals(callID)) |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 209 | return true; |
| 210 | } |
| 211 | return false; |
| 212 | } |
| 213 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 214 | public SipCall getCallById(String callID) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 215 | for (int i = 0; i < participants.size(); ++i) { |
| 216 | if (participants.get(i).getCallId().contentEquals(callID)) |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 217 | return participants.get(i); |
| 218 | } |
| 219 | return null; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 220 | } |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 221 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 222 | /** |
| 223 | * Compare conferences based on confID/participants |
| 224 | */ |
| 225 | @Override |
| 226 | public boolean equals(Object c) { |
| 227 | if (c instanceof Conference) { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 228 | if (((Conference) c).id.contentEquals(id) && !id.contentEquals("-1")) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 229 | return true; |
| 230 | } else { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 231 | if (((Conference) c).id.contentEquals(id)) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 232 | 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 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 243 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 244 | public boolean hasMultipleParticipants() { |
| 245 | return participants.size() > 1; |
| 246 | } |
| 247 | |
| 248 | public boolean isOnHold() { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 249 | if (participants.size() == 1 && participants.get(0).isOnHold()) |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 250 | return true; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 251 | return getConferenceStateString().contentEquals("HOLD"); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 252 | } |
| 253 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 254 | public boolean isIncoming() { |
| 255 | if (participants.size() == 1 && participants.get(0).isIncoming()) |
| 256 | return true; |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 261 | public void setRecording(boolean b) { |
| 262 | recording = b; |
| 263 | } |
| 264 | |
| 265 | public boolean isRecording() { |
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 266 | return recording; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 267 | } |
| 268 | |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 269 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 270 | public boolean isOnGoing() { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 271 | if (participants.size() == 1 && participants.get(0).isOngoing()) |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 272 | return true; |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 273 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 274 | if (participants.size() > 1) |
| 275 | return true; |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 276 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 277 | return false; |
| 278 | } |
| 279 | |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 280 | public ArrayList<SipMessage> getMessages() { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 281 | return messages; |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 282 | } |
| 283 | |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 284 | public void addSipMessage(SipMessage sipMessage) { |
| 285 | messages.add(sipMessage); |
| 286 | } |
| 287 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 288 | public void addParticipant(SipCall part) { |
| 289 | participants.add(part); |
| 290 | } |
| 291 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 292 | } |