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; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 42 | private String state = ""; |
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 | |
| 47 | public interface state { |
| 48 | int ACTIVE_ATTACHED = 0; |
| 49 | int ACTIVE_DETACHED = 1; |
| 50 | int ACTIVE_ATTACHED_REC = 2; |
| 51 | int ACTIVE_DETACHED_REC = 3; |
| 52 | int HOLD = 4; |
| 53 | int HOLD_REC = 5; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public int describeContents() { |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public void writeToParcel(Parcel out, int flags) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 63 | out.writeString(id); |
| 64 | out.writeString(state); |
| 65 | out.writeTypedList(participants); |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 66 | out.writeByte((byte) (recording ? 1 : 0)); |
| 67 | out.writeTypedList(messages); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | public static final Parcelable.Creator<Conference> CREATOR = new Parcelable.Creator<Conference>() { |
| 71 | public Conference createFromParcel(Parcel in) { |
| 72 | return new Conference(in); |
| 73 | } |
| 74 | |
| 75 | public Conference[] newArray(int size) { |
| 76 | return new Conference[size]; |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | private Conference(Parcel in) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 81 | participants = new ArrayList<SipCall>(); |
| 82 | id = in.readString(); |
| 83 | state = in.readString(); |
| 84 | in.readTypedList(participants, SipCall.CREATOR); |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 85 | recording = in.readByte() == 1 ? true : false; |
| 86 | messages = new ArrayList<SipMessage>(); |
| 87 | in.readTypedList(messages, SipMessage.CREATOR); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | public Conference(String cID) { |
| 91 | id = cID; |
| 92 | participants = new ArrayList<SipCall>(); |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 93 | recording = false; |
| 94 | messages = new ArrayList<SipMessage>(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 95 | } |
| 96 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 97 | public Conference(Conference c) { |
| 98 | id = c.id; |
| 99 | state = c.state; |
| 100 | participants = new ArrayList<SipCall>(c.participants); |
| 101 | recording = c.recording; |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 102 | messages = new ArrayList<SipMessage>(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 103 | } |
| 104 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 105 | public String getId() { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 106 | if(hasMultipleParticipants()) |
| 107 | return id; |
| 108 | else |
| 109 | return participants.get(0).getCallId(); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 110 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 111 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 112 | public String getState() { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 113 | if (participants.size() == 1) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 114 | return participants.get(0).getCallStateString(); |
| 115 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 116 | return state; |
| 117 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 118 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 119 | public void setState(String state) { |
| 120 | this.state = state; |
| 121 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 122 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 123 | public ArrayList<SipCall> getParticipants() { |
| 124 | return participants; |
| 125 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 126 | |
| 127 | public boolean contains(String callID) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 128 | for (int i = 0; i < participants.size(); ++i) { |
| 129 | if (participants.get(i).getCallId().contentEquals(callID)) |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 130 | return true; |
| 131 | } |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | public SipCall getCall(String callID) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 136 | for (int i = 0; i < participants.size(); ++i) { |
| 137 | if (participants.get(i).getCallId().contentEquals(callID)) |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 138 | return participants.get(i); |
| 139 | } |
| 140 | return null; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 141 | } |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 142 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 143 | /** |
| 144 | * Compare conferences based on confID/participants |
| 145 | */ |
| 146 | @Override |
| 147 | public boolean equals(Object c) { |
| 148 | if (c instanceof Conference) { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 149 | if (((Conference) c).id.contentEquals(id) && !id.contentEquals("-1")) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 150 | return true; |
| 151 | } else { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 152 | if (((Conference) c).id.contentEquals(id)) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 153 | for (int i = 0; i < participants.size(); ++i) { |
| 154 | if (!((Conference) c).contains(participants.get(i).getCallId())) |
| 155 | return false; |
| 156 | } |
| 157 | return true; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | return false; |
| 162 | |
| 163 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 164 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 165 | public boolean hasMultipleParticipants() { |
| 166 | return participants.size() > 1; |
| 167 | } |
| 168 | |
| 169 | public boolean isOnHold() { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 170 | if (participants.size() == 1 && participants.get(0).isOnHold()) |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 171 | return true; |
| 172 | return state.contentEquals("HOLD"); |
| 173 | } |
| 174 | |
| 175 | public void setRecording(boolean b) { |
| 176 | recording = b; |
| 177 | } |
| 178 | |
| 179 | public boolean isRecording() { |
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 180 | if(hasMultipleParticipants()) |
| 181 | return recording; |
| 182 | else |
| 183 | return participants.get(0).isRecording(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | public boolean isOnGoing() { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 187 | if (participants.size() == 1 && participants.get(0).isOngoing()) |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 188 | return true; |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 189 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 190 | if (participants.size() > 1) |
| 191 | return true; |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 192 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 193 | return false; |
| 194 | } |
| 195 | |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 196 | public ArrayList<SipMessage> getMessages() { |
| 197 | if (hasMultipleParticipants()) |
| 198 | return messages; |
| 199 | else |
| 200 | return participants.get(0).getMessages(); |
| 201 | |
| 202 | } |
| 203 | |
Alexandre Lision | d554523 | 2013-10-29 11:24:02 -0400 | [diff] [blame] | 204 | public void addSipMessage(SipMessage sipMessage) { |
| 205 | messages.add(sipMessage); |
| 206 | } |
| 207 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 208 | } |