1 | /* |
2 | * $Id: ComInterfaceEntry.java,v 1.4 2005/12/02 19:59:57 hastings Exp $ |
3 | * |
4 | * (c) Copyright, Moebius Solutions, Inc., 2004 |
5 | * |
6 | * All Rights Reserved |
7 | * |
8 | * This material may be reproduced by or for the U. S. Government |
9 | * pursuant to the copyright license under the clause at |
10 | * DFARS 252.227-7014 (OCT 2001). |
11 | */ |
12 | package com.moesol.bindings.platform_sdk.component_services; |
13 | |
14 | public class ComInterfaceEntry { |
15 | private final GUID m_iid; |
16 | private final Class m_iface_class; |
17 | private IUnknown m_java_sink; |
18 | private long m_thunk_ptr; |
19 | |
20 | public ComInterfaceEntry(GUID iid, Class iface_class, IUnknown java_sink) { |
21 | m_iid = iid; |
22 | m_iface_class = iface_class; |
23 | m_java_sink = java_sink; |
24 | } |
25 | |
26 | public String toString() { |
27 | StringBuffer sb = new StringBuffer(); |
28 | sb.append('['); |
29 | sb.append(m_iface_class.getName()); |
30 | sb.append(' '); |
31 | sb.append(m_java_sink.getClass().getName()); |
32 | sb.append(' '); |
33 | sb.append(m_thunk_ptr); |
34 | sb.append(']'); |
35 | sb.append('\n'); |
36 | return sb.toString(); |
37 | } |
38 | |
39 | public GUID getIID() { |
40 | return m_iid; |
41 | } |
42 | public Class getIfaceClass() { |
43 | return m_iface_class; |
44 | } |
45 | public IUnknown getJavaSink() { |
46 | return m_java_sink; |
47 | } |
48 | |
49 | // TODO rename |
50 | public IUnknown getVtableInterface() { |
51 | if (m_thunk_ptr == 0) { |
52 | newThunk(); |
53 | } |
54 | return wrapThunk(); |
55 | } |
56 | |
57 | private void newThunk() { |
58 | m_thunk_ptr = jni_newThunk(m_java_sink, getIfaceClass(), getIID()._getStructureBytes()); |
59 | if (m_thunk_ptr == 0) { |
60 | throw new OutOfMemoryError("Unable to create vtable thunk"); |
61 | } |
62 | } |
63 | private static native long jni_newThunk(IUnknown java_sink, Class interface_class, byte[] iid_bytes); |
64 | |
65 | private IUnknown wrapThunk() { |
66 | assert m_thunk_ptr != 0; |
67 | if (m_thunk_ptr == 0) { |
68 | return null; |
69 | } |
70 | |
71 | InterfaceBuilder ib = new InterfaceBuilder(getIfaceClass()); |
72 | jni_wrapThunk(m_thunk_ptr, ib.getResult()); |
73 | return ib.getResult(); |
74 | } |
75 | private static native void jni_wrapThunk(long thunk_ptr, IUnknown result); |
76 | |
77 | |
78 | /** |
79 | * Should only be called by ComCoClass |
80 | */ |
81 | void deleteThunk() { |
82 | if (m_thunk_ptr == 0) { |
83 | return; |
84 | } |
85 | jni_deleteThunk(m_thunk_ptr); |
86 | } |
87 | private static native void jni_deleteThunk(long thunk_ptr); |
88 | } |