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

📄 emprovider.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 * All my terminals handle media.
 */
public boolean isMediaTerminal(java.lang.String terminal) {
	return true;
}
/**
 * Join two calls
 */
public CallId join(CallId call1, CallId call2, String address, String terminal) throws MethodNotSupportedException {
	RawCall from = (RawCall)call1;
	RawCall to = (RawCall)call2;

	from.join(to);

	return from;
}
/**
 * This method loads the Provider's initial values.
 * Creation date: (2000-02-10 10:11:41)
 * @author: Richard Deadman
 */
private Properties loadResources(String resName) {
	// We must be able to load the properties file
	Properties props = new Properties();
	try {
		props.load(this.getClass().getResourceAsStream(resName));
	} catch (IOException ioe) {
		// eat and hope that the initialize method sets my required properties
	}

	// delay initialization until initialize() called -- allow property replacement

	// return
	return props;
}
/**
 * Since I don't have any real playing resources, I just pause and then report success.
 */
public void play(String terminal, String[] streamIds, int offset, javax.telephony.media.RTC[] rtcs, Dictionary optArgs) throws javax.telephony.media.MediaResourceException {
	TestPhone phone = (TestPhone)this.getPhone(terminal);
	PhoneModel pm = phone.getModel();
	try {
		// ask the terminal to pretend to play the file
		StringBuffer sb = new StringBuffer("Playing files:");
		for (int i = 0; i < streamIds.length; i++)
			sb.append(" ").append(streamIds[i]);
		phone.setStatus(sb.toString());
		pm.setPlayThread(Thread.currentThread());
		java.applet.AudioClip ac = null;
		for (int i = 0; i < streamIds.length; i++) {
			String media = streamIds[i];
			try {
				ac = java.applet.Applet.newAudioClip(new java.net.URL(media));
				ac.play();
			} catch (java.net.MalformedURLException mfe) {
				System.out.println("Bad URL: " + media);
				Thread.sleep(2000);
			}
		}
	} catch (InterruptedException ie) {
		// continue then
	}
	// clean up
	pm.setPlayThread(null);
}
/**
 * I can't really listen, so I just return some stuff
 * If an Http URL is give, I try putting to the url.
 *
 * Updates to the HTTP and URLConnection output code from Mario Dorion, May 10, 2000
 */
public void record(String terminal, String streamId, RTC[] rtcs, Dictionary optArgs)
	throws MediaResourceException {
		// pause for two seconds
	PhoneModel pm = ((TestPhone)this.getPhone(terminal)).getModel();
	pm.setRecordThread(Thread.currentThread());
	try {
		Thread.sleep(2000);
	} catch (InterruptedException ie) {
		// continue then
	}
	pm.setRecordThread(null);

	// try to construct a URL from the streamId
	try {
		java.net.URL url = new java.net.URL(streamId);
		java.io.OutputStream os = null;
		if (url.getProtocol().equals("file")) {
			os = new FileOutputStream(url.getFile());
		} else {
			java.net.URLConnection cnx = url.openConnection();
			cnx.setDoOutput(true);
			if (cnx instanceof java.net.HttpURLConnection)
				((java.net.HttpURLConnection)cnx).setRequestMethod("PUT");	// POST or PUT
			os = cnx.getOutputStream();
		}
		os.write("Hello World".getBytes());
		os.flush();
		os.close();
	} catch (java.net.MalformedURLException mue) {
		throw new MediaResourceException("Could not record to streamId: not URL");
	} catch (java.io.IOException ioe) {
		throw new MediaResourceException("Error recording to URL: " + streamId);
	}
}
/**
 * release a terminal from a call
 */
public void release(String address, CallId call) throws RawStateException {
	// For the emulator, phones and addresses have a 1:1 relationship
	RawPhone phone = this.getPhone(address);
	Leg leg = null;
	if (phone != null)
		leg = ((RawCall)call).getLeg(phone);
	
	if (leg != null)
		leg.drop();
	else
		throw new RawStateException(call, address, null,
				javax.telephony.InvalidStateException.CONNECTION_OBJECT,
				javax.telephony.TerminalConnection.UNKNOWN);
}
/**
 * Release a CallId.  Ignored by this provider.
 *
 * @param id The call id no longer used by the JTAPI layer.
 * @author: Richard Deadman
 */
public void releaseCallId(CallId id) {}
/**
 * Remove an event observer
 */
public void removeListener(TelephonyListener rl) {
	TestManager mgr = this.getMgr();
	if (rl.equals(mgr.getListener()))
		mgr.setListener(null);
}
/**
 * reportCallsOnAddress method comment.
 */
public void reportCallsOnAddress(java.lang.String address, boolean flag) {
}
/**
 * reportCallsOnTerminal method comment.
 */
public void reportCallsOnTerminal(java.lang.String terminal, boolean flag) {
}
/**
 * Reserve a callId for future use.
 */
public net.sourceforge.gjtapi.CallId reserveCallId(String address) throws InvalidArgumentException {
	// test if valid address
	if (this.getMgr().getPhone(address) == null)
		throw new InvalidArgumentException("Address " + address + " unknown by emulator");
	return new RawCall(this.getMgr());
}
/**
 * Retrieve up to num signals from the signal buffer associated with terminal, waiting until either
 * then number of signals is available, a patterns is met, a rtc is fired to stop retrieving, or a
 * timeout occurs.
 * <P> Note that currently this implementation does not wait for signals to arrive.
 *
 * @param terminal The terminal name to retrieve patterns from
 * @param num The maximum number of signals to return
 * @param patterns A set of signals that cause the call to return early.
 * @param rtcs A set of run-time controls to control the signal detector.
 * @param optArgs Optional signal detector arguments.
 * @return An event factory that holds the detected signals and any reasons.
 */
public RawSigDetectEvent retrieveSignals(String terminal, int num, Symbol[] patterns, RTC[] rtcs, Dictionary optArgs)
		throws MediaResourceException {
	//---------------------------------------------------------------------------
	// Bugs remaining - don't allow -1
	//                  dont check patterns or rtcs,
	//                  timouts - only obey p_Duration in the LOCAL dictionary
	//---------------------------------------------------------------------------
	String sigs = "";

 
	//---------------------------------------------------------------------------
	// Get the local p_Duration (if any).
	//---------------------------------------------------------------------------
	Object lTimeoutVal = null;

	if (optArgs != null) {
		Object lTimeoutKey = SignalDetectorConstants.p_Duration;
		lTimeoutVal = optArgs.get(lTimeoutKey);
	}

	boolean lTimed = (lTimeoutVal != null);
	int ltmout = (lTimed ? ((Integer) lTimeoutVal).intValue() : 0);
	int ltmdone = 0;

	while ((sigs.length() < num)
		&& ((!lTimed) || (ltmdone < ltmout))) {
		sigs += this.getMgr().getPhone(terminal).reportDTMF(num - sigs.length());
		ltmdone += 100;
		try {
			Thread.sleep(100);
		} catch (Exception e) {
		}
	}

	//---------------------------------------------------------------------------
	// Check for timeout
	//---------------------------------------------------------------------------
	if (sigs.length() < num) {
		return RawSigDetectEvent.timeout(
			terminal,
			SymbolConvertor.convert(sigs));
	}
	//	now turn the found characters into a GenericSignalDetectorEvent
	return RawSigDetectEvent.maxDetected(terminal, SymbolConvertor.convert(sigs));
 }					// we should wait until num is met or a pattern is met or a rtc tells us to stop...

/**
 * Send the passed data to a terminal, if one indicated.
 * This is just simple testing.
 */
public Object sendPrivateData(CallId call, String address, String terminal, Object data) {
	if (terminal != null) {
		RawPhone rp = this.getPhone(terminal);
		
		if (rp != null) {
			rp.setStatus(data.toString());

			// send back private data response
			this.getMgr().getListener().terminalPrivateData(terminal, "Ouch!", javax.telephony.events.Ev.CAUSE_NORMAL);
		}
	}
	return "Yea!";
}
/**
 * Send the DTMF signals on to the appropriate phone.
 */
public void sendSignals(String terminal, Symbol[] syms, RTC[] rtcs, Dictionary optArgs) throws MediaResourceException {
	RawPhone rp = this.getMgr().getPhone(terminal);
	if (rp != null) {
		rp.sendDTMF(SymbolConvertor.convert(syms));
	}
}
/**
 * Insert the method's description here.
 * Creation date: (2000-02-10 10:07:53)
 * @author: 
 * @param newMgr net.sourceforge.gjtapi.raw.emulator.TestManager
 */
private void setMgr(TestManager newMgr) {
	mgr = newMgr;
}
/**
 * setPrivateData method comment.
 */
public void setPrivateData(net.sourceforge.gjtapi.CallId call, java.lang.String address, java.lang.String terminal, java.lang.Object data) {}
/**
 * Internal setter
 * Creation date: (2000-02-22 14:20:52)
 * @author: Richard Deadman
 * @param newProvProps A new set of properties
 */
private void setProvProps(Properties newProvProps) {
	provProps = newProvProps;
}
/**
 * Clean up any resources
 */
public void shutdown() {
	// close my manager
	this.getMgr().close();
	
	// throw away my manager
	this.setMgr(null);

	// remove myself from the universe
	EmProvider.universe.remove(this);
}
/**
 * stop method comment.
 */
public void stop(java.lang.String terminal) {
	PhoneModel pm = ((TestPhone)this.getPhone(terminal)).getModel();
	Thread t = pm.getPlayThread();;
	if (t != null)
		t.interrupt();
	t = pm.getRecordThread();
	if (t != null)
		t.interrupt();
}
/**
 * Since I don't support call throttling, I should never be called.
 */
public boolean stopReportingCall(CallId call) {
	return true;
}
/**
 * Describe myself
 * @return a string representation of the receiver
 */
public String toString() {
	return "A JTAPI Raw Provider for: " + this.getMgr();
}
/**
 * Only triggers we support are for shutting down any player or recorders
 */
public void triggerRTC(java.lang.String terminal, javax.telephony.media.Symbol action) {
	if (action.equals(PlayerConstants.rtca_Stop)) {
		Thread t = ((TestPhone)this.getPhone(terminal)).getModel().getPlayThread();
		if (t != null)
			t.interrupt();
	} else if (action.equals(RecorderConstants.rtca_Stop)) {
		Thread t = ((TestPhone)this.getPhone(terminal)).getModel().getRecordThread();
		if (t != null)
			t.interrupt();
	}
}
/**
 * unHold method comment.
 */
public void unHold(CallId call, String address, String term) throws RawStateException {
	try {
		this.getPhone(term).unHold();
	} catch (NullPointerException npe) {
		// No phone matched
		throw new RawStateException(call, term, term,
				javax.telephony.InvalidStateException.TERMINAL_CONNECTION_OBJECT,
				javax.telephony.TerminalConnection.UNKNOWN);
	}
}
}

⌨️ 快捷键说明

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