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); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 99 | out.writeTypedList(participants); |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 100 | out.writeByte((byte) (recording ? 1 : 0)); |
| 101 | out.writeTypedList(messages); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 102 | } |
| 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 Lision | 96db803 | 2014-01-17 16:43:51 -0500 | [diff] [blame] | 114 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 115 | private Conference(Parcel in) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 116 | participants = new ArrayList<SipCall>(); |
| 117 | id = in.readString(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 118 | mConfState = in.readInt(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 119 | in.readTypedList(participants, SipCall.CREATOR); |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 120 | recording = in.readByte() == 1 ? true : false; |
| 121 | messages = new ArrayList<SipMessage>(); |
| 122 | in.readTypedList(messages, SipMessage.CREATOR); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 125 | public Conference(SipCall call) { |
| 126 | this(DEFAULT_ID); |
| 127 | participants.add(call); |
| 128 | } |
| 129 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 130 | public Conference(String cID) { |
| 131 | id = cID; |
| 132 | participants = new ArrayList<SipCall>(); |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 133 | recording = false; |
| 134 | messages = new ArrayList<SipMessage>(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 135 | } |
| 136 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 137 | public Conference(Conference c) { |
| 138 | id = c.id; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 139 | mConfState = c.mConfState; |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 140 | participants = new ArrayList<SipCall>(c.participants); |
| 141 | recording = c.recording; |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 142 | messages = new ArrayList<SipMessage>(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 143 | } |
| 144 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 145 | public String getId() { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 146 | if(hasMultipleParticipants()) |
| 147 | return id; |
| 148 | else |
| 149 | return participants.get(0).getCallId(); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 150 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 151 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 152 | public String getState() { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 153 | if (participants.size() == 1) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 154 | return participants.get(0).getCallStateString(); |
| 155 | } |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 156 | return getConferenceStateString(); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 157 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 158 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 159 | 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; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 187 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 188 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 189 | public ArrayList<SipCall> getParticipants() { |
| 190 | return participants; |
| 191 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 192 | |
| 193 | public boolean contains(String callID) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 194 | for (int i = 0; i < participants.size(); ++i) { |
| 195 | if (participants.get(i).getCallId().contentEquals(callID)) |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 196 | return true; |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 201 | public SipCall getCallById(String callID) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 202 | for (int i = 0; i < participants.size(); ++i) { |
| 203 | if (participants.get(i).getCallId().contentEquals(callID)) |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 204 | return participants.get(i); |
| 205 | } |
| 206 | return null; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 207 | } |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 208 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 209 | /** |
| 210 | * Compare conferences based on confID/participants |
| 211 | */ |
| 212 | @Override |
| 213 | public boolean equals(Object c) { |
| 214 | if (c instanceof Conference) { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 215 | if (((Conference) c).id.contentEquals(id) && !id.contentEquals("-1")) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 216 | return true; |
| 217 | } else { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 218 | if (((Conference) c).id.contentEquals(id)) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 219 | 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 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 230 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 231 | public boolean hasMultipleParticipants() { |
| 232 | return participants.size() > 1; |
| 233 | } |
| 234 | |
| 235 | public boolean isOnHold() { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 236 | if (participants.size() == 1 && participants.get(0).isOnHold()) |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 237 | return true; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 238 | return getConferenceStateString().contentEquals("HOLD"); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 239 | } |
| 240 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 241 | public boolean isIncoming() { |
| 242 | if (participants.size() == 1 && participants.get(0).isIncoming()) |
| 243 | return true; |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 248 | public void setRecording(boolean b) { |
| 249 | recording = b; |
| 250 | } |
| 251 | |
| 252 | public boolean isRecording() { |
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 253 | return recording; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 256 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 257 | public boolean isOnGoing() { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 258 | if (participants.size() == 1 && participants.get(0).isOngoing()) |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 259 | return true; |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 260 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 261 | if (participants.size() > 1) |
| 262 | return true; |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 263 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 264 | return false; |
| 265 | } |
| 266 | |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 267 | public ArrayList<SipMessage> getMessages() { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 268 | return messages; |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 269 | } |
| 270 | |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 271 | public void addSipMessage(SipMessage sipMessage) { |
| 272 | messages.add(sipMessage); |
| 273 | } |
| 274 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 275 | public void addParticipant(SipCall part) { |
| 276 | participants.add(part); |
| 277 | } |
| 278 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 279 | } |