www.pudn.com > d4j.zip > Test.java
import local.dialogic.*;
import java.io.*;
import java.util.*;
public class Test implements CallHandler, Application
{
public void handleCall(Call aCall, Properties props) {
handleCall(aCall);
}
public void handleCall(Call aCall) {
Channel ch = null;
try {
aCall.accept(1); // 1 ring, then accept
Voice d4dev = aCall.channel().getVoice();
// IOTT iott = new IOTT(new RandomAccessFile("hello.vox", "rw"));
// iott.add(new RandomAccessFile("oops.vox", "r"));
XPB xpb = new XPB(Dialogic.FILE_FORMAT_WAVE, 0, 0, 0);
IOTT iott = new IOTT("hello.wav");
TPT tpt = new TPT(TPT.MAXDTMF,1,TPT.USE|TPT.LEVEL,0);
tpt.add(TPT.MAXTIME, 40, 0, 0);
// d4dev.digitEvents(true);
//d4dev.play(iott, tpt, Dialogic.SR_6);
//d4dev.record(iott, tpt, Dialogic.SR_8);
// d4dev.cleardig();
// d4dev.play(iott, tpt, Dialogic.SR_8);
System.out.println("Setting XFERBUFSIZE to 1024");
d4dev.setBufSize(1024);
System.out.print("Reading XFERBUFSIZE: " + d4dev.getBufSize());
d4dev.playiottdata(iott, tpt, xpb, 0);
EVT evt = aCall.channel().waitEvent(); // Wait for play to complete
System.out.println("Got " + evt);
String dig = d4dev.getdig(tpt);
System.out.println("Got "+ dig);
aCall.clear();
} catch (Exception e) {
System.out.println("Error in handling call: " + e);
aCall.clear();
}
}
public static void main(String argv[]) {
// instantiate our class
String s;
int nv = 0;
System.out.println("Starting...");
if (argv.length > 0)
try {
Dialogic.debug = Integer.parseInt(argv[0]);
System.out.println("Debugging with " + Dialogic.debug);
} catch (NumberFormatException nfe) {}
try {
nv = Dialogic.sr_getboardcnt("Voice");
System.out.println("Do we have " + nv + " boards ?");
Channel c1 = new AnalogChannel("dxxxB1C1" , "one");
((AnalogChannel)c1).setCallerIdEnabled(false);
System.out.print("Waiting..");
waitOk(c1);
System.out.println(".");
System.out.print("Setting PCA");
((AnalogChannel)c1).setPerfectCall(true);
System.out.println(".");
System.out.print("Setting caller id");
((AnalogChannel)c1).setCallerIdEnabled(false);
System.out.println(".");
Channel c2 = new AnalogChannel("dxxxB1C3" , "two");
System.out.print("Setting caller id");
((AnalogChannel)c2).setCallerIdEnabled(false);
System.out.println(".");
//Channel c1 = new GCChannel(":N_dtiB1T1:P_ar_r2_io:V_dxxxB1C1");
//Channel c1 = new GCChannel(":N_dtiB1T1:P_isdn");
//System.out.println("Got a GC channel");
//Channel c2 = new GCChannel(":N_dtiB1T2:P_isdn");
//Channel c1 = new R2CASChannel("dtiB1T1" , "dxxxB1C1"); ((R2CASChannel)c1).setDnisLength(4);
Call.setDialout(c1);
c1.setCallHandler(new Test());
//Channel c2 = new R2CASChannel("dtiB1T2" , "dxxxB1C2"); ((R2CASChannel)c2).setDnisLength(4);
Call.setDialout(c2);
c2.setCallHandler(new Test());
System.out.print("Waiting..");
waitOk(c1);
System.out.println(".");
Call call;
if(false) {
try {
System.out.print("Calling 11...");
call = new Call("11");
} catch (BusyException ce) {
// Busy
System.out.println("Got busy");
return;
} catch (ChannelException ce) {
// Bad call
System.out.println("Got bad call");
return;
} catch (RuntimeException rte) {
// Overrev ? i.e. No more channels to dial...
System.out.println("Got RTE");
return;
}
Test t = new Test();
t.handleCall(call);
}
} catch (Exception e) {
System.out.println("Exception.");
e.printStackTrace();
}
}
private static void waitOk(Channel c) {
int waited = 0;
while(c.getState() == Channel.OOS)
{
try {
Thread.currentThread().sleep(50);
} catch (InterruptedException ie) {}
waited += 50;
if(waited >= 2000)
{
System.out.println("timed out opening line" + c + "!");
System.exit(1);
}
}
}
}