⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gcprovider.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package net.sourceforge.gjtapi.raw.dialogic;
import java.util.*;
import net.sourceforge.gjtapi.*;
import javax.telephony.*;
import net.sourceforge.gjtapi.raw.BasicJtapiTpi;
/*
    Copyright (c) 2002 Westhawk Ltd. (www.westhawk.co.uk) 

    All rights reserved. 

    Permission is hereby granted, free of charge, to any person obtaining a 
    copy of this software and associated documentation files (the 
    "Software"), to deal in the Software without restriction, including 
    without limitation the rights to use, copy, modify, merge, publish, 
    distribute, and/or sell copies of the Software, and to permit persons 
    to whom the Software is furnished to do so, provided that the above 
    copyright notice(s) and this permission notice appear in all copies of 
    the Software and that both the above copyright notice(s) and this 
    permission notice appear in supporting documentation. 

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 
    OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
    HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 
    INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 
    FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 
    NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 

    Except as contained in this notice, the name of a copyright holder 
    shall not be used in advertising or otherwise to promote the sale, use 
    or other dealings in this Software without prior written authorization 
    of the copyright holder.
*/
/**
 * GJTAPI Provider for Dialogic GlobalCall 
 * It uses a native library to talk to libgc.
 * Simply translating the events/calls and passing them on.
 * We try to minimize the state that we keep here, since
 * both GC and GJTAPI do this fine, an extra layer would  get in the way.
 * We _depend_ on JDK 1_4 and use dialogic's Signaling mode.
 * There is also code that supports Async polling mode.
 * This was written to run on RedHat 7.2 and Dialogic 5.1
 * and tested on a D/300SCPCI with ctr4 (EuroISDN) on the
 * public network.
 */

public class GCProvider implements BasicJtapiTpi, Runnable {
    
    boolean polling = true;
    boolean done = true;
    int debug_level =0;
    Thread eventThread;
    
    public GCProvider() {
    }
    
    protected String [] addresses;
    protected GCTermData [] terminals;
    protected TelephonyListener nails;
    protected Hashtable calls;
    protected Properties caps;
    
    void debug(int level, String s){
        if (debug_level >= level){
            System.err.println(s);
        }
    }
    
    // GJTAPI methods to fill in
    public String[] getAddresses() throws ResourceUnavailableException {
        return addresses;
    }

    public String[] getAddresses(String terminal) throws InvalidArgumentException {
        return addresses;
    }

    public TermData[] getTerminals() throws ResourceUnavailableException {
        return terminals;
    }
    
    public TermData[] getTerminals(String address) throws InvalidArgumentException {
        return terminals;
    }
    
    public void release(String address, CallId id) throws PrivilegeViolationException, ResourceUnavailableException, MethodNotSupportedException, RawStateException {
        if ((id == null) || !( id instanceof DCall)){
            throw new RawStateException(id,Call.INVALID);
        }
        DCall dc = (DCall) id;
        try {
            int crn = dc.getCrnInt();
            gc_DropCall(crn,true,false);
        } catch (RuntimeException rx){
            throw new RawStateException(id,Call.INVALID);
        }
    }
    
    public void addListener(TelephonyListener ro) {
        nails = ro;
    }
    
    public void answerCall(CallId call, String address, String terminal) throws PrivilegeViolationException, ResourceUnavailableException, MethodNotSupportedException, RawStateException {
        /* should do something with the other params, but.... */
        try {
            DCall dc = (DCall) call;
            int crno = dc.getCrnInt();
            this.gc_AnswerCall(crno,0,false);
        } catch (RuntimeException rx) {
            RawStateException rsx = new RawStateException(call,Call.INVALID);
            throw rsx;
        }
    }
    
    public CallId createCall(CallId id, String address, String term, String dest) throws ResourceUnavailableException, PrivilegeViolationException, InvalidPartyException, InvalidArgumentException, RawStateException, MethodNotSupportedException {
        GCTermData gct = this.getTerminal(term);
        if ((id == null) || !( id instanceof DCall)){
            throw new InvalidArgumentException("Call must be from this TPI");
        }
        
        DCall dc = (DCall) id;

        if (gct == null) {
            throw new InvalidArgumentException(term+" not found");
        }

        try {
            int ldev = gct.getLinedev();
            int crn = gc_MakeCall(ldev,dest,0,false);
            dc.setCrn(new Integer(crn));
            dc.setLinedev(new Integer(ldev));
            dc.setDestaddr(dest);
            dc.setOrigaddr(address);
            calls.put(dc.getCrn(),dc); // use crn as the key -
        } catch (RuntimeException rx){
            throw new RawStateException(dc,Call.INVALID);
        }
        return dc;// actually it's ignored 
    }
    
    public Properties getCapabilities() {
        return caps; // defaults....
    }
    
    
    public void initialize(Map props) throws ProviderUnavailableException {
        //extract addresses and dev the properties

        try {
            srlibinit(polling);
            done = false;
            if (polling) {
                Thread t = new Thread(this,"gc_events");
                t.setPriority(Thread.MAX_PRIORITY);
                eventThread = t;
                t.start();
            }
        } catch (RuntimeException x) {
            throw new ProviderUnavailableException(x.getMessage());
        } 
        //extract addresses and dev from the properties

        parseProps(props);
        caps = new Properties();
        calls = new Hashtable();
        try {
            openAll();
        } catch (RuntimeException x) {
            closeAll();
            gc_stop();
            throw new ProviderUnavailableException(x.getMessage());
        }
    }
    
    
    public void releaseCallId(CallId id) {

    }
    
    public void removeListener(TelephonyListener ro) {
        nails = null;
    }
    
    public CallId reserveCallId(String address) throws InvalidArgumentException {
        DCall rcall = new DCall();
        rcall.setOrigaddr(address);
        return rcall;
    }
    
    public void shutdown() {
        RuntimeException x = null;
        try {
            closeAll();
        } catch (RuntimeException rx) { 
            x = rx;
        }
        gc_stop();
        if (x != null) {
            throw (x);
        }
        done = true;
        if (eventThread != null){
            try {
                eventThread.join(5000);
            } catch (Exception y) {
                y.printStackTrace();
            }
        }
    }
    
 
  // and our 'event' methods - one per GC event type
  
  void alerting(int linedev){
    debug(1,"alerting event on line "+linedev);
    /**@todo: event to deal with */
    /*DCall dc = (DCall) calls.get(new Integer(crn));
    if (dc != null){
        if (dc.getLinedev() != null){
            String te = getTermName(dc.getLinedev().intValue());
            if(nails!=null){
                nails.terminalConnectionRinging(dc, dc.getOrigaddr(),te,CAUSE_NEW_CALL);
            }
        }
    }
    */    
  }
  
  void unblocked(int linedev){
    debug(1,"unblocked event on line "+linedev);    

  }
  
  void blocked(int linedev){
    debug(1,"blocked event on line "+linedev);    
  }
  
  void opened(int linedev){
    debug(1,"opened event on line "+linedev);  
    gc_WaitCall(linedev,0,false);   
  }
  
  void openFailed(int linedev){
    debug(1,"openFailed event on line "+linedev);    
  }
  
  void miscEvent(int linedev, int eventtype){
    debug(1,"got unclaimed event "+eventtype+" on line "+linedev);
  }
  
  /**
   * We handle internally - call Accept immediately
   */
  void offered(int crn){
    debug(1,"offered event on line "+crn);
    gc_AcceptCall(crn,0,false);
  }
  
  void proceeding(int crn){
    debug(1,"proceeding event on call "+crn);
    DCall dc = (DCall) calls.get(new Integer(crn));

⌨️ 快捷键说明

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