From 976ac65add64ef4c912b1b8d41c071baff9e85e3 Mon Sep 17 00:00:00 2001 From: Michael Kunz Date: Thu, 5 Jan 2017 09:58:49 +0100 Subject: [PATCH] make EventProxy thread aware so that unadvice will be called in the context of the connection point owner --- runtime/src/main/java/com4j/EventProxy.java | 6 ++++-- runtime/src/main/java/com4j/Wrapper.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) mode change 100644 => 100755 runtime/src/main/java/com4j/EventProxy.java mode change 100644 => 100755 runtime/src/main/java/com4j/Wrapper.java diff --git a/runtime/src/main/java/com4j/EventProxy.java b/runtime/src/main/java/com4j/EventProxy.java old mode 100644 new mode 100755 index 9328cc6..a4cb08e --- a/runtime/src/main/java/com4j/EventProxy.java +++ b/runtime/src/main/java/com4j/EventProxy.java @@ -25,6 +25,7 @@ final class EventProxy implements EventCookie { private final EventInterfaceDescriptor descriptor; private final T javaObject; + private final ComThread thread; /** * Pointer to the native proxy. @@ -35,9 +36,10 @@ final class EventProxy implements EventCookie { * Creates a new event proxy that implements the event interface {@code intf} * and delivers events to {@code javaObject}. */ - EventProxy(Class intf, T javaObject) { + EventProxy(Class intf, T javaObject, ComThread thread) { this.descriptor = getDescriptor(intf); this.javaObject = javaObject; + this.thread = thread; } /** @@ -50,7 +52,7 @@ public Void call() { Native.unadvise(nativeProxy); return null; } - }.execute(); + }.execute(thread); nativeProxy = 0; } } diff --git a/runtime/src/main/java/com4j/Wrapper.java b/runtime/src/main/java/com4j/Wrapper.java old mode 100644 new mode 100755 index 5b0cd20..fff4b01 --- a/runtime/src/main/java/com4j/Wrapper.java +++ b/runtime/src/main/java/com4j/Wrapper.java @@ -275,7 +275,7 @@ public EventProxy call() { throw new ComException("This object doesn't have event source",-1); GUID iid = COM4J.getIID(eventInterface); Com4jObject cp = cpc.FindConnectionPoint(iid); - EventProxy proxy = new EventProxy(eventInterface, object); + EventProxy proxy = new EventProxy(eventInterface, object, thread); proxy.nativeProxy = Native.advise(cp.getPointer(), proxy,iid.v[0], iid.v[1]); // clean up resources to be nice