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

📄 tapi3provider.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
	Copyright (c) 2005 Serban Iordache 
	
	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.
*/
package net.sourceforge.gjtapi.raw.tapi3;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import javax.telephony.Event;
import javax.telephony.InvalidArgumentException;
import javax.telephony.InvalidPartyException;
import javax.telephony.MethodNotSupportedException;
import javax.telephony.PrivilegeViolationException;
import javax.telephony.ProviderUnavailableException;
import javax.telephony.ResourceUnavailableException;
import javax.telephony.TerminalConnection;
import javax.telephony.media.MediaResourceException;
import javax.telephony.media.MediaRuntimeException;
import javax.telephony.media.RTC;
import javax.telephony.media.SignalConstants;
import javax.telephony.media.Symbol;

import net.sourceforge.gjtapi.CallId;
import net.sourceforge.gjtapi.RawSigDetectEvent;
import net.sourceforge.gjtapi.RawStateException;
import net.sourceforge.gjtapi.TelephonyListener;
import net.sourceforge.gjtapi.TermData;
import net.sourceforge.gjtapi.capabilities.Capabilities;
import net.sourceforge.gjtapi.raw.CCTpi;
import net.sourceforge.gjtapi.raw.MediaTpi;
import net.sourceforge.gjtapi.raw.PrivateDataTpi;
import net.sourceforge.gjtapi.raw.tapi3.logging.ConsoleLogger;
import net.sourceforge.gjtapi.raw.tapi3.logging.Logger;
import net.sourceforge.gjtapi.raw.tapi3.logging.PrintStreamLogger;

/**
 * An implementation of a Jtapi provider which uses Microsoft TAPI 3.0
 * @author Serban Iordache
 */
public class Tapi3Provider implements CCTpi, MediaTpi, PrivateDataTpi {
    private static Logger logger = new ConsoleLogger(); // new NullLogger();

    /**
     * Method identifier for <i>addressPrivateData</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_ADDRESS_PRIVATE_DATA = 1;
    /**
     * Method identifier for <i>callActive</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_CALL_ACTIVE = 2;
    /**
     * Method identifier for <i>callInvalid</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_CALL_INVALID = 3;
    /**
     * Method identifier for <i>callPrivateData</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_CALL_PRIVATE_DATA = 4;
    /**
     * Method identifier for <i>connectionAlerting</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_CONNECTION_ALERTING = 5;
    /**
     * Method identifier for <i>connectionConnected</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_CONNECTION_CONNECTED = 6;
    /**
     * Method identifier for <i>connectionDisconnected</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_CONNECTION_DISCONNECTED = 7;
    /**
     * Method identifier for <i>connectionFailed</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_CONNECTION_FAILED = 8;
    /**
     * Method identifier for <i>connectionInProgress</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_CONNECTION_IN_PROGRESS = 9;
    /**
     * Method identifier for <i>providerPrivateData</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_PROVIDER_PRIVATE_DATA = 10;
    /**
     * Method identifier for <i>terminalConnectionCreated</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_TERMINAL_CONNECTION_CREATED = 11;
    /**
     * Method identifier for <i>terminalConnectionDropped</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_TERMINAL_CONNECTION_DROPPED = 12;
    /**
     * Method identifier for <i>terminalConnectionHeld</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_TERMINAL_CONNECTION_HELD = 13;
    /**
     * Method identifier for <i>terminalConnectionRinging</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_TERMINAL_CONNECTION_RINGING = 14;
    /**
     * Method identifier for <i>terminalConnectionTalking</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_TERMINAL_CONNECTION_TALKING = 15;
    /**
     * Method identifier for <i>terminalPrivateData</i>; used as methodID parameter for the {@link #callback} method.  
     */
    public static final int METHOD_TERMINAL_PRIVATE_DATA = 16;

    /**
     * Array of friendly names for the <i>METHOD_XXX</i> values
     */
    private static final String[] METHOD_NAMES = {
            "METHOD_NONE",
            "METHOD_ADDRESS_PRIVATE_DATA",
            "METHOD_CALL_ACTIVE",
            "METHOD_CALL_INVALID",
            "METHOD_CALL_PRIVATE_DATA",
            "METHOD_CONNECTION_ALERTING",
            "METHOD_CONNECTION_CONNECTED",
            "METHOD_CONNECTION_DISCONNECTED",
            "METHOD_CONNECTION_FAILED",
            "METHOD_CONNECTION_IN_PROGRESS",
            "METHOD_PROVIDER_PRIVATE_DATA",
            "METHOD_TERMINAL_CONNECTION_CREATED",
            "METHOD_TERMINAL_CONNECTION_DROPPED",
            "METHOD_TERMINAL_CONNECTION_HELD",
            "METHODTERMINAL_CONNECTION_RINGING",
            "METHOD_TERMINAL_CONNECTION_TALKING",
            "METHOD_TERMINAL_PRIVATE_DATA",
    };

    /**
     * Cause identifier for <i>CAUSE_UNKNOWN</i>; used as jniCause parameter for the {@link #callback} method.  
     */
    public static final int JNI_CAUSE_UNKNOWN = -1;
    /**
     * Cause identifier for <i>CAUSE_NORMAL</i>; used as jniCause parameter for the {@link #callback} method.  
     */
    public static final int JNI_CAUSE_NORMAL = 1;
    /**
     * Cause identifier for <i>CAUSE_NEW_CALL</i>; used as jniCause parameter for the {@link #callback} method.  
     */
    public static final int JNI_CAUSE_NEW_CALL = 2;
    /**
     * Cause identifier for <i>CAUSE_SNAPSHOT</i>; used as jniCause parameter for the {@link #callback} method.  
     */
    public static final int JNI_CAUSE_SNAPSHOT = 3;
    /**
     * Cause identifier for <i>CAUSE_DEST_NOT_OBTAINABLE</i>; used as jniCause parameter for the {@link #callback} method.  
     */
    public static final int JNI_CAUSE_DEST_NOT_OBTAINABLE = 4;

    /**
     * The concrete Tapi3Native implementation
     */
    private static Tapi3Native tapi3Native;
    
    /**
     * The array of addresses
     */
    private String[] addresses = new String[0];
    /**
     * The array of terminals
     */
    private TermData[] terminals = new TermData[0];
    /**
     * The list of TelephonyListeners 
     */
    private ArrayList listenerList = new ArrayList();

    /**
     * Return the logger
     * @return The logger
     */
    public static Logger getLogger() {
        return logger;
    }

    /**
     * Configure the logger
     * @param props The name value properties map used to configure the logger 
     */
    private static void configureLogger(Map props) {
        String tapi3LogOut = (String)props.get("tapi3.log.out");
        if(tapi3LogOut != null) {
            if("console".equals(tapi3LogOut)) {
                logger = new PrintStreamLogger(System.err);
            } else {
                try {
                    PrintStream logStream = new PrintStream(new FileOutputStream(tapi3LogOut));
                    logger = new PrintStreamLogger(logStream);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                    logger = new PrintStreamLogger(System.err);
                }
            }
        }
        String tapi3LogClass = (String)props.get("tapi3.log.class");
        if(tapi3LogClass != null) {
            try {
                Class cls = Class.forName(tapi3LogClass);
                logger = (Logger)cls.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
                logger = new PrintStreamLogger(System.err);
            }
        }
    }

    /**
     * Configure a concrete implementation of the {@link Tapi3Native} interface
     * @param props The name value properties map used to configure the {@link Tapi3Native} implementation 
     */
    private static void configureNative(Map props) {
        String tapi3ImplClass = (String)props.get("tapi3.impl.class");
        if(tapi3ImplClass == null) {
            tapi3ImplClass = "net.sourceforge.gjtapi.raw.tapi3.Tapi3NativeImpl";
        }

⌨️ 快捷键说明

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