www.pudn.com > d4j.zip > ISDNLine.java


// ISDNLine: Dialogic ISDN line devices 
// $Id: ISDNLine.java,v 1.4 2003/11/13 11:46:17 cgm8 Exp $ 
/*  
 * Copyright (c) 1999-2003 Carlos G Mendioroz. 
 * 
 *  This file is part of D4J. 
 * 
 *  D4J is free software; you can redistribute it and/or 
 *  modify it under the terms of the GNU Lesser General Public 
 *  License as published by the Free Software Foundation; either 
 *  version 2 of the License, or (at your option) any later version. 
 *   
 *  D4J is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 *  Lesser General Public License for more details. 
 *   
 *  You should have received a copy of the GNU Lesser General Public 
 *  License along with this library; if not, write to the 
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
 *  Boston, MA  02111-1307, USA. 
 * 
 * Report problems and direct all questions to: 
 * 
 *	tron@acm.org 
 */ 
package local.dialogic; 
 
public class ISDNLine extends Device 
{ 
 
    // Class variables 
 
    // Instance variables 
    int ts; 
 
    /** Open a dt device */ 
    public ISDNLine(Channel ch, String devname) 
    { 
        super(ch, devname); 
        // dtiBnTm 
        this.name = devname; 
         
        Runnable r = new Runnable() { 
          public void run() { 
            device = Dialogic.cc_Open(name, 0); 
            register(); 
          } 
        }; 
         
        Channel.atomicAction(r); 
         
        EVT.setISDN(device); // Let EVT know this is an ISDN device 
        ts = Dialogic.dt_getxmitslot(device); 
    } 
 
    public void finalize() throws Throwable 
    { 
        close(); 
        super.finalize(); 
    } 
 
    public void close() 
    { 
        if (device != 0) { 
            Dialogic.cc_Close(device); 
            super.close(); 
            EVT.resetISDN(device); 
            device = 0;     // just in case 
        } 
    } 
 
    public int getTs() { 
        return ts; 
    } 
 
    public void listen(Device source) { 
        if (source != null) 
            Dialogic.dt_listen(device, source.getTs()); 
        else 
            Dialogic.dt_unlisten(device); 
    } 
 
    public void listen(Channel ch, Resource res) { 
        int ts = res.getTs(ch); 
        if (ts < 0) 
            Dialogic.dt_unlisten(device); 
        else 
            Dialogic.dt_listen(device, ts); 
    } 
 
    public void waitCall() { 
        Dialogic.cc_WaitCall(device, null, 0, Dialogic.EV_ASYNC); 
    } 
 
    /**  
     * Restart: bring firmware to state 0, any call to null state 
     */ 
    public void restart() { 
        if ((Dialogic.debug & Dialogic.DEBUG_ISDN) != 0) 
            System.out.println(new java.util.Date().toString().substring(11,19) +": Restart " + this); 
        Dialogic.cc_Restart(device, Dialogic.EV_ASYNC); 
    } 
     
    public long dial(String num, int timeout){ 
        if ((Dialogic.debug & Dialogic.DEBUG_ISDN) != 0) 
            System.out.println(new java.util.Date().toString().substring(11,19) +": " + this + " calling " + num); 
        return Dialogic.cc_MakeCall(device, num, null, timeout, Dialogic.EV_ASYNC); 
    } 
}