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

📄 abstractmodem.java

📁 jtapi for telephone
💻 JAVA
字号:
package net.sourceforge.gjtapi.raw.modem;
// NAME
//      $RCSfile: AbstractModem.java,v $
// DESCRIPTION
//      [given below in javadoc format]
// DELTA
//      $Revision: 1.1 $
// CREATED
//      $Date: 2003/01/16 10:48:49 $
// COPYRIGHT
//      Westhawk Ltd
// TO DO
//

import java.io.IOException;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;

import net.sourceforge.gjtapi.CallId;

/**
 * An abstract implementation of Modem. This should be extended to support
 * specific modems.
 * 
 * @author <a href="mailto:ray@westhawk.co.uk">Ray Tran</a>
 * @version $Revision: 1.1 $ $Date: 2003/01/16 10:48:49 $
 */
public abstract class AbstractModem implements Modem{
    private static final String     version_id =
        "@(#)$Id: AbstractModem.java,v 1.1 2003/01/16 10:48:49 raytran Exp $ Copyright Westhawk Ltd";

    protected int state;
    protected ModemIO io;
    protected ModemListener listener;

    private CallId ringId;
    private Timer watchdog;

    public AbstractModem(ModemListener prov) {
        state = INVALID;
        listener = prov;
    }

    public boolean initialize(String portname){
        //Try to open a port to the modem
        io = new ModemIO(portname, this);
        
        watchdog = new Timer(5500, new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                ringingStopped();
            }
        });
        watchdog.setRepeats(false);


        return (io != null);
    }

    public void shutdown() {
        state = INVALID;
        try {
            io.close();
            //disconnects provider..
            System.out.println("Disconnected Provider");
        }
        catch (IOException ex) {
            System.err.println("IOException in Modem.shutdown()");
        }
    }
    
    /**
     * Incomplete implementation which just does enough to allow ringing() &
     * ringingStopped() to work correctly. Subclasses must call this method
     * in their answer(CallId) implementation.
     * 
     * @param id - the CallId of the call to answer.
     */
    public void answer(CallId id){
        ringId = null;
    }

    public int getState(){
        return state;
    }
    
    /**
     * The phone line connected to the modem is ringing
     */
    public void ringing(){
        watchdog.restart();
        if (state == IDLE){
            state = RINGING;
            ringId = listener.modemRinging();
        }
    }
    
    /**
     * The phone line connected to the modem has stopped ringing.
     * n.b. Ringing may have stopped because the call has been answered or
     * the caller has hung up.
     */
    private void ringingStopped(){
        //Only do something if the caller has hung up
        if (state == RINGING){
            state = IDLE;
            if (ringId != null){
                listener.ringingStopped(ringId);
            }
            //We don't need a ref to the ringId any more
            ringId = null;
        }
    }
}

⌨️ 快捷键说明

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