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

📄 modemprovider.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public String[] getAddresses(String terminal) throws InvalidArgumentException {
        //We only support a single terminal which maps to all addresses
        if (terminal.equals((String) provProps.get(SERIAL)) == false){
            System.err.println("Terminal " + terminal + " is unknown, throwing exception");
            throw new InvalidArgumentException("Terminal " + terminal + "is unknown");
        }

        String[] result = null;
        try {
            result = getAddresses();
        }
        catch (ResourceUnavailableException ex) {
            //This shouldn't happen!
            throw new InvalidArgumentException();
        }
        return result;
    }

    public TermData[] getTerminals() throws ResourceUnavailableException {
        if (terminal != null){
            return new TermData[]{terminal};
        }else{
            int reason = ResourceUnavailableException.ORIGINATOR_UNAVAILABLE;
            throw new ResourceUnavailableException(reason);
        }
    }

    public TermData[] getTerminals(String address) throws InvalidArgumentException {
        //We only support a single terminal which maps to all addresses
        if (addresses.contains(address) == false){
            System.err.println("Address " + address + " is unknown, throwing exception");
            throw new InvalidArgumentException("Address " + address + " is unknown");
        }

        TermData[] tda = null;
        try {
            tda = getTerminals();
        }
        catch (ResourceUnavailableException ex) {
            //This shouldn't happen!
            throw new InvalidArgumentException();
        }

        return tda;
    }

    public Properties getCapabilities() {
        return provProps;
    }

    //Doc is a bit unclear on whether this parameter is an address or a terminal
    //we seem to get passed a terminal so for now I have disabled checking!
    public CallId reserveCallId(String address) throws InvalidArgumentException {
        //if (addresses.contains(address)){
            return new ModemCallId();
        //}else{
        //    throw new InvalidArgumentException("Invalid address");
        //}
    }

    public void releaseCallId(CallId id) {
        //Nothing to do
    }

    public CallId createCall(CallId id, String address, String term, String dest)
        throws ResourceUnavailableException,
        PrivilegeViolationException,
        InvalidPartyException,
        InvalidArgumentException,
        RawStateException,
        MethodNotSupportedException
    {
        if (id instanceof ModemCallId == false){
            throw new InvalidArgumentException("createCall requires a ModemCallId");
        }else if (addresses.contains(address) == false){
            throw new InvalidArgumentException("Invalid address");
        }else if (terminal.terminal.equals(term) == false){
            throw new InvalidArgumentException("Invalid terminal");
        }else if (modem == null){
            throw new RawStateException(id,
                address,
                term,
                RawStateException.TERMINAL_OBJECT,
                Call.INVALID,
                "Modem is null"
            );
        }else if (modem.getState() != Modem.IDLE){
            throw new RawStateException(id,
                address,
                term,
                RawStateException.TERMINAL_OBJECT,
                Call.INVALID,
                "Modem is not idle"
            );
        }

        //Passed all tests so get the modem to make the call
        if (modem.call(id, dest) == false){
            id = null;
        }

        return id;
    }

    public void answerCall(CallId id, String address, String term)
        throws PrivilegeViolationException,
        ResourceUnavailableException,
        MethodNotSupportedException,
        RawStateException
    {
        if (id instanceof ModemCallId == false){
            throw new MethodNotSupportedException("createCall requires a ModemCallId");
        }else if (addresses.contains(address) == false){
            throw new MethodNotSupportedException("Invalid address");
        }else if (terminal.terminal.equals(term) == false){
            throw new MethodNotSupportedException("Invalid terminal");
        }else if (modem == null){
            throw new RawStateException(id,
                address,
                term,
                RawStateException.TERMINAL_OBJECT,
                Call.INVALID,
                "Modem is null"
            );
        }else if (modem.getState() != Modem.RINGING){
            throw new RawStateException(id,
               address,
                term,
                RawStateException.TERMINAL_OBJECT,
                Call.INVALID,
                "Modem is not ringing"
            );
        }

        //Passed all test so get the modem to answer the call
        modem.answer(id);
    }
    
    public void release(String address, CallId call)    
            throws PrivilegeViolationException, ResourceUnavailableException,
                   MethodNotSupportedException, RawStateException
    {
        if ((modem != null) &&
            (modem.getState() == Modem.BUSY) &&
            (addresses.contains(address)))
        {
            modem.drop(call);
        }
    }

    public void shutdown() {
        if (modem != null){
            modem.shutdown();
            modem = null;
        }
    }

    //MediaTpi implementation
    public boolean allocateMedia(String terminal, int type, Dictionary resourceArgs) {
        return true;
    }
    
    public boolean freeMedia(String terminal, int type) {
        return true;
    }
    
    public boolean isMediaTerminal(String terminal) {
        return true;
    }
    
    public void play(String terminal, String[] streamIds, int offset,RTC[] rtcs,
                     Dictionary optArgs) throws MediaResourceException {
        for (int i=0, len=streamIds.length; i<len; i++){
            try{
                URL url = new URL(streamIds[i]);
                InputStream is = url.openStream();
                modem.play(is);
                is.close();
            }catch (Exception ex){
                System.err.println("Exception in play()");
                ex.printStackTrace();
            }
        }
    }
    
    public void record(String terminal, String streamId, RTC[] rtcs,
                       Dictionary optArgs) throws MediaResourceException {
        try{
            URI uri = new URI(streamId);
            File file = new File(uri);
            FileOutputStream fos = new FileOutputStream(file, false);
            modem.record(fos);
            fos.close();
        }catch (Exception ex){
            System.err.println("Exception in record()");
            ex.printStackTrace();
        }
    }
    
    public RawSigDetectEvent retrieveSignals(String terminal, int num,
            Symbol[] patterns, RTC[] rtcs, Dictionary optArgs)
            throws MediaResourceException {
        String sigs = modem.reportDTMF(num);
        return RawSigDetectEvent.maxDetected(terminal, SymbolConvertor.convert(sigs));
    }
    
    public void sendSignals(String terminal, Symbol[] syms, RTC[] rtcs,
                            Dictionary optArgs) throws MediaResourceException {
        String tones = SymbolConvertor.convert(syms);
        modem.sendDTMF(tones);
    }
    
    public void stop(String terminal) {

    }
    
    public void triggerRTC(String terminal, Symbol action) {

    }
	/**
	 * Tells GJTAPI that we are starting to dial out
	 * @see net.sourceforge.gjtapi.raw.modem.ModemListener#modemDialing(net.sourceforge.gjtapi.CallId)
	 */
	public void modemDialing(CallId id, String destinationAddress) {
		if (listener != null){
			listener.connectionAlerting(id, destinationAddress, ConnectionEvent.CAUSE_NORMAL);
		}
	}
	
	public void modemConnected(CallId id, String remoteLeg) {
		if (listener != null){
			listener.connectionConnected(id, remoteLeg, ConnectionEvent.CAUSE_NORMAL);
		}
	}

	/**
	 * Note that an alerting connection failed (i.e. was busy)
	 * @see net.sourceforge.gjtapi.raw.modem.ModemListener#modemFailed(net.sourceforge.gjtapi.CallId, java.lang.String)
	 */
	public void modemFailed(CallId id, String remoteLeg) {
		if (listener != null){
			listener.connectionFailed(id, remoteLeg, ConnectionEvent.CAUSE_DEST_NOT_OBTAINABLE);
		}
	}

}

⌨️ 快捷键说明

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