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

📄 conference.java

📁 著名的dialogic电话语音卡的java驱动程序,已经验证可用。
💻 JAVA
字号:
// Conference: Manage conferences
// $Id: Conference.java,v 1.4 2003/07/24 20:24:44 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;

import java.util.*;

public abstract class Conference implements Resource, ResourceServer
{

    // Handy constants
    public static final int NORMAL = Dialogic.MSPA_NULL;
    public static final int MUTE = Dialogic.MSPA_RO;
    public static final int TARIFF = Dialogic.MSPA_TARIFF;
    public static final int PUPIL = Dialogic.MSPA_PUPIL;
    public static final int COACH = Dialogic.MSPA_COACH;
    
    public static final int BEEP = Dialogic.MSCA_ND|Dialogic.MSCA_ND;
    public static final int BEEPALL = Dialogic.MSCA_ND;
    public static final int NOBEEP = Dialogic.MSCA_NULL;
    
    public static final int ALLDIGITS = Dialogic.CBMM_ALL;
    public static final int NODIGITS = 0;
    
    // Class variables
    static Hashtable boards;
    static Vector dsps;
    static int openDsps = 0;
    
    static {
        boards = new Hashtable();
        dsps = new Vector(1);
    }
    
    // Instance variables
    Hashtable members; // Channel -> CDT
    Hashtable active; // Channel -> CDT for connected channels
    int dsp;
    int conf;
    int attr;
    int digits; // Only used by DCB's confs

    public Conference(int attributes, int digitMask) {
        attr = attributes;
        digits = digitMask;
        members = new Hashtable();
        active = new Hashtable();
        if (openDsps == 0) 
            throw new RuntimeException("No DSPs available!");
        // We support only one dsp for now...
        dsp = ((Integer)dsps.elementAt(0)).intValue();
        conf = -1;
    }
    
    public void add(Channel aChannel) {
        add(aChannel, NORMAL);
    }
    
    public synchronized void add(Channel aChannel, int attributes) {
        CDT cdt = new CDT(aChannel, attributes);
        if ((Dialogic.debug & Dialogic.DEBUG_CONFERENCE) != 0)
            System.out.println("Adding " + cdt.toString() + " to " + this.toString());
        _add(cdt);
        members.put(aChannel, cdt);
        EVT evt = new EVT();
        evt.type = EVT.DCBEV_NEW;
        evt.conf = conf;
        evt.line = cdt.chan_num;
        for (Enumeration e = members.keys() ; e.hasMoreElements() ;) {
            Channel member = (Channel)e.nextElement();
            if (member == aChannel)
                continue;
            member.newEvent(evt);
        }
        connect(aChannel);
        aChannel.attach(this);
    }
    
    // Specialized add fn (called before actual add)
    abstract void _add(CDT cdt);
    
    public int getTs(Channel aChannel) {
        CDT cdt = (CDT)members.get(aChannel);
        if (cdt == null)
            return 0;
        return cdt.chan_lts;
    }

    public synchronized void close()
    {
        if (conf < 0)
            return;
        EVT evt = new EVT();
        evt.type = EVT.DCBEV_CLOSED;
        conf = -1;
        for (Enumeration e = members.elements() ; e.hasMoreElements() ;) {
            CDT cdt = (CDT)e.nextElement();
            disconnect(cdt.channel);
            cdt.channel.dettach(this);
            cdt.channel.newEvent(evt);
        }
        members.clear();
        active.clear();
    }
    
    public boolean service(EVT evt) {
        return false;
    }
    
    public synchronized void free(Channel ch) {
        CDT cdt = (CDT)members.get(ch);
        if (cdt == null)
            return;
        if ((Dialogic.debug & Dialogic.DEBUG_CONFERENCE) != 0)
            System.out.println("Freeing " + cdt.toString() + " from " + this.toString());
        _free(cdt);
        disconnect(cdt.channel);
        members.remove(ch);
        EVT evt = new EVT();
        evt.type = EVT.DCBEV_GONE;
        evt.conf = conf;
        evt.line = cdt.chan_num;
        for (Enumeration e = members.keys() ; e.hasMoreElements() ;) {
            Channel member = (Channel)e.nextElement();
            member.newEvent(evt);
        }
        ch.dettach(this);
    }
    
    // Specialized free fn (called before actual removal)
    abstract void _free(CDT cdt);
    
    public void connect(Channel ch) {
        CDT cdt = (CDT)members.get(ch);
        if (cdt == null)
            return;
        if ((Dialogic.debug & Dialogic.DEBUG_CONFERENCE) != 0)
            System.out.println("Connecting " + cdt.toString() + " to " + this.toString());
        cdt.channel.listen(this);
        active.put(ch, cdt);
    }
    
    public void disconnect(Channel ch) {
        CDT cdt = (CDT)members.get(ch);
        if (cdt == null)
            return;
        if (active.get(ch) == null)
            return;
        if ((Dialogic.debug & Dialogic.DEBUG_CONFERENCE) != 0)
            System.out.println("Disconnecting " + cdt.toString() + " from " + this.toString());
        ch.getNetwork().listen(ch.getVoice());
        active.remove(ch);
    }
    
    public int size() {
        return members.size();
    }
    
    public String toString() {
        StringBuffer desc = new StringBuffer();
        if (conf < 0) {
            if (attr == -1)
                return "DCB service";
            desc.append("Unestablished conference");
        } else
            desc.append("Conference " + conf);
        desc.append(" with "+ members.size() + " (" + attr + ")");
        return desc.toString();
    }
}

⌨️ 快捷键说明

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