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

📄 tapi3provider.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            }
        }
        return new TermData[0];
    }

    /* (non-Javadoc)
     * @see net.sourceforge.gjtapi.raw.CoreTpi#reserveCallId(java.lang.String)
     */
    public CallId reserveCallId(String address) throws InvalidArgumentException {
        logger.debug("reserveCallId(" + address + ")");
        int id = tapi3Native.tapi3ReserveCallId(address);
        return (id < 0) ? null : new Tapi3CallID(id);
    }

    /* (non-Javadoc)
     * @see net.sourceforge.gjtapi.raw.CoreTpi#releaseCallId(net.sourceforge.gjtapi.CallId)
     */
    public void releaseCallId(CallId id) {
        logger.debug("releaseCallId(" + id + ")");
        if(id instanceof Tapi3CallID) {
            Tapi3CallID tapi3CallID = (Tapi3CallID)id;
            int retCode = tapi3Native.tapi3ReleaseCall(tapi3CallID.getCallID());
            logger.debug("tapi3ReleaseCall() returned: " + retCode);
        } else {
            logger.warn("Not a Tapi3CallID: " + id);
        }
    }

    /* (non-Javadoc)
     * @see net.sourceforge.gjtapi.raw.CoreTpi#createCall(net.sourceforge.gjtapi.CallId, java.lang.String, java.lang.String, java.lang.String)
     */
    public CallId createCall(CallId id, String address, String term, String dest) throws ResourceUnavailableException,
            PrivilegeViolationException, InvalidPartyException, InvalidArgumentException, RawStateException,
            MethodNotSupportedException {
        logger.debug("createCall(" + id + ", " + address + ", " + term + ", " + dest + ")");
        if(id instanceof Tapi3CallID) {
            Tapi3CallID tapi3CallID = (Tapi3CallID)id;
            int retCode = tapi3Native.tapi3CreateCall(tapi3CallID.getCallID(), address, dest);
            logger.debug("tapi3CreateCall() returned: " + Integer.toHexString(retCode));
            if(retCode < 0) {
                throw new InvalidPartyException(InvalidPartyException.UNKNOWN_PARTY, "Error code: " + Integer.toHexString(retCode));
            }
            return id;
        } else {
            throw new MethodNotSupportedException("Not a Tapi3CallID: " + id);
        }
    }

    /* (non-Javadoc)
     * @see net.sourceforge.gjtapi.raw.CoreTpi#answerCall(net.sourceforge.gjtapi.CallId, java.lang.String, java.lang.String)
     */
    public void answerCall(CallId call, String address, String terminal) throws PrivilegeViolationException,
            ResourceUnavailableException, MethodNotSupportedException, RawStateException {
        logger.debug("answerCall(" + call + ", " + address + ", " + terminal + ")");
        if(call instanceof Tapi3CallID) {
            Tapi3CallID tapi3CallID = (Tapi3CallID)call;
            int retCode = tapi3Native.tapi3AnswerCall(tapi3CallID.getCallID());
            logger.debug("tapi3AnswerCall() returned: 0x" + Integer.toHexString(retCode));
            if(retCode != 0) {
                throw new RawStateException(call, TerminalConnection.UNKNOWN);
            }
        } else {
            logger.warn("Not a Tapi3CallID: " + call);
            throw new MethodNotSupportedException("Not a Tapi3CallID: " + call);
        }
    }

    /* (non-Javadoc)
     * @see net.sourceforge.gjtapi.raw.BasicJtapiTpi#release(java.lang.String, net.sourceforge.gjtapi.CallId)
     */
    public void release(String address, CallId call) throws PrivilegeViolationException, ResourceUnavailableException,
            MethodNotSupportedException, RawStateException {
        logger.debug("release(" + address + ", " + call + ")");
        if(call instanceof Tapi3CallID) {
            Tapi3CallID tapi3CallID = (Tapi3CallID)call;
            int retCode = tapi3Native.tapi3DisconnectCall(tapi3CallID.getCallID());
            logger.debug("tapi3DisconnectCall() returned: 0x" + Integer.toHexString(retCode));
            if(retCode != 0) {
                throw new RawStateException(call, TerminalConnection.UNKNOWN);
            }
        } else {
            logger.warn("Not a Tapi3CallID: " + call);
            throw new MethodNotSupportedException("Not a Tapi3CallID: " + call);
        }
    }

    /* (non-Javadoc)
     * @see net.sourceforge.gjtapi.raw.CCTpi#hold(net.sourceforge.gjtapi.CallId, java.lang.String, java.lang.String)
     */
    public void hold(CallId call, String address, String terminal) throws RawStateException, MethodNotSupportedException, PrivilegeViolationException, ResourceUnavailableException {
        logger.debug("hold(" + call + ", " + address + ", " + terminal + ")");
        if(call instanceof Tapi3CallID) {
            Tapi3CallID tapi3CallID = (Tapi3CallID)call;
            int retCode = tapi3Native.tapi3Hold(tapi3CallID.getCallID());
            logger.debug("tapi3Hold() returned: 0x" + Integer.toHexString(retCode));
            if(retCode != 0) {
                throw new RawStateException(call, TerminalConnection.UNKNOWN);
            }
        } else {
            logger.warn("Not a Tapi3CallID: " + call);
            throw new MethodNotSupportedException("Not a Tapi3CallID: " + call);
        }
    }

    /* (non-Javadoc)
     * @see net.sourceforge.gjtapi.raw.CCTpi#join(net.sourceforge.gjtapi.CallId, net.sourceforge.gjtapi.CallId, java.lang.String, java.lang.String)
     */
    public CallId join(CallId call1, CallId call2, String address, String terminal) throws RawStateException, InvalidArgumentException, MethodNotSupportedException, PrivilegeViolationException, ResourceUnavailableException {
        logger.debug("join(" + call1 + ", " + call2 + ", " + address + ", " + terminal + ")");
        if((call1 instanceof Tapi3CallID) && (call2 instanceof Tapi3CallID)) {
            Tapi3CallID tapi3CallID1 = (Tapi3CallID)call1;
            Tapi3CallID tapi3CallID2 = (Tapi3CallID)call2;
            int joinCallID = tapi3Native.tapi3Join(tapi3CallID1.getCallID(), tapi3CallID2.getCallID());
            if(joinCallID >= 0) {
                logger.debug("tapi3Hold() returned callID: " + joinCallID);
                return new Tapi3CallID(joinCallID);
            } else {
                logger.error("Cannot join (errorCode=" + joinCallID + ")");
                throw new RawStateException(call1, TerminalConnection.UNKNOWN);
            }
        } else {
            logger.warn("Not a Tapi3CallID: " + call1 + ", " + call2);
           throw new InvalidArgumentException("Not a Tapi3CallID: " + call1 + ", " + call2);
        }
    }

    /* (non-Javadoc)
     * @see net.sourceforge.gjtapi.raw.CCTpi#unHold(net.sourceforge.gjtapi.CallId, java.lang.String, java.lang.String)
     */
    public void unHold(CallId call, String address, String terminal) throws RawStateException, MethodNotSupportedException, PrivilegeViolationException, ResourceUnavailableException {
        logger.debug("unHold(" + call + ", " + address + ", " + terminal + ")");
        if(call instanceof Tapi3CallID) {
            Tapi3CallID tapi3CallID = (Tapi3CallID)call;
            int retCode = tapi3Native.tapi3UnHold(tapi3CallID.getCallID());
            logger.debug("tapi3UnHold() returned: 0x" + Integer.toHexString(retCode));
            if(retCode != 0) {
                throw new RawStateException(call, TerminalConnection.UNKNOWN);
            }
        } else {
            logger.warn("Not a Tapi3CallID: " + call);
            throw new MethodNotSupportedException("Not a Tapi3CallID: " + call);
        }
    }


    // *** MediaTpi ***    
    public boolean allocateMedia(String terminal, int type, Dictionary resourceArgs) {
        return false;
    }
    public boolean freeMedia(String terminal, int type) {
        return false;
    }
    public boolean isMediaTerminal(String terminal) {
        return true;
    }
    public void play(String terminal, String[] streamIds, int offset, RTC[] rtcs, Dictionary optArgs) throws MediaResourceException {
        throw new MediaResourceException("Not implemented.");
    }
    public void record(String terminal, String streamId, RTC[] rtcs, Dictionary optArgs) throws MediaResourceException {
        throw new MediaResourceException("Not implemented.");
    }
    public void stop(String terminal) {
        throw new MediaRuntimeException("Not implemented.") {};
    }
    public void triggerRTC(String terminal, Symbol action) {
        throw new MediaRuntimeException("Not implemented.") {};
    }
    public RawSigDetectEvent retrieveSignals(String terminal, int num, Symbol[] patterns, RTC[] rtcs, Dictionary optArgs) throws MediaResourceException {
        throw new MediaResourceException("Not implemented.");
    }
    public void sendSignals(String terminal, Symbol[] syms, RTC[] rtcs, Dictionary optArgs) throws MediaResourceException {
        logger.debug("sendSignals(" + terminal + ", " + Arrays.asList(syms) + ")");
        int retCode = tapi3Native.tapi3SendSignals(terminal, getSymbolsAsString(syms));
        logger.debug("sendSignals() returned: 0x" + Integer.toHexString(retCode));
        if(retCode != 0) {
            throw new MediaResourceException("Failed to send DTMF tones: errorCode = 0x" + Integer.toHexString(retCode));
        }
    }
    
	/* (non-Javadoc)
	 * This is used to get any private data
	 * @see net.sourceforge.gjtapi.raw.PrivateDataTpi#getPrivateData(net.sourceforge.gjtapi.CallId, java.lang.String, java.lang.String)
	 */
	public Object getPrivateData(CallId call, String address, String terminal) {
		// Don't have any private data
		return null;
	}
	/* This is used to send in-call dialing information.
	 * @see net.sourceforge.gjtapi.raw.PrivateDataTpi#sendPrivateData(net.sourceforge.gjtapi.CallId, java.lang.String, java.lang.String, java.lang.Object)
	 */
	public Object sendPrivateData(CallId call, String address, String terminal,
			Object data) {
		// If the data is a PrivateDialCommand, send it to the native level
		if ((call instanceof Tapi3CallID) && (data instanceof PrivateDialCommand))
		{
			PrivateDialCommand dialCommand = (PrivateDialCommand)data;
			int result = tapi3Native.tapi3Dial(((Tapi3CallID)call).getCallID(), dialCommand.getNumberToDial());
			return new Integer(result);
		}
		return null;
	}
	/* (non-Javadoc)
	 * @see net.sourceforge.gjtapi.raw.PrivateDataTpi#setPrivateData(net.sourceforge.gjtapi.CallId, java.lang.String, java.lang.String, java.lang.Object)
	 */
	public void setPrivateData(CallId call, String address, String terminal,
			Object data) {
		// Don't do anything with this

	}


    /**
     * Convert an array of {@link javax.telephony.media.Symbol}s to a String of DTMF digits 
     * @param symbols The array of {@link javax.telephony.media.Symbol}s
     * @return A String containing the corresponding DTMF digits
     */
    public static String getSymbolsAsString(Symbol[] symbols) {
        StringBuffer sbuf = new StringBuffer(symbols.length);
        for(int i=0; i<symbols.length; i++) {
            char ch = getSymbolAsChar(symbols[i]);
            sbuf.append(ch);
        }
        return sbuf.toString();
    }
    
    /**
     * Convert a {@link javax.telephony.media.Symbol} to a DTMF digit
     * @param symbol The {@link javax.telephony.media.Symbol} to be converted
     * @return The corresponding DTMF digit
     */
    public static char getSymbolAsChar(Symbol symbol) {
        if(symbol == SignalConstants.v_DTMF0) return '0';
        if(symbol == SignalConstants.v_DTMF1) return '1';
        if(symbol == SignalConstants.v_DTMF2) return '2';
        if(symbol == SignalConstants.v_DTMF3) return '3';
        if(symbol == SignalConstants.v_DTMF4) return '4';
        if(symbol == SignalConstants.v_DTMF5) return '5';
        if(symbol == SignalConstants.v_DTMF6) return '6';
        if(symbol == SignalConstants.v_DTMF7) return '7';
        if(symbol == SignalConstants.v_DTMF8) return '8';
        if(symbol == SignalConstants.v_DTMF9) return '9';
        if(symbol == SignalConstants.v_DTMFA) return 'A';
        if(symbol == SignalConstants.v_DTMFB) return 'B';
        if(symbol == SignalConstants.v_DTMFC) return 'C';
        if(symbol == SignalConstants.v_DTMFD) return 'D';
        if(symbol == SignalConstants.v_DTMFHash) return '#';
        if(symbol == SignalConstants.v_DTMFStar) return '*';        
        return '\0';
    }
}

⌨️ 快捷键说明

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