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

📄 xtapiprovider.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                break;
                
            case LINE_REQUEST:
                break;
                
            case PHONE_BUTTON:
                break;
                
            case PHONE_CLOSE:
                break;
                
            case PHONE_DEVSPECIFIC:
                break;
                
            case PHONE_REPLY:
                break;
                
            case PHONE_STATE:
                break;
                
            case LINE_CREATE:
                break;
                
            case PHONE_CREATE:
                break;
                
            default:
                System.out.println("UNKNOWN TAPI EVENT: " + dwMessage);
                break;
        }
        }catch(Exception e){
            System.out.println("Exception " + e.toString() + " in callback()");
        }

	}

    //callback recieved a LINE_CALLSTATE event:
    private void lineCallState(int dwDevice,int dwInstance,
           int dwParam1,int dwParam2,int dwParam3)
    {
    	Integer lineKey = new Integer(dwInstance);
		//System.out.println("Line: " + dwInstance);
		//System.out.println("Params: dwDevice -> " + dwDevice + " dwInstance -> " + dwInstance +
			//" dwParam1 -> "  + dwParam1 + " dwParam2 -> " + dwParam2 + 
			//" dwParam3 -> " + dwParam3);
        switch (dwParam1)
        {
            case LINECALLSTATE_IDLE:
                try{
                	XtapiCallId callId = (XtapiCallId)this.lineToCalls.get(lineKey);
	                if (callId != null) {
	                	AddressInfo ai = (AddressInfo)this.lineToAddr.get(lineKey);
	                	if (ai != null) {
	                		this.gjListener.connectionDisconnected(callId, ai.getName(), Event.CAUSE_NORMAL);
	                	}
	                	// now see if we can disconnect the remote leg
	                	String remoteAddress = callId.getRemoteAddress();
	                	if (remoteAddress != null)
	                		this.gjListener.connectionDisconnected(callId, remoteAddress, Event.CAUSE_NORMAL);
	                }
                }catch(Exception e){
                    System.out.println("LINECALLSTATE_IDLE exception: " + e.toString());
                }
                
                //Connection.DISCONNECTED
                break;

            case LINECALLSTATE_OFFERING:
                
				try{
					// create a call
	                //AddressInfo ai = (AddressInfo)this.lineToAddr.get(lineKey);
                        //sf
					AddressInfo ai = (AddressInfo)this.addInfoMap.get("addr_" + lineKey);
                        //end sf
	                if (ai != null) {
						XtapiCallId callId = new XtapiCallId();
	                	//callId.setCallNumber(dwInstance); // dwInstance contains the line id (NOT the line handle!)
                                //sf
						callId.setCallNumber(dwDevice); // dwDevice contains the call handle
						this.callNumToCalls.put(new Integer(dwDevice), callId);
						
                		// register the call with the line
		                this.lineToCalls.put(new Integer(ai.line), callId); 
                                //end sf
						// and register the call with a terminal
						this.termToCalls.put(ai.terminal, callId);
                                
	                	// get the calling connection and notify of new connection
	                	this.gjListener.connectionAlerting(callId, ai.getName(), Event.CAUSE_NORMAL);
	                	this.gjListener.terminalConnectionRinging(callId, ai.getName(), ai.terminal, Event.CAUSE_NORMAL);
	                	if (this.remoteNumber != null) {
		                	this.gjListener.connectionConnected(callId, this.remoteNumber, Event.CAUSE_NORMAL);
		                	callId.setRemoteAddress(this.remoteNumber);
		                	// now handle the remote terminal connection
		                	if (this.remoteName != null) {
			                	this.gjListener.terminalConnectionTalking(callId, this.remoteNumber, this.remoteName, Event.CAUSE_NORMAL);
			                	// clear remoteName for next call
			                	this.remoteName = null;
							}
							// clear remoteNumber for next call
							this.remoteNumber = null;
		            	}
	                }
				}catch(Exception e){
					System.out.println("Exception in LINECALLSTATE_OFFERING: " +
						e.toString());
				}
                break;

            case LINECALLSTATE_ACCEPTED:
                break;

            case LINECALLSTATE_DIALTONE:
                break;

            case LINECALLSTATE_DIALING:
                break;

            case LINECALLSTATE_RINGBACK:
                //event.add(new XEv(ConnAlertingEv.ID,Ev.CAUSE_NEW_CALL,                            0,false));                
                break;

            case LINECALLSTATE_BUSY:
                break;

            case LINECALLSTATE_SPECIALINFO:
                break;

            case LINECALLSTATE_CONNECTED:
                try{
                	XtapiCallId callId = (XtapiCallId)this.lineToCalls.get(lineKey);
	                if (callId != null) {
                                //sf
	                	//AddressInfo ai = (AddressInfo)this.lineToAddr.get(lineKey);
						AddressInfo ai = (AddressInfo)this.addInfoMap.get("addr_" + dwInstance);
                                //end sf
	                	if (ai != null) {
	                		this.gjListener.connectionConnected(callId, ai.getName(), Event.CAUSE_NORMAL);
//	                		this.gjListener.connectionConnected(callId, "UNKNOWN", Event.CAUSE_NORMAL);
                                        //sf
							this.gjListener.terminalConnectionTalking(callId, ai.getName(), ai.terminal, Event.CAUSE_NORMAL);
                                        //end sf
//							this.gjListener.terminalConnectionTalking(callId, "UNKNOWN", "UNKNOWN", Event.CAUSE_NORMAL);
	                	}
	                	// now note that the remote connection is connected
	                	String remoteAddress = callId.getRemoteAddress();
	                	if (remoteAddress != null)
	                		this.gjListener.connectionConnected(callId, remoteAddress, Event.CAUSE_NORMAL);
	                }
                }catch(Exception e){
                	e.printStackTrace();
                    System.out.println("LINECALLSTATE_CONNECTED exception: " + e.toString());
                }
                break;

            case LINECALLSTATE_PROCEEDING:
                // Outgoing call invokes two JTAPI Connection events.
                
                try{
                	XtapiCallId callId = (XtapiCallId)this.lineToCalls.get(lineKey);
	                if (callId != null) {
                                //sf
	                	//AddressInfo ai = (AddressInfo)this.lineToAddr.get(lineKey);
						AddressInfo ai = (AddressInfo)this.addInfoMap.get("addr_" + lineKey);
                                //end sf
	                	if (ai != null) {
	                		this.gjListener.connectionInProgress(callId, ai.getName(), Event.CAUSE_NORMAL);
                                        //sf
							this.gjListener.connectionAlerting(callId, ai.getName(), Event.CAUSE_NORMAL);
                                        //end sf
	                	}
	                }
                }catch(Exception e){
                    //sf
                    System.out.println("LINECALLSTATE_PROCEEDING exception: " + e.toString());
                    //end sf
                }
                break;

            case LINECALLSTATE_ONHOLD:
                break;

            case LINECALLSTATE_CONFERENCED:
                break;

            case LINECALLSTATE_ONHOLDPENDCONF:
                break;

            case LINECALLSTATE_ONHOLDPENDTRANSFER:
                break;

            case LINECALLSTATE_DISCONNECTED:
                try{
                	XtapiCallId callId = (XtapiCallId)this.lineToCalls.get(lineKey);
	                if (callId != null) {
                                //sf
	                	//AddressInfo ai = (AddressInfo)this.lineToAddr.get(lineKey);
						AddressInfo ai = (AddressInfo)this.addInfoMap.get("addr_" + dwInstance);
                                //end sf
	                	if (ai != null) {
                                        //sf
							this.gjListener.terminalConnectionDropped(callId, ai.getName(), ai.terminal, Event.CAUSE_NORMAL);
                                        //end sf
	                		this.gjListener.connectionDisconnected(callId, ai.getName(), Event.CAUSE_NORMAL);
//	                		this.gjListener.connectionDisconnected(callId, "UNKNOWN", Event.CAUSE_NORMAL);
								// we can get the terminal, and remove the call from the term -> call map
							this.termToCalls.remove(ai.terminal);
							}
						// disconnect the remote Connection
						String remoteAddress = callId.getRemoteAddress();
						if (remoteAddress != null)
							this.gjListener.connectionDisconnected(callId, remoteAddress, Event.CAUSE_NORMAL);
							// now remove the entry from the line -> CallId map
						this.lineToCalls.remove(lineKey);
							// and the callNum -> call map
						this.callNumToCalls.remove(new Integer(callId.getCallNum()));
	                }
                }catch(Exception e){
                    System.out.println("LINECALLSTATE_IDLE exception: " + e.toString());
                }
                break;

            case LINECALLSTATE_UNKNOWN:
                break;
                
            default:
                break; 
        }
    }

    //callback recieved a LINE_DEVSTATE event:
    private void lineDevState(int dwDevice,int dwInstance,
           int dwParam1,int dwParam2,int dwParam3)
    {
        switch(dwParam1)
        {
            case LINEDEVSTATE_OTHER:
                break;
                
            case LINEDEVSTATE_RINGING:
            	// this may be for subsequent rings, in which case we don't need it.
               //dwParam3 contains the ring count.
                XtapiCallId xCallId = (XtapiCallId)this.lineToCalls.get(new Integer(dwInstance));
                if (xCallId != null) {
                        //sf
                	//AddressInfo ai = (AddressInfo)this.lineToAddr.get(new Integer(dwInstance));
					AddressInfo ai = (AddressInfo)this.addInfoMap.get("addr_" + dwInstance);
                        //end sf
                	if (ai != null) {
                		this.gjListener.connectionAlerting(xCallId, ai.getName(), Event.CAUSE_NEW_CALL);
//                		this.gjListener.connectionAlerting(xCallId, "UNKNOWN", Event.CAUSE_NEW_CALL);
							//sf
						this.gjListener.terminalConnectionRinging(xCallId, ai.getName(), ai.terminal, Event.CAUSE_NORMAL);
							//end sf
                	}
                }
                break;
                
            case LINEDEVSTATE_CONNECTED:
                break;
                
            case LINEDEVSTATE_DISCONNECTED:
                break;
                
            case LINEDEVSTATE_MSGWAITON:
                break;
                
            case LINEDEVSTATE_MSGWAITOFF:
                break;
                
            case LINEDEVSTATE_INSERVICE:
                break;
                
            case LINEDEVSTATE_OUTOFSERVICE:
                break;
                
            case LINEDEVSTATE_MAINTENANCE:
                break;
                
            case LINEDEVSTATE_OPEN:
                break;
                
            case LINEDEVSTATE_CLOSE:
                break;
                
            case LINEDEVSTATE_NUMCALLS:
                break;
                
            case LINEDEVSTATE_NUMCOMPLETIONS:
                break;
                
            case LINEDEVSTATE_TERMINALS:
                break;

            case LINEDEVSTATE_ROAMMODE:
                break;

            case LINEDEVSTATE_BATTERY:
                break;

            case LINEDEVSTATE_SIGNAL:
                break;

            case LINEDEVSTATE_DEVSPECIFIC:
                break;

            case LINEDEVSTATE_REINIT:
                break;

            case LINEDEVSTATE_LOCK:
                break;

            case LINEDEVSTATE_CAPSCHANGE:
                break;

            case LINEDEVSTATE_CONFIGCHANGE:
                break;

            case LINEDEVSTATE_TRANSLATECHANGE:
                break;

            case LINEDEVSTATE_COMPLCANCEL:
                break;

            case LINEDEVSTATE_REMOVED:
                break;

            default:
                break; 
        }
    }
	// end of interface implementation
	
	/**
	 * Helper function for getting a call id from a terminal name
	 */
	private int getCallId(String terminal) {
		return ((XtapiCallId)this.termToCalls.get(terminal)).getCallNum();
	}
	
	/**
	 * Helper function for getting a line id from a terminal name
	 */
	private int getLineId(String terminal) {
		return ((AddressInfo)this.termToAddr.get(terminal)).rawHandle;
	}
	
	/**
	 * Describe myself
	 */
	public String toString() {
		return "GJTAPI bridge to XTAPI service provider: " + realProvider.toString();
	}
	/**
	 * @see BasicJtapiTpi#release(String, CallId)
	 */
	public void release(String address, CallId call)
		throws
			PrivilegeViolationException,
			ResourceUnavailableException,
			MethodNotSupportedException,
			RawStateException {
		// check if this is a local address
		AddressInfo addInfo = (AddressInfo)this.addInfoMap.get(address);
		if (addInfo != null)
			try {
				this.realProvider.XTDropCall(((XtapiCallId)call).getCallNum());
			} catch (InvalidStateException ise) {
				throw new RawStateException(call, ise.getState());
			}
	}

	/**
	 * Stores signals for a terminal and notifies any waiting
	 * threads of the arrival of the digits.
	 * @param terminalName
	 * @param digits
	 */
	private void storeSignals(String terminalName, char[] digits) {
		StringBuffer sb = this.getSignalBuffer(terminalName);
		synchronized (sb) {
			sb.append(digits);
			
			// now we notify anyone waiting for digits
			sb.notify();
		}
	}

	/**
	 * Retrieves the latest uncollected signals on a
	 * terminal and clears the terminal signal bucket.
	 * @param terminalName
	 * @return
	 */
	private String retrieveSignals(String terminalName) {
		StringBuffer sb = this.getSignalBuffer(terminalName);
		synchronized (sb) {
			String signals = sb.toString();
			sb.delete(0, sb.length());
			return signals;
		}		
	}
	
	/**
	 * Get a StringBuffer for a terminal, used to store
	 * the latest unretrieved signals on that terminal.
	 * @param terminalName
	 * @return A StringBuffer holding signals for the terminal.
	 */
	private StringBuffer getSignalBuffer(String terminalName) {
		Map bucketSet = this.termToBuckets;
		StringBuffer signalBuffer = (StringBuffer)bucketSet.get(terminalName);
		if (signalBuffer == null) {
			synchronized (bucketSet) {
				// try again to avoid double creation error
				signalBuffer = (StringBuffer)bucketSet.get(terminalName);
				if (signalBuffer == null) {
					signalBuffer = new StringBuffer();
					bucketSet.put(terminalName, signalBuffer);
				}
			}
		}
		return signalBuffer;
	}
}

⌨️ 快捷键说明

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