gcline.java

来自「著名的dialogic电话语音卡的java驱动程序,已经验证可用。」· Java 代码 · 共 133 行

JAVA
133
字号
// GCLine: Dialogic Global Call line devices
// $Id: GCLine.java,v 1.3 2003/11/13 11:44:16 cgm8 Exp $
/* 
 * Copyright (c) 1999 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 GCLine extends Device
{

    // Class variables

    // Instance variables
    int ts;
    int dtidev;
    boolean anapi = false; /* The beauty of GC: functionality may depend on lower layer */

    /** Open a dt device */
    public GCLine(Channel ch, String newName)
    {
        super(ch, newName);
        // dtiBnTm
        this.name = newName;
        Runnable r = new Runnable() {
          public void run() {
            device = Dialogic.gc_Open(name);
            register();
          }
        };

        Channel.atomicAction(r);

		try {
	        dtidev = Dialogic.gc_GetNetworkH(device);
    	    ts = Dialogic.dt_getxmitslot(dtidev);
    	} catch(RuntimeException rte) {
    		// No network ?
    		dtidev = Dialogic.gc_GetVoiceH(device);
    		ts = Dialogic.dx_getxmitslot(dtidev);
    		anapi = true;
    	}
    }

    public void finalize() throws Throwable
    {
        close();
        super.finalize();
    }

    public void close()
    {
        if (device != 0) {
            Dialogic.gc_Close(device);
            super.close();
            device = 0;     // just in case
        }
    }

    public Voice getVoice(Channel channel) {
   		int vh = Dialogic.gc_GetVoiceH(device);
      	return new Voice(channel, vh);
    }

    public int getTs() {
        return ts;
    }
    
    public boolean isAnalog() {
    	return anapi;
    }

    public void listen(Device source) {
        if (source != null) {
        	if (anapi)
				Dialogic.ag_listen(dtidev, source.getTs());
        	else
    	        Dialogic.dt_listen(dtidev, source.getTs());
        } else {
			if (anapi)
				Dialogic.ag_unlisten(dtidev);
			else
	            Dialogic.dt_unlisten(dtidev);
		}
    }

    public void listen(Channel ch, Resource res) {
        int ts = res.getTs(ch);
        if (ts >= 0) {
			if (anapi)
				Dialogic.ag_listen(dtidev, ts);
			else
				Dialogic.dt_listen(dtidev, ts);
		} else {
			if (anapi)
				Dialogic.ag_unlisten(dtidev);
			else
				Dialogic.dt_unlisten(dtidev);
		}
    }

    public void waitCall() {
        Dialogic.gc_WaitCall(device, 0, Dialogic.EV_ASYNC);
    }
    
    public void reset() {
    	Dialogic.gc_ResetLineDev(device, Dialogic.EV_ASYNC);
   	}

    public int dial(String num, int timeout){
        return Dialogic.gc_MakeCall(device, num, timeout, Dialogic.EV_ASYNC);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?