| 1 | /* |
| 2 | * $Id: IGlobalInterfaceTable.java,v 1.3 2004/06/16 20:27:28 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 | |
| 13 | package com.moesol.bindings.platform_sdk.component_services; |
| 14 | |
| 15 | /** |
| 16 | * @author Adam |
| 17 | * |
| 18 | * To change the template for this generated type comment go to |
| 19 | * Window>Preferences>Java>Code Generation>Code and Comments |
| 20 | */ |
| 21 | public class IGlobalInterfaceTable extends IUnknown.Jni { |
| 22 | |
| 23 | // 00000323-0000-0000-C000-000000000046 |
| 24 | private static final GUID CLSID_StdGlobalInterfaceTable = new GUID( |
| 25 | 0x00000323, (short)0x0000, (short)0x0000, |
| 26 | new byte[] { |
| 27 | (byte)0xC0, (byte)0x00, |
| 28 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x46 |
| 29 | } ); |
| 30 | |
| 31 | // 00000146-0000-0000-C000-000000000046 |
| 32 | public static final GUID IID = new GUID( |
| 33 | 0x00000146, (short)0x0000, (short)0x0000, |
| 34 | new byte[] { |
| 35 | (byte)0xC0, (byte)0x00, |
| 36 | (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x46 |
| 37 | } ); |
| 38 | |
| 39 | public GUID getIID(){ |
| 40 | return IGlobalInterfaceTable.IID; |
| 41 | } |
| 42 | |
| 43 | private IGlobalInterfaceTable () { |
| 44 | } |
| 45 | |
| 46 | public static IGlobalInterfaceTable instance() { |
| 47 | if (singleton == null) { |
| 48 | IGlobalInterfaceTable[] outGIT = { null }; |
| 49 | OleThread.oleInitialize(); |
| 50 | COM.CoCreateInstance( |
| 51 | CLSID_StdGlobalInterfaceTable, |
| 52 | null, |
| 53 | COM.CLSCTX_ALL, |
| 54 | outGIT); |
| 55 | singleton = outGIT[0]; |
| 56 | } |
| 57 | return singleton; |
| 58 | } |
| 59 | |
| 60 | public static boolean isCreated() { |
| 61 | return singleton != null; |
| 62 | } |
| 63 | |
| 64 | public int _spoofRelease(){ |
| 65 | return super.Release(); |
| 66 | } |
| 67 | |
| 68 | public int RegisterInterfaceInGlobal(IUnknown iface) { |
| 69 | int hr = 0; |
| 70 | int[] outCookie = { 0 }; |
| 71 | |
| 72 | hr = |
| 73 | jni_RegisterInterfaceInGlobal( |
| 74 | iface, |
| 75 | COM.extractIID(iface)._getStructureBytes(), |
| 76 | outCookie); |
| 77 | if (HRESULT.FAILED(hr)) { |
| 78 | throw new COMException(hr); |
| 79 | } |
| 80 | return outCookie[0]; |
| 81 | } |
| 82 | |
| 83 | public void RevokeInterfaceFromGlobal(int cookie){ |
| 84 | int hr = jni_RevokeInterfaceFromGlobal(cookie); |
| 85 | if (HRESULT.FAILED(hr)) { |
| 86 | throw new COMException(hr); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | public void GetInterfaceFromGlobal(int cookie, Object [] outIFace){ |
| 91 | int hr = 0; |
| 92 | InterfaceBuilder ib = new InterfaceBuilder(outIFace); |
| 93 | hr = jni_GetInterfaceFromGlobal(cookie, ib.getIIDBytes(), ib.getResult()); |
| 94 | if(HRESULT.FAILED(hr)){ |
| 95 | throw new COMException(hr); |
| 96 | } |
| 97 | outIFace[0] = ib.getResult(); |
| 98 | } |
| 99 | |
| 100 | public int Release(){ |
| 101 | throw new RuntimeException("IGlobalInterfaceTable is a singleton, " + |
| 102 | "call IGlobalInterfaceTable.ReleaseInstance instead of iGITRef.Release()."); |
| 103 | } |
| 104 | |
| 105 | private native int jni_RevokeInterfaceFromGlobal(int cookie); |
| 106 | private native int jni_RegisterInterfaceInGlobal( IUnknown toRegister, byte [] iid, int [] outCookie); |
| 107 | private native int jni_GetInterfaceFromGlobal(int cookie, byte [] nativeBytes, IUnknown result); |
| 108 | |
| 109 | private boolean released = false; |
| 110 | private static IGlobalInterfaceTable singleton = null; |
| 111 | } |
| 112 | |