SF2927058 add hasExited() method to support polling for server termination
This commit is contained in:
@@ -59,6 +59,11 @@
|
||||
<td width="87%" valign="top">Convert API to use var args and remove the many overloaded Dispatch
|
||||
methods that each added one more parameter.(M4)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="13%" valign="top">2927058</td>
|
||||
<td width="87%" valign="top">a hasExited() method that allows polling until a COM server is
|
||||
terminated and implemented this method in JACOB(M4)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="13%" valign="top"> </td>
|
||||
<td width="87%" valign="top"> </td>
|
||||
|
||||
@@ -555,6 +555,26 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
|
||||
return newVariant;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait method added so folks could wait until a com server terminated
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Dispatch_hasExited
|
||||
(JNIEnv *env,jclass clazz, jobject disp, jint dispid, jint lcid) {
|
||||
IDispatch *pIDispatch = extractDispatch(env, disp);
|
||||
if (!pIDispatch) {
|
||||
// should we return 0?
|
||||
return NULL;
|
||||
}
|
||||
ITypeInfo *v;
|
||||
HRESULT hr = pIDispatch->GetTypeInfo(dispid, lcid, &v);
|
||||
if (hr == RPC_E_SERVERCALL_RETRYLATER || hr == RPC_E_CALL_REJECTED || hr
|
||||
== 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -81,6 +81,14 @@ JNIEXPORT jintArray JNICALL Java_com_jacob_com_Dispatch_getIDsOfNames
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
|
||||
(JNIEnv *, jclass, jobject, jstring, jint, jint, jint, jobjectArray, jintArray);
|
||||
|
||||
/*
|
||||
* Class: Dispatch
|
||||
* Method: wait
|
||||
* Signature: (Ljava/lang/Object;I;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Dispatch_hasExited
|
||||
(JNIEnv *, jclass, jobject, jint, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -845,4 +845,28 @@ public class Dispatch extends JacobObject {
|
||||
throw new NotImplementedException("not implemented yet");
|
||||
}
|
||||
|
||||
/**
|
||||
* Cover for native method
|
||||
*
|
||||
* @param disp
|
||||
* @param dispid
|
||||
* @param lcid
|
||||
* @return 0 if the dispatch is still active and 1 if it has exited
|
||||
*/
|
||||
public static native int hasExited(Dispatch disp, int dispid, int lcid);
|
||||
|
||||
/**
|
||||
* The method is used to poll until it returns 1, indicating that the COM
|
||||
* server in gone.
|
||||
* <p>
|
||||
* Sourceforge feature request 2927058
|
||||
*
|
||||
* @param dispatchTarget
|
||||
* @return 0 if the dispatch is still active and 1 if it has exited
|
||||
*/
|
||||
public static int hasExited(Dispatch dispatchTarget) {
|
||||
throwIfUnattachedDispatch(dispatchTarget);
|
||||
return hasExited(dispatchTarget, 0, LOCALE_SYSTEM_DEFAULT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jacob.com;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.test.BaseTestCase;
|
||||
|
||||
/**
|
||||
@@ -12,9 +13,21 @@ import com.jacob.test.BaseTestCase;
|
||||
public class DispatchTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* Dummy test until someone gets their act together
|
||||
* Verify this detects word's exit
|
||||
*/
|
||||
public void testDispatch() {
|
||||
// what should we test
|
||||
public void testDispatchHasExited() {
|
||||
String pid = "Word.Application";
|
||||
ActiveXComponent axc = new ActiveXComponent(pid);
|
||||
assertEquals(0, Dispatch.hasExited(axc));
|
||||
axc.invoke("Quit", new Variant[] {});
|
||||
// should take some amount of time for Word to Quit so should = !exited
|
||||
assertEquals(0, Dispatch.hasExited(axc));
|
||||
try {
|
||||
// sleep some reasonable amount of time waiting for it to quit
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
fail("should not have been interrupted");
|
||||
}
|
||||
assertEquals(1, Dispatch.hasExited(axc));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user