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

📄 sipprovider.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * Large portions of this software are based upon public domain software
 * https://sip-communicator.dev.java.net/
 *
 *//*
 * SipProvider.java
 *
 * Created on November 18, 2003, 2:18 PM
 */

package net.sourceforge.gjtapi.raw.sipprovider;

import net.sourceforge.gjtapi.raw.sipprovider.sip.SipManager;
import net.sourceforge.gjtapi.raw.sipprovider.common.Console;
import java.util.*;
import java.io.*;
import net.sourceforge.gjtapi.*;
import javax.telephony.*;
/**
 *
 * @author  root
 */
public class SipProvider implements net.sourceforge.gjtapi.raw.MediaTpi
{
    private TelephonyListener listener;
    private List addresses;
    //private TermData terminal;
    private final static String RESOURCE_NAME = "sip.props";
    private Properties properties = System.getProperties();
    protected static Console console = Console.getConsole(SipProvider.class);
    private CallId idd;    
    private Vector sipPhoneVector = new Vector();
    
    /** Add an observer for RawEvents
     *
     * @param ro New event listener
     * @return void
     *
     */
    //constructeur
    public SipProvider()
    {
        
    }
    
    //ajoute un listener TelephonyListener
    public void addListener(TelephonyListener ro)
    {
        console.logEntry();
        if (listener == null)
        {
            listener = ro;
        }else
        {
            System.err.println("Request to add a TelephonyListener to "
            + this.getClass().getName() + ", but one is already registered");
        }
        
    }
    
    /** Answer a call that has appeared at a particular terminal
     *
     * @param call The system identifier for the call
     * @param address The address of the connection that is ringing.
     * @param terminal the terminal to answer the call on.
     * @exception RawStateException A holder for a low-level state problem.
     *
     */
    public void answerCall(CallId call, String address, String terminal) throws PrivilegeViolationException, ResourceUnavailableException, MethodNotSupportedException, RawStateException
    {
        console.logEntry();
    }
    
    
    /** Tell the provider to reserve a call id for future use.  The provider does not have to hang onto it.
     * Creation date: (2000-02-16 14:48:48)
     * @author: Richard Deadman
     * @return The CallId created by the provider.
     * @param term The address that the call will start on.  Used by muxes to isolate the correct provider.
     * @exception InvalidArgumentException If the Address is not in the provider's domain.
     *
     */
    //prepare un jtapi CallId
    public CallId reserveCallId(String address) throws InvalidArgumentException
    {
        SipCallId id = new SipCallId();
        return id ;
    }
    
    /** Make a call.  Not that this follows the JTAPI sematics of an idle call
     * being created synchronusly (two connections).  Events from the raw provider
     * will indicate state transitions.
     *
     * @param id The callId reserved for the call.
     * @param address The logical address to make a call from
     * @param term The physical address for the call, if applicable
     * @param dest The destination address
     * @return A call Id.  This may be used later to track call progress.
     * @exception RawStateException One of the objects is not in the correct state.
     *
     */
    public CallId createCall(CallId id, String address, String term, String dest) throws
    ResourceUnavailableException, PrivilegeViolationException, InvalidPartyException, InvalidArgumentException, RawStateException, MethodNotSupportedException
    
    {
        console.logEntry();
        console.debug("id = " + id);
        
        console.debug("trentative de connection  a " +address);
        //CREATION D'UN CALL (SIP)
        SipPhone mySP = getSipPhoneByAddress(address);
        mySP.createCall(id, address, term,  dest);
        
        return id;
        
    }
    
    /** Get a list of available addresses.
     * This may be null if the Telephony (raw) Provider does not support Addresses!
     * If the Address set it too large, this will throw a ResourceUnavailableException
     * Creation date: (2000-02-11 12:29:00)
     * @author: Richard Deadman
     * @return An array of address names
     * @exception ResourceUnavailableException if the set it too large to be returned dynamically.
     *
     */
    public String[] getAddresses() throws ResourceUnavailableException
    {
        console.logEntry();
        String [] ret = new String [sipPhoneVector.size()];
        Enumeration enum = sipPhoneVector.elements();
        int i=0;
        while (enum.hasMoreElements())
        {
            SipPhone sp = (SipPhone)enum.nextElement();
            SipManager sm = sp.getSipManager();
            ret[i]=sp.getAddress();
            i++;
        }
        return ret;
    }
    
    /** Get all the addresses associated with a terminal.
     * Creation date: (2000-06-02 12:30:54)
     * @author: Richard Deadman
     * @return An array of address numbers.
     * @param terminal The terminal name we want address numbers for.
     * @throws InvalidArgumentException indicating that the terminal is unknown.
     *
     */
    public String[] getAddresses(String terminal) throws InvalidArgumentException
    {
        console.logEntry();
        Enumeration enum = sipPhoneVector.elements();
        int size = 0;
        while (enum.hasMoreElements())
        {
            SipPhone sp = (SipPhone)enum.nextElement();
            SipManager sm = sp.getSipManager();
            if (sm.getAddress().equals(terminal));
            size++;
            
        }
        String [] ret = new String [size];
        enum = sipPhoneVector.elements();
        int i=0;
        while (enum.hasMoreElements())
        {
            SipPhone sp = (SipPhone)enum.nextElement();
            SipManager sm = sp.getSipManager();
            if (sm.getAddress().equals(terminal));
            ret[i] = sp.getAddress();
            i++;
        }
        return ret;
    }
    
    /** Ask the raw provider to update the capabilities offered by the provider
     * This is expected to return a map of capability names to strings.  If the string starts with
     * 't' or 'T', the capability is turned on, otherwise it is turned off.  Alternatively Boolean values
     * can be used.  If the value is not found for a key, the default value is used.
     * <P>To use this feature, the RawProvider needs to copy the GenericCapabilities.props file and change any
     * properties that are supported differently.  The the RawProvider could load the properties file into
     * a Properties object and return it.  If the default value is supported, then the corresponding line
     * may be omitted from the file.
     * Creation date: (2000-03-14 14:48:36)
     * @author: Richard Deadman
     * @return A properties file with name to value pairs for the basic raw provider functions.
     *
     */
    public java.util.Properties getCapabilities()
    {
        console.logEntry();
        return null;
    }
    
    /** Get a list of available terminals.
     * This may be null if the Telephony (raw) Provider does not support Terminals.
     * If the Terminal set it too large, this will throw a ResourceUnavailableException
     * <P>Since we went to lazy connecting between Addresses and Terminals, this is called so
     * we don't have to follow all Address->Terminal associations to get the full set of Terminals.
     * Creation date: (2000-02-11 12:29:00)
     * @author: Richard Deadman
     * @return An array of terminal names, media type containers.
     * @exception ResourceUnavailableException if the set it too large to be returned dynamically.
     *
     */
    public TermData[] getTerminals() throws ResourceUnavailableException
    {
        console.logEntry();
        TermData[] ret = new TermData [sipPhoneVector.size()];
        Enumeration enum = sipPhoneVector.elements();
        int i=0;
        while (enum.hasMoreElements())
        {
            SipPhone sp = (SipPhone)enum.nextElement();
            SipManager sm = sp.getSipManager();
            ret[i] =  new TermData(sm.getAddress(), true);
            ret[i] =  new TermData(sp.getAddress(), true);
            i++;
        }
        return ret;
        
    }
    
    /** Get all the terminals associated with an address.
     * Creation date: (2000-02-11 12:30:54)
     * @author: Richard Deadman
     * @return An array of terminal name, media type containers.
     * @param address The address number we want terminal names for.
     * @throws InvalidArgumentException indicating that the address is unknown.
     *
     */
    public TermData[] getTerminals(String address) throws InvalidArgumentException
    {
        console.logEntry();
        Enumeration enum = sipPhoneVector.elements();
        int size = 0;
        while (enum.hasMoreElements())
        {
            SipPhone sp = (SipPhone)enum.nextElement();
            SipManager sm = sp.getSipManager();
            if (sm.getAddress().equals(address));
            size++;
            
        }
        TermData[] ret = new TermData [size];

⌨️ 快捷键说明

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