| 1 | /* |
| 2 | * $Id: ComIUnknownOuter.java,v 1.1 2005/12/03 08:14:40 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 | import java.nio.ByteBuffer; |
| 15 | |
| 16 | /** |
| 17 | * Implements ComIUnknown by delegating to an actual "outer" native IUnknown. |
| 18 | * When we are aggregated we use this class to link lifespan and QueryInterface |
| 19 | * control to the "outer" COM server. |
| 20 | * |
| 21 | * @author Hastings |
| 22 | */ |
| 23 | class ComIUnknownOuter implements ComIUnknown { |
| 24 | private final long m_iface_ptr; |
| 25 | |
| 26 | public ComIUnknownOuter(IUnknown unk) { |
| 27 | m_iface_ptr = jni_ctor(unk); |
| 28 | } |
| 29 | |
| 30 | public IUnknown queryInterface(GUID iid) { |
| 31 | InterfaceBuilder ib = new InterfaceBuilder(IUnknown.class); |
| 32 | int hr = jni_QueryInterface(m_iface_ptr, iid.getByteBuffer(), ib.getResult()); |
| 33 | if (HRESULT.FAILED(hr)) { |
| 34 | throw new COMException(hr); |
| 35 | } |
| 36 | return ib.getResult(); |
| 37 | } |
| 38 | |
| 39 | public long addRef() { |
| 40 | return jni_AddRef(m_iface_ptr); |
| 41 | } |
| 42 | |
| 43 | public long release() { |
| 44 | return jni_Release(m_iface_ptr); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Take over all of the {@code m_unknown_support} pointers |
| 49 | * except @{code inner}. See the graph in the Reverse COM |
| 50 | * design guide. |
| 51 | * |
| 52 | * @param inner |
| 53 | */ |
| 54 | public void aggregate(ComObject inner) { |
| 55 | ComIUnknownImpl inner_unk_impl = (ComIUnknownImpl)inner.m_iunknown_support; // save |
| 56 | inner_unk_impl.linkTo(this); |
| 57 | inner.m_iunknown_support = inner_unk_impl; // restore |
| 58 | } |
| 59 | |
| 60 | private static native long jni_ctor(IUnknown unk); |
| 61 | private static native int jni_QueryInterface(long ptr, ByteBuffer bb_iid, IUnknown result); |
| 62 | private static native long jni_AddRef(long ptr); |
| 63 | private static native long jni_Release(long ptr); |
| 64 | } |