📄 gcchannel.java
字号:
}
public Voice getVoice() {
return voiceDev;
}
public Device getNetwork() {
return lineDev;
}
public void run() {
EVT evt;
while(true) try {
clear();
while (blocked)
evt = serviceWaitEvent();
if (!waiting) {
lineDev.waitCall();
waiting = true;
}
beginService();
while(true) {
evt = serviceWaitEvent();
if (evt.type == GCEV_OFFERED) {
linestate = ICALL;
setState(INCOMING);
crn = (int)evt.crn;
call = new Call(GCChannel.this);
byte dnis[] = new byte[10];
try {
int dnisl = Dialogic.gc_GetDNIS(crn, dnis);
call.dnis = dnisPref + new String(dnis, 0, dnisl);
} catch (RuntimeException rte) {
call.dnis = dnisPref;
}
if ((Dialogic.debug & Dialogic.DEBUG_GC) != 0)
System.out.println(new java.util.Date().toString().substring(11,19) + this + ": Call to " + call.dnis + "(" + crn + ")");
if (handler != null) {
endService();
handler.handleCall(call);
}
} else {
if ((Dialogic.debug & Dialogic.DEBUG_GC) != 0)
System.out.println(new java.util.Date().toString().substring(11,19) + this + ": Event " + evt);
}
}
}
catch (Exception e) {
if (linestate == DIAL)
// Someone asking me to leave...
return;
System.err.println(this.toString() + " service loop: " + e);
}
finally {
endService();
}
}
public String toString() {
return "GCChannel on " + name;
}
void accept() {
if (linestate != ICALL)
throw new ChannelException("accept(): wrong state");
if ((Dialogic.debug & Dialogic.DEBUG_GC) != 0)
System.out.println(new java.util.Date().toString().substring(11,19) + this + ": accepting " + crn);
try {
beginService();
Dialogic.gc_AcceptCall(crn, 0, Dialogic.EV_ASYNC);
EVT evt = serviceWaitEvent();
if (evt.type != GCEV_ACCEPT)
throw new ChannelException("Accept error:" + evt);
linestate = RINGS;
} finally {
endService();
}
}
void answer(int rings) {
// It is ok to answer w/o accept...
if (!(linestate == RINGS || linestate == ICALL))
throw new ChannelException("answer(): wrong state");
if (linestate == ICALL)
accept();
// Ring cycle
EVT evt = null;
long now = System.currentTimeMillis();
long conn = call.startTime() + rings * 3000; // 3 secs each
try {
beginService();
if (conn > now)
evt = serviceWaitEvent(conn - now);
if (evt == null) {
if ((Dialogic.debug & Dialogic.DEBUG_GC) != 0)
System.out.println(new java.util.Date().toString().substring(11,19) + this + ": answering " + crn);
Dialogic.gc_AnswerCall(crn, 0, Dialogic.EV_ASYNC);
evt = serviceWaitEvent();
if (evt.type != GCEV_ANSWERED)
throw new ChannelException("Answer error:" + evt);
linestate = IN;
} else {
linestate = ERROR;
setState(OOS);
throw new ChannelException("answer():" + evt);
}
} finally {
endService();
}
}
void reject(int reason) {
if (linestate != ICALL)
throw new ChannelException("reject(): wrong state");
throw new ChannelException("reject: not implemented!");
}
void dial(Call call, String number) {
if (linestate != IDLE)
throw new ChannelException("dial(): wrong state");
if (blocked)
throw new ChannelException("dial(): blocked");
linestate = DIAL;
if (serviceThread != null) {
Channel.stopGroup(this);
serviceThread.interrupt();
/* Service thread will normally die,
* but simultaneous seizure may prevent that from happening... */
try {
serviceThread.join(500);
}
catch(InterruptedException ie) {
Thread.currentThread().interrupt();
}
// Give up if it did not quit...
if (serviceThread.isAlive()) {
System.err.println("Seizure failure: service not quitting");
throw new ChannelException("dial(): seizure failure");
}
serviceThread = null;
}
this.call = call;
setState(OUTGOING);
// Wait for call completion...
try {
beginService();
if ((Dialogic.debug & Dialogic.DEBUG_GC) != 0)
System.out.println(new java.util.Date().toString().substring(11,19) + this + ": dialing " + number);
crn = lineDev.dial(number, 30); // Note the 30 seconds timeout
EVT evt = serviceWaitEvent();
if (evt.type != GCEV_ALERTING)
throw new ChannelException("Dial error:" + evt);
} finally {
endService();
}
return;
}
String ani() {
String ani = "";
if (crn == 0)
return "";
byte anis[] = new byte[40];
try {
int anisl = Dialogic.gc_GetANI(crn,anis);
ani = new String(anis, 0, anisl);
} catch (Exception e) {
// Runtime exception thrown by GC layer if ani not available
ani = "";
}
return ani;
}
int pulses() {
throw new ChannelException("pulses: not implemented!");
}
synchronized void clear() {
if (linestate == RESET)
return;
linestate = RESET;
super.clear();
if (voiceDev != null) {
voiceDev.stop();
voiceDev.clear();
if (cas) {
lineDev.listen(voiceDev);
voiceDev.listen(lineDev);
}
}
if (crn != 0) {
if ((Dialogic.debug & Dialogic.DEBUG_GC) != 0)
System.out.println(new java.util.Date().toString().substring(11,19) + this + ": dropping " + crn);
Dialogic.gc_DropCall(crn, GC_NORMAL_CLEARING, Dialogic.EV_ASYNC);
}
flush();
if (serviceThread == null) {
serviceThread = new Thread(group, this, name + " service");
serviceThread.start();
}
}
// Our line state service fn
protected EVT service(EVT evt) {
switch (evt.type) {
case GCEV_BLOCKED:
blocked = true;
waiting = false;
evt = null;
linestate = ERROR;
setState(OOS);
if ((Dialogic.debug & Dialogic.DEBUG_GC) != 0)
System.out.println(new java.util.Date().toString().substring(11,19) + this + ": resetting");
lineDev.reset();
break;
case GCEV_UNBLOCKED:
blocked = false;
if (linestate == RESET) {
linestate = IDLE;
setState(FREE);
}
break;
case GCEV_DISCONNECTED:
voiceDev.stop();
if ((Dialogic.debug & Dialogic.DEBUG_GC) != 0)
System.out.println(new java.util.Date().toString().substring(11,19) + this + ": dropping " + crn);
Dialogic.gc_DropCall(crn, GC_NORMAL_CLEARING, Dialogic.EV_ASYNC);
if (call != null) call.drop();
clear();
throw new HangUpException();
case GCEV_DROPCALL:
voiceDev.stop();
if ((Dialogic.debug & Dialogic.DEBUG_GC) != 0)
System.out.println(new java.util.Date().toString().substring(11,19) + this + ": releasing " + crn);
Dialogic.gc_ReleaseCall(crn);
if (call != null) call.drop();
crn = 0;
evt = null;
linestate = IDLE;
setState(FREE);
break;
case GCEV_CONNECTED:
// Remote answer
if (call != null) call.connect();
break; // Let the event go up
}
return evt;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -