-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathCallListenerThread.java
More file actions
88 lines (69 loc) · 2.17 KB
/
CallListenerThread.java
File metadata and controls
88 lines (69 loc) · 2.17 KB
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
import java.io.IOException;
import java.net.SocketAddress;
import java.util.Observable;
import java.util.concurrent.TimeUnit;
public class CallListenerThread extends Observable implements Runnable {
private CallListener callListener;
private Caller.CallStatus callStatus;
private Connection connection;
private volatile boolean isOpen;
// TODO: Add lastEvent;
public CallListenerThread() throws IOException {
callListener = new CallListener();
}
public CallListenerThread(String localNick) throws IOException {
callListener = new CallListener(localNick);
}
public CallListenerThread(String localNick, String localIp) throws IOException {
callListener = new CallListener(localNick, localIp);
}
public Caller.CallStatus getCallStatus() {
return callStatus;
}
public SocketAddress getListenAddress() throws IOException {
return callListener.getListenAddress();
}
public String getLocalNick() {
return callListener.getLocalNick();
}
public SocketAddress getRemoteAddress() throws IOException {
return callListener.getRemoteAdress();
}
public Connection getConnection() {
return connection;
}
public boolean isBusy() {
return callListener.isBusy();
}
@Override
public void run() {
while (true) {
try {
connection = callListener.getConnection();
if (connection == null) {
callStatus = Caller.CallStatus.valueOf("BUSY");
} else {
callStatus = Caller.CallStatus.valueOf("OK");
}
} catch (IOException e) {
System.out.println("SmthWrong");
}
setChanged();
notifyObservers();
}
}
public void setBusy(boolean busy) {
callListener.setBusy(busy);
}
public void setLocalNick(String localNick) {
callListener.setLocalNick(localNick);
}
public void start() {
this.isOpen = true;
Thread t = new Thread(this);
t.start();
};
public void stop() {
this.isOpen = false;
}
}