1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.protocol;
import java.util.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* A represenation of a Call. The Call class must obly be created by users (i.e.
* telephony protocols) of the PhoneUIService such as a SIP protocol
* implemenation. Extensions of this class might have names like SipCall
* or H323Call or AnyOtherTelephonyProtocolCall
*
* @author Emil Ivov
* @author Emanuel Onica
*/
public abstract class Call
{
private static final Logger logger
= Logger.getLogger(Call.class);
/**
* An identifier uniquely representing the call.
*/
private String callID = null;
/**
* A list of all listeners currently registered for
* <tt>CallChangeEvent</tt>s
*/
private Vector<CallChangeListener> callListeners
= new Vector<CallChangeListener>();
/**
* A reference to the ProtocolProviderService instance that created us.
*/
private ProtocolProviderService protocolProvider = null;
/**
* A collection of various GUI components used for a call management that might
* be needed inside specific layers of the call securing, depending on the
* securing algorithm used
*/
private Hashtable<Object, SecurityGUIListener> securityGUIListeners;
/**
* If this flag is set to true according to the account properties
* related with the sourceProvider the associated CallSession will start
* encrypted by default (where applicable)
*/
private final boolean defaultEncryption;
/**
* Creates a new Call instance.
*
* @param sourceProvider the proto provider that created us.
*/
protected Call(ProtocolProviderService sourceProvider)
{
//create the uid
this.callID = String.valueOf( System.currentTimeMillis())
+ String.valueOf(super.hashCode());
this.protocolProvider = sourceProvider;
AccountID accountID = sourceProvider.getAccountID();
defaultEncryption =
accountID.getAccountPropertyBoolean(
ProtocolProviderFactory.DEFAULT_ENCRYPTION, false);
}
/**
* Returns the id of the specified Call.
* @return a String uniquely identifying the call.
*/
public String getCallID()
{
return callID;
}
/**
* Compares the specified object with this call and returns true if it the
* specified object is an instance of a Call object and if the
* extending telephony protocol considers the calls represented by both
* objects to be the same.
*
* @param obj the call to compare this one with.
* @return true in case both objects are pertaining to the same call and
* false otherwise.
*/
public boolean equals(Object obj)
{
if(obj == null
|| !(obj instanceof Call))
return false;
if (obj == this
|| ((Call)obj).getCallID().equals( getCallID() ))
return true;
return false;
}
/**
* Returns a hash code value for this call.
*
* @return a hash code value for this call.
*/
public int hashCode()
{
return getCallID().hashCode();
}
/**
* Returns an iterator over all call participants.
* @return an Iterator over all participants currently involved in the call.
*/
public abstract Iterator<CallParticipant> getCallParticipants();
/**
* Returns the number of participants currently associated with this call.
* @return an <tt>int</tt> indicating the number of participants currently
* associated with this call.
*/
public abstract int getCallParticipantsCount();
/**
* Adds a call change listener to this call so that it could receive events
* on new call participants, theme changes and others.
*
* @param listener the listener to register
*/
public void addCallChangeListener(CallChangeListener listener)
{
synchronized(callListeners)
{
if(!callListeners.contains(listener))
this.callListeners.add(listener);
}
}
/**
* Removes <tt>listener</tt> to this call so that it won't receive further
* <tt>CallChangeEvent</tt>s.
* @param listener the listener to register
*/
public void removeCallChangeListener(CallChangeListener listener)
{
synchronized(callListeners)
{
this.callListeners.remove(listener);
}
}
/**
* Returns a reference to the <tt>ProtocolProviderService</tt> instance
* that created this call.
* @return a reference to the <tt>ProtocolProviderService</tt> instance that
* created this call.
*/
public ProtocolProviderService getProtocolProvider()
{
return this.protocolProvider;
}
/**
* Creates a <tt>CallParticipantEvent</tt> with
* <tt>sourceCallParticipant</tt> and <tt>eventID</tt> and dispatches it on
* all currently registered listeners.
*
* @param sourceCallParticipant the source <tt>CallParticipant</tt> for the
* newly created event.
* @param eventID the ID of the event to create (see CPE member ints)
*/
protected void fireCallParticipantEvent(CallParticipant sourceCallParticipant,
int eventID)
{
CallParticipantEvent cpEvent = new CallParticipantEvent(
sourceCallParticipant, this, eventID);
logger.debug("Dispatching a CallParticipant event to "
+ callListeners.size()
+" listeners. event is: " + cpEvent.toString());
Iterator listeners = null;
synchronized(callListeners)
{
listeners = new ArrayList(callListeners).iterator();
}
while(listeners.hasNext())
{
CallChangeListener listener = (CallChangeListener)listeners.next();
if(eventID == CallParticipantEvent.CALL_PARTICIPANT_ADDED)
listener.callParticipantAdded(cpEvent);
else if (eventID == CallParticipantEvent.CALL_PARTICIPANT_REMVOVED)
listener.callParticipantRemoved(cpEvent);
}
}
/**
* Returns a string textually representing this Call.
*
* @return a string representation of the object.
*/
public String toString()
{
return "Call: id=" + getCallID() + " participants="
+ getCallParticipantsCount();
}
/**
* Creates a <tt>CallChangeEvent</tt> with this class as
* <tt>sourceCall</tt>, and the specified <tt>eventID</tt> and old and new
* values and dispatches it on all currently registered listeners.
*
* @param type the type of the event to create (see CallChangeEvent member
* ints)
* @param oldValue the value of the call property that changed, before the
* event had occurred.
* @param newValue the value of the call property that changed, after the
* event has occurred.
*/
protected void fireCallChangeEvent( String type,
Object oldValue,
Object newValue)
{
CallChangeEvent ccEvent = new CallChangeEvent(
this, type, oldValue, newValue);
logger.debug("Dispatching a CallChange event to "
+ callListeners.size()
+" listeners. event is: " + ccEvent.toString());
Iterator listeners = null;
synchronized(callListeners)
{
listeners = new ArrayList(callListeners).iterator();
}
while(listeners.hasNext())
{
CallChangeListener listener = (CallChangeListener)listeners.next();
if(type.equals(CallChangeEvent.CALL_STATE_CHANGE))
listener.callStateChanged(ccEvent);
}
}
/**
* Returns the state that this call is currently in.
*
* @return a reference to the <tt>CallState</tt> instance that the call is
* currently in.
*/
public abstract CallState getCallState();
/**
* This method is used to add references to various GUI components related to
* securing the call that might be used in different way in by various securing
* algorithms, and consequently might be needed for particular usage at the layers
* where the specified algorithms operate
*
* @param key a key used by a securing algorithm implementation
* to identify the GUI item needed
* @param the GUI listener
*/
public void addSecurityGUIListener(Object key, SecurityGUIListener value)
{
if (securityGUIListeners == null)
securityGUIListeners = new Hashtable<Object, SecurityGUIListener>();
securityGUIListeners.put(key, value);
}
/**
* This method is used to obtain the reference to various GUI components related to
* securing the call that might be used in different way in by various securing
* algorithms, and consequently might be needed for particular usage at the layers
* where the specified algorithms operate
*
* @param key a key used by a securing algorithm implementation
* to identify the GUI item needed
* @return the GUI listener
*/
public SecurityGUIListener getSecurityGUIListener(Object key)
{
if (securityGUIListeners == null)
return null;
else
return securityGUIListeners.get(key);
}
/**
* Returns the default call encryption flag
*
* @return the default call encryption flag
*/
public boolean isDefaultEncrypted()
{
return defaultEncryption;
}
}
|