Ignore:
Timestamp:
Sep 15, 2001, 11:28:23 AM (24 years ago)
Author:
sandervl
Message:

wine update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/quartz/iunk.c

    r6649 r6710  
    1 /* $Id: iunk.c,v 1.3 2001-09-05 13:36:37 bird Exp $ */
    21/*
    32 * An implementation of IUnknown.
     
    109#include "windef.h"
    1110#include "winerror.h"
     11#include "winbase.h"
    1212#include "wine/obj_base.h"
    1313
     
    2222IUnknown_fnQueryInterface(IUnknown* iface,REFIID riid,LPVOID *ppobj)
    2323{
    24     ICOM_THIS(QUARTZ_IUnkImpl,iface);
    25     size_t  ofs;
    26     DWORD   dwIndex;
     24        ICOM_THIS(QUARTZ_IUnkImpl,iface);
     25        size_t  ofs;
     26        DWORD   dwIndex;
     27        QUARTZ_IFDelegation*    pDelegation;
     28        HRESULT hr;
    2729
    28     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
     30        TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
    2931
    30     if ( ppobj == NULL )
    31         return E_POINTER;
    32     *ppobj = NULL;
     32        if ( ppobj == NULL )
     33                return E_POINTER;
     34        *ppobj = NULL;
    3335
    34     ofs = 0;
     36        ofs = 0;
    3537
    36     if ( IsEqualGUID( &IID_IUnknown, riid ) )
    37     {
    38         TRACE("IID_IUnknown - returns inner object.\n");
    39     }
    40     else
    41     {
    42         for ( dwIndex = 0; dwIndex < This->dwEntries; dwIndex++ )
    43         {
    44             if ( IsEqualGUID( This->pEntries[dwIndex].piid, riid ) )
    45             {
    46                 ofs = This->pEntries[dwIndex].ofsVTPtr;
    47                 break;
    48             }
    49         }
    50         if ( dwIndex == This->dwEntries )
    51         {
    52             FIXME("unknown interface: %s\n",debugstr_guid(riid));
    53             return E_NOINTERFACE;
    54         }
    55     }
     38        if ( IsEqualGUID( &IID_IUnknown, riid ) )
     39        {
     40                TRACE("IID_IUnknown - returns inner object.\n");
     41        }
     42        else
     43        {
     44                for ( dwIndex = 0; dwIndex < This->dwEntries; dwIndex++ )
     45                {
     46                        if ( IsEqualGUID( This->pEntries[dwIndex].piid, riid ) )
     47                        {
     48                                ofs = This->pEntries[dwIndex].ofsVTPtr;
     49                                break;
     50                        }
     51                }
     52                if ( dwIndex == This->dwEntries )
     53                {
     54                        hr = E_NOINTERFACE;
    5655
    57     *ppobj = (LPVOID)(((char*)This) + ofs);
    58     IUnknown_AddRef((IUnknown*)(*ppobj));
     56                        /* delegation */
     57                        pDelegation = This->pDelegationFirst;
     58                        while ( pDelegation != NULL )
     59                        {
     60                                hr = (*pDelegation->pOnQueryInterface)( iface, riid, ppobj );
     61                                if ( hr != E_NOINTERFACE )
     62                                        break;
     63                                pDelegation = pDelegation->pNext;
     64                        }
    5965
    60     return S_OK;
     66                        if ( hr == E_NOINTERFACE )
     67                        {
     68                                FIXME("unknown interface: %s\n",debugstr_guid(riid));
     69                        }
     70
     71                        return hr;
     72                }
     73        }
     74
     75        *ppobj = (LPVOID)(((char*)This) + ofs);
     76        IUnknown_AddRef((IUnknown*)(*ppobj));
     77
     78        return S_OK;
    6179}
    6280
     
    6482IUnknown_fnAddRef(IUnknown* iface)
    6583{
    66     ICOM_THIS(QUARTZ_IUnkImpl,iface);
     84        ICOM_THIS(QUARTZ_IUnkImpl,iface);
    6785
    68     TRACE("(%p)->()\n",This);
     86        TRACE("(%p)->()\n",This);
    6987
    70     return ++(This->ref);
     88        return InterlockedExchangeAdd(&(This->ref),1) + 1;
    7189}
    7290
     
    7492IUnknown_fnRelease(IUnknown* iface)
    7593{
    76     ICOM_THIS(QUARTZ_IUnkImpl,iface);
     94        ICOM_THIS(QUARTZ_IUnkImpl,iface);
     95        LONG    ref;
    7796
    78     TRACE("(%p)->()\n",This);
    79     if ( (--(This->ref)) > 0 )
    80         return This->ref;
     97        TRACE("(%p)->()\n",This);
     98        ref = InterlockedExchangeAdd(&(This->ref),-1) - 1;
     99        if ( ref > 0 )
     100                return (ULONG)ref;
    81101
    82     QUARTZ_FreeObj(This);
     102        if ( This->pOnFinalRelease != NULL )
     103                (*(This->pOnFinalRelease))(iface);
    83104
    84     return 0;
     105        QUARTZ_FreeObj(This);
     106
     107        return 0;
    85108}
    86109
    87110static ICOM_VTABLE(IUnknown) iunknown =
    88111{
    89     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
    90     /* IUnknown fields */
    91     IUnknown_fnQueryInterface,
    92     IUnknown_fnAddRef,
    93     IUnknown_fnRelease,
     112        ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
     113        /* IUnknown fields */
     114        IUnknown_fnQueryInterface,
     115        IUnknown_fnAddRef,
     116        IUnknown_fnRelease,
    94117};
    95118
     
    97120void QUARTZ_IUnkInit( QUARTZ_IUnkImpl* pImpl, IUnknown* punkOuter )
    98121{
    99     TRACE("(%p)\n",pImpl);
     122        TRACE("(%p)\n",pImpl);
    100123
    101     ICOM_VTBL(pImpl) = &iunknown;
    102     pImpl->pEntries = NULL;
    103     pImpl->dwEntries = 0;
    104     pImpl->ref = 1;
    105     pImpl->punkControl = (IUnknown*)pImpl;
     124        ICOM_VTBL(pImpl) = &iunknown;
     125        pImpl->pEntries = NULL;
     126        pImpl->dwEntries = 0;
     127        pImpl->pDelegationFirst = NULL;
     128        pImpl->pOnFinalRelease = NULL;
     129        pImpl->ref = 1;
     130        pImpl->punkControl = (IUnknown*)pImpl;
    106131
    107     /* for delegation. */
    108     if ( punkOuter != NULL )
    109         pImpl->punkControl = punkOuter;
     132        /* for implementing aggregation. */
     133        if ( punkOuter != NULL )
     134                pImpl->punkControl = punkOuter;
    110135}
    111136
     137void QUARTZ_IUnkAddDelegation(
     138        QUARTZ_IUnkImpl* pImpl, QUARTZ_IFDelegation* pDelegation )
     139{
     140        pDelegation->pNext = pImpl->pDelegationFirst;
     141        pImpl->pDelegationFirst = pDelegation;
     142}
     143
Note: See TracChangeset for help on using the changeset viewer.