blob: 0047f3b62e3333466f0ea43612c53a3ef93a8423 [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;
alisiondf1dac92013-06-27 17:35:53 -040042 private String state = "";
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
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) {
alision806e18e2013-06-21 15:30:17 -040063 out.writeString(id);
64 out.writeString(state);
65 out.writeTypedList(participants);
Alexandre Lisiond5686032013-10-29 11:09:21 -040066 out.writeByte((byte) (recording ? 1 : 0));
67 out.writeTypedList(messages);
alision806e18e2013-06-21 15:30:17 -040068 }
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) {
alision806e18e2013-06-21 15:30:17 -040081 participants = new ArrayList<SipCall>();
82 id = in.readString();
83 state = in.readString();
84 in.readTypedList(participants, SipCall.CREATOR);
Alexandre Lisiond5686032013-10-29 11:09:21 -040085 recording = in.readByte() == 1 ? true : false;
86 messages = new ArrayList<SipMessage>();
87 in.readTypedList(messages, SipMessage.CREATOR);
alision806e18e2013-06-21 15:30:17 -040088 }
89
90 public Conference(String cID) {
91 id = cID;
92 participants = new ArrayList<SipCall>();
Alexandre Lisiond5545232013-10-29 11:24:02 -040093 recording = false;
94 messages = new ArrayList<SipMessage>();
alision806e18e2013-06-21 15:30:17 -040095 }
96
alisioncd8fb912013-06-28 14:43:51 -040097 public Conference(Conference c) {
98 id = c.id;
99 state = c.state;
100 participants = new ArrayList<SipCall>(c.participants);
101 recording = c.recording;
Alexandre Lisiond5545232013-10-29 11:24:02 -0400102 messages = new ArrayList<SipMessage>();
alisioncd8fb912013-06-28 14:43:51 -0400103 }
104
alision806e18e2013-06-21 15:30:17 -0400105 public String getId() {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400106 if(hasMultipleParticipants())
107 return id;
108 else
109 return participants.get(0).getCallId();
alision907bde72013-06-20 14:40:37 -0400110 }
alision806e18e2013-06-21 15:30:17 -0400111
alision907bde72013-06-20 14:40:37 -0400112 public String getState() {
alisioncd8fb912013-06-28 14:43:51 -0400113 if (participants.size() == 1) {
alisiondf1dac92013-06-27 17:35:53 -0400114 return participants.get(0).getCallStateString();
115 }
alision907bde72013-06-20 14:40:37 -0400116 return state;
117 }
alision806e18e2013-06-21 15:30:17 -0400118
alision907bde72013-06-20 14:40:37 -0400119 public void setState(String state) {
120 this.state = state;
121 }
alision806e18e2013-06-21 15:30:17 -0400122
alision907bde72013-06-20 14:40:37 -0400123 public ArrayList<SipCall> getParticipants() {
124 return participants;
125 }
alision806e18e2013-06-21 15:30:17 -0400126
127 public boolean contains(String callID) {
alisioncd8fb912013-06-28 14:43:51 -0400128 for (int i = 0; i < participants.size(); ++i) {
129 if (participants.get(i).getCallId().contentEquals(callID))
alision806e18e2013-06-21 15:30:17 -0400130 return true;
131 }
132 return false;
133 }
134
135 public SipCall getCall(String callID) {
alisioncd8fb912013-06-28 14:43:51 -0400136 for (int i = 0; i < participants.size(); ++i) {
137 if (participants.get(i).getCallId().contentEquals(callID))
alision806e18e2013-06-21 15:30:17 -0400138 return participants.get(i);
139 }
140 return null;
alision907bde72013-06-20 14:40:37 -0400141 }
Alexandre Lisiond5686032013-10-29 11:09:21 -0400142
alision465ceba2013-07-04 09:24:30 -0400143 /**
144 * Compare conferences based on confID/participants
145 */
146 @Override
147 public boolean equals(Object c) {
148 if (c instanceof Conference) {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400149 if (((Conference) c).id.contentEquals(id) && !id.contentEquals("-1")) {
alision465ceba2013-07-04 09:24:30 -0400150 return true;
151 } else {
Alexandre Lisiond5686032013-10-29 11:09:21 -0400152 if (((Conference) c).id.contentEquals(id)) {
alision465ceba2013-07-04 09:24:30 -0400153 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 }
alision907bde72013-06-20 14:40:37 -0400164
alisiondf1dac92013-06-27 17:35:53 -0400165 public boolean hasMultipleParticipants() {
166 return participants.size() > 1;
167 }
168
169 public boolean isOnHold() {
alisioncd8fb912013-06-28 14:43:51 -0400170 if (participants.size() == 1 && participants.get(0).isOnHold())
alisiondf1dac92013-06-27 17:35:53 -0400171 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 Lision3874e552013-11-04 17:20:12 -0500180 return recording;
alisiondf1dac92013-06-27 17:35:53 -0400181 }
182
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500183
alisiondf1dac92013-06-27 17:35:53 -0400184 public boolean isOnGoing() {
alisioncd8fb912013-06-28 14:43:51 -0400185 if (participants.size() == 1 && participants.get(0).isOngoing())
alisiondf1dac92013-06-27 17:35:53 -0400186 return true;
alisioncd8fb912013-06-28 14:43:51 -0400187
alisiondf1dac92013-06-27 17:35:53 -0400188 if (participants.size() > 1)
189 return true;
alisioncd8fb912013-06-28 14:43:51 -0400190
alisiondf1dac92013-06-27 17:35:53 -0400191 return false;
192 }
193
Alexandre Lisiond5686032013-10-29 11:09:21 -0400194 public ArrayList<SipMessage> getMessages() {
195 if (hasMultipleParticipants())
196 return messages;
197 else
198 return participants.get(0).getMessages();
199
200 }
201
Alexandre Lisiond5545232013-10-29 11:24:02 -0400202 public void addSipMessage(SipMessage sipMessage) {
203 messages.add(sipMessage);
204 }
205
alision907bde72013-06-20 14:40:37 -0400206}