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/main.c

    r6649 r6710  
    1 /* $Id: main.c,v 1.3 2001-09-05 13:36:37 bird Exp $ */
    2 
    31#include "config.h"
    42
     
    2018#include "sysclock.h"
    2119#include "memalloc.h"
     20#include "devenum.h"
     21#include "fmap.h"
     22#include "fmap2.h"
     23#include "seekpass.h"
    2224
    2325
    2426typedef struct QUARTZ_CLASSENTRY
    2527{
    26     const CLSID*    pclsid;
    27     QUARTZ_pCreateIUnknown  pCreateIUnk;
     28        const CLSID*    pclsid;
     29        QUARTZ_pCreateIUnknown  pCreateIUnk;
    2830} QUARTZ_CLASSENTRY;
    2931
     
    3840static ICOM_VTABLE(IClassFactory) iclassfact =
    3941{
    40     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
    41     IClassFactory_fnQueryInterface,
    42     IClassFactory_fnAddRef,
    43     IClassFactory_fnRelease,
    44     IClassFactory_fnCreateInstance,
    45     IClassFactory_fnLockServer
     42        ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
     43        IClassFactory_fnQueryInterface,
     44        IClassFactory_fnAddRef,
     45        IClassFactory_fnRelease,
     46        IClassFactory_fnCreateInstance,
     47        IClassFactory_fnLockServer
    4648};
    4749
    4850typedef struct
    4951{
    50     /* IUnknown fields */
    51     ICOM_VFIELD(IClassFactory);
    52     DWORD   ref;
    53     /* IClassFactory fields */
    54     const QUARTZ_CLASSENTRY* pEntry;
     52        /* IUnknown fields */
     53        ICOM_VFIELD(IClassFactory);
     54        LONG    ref;
     55        /* IClassFactory fields */
     56        const QUARTZ_CLASSENTRY* pEntry;
    5557} IClassFactoryImpl;
    5658
    5759static const QUARTZ_CLASSENTRY QUARTZ_ClassList[] =
    5860{
    59     { &CLSID_FilterGraph, &QUARTZ_CreateFilterGraph },
    60     { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
    61     { &CLSID_MemoryAllocator, &QUARTZ_CreateMemoryAllocator },
    62     { NULL, NULL },
     61        { &CLSID_FilterGraph, &QUARTZ_CreateFilterGraph },
     62        { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
     63        { &CLSID_MemoryAllocator, &QUARTZ_CreateMemoryAllocator },
     64        { &CLSID_SystemDeviceEnum, &QUARTZ_CreateSystemDeviceEnum },
     65        { &CLSID_FilterMapper, &QUARTZ_CreateFilterMapper },
     66        { &CLSID_FilterMapper2, &QUARTZ_CreateFilterMapper2 },
     67        { &CLSID_SeekingPassThru, &QUARTZ_CreateSeekingPassThru },
     68        { NULL, NULL },
    6369};
    6470
     
    7076void* QUARTZ_AllocObj( DWORD dwSize )
    7177{
    72     void*   pv;
    73 
    74     EnterCriticalSection( &csHeap );
    75     dwClassObjRef ++;
    76     pv = HeapAlloc( hDLLHeap, 0, dwSize );
    77     if ( pv == NULL )
    78         dwClassObjRef --;
    79     LeaveCriticalSection( &csHeap );
    80 
    81     return pv;
     78        void*   pv;
     79
     80        EnterCriticalSection( &csHeap );
     81        dwClassObjRef ++;
     82        pv = HeapAlloc( hDLLHeap, 0, dwSize );
     83        if ( pv == NULL )
     84                dwClassObjRef --;
     85        LeaveCriticalSection( &csHeap );
     86
     87        return pv;
    8288}
    8389
    8490void QUARTZ_FreeObj( void* pobj )
    8591{
    86     EnterCriticalSection( &csHeap );
    87     HeapFree( hDLLHeap, 0, pobj );
    88     dwClassObjRef --;
    89     LeaveCriticalSection( &csHeap );
     92        EnterCriticalSection( &csHeap );
     93        HeapFree( hDLLHeap, 0, pobj );
     94        dwClassObjRef --;
     95        LeaveCriticalSection( &csHeap );
    9096}
    9197
    9298void* QUARTZ_AllocMem( DWORD dwSize )
    9399{
    94     return HeapAlloc( hDLLHeap, 0, dwSize );
     100        return HeapAlloc( hDLLHeap, 0, dwSize );
    95101}
    96102
    97103void QUARTZ_FreeMem( void* pMem )
    98104{
    99     HeapFree( hDLLHeap, 0, pMem );
     105        HeapFree( hDLLHeap, 0, pMem );
    100106}
    101107
     
    105111IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
    106112{
    107     ICOM_THIS(IClassFactoryImpl,iface);
    108 
    109     TRACE("(%p)->(%p,%p)\n",This,riid,ppobj);
    110     if ( ( IsEqualGUID( &IID_IUnknown, riid ) ) ||
    111          ( IsEqualGUID( &IID_IClassFactory, riid ) ) )
    112     {
    113         *ppobj = iface;
    114         IClassFactory_AddRef(iface);
    115         return S_OK;
    116     }
    117 
    118     return E_NOINTERFACE;
     113        ICOM_THIS(IClassFactoryImpl,iface);
     114
     115        TRACE("(%p)->(%p,%p)\n",This,riid,ppobj);
     116        if ( ( IsEqualGUID( &IID_IUnknown, riid ) ) ||
     117             ( IsEqualGUID( &IID_IClassFactory, riid ) ) )
     118        {
     119                *ppobj = iface;
     120                IClassFactory_AddRef(iface);
     121                return S_OK;
     122        }
     123
     124        return E_NOINTERFACE;
    119125}
    120126
    121127static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
    122128{
    123     ICOM_THIS(IClassFactoryImpl,iface);
    124 
    125     TRACE("(%p)->()\n",This);
    126 
    127     return ++(This->ref);
     129        ICOM_THIS(IClassFactoryImpl,iface);
     130
     131        TRACE("(%p)->()\n",This);
     132
     133        return InterlockedExchangeAdd(&(This->ref),1) + 1;
    128134}
    129135
    130136static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
    131137{
    132     ICOM_THIS(IClassFactoryImpl,iface);
    133 
    134     TRACE("(%p)->()\n",This);
    135     if ( (--(This->ref)) > 0 )
    136         return This->ref;
    137 
    138     QUARTZ_FreeObj(This);
    139     return 0;
     138        ICOM_THIS(IClassFactoryImpl,iface);
     139        LONG    ref;
     140
     141        TRACE("(%p)->()\n",This);
     142        ref = InterlockedExchangeAdd(&(This->ref),-1) - 1;
     143        if ( ref > 0 )
     144                return (ULONG)ref;
     145
     146        QUARTZ_FreeObj(This);
     147        return 0;
    140148}
    141149
    142150static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj)
    143151{
    144     ICOM_THIS(IClassFactoryImpl,iface);
    145     HRESULT hr;
    146     IUnknown*   punk;
    147 
    148     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
    149 
    150     if ( ppobj == NULL )
    151         return E_POINTER;
    152     if ( pOuter != NULL && !IsEqualGUID( riid, &IID_IUnknown ) )
    153         return CLASS_E_NOAGGREGATION;
    154 
    155     *ppobj = NULL;
    156 
    157     hr = (*This->pEntry->pCreateIUnk)(pOuter,(void**)&punk);
    158     if ( hr != S_OK )
    159         return hr;
    160 
    161     hr = IUnknown_QueryInterface(punk,riid,ppobj);
    162     IUnknown_Release(punk);
    163 
    164     return hr;
     152        ICOM_THIS(IClassFactoryImpl,iface);
     153        HRESULT hr;
     154        IUnknown*       punk;
     155
     156        TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
     157
     158        if ( ppobj == NULL )
     159                return E_POINTER;
     160        if ( pOuter != NULL && !IsEqualGUID( riid, &IID_IUnknown ) )
     161                return CLASS_E_NOAGGREGATION;
     162
     163        *ppobj = NULL;
     164
     165        hr = (*This->pEntry->pCreateIUnk)(pOuter,(void**)&punk);
     166        if ( hr != S_OK )
     167                return hr;
     168
     169        hr = IUnknown_QueryInterface(punk,riid,ppobj);
     170        IUnknown_Release(punk);
     171
     172        return hr;
    165173}
    166174
    167175static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
    168176{
    169     ICOM_THIS(IClassFactoryImpl,iface);
    170     HRESULT hr;
    171 
    172     FIXME("(%p)->(%d),stub!\n",This,dolock);
    173     if (dolock)
    174         hr = IClassFactory_AddRef(iface);
    175     else
    176         hr = IClassFactory_Release(iface);
    177 
    178     return hr;
     177        ICOM_THIS(IClassFactoryImpl,iface);
     178        HRESULT hr;
     179
     180        TRACE("(%p)->(%d)\n",This,dolock);
     181        if (dolock)
     182                hr = IClassFactory_AddRef(iface);
     183        else
     184                hr = IClassFactory_Release(iface);
     185
     186        return hr;
    179187}
    180188
     
    183191static HRESULT IClassFactory_Alloc( const CLSID* pclsid, void** ppobj )
    184192{
    185     const QUARTZ_CLASSENTRY*    pEntry;
    186     IClassFactoryImpl*  pImpl;
    187 
    188     TRACE( "(%s,%p)\n", debugstr_guid(pclsid), ppobj );
    189 
    190     pEntry = QUARTZ_ClassList;
    191     while ( pEntry->pclsid != NULL )
    192     {
    193         if ( IsEqualGUID( pclsid, pEntry->pclsid ) )
    194             goto found;
    195     }
    196 
    197     return CLASS_E_CLASSNOTAVAILABLE;
     193        const QUARTZ_CLASSENTRY*        pEntry;
     194        IClassFactoryImpl*      pImpl;
     195
     196        TRACE( "(%s,%p)\n", debugstr_guid(pclsid), ppobj );
     197
     198        pEntry = QUARTZ_ClassList;
     199        while ( pEntry->pclsid != NULL )
     200        {
     201                if ( IsEqualGUID( pclsid, pEntry->pclsid ) )
     202                        goto found;
     203                pEntry ++;
     204        }
     205
     206        return CLASS_E_CLASSNOTAVAILABLE;
    198207found:
    199     pImpl = (IClassFactoryImpl*)QUARTZ_AllocObj( sizeof(IClassFactoryImpl) );
    200     if ( pImpl == NULL )
    201         return E_OUTOFMEMORY;
    202 
    203     ICOM_VTBL(pImpl) = &iclassfact;
    204     pImpl->ref = 1;
    205     pImpl->pEntry = pEntry;
    206 
    207     *ppobj = (void*)pImpl;
    208     return S_OK;
    209 }
    210 
    211 
    212 /***********************************************************************
    213  *      QUARTZ_InitProcess (internal)
     208        pImpl = (IClassFactoryImpl*)QUARTZ_AllocObj( sizeof(IClassFactoryImpl) );
     209        if ( pImpl == NULL )
     210                return E_OUTOFMEMORY;
     211
     212        TRACE( "allocated successfully.\n" );
     213
     214        ICOM_VTBL(pImpl) = &iclassfact;
     215        pImpl->ref = 1;
     216        pImpl->pEntry = pEntry;
     217
     218        *ppobj = (void*)pImpl;
     219        return S_OK;
     220}
     221
     222
     223/***********************************************************************
     224 *              QUARTZ_InitProcess (internal)
    214225 */
    215226static BOOL QUARTZ_InitProcess( void )
    216227{
    217     TRACE("()\n");
    218 
    219     dwClassObjRef = 0;
    220     hDLLHeap = (HANDLE)NULL;
    221     InitializeCriticalSection( &csHeap );
    222 
    223     hDLLHeap = HeapCreate( 0, 0x10000, 0 );
    224     if ( hDLLHeap == (HANDLE)NULL )
    225         return FALSE;
    226 
    227     return TRUE;
    228 }
    229 
    230 /***********************************************************************
    231  *      QUARTZ_UninitProcess (internal)
     228        TRACE("()\n");
     229
     230        dwClassObjRef = 0;
     231        hDLLHeap = (HANDLE)NULL;
     232        InitializeCriticalSection( &csHeap );
     233
     234        hDLLHeap = HeapCreate( 0, 0x10000, 0 );
     235        if ( hDLLHeap == (HANDLE)NULL )
     236                return FALSE;
     237
     238        return TRUE;
     239}
     240
     241/***********************************************************************
     242 *              QUARTZ_UninitProcess (internal)
    232243 */
    233244static void QUARTZ_UninitProcess( void )
    234245{
    235     TRACE("()\n");
    236 
    237     if ( dwClassObjRef != 0 )
    238         ERR( "you must release some objects allocated from quartz.\n" );
    239     if ( hDLLHeap != (HANDLE)NULL )
    240     {
    241         HeapDestroy( hDLLHeap );
    242         hDLLHeap = (HANDLE)NULL;
    243     }
    244     DeleteCriticalSection( &csHeap );
    245 }
    246 
    247 /***********************************************************************
    248  *      QUARTZ_DllMain
     246        TRACE("()\n");
     247
     248        if ( dwClassObjRef != 0 )
     249                ERR( "you must release some objects allocated from quartz.\n" );
     250        if ( hDLLHeap != (HANDLE)NULL )
     251        {
     252                HeapDestroy( hDLLHeap );
     253                hDLLHeap = (HANDLE)NULL;
     254        }
     255        DeleteCriticalSection( &csHeap );
     256}
     257
     258/***********************************************************************
     259 *              QUARTZ_DllMain
    249260 */
    250261BOOL WINAPI QUARTZ_DllMain(
    251     HINSTANCE hInstDLL,
    252     DWORD fdwReason,
    253     LPVOID lpvReserved )
    254 {
    255     switch ( fdwReason )
    256     {
    257     case DLL_PROCESS_ATTACH:
    258         if ( !QUARTZ_InitProcess() )
    259             return FALSE;
    260         break;
    261     case DLL_PROCESS_DETACH:
    262         QUARTZ_UninitProcess();
    263         break;
    264     case DLL_THREAD_ATTACH:
    265         break;
    266     case DLL_THREAD_DETACH:
    267         break;
    268     }
    269 
    270     return TRUE;
    271 }
    272 
    273 
    274 /***********************************************************************
    275  *      DllCanUnloadNow (QUARTZ.@)
     262        HINSTANCE hInstDLL,
     263        DWORD fdwReason,
     264        LPVOID lpvReserved )
     265{
     266        switch ( fdwReason )
     267        {
     268        case DLL_PROCESS_ATTACH:
     269                if ( !QUARTZ_InitProcess() )
     270                        return FALSE;
     271                break;
     272        case DLL_PROCESS_DETACH:
     273                QUARTZ_UninitProcess();
     274                break;
     275        case DLL_THREAD_ATTACH:
     276                break;
     277        case DLL_THREAD_DETACH:
     278                break;
     279        }
     280
     281        return TRUE;
     282}
     283
     284
     285/***********************************************************************
     286 *              DllCanUnloadNow (QUARTZ.@)
    276287 *
    277288 * RETURNS
     
    281292HRESULT WINAPI QUARTZ_DllCanUnloadNow(void)
    282293{
    283     HRESULT hr;
    284 
    285     EnterCriticalSection( &csHeap );
    286     hr = ( dwClassObjRef == 0 ) ? S_OK : S_FALSE;
    287     LeaveCriticalSection( &csHeap );
    288 
    289     return hr;
    290 }
    291 
    292 /***********************************************************************
    293  *      DllGetClassObject (QUARTZ.@)
     294        HRESULT hr;
     295
     296        EnterCriticalSection( &csHeap );
     297        hr = ( dwClassObjRef == 0 ) ? S_OK : S_FALSE;
     298        LeaveCriticalSection( &csHeap );
     299
     300        return hr;
     301}
     302
     303/***********************************************************************
     304 *              DllGetClassObject (QUARTZ.@)
    294305 */
    295306HRESULT WINAPI QUARTZ_DllGetClassObject(
    296         const CLSID* pclsid,const IID* piid,void** ppv)
    297 {
    298     *ppv = NULL;
    299     if ( IsEqualCLSID( &IID_IUnknown, piid ) ||
    300          IsEqualCLSID( &IID_IClassFactory, piid ) )
    301     {
    302         return IClassFactory_Alloc( pclsid, ppv );
    303     }
    304 
    305     return CLASS_E_CLASSNOTAVAILABLE;
    306 }
    307 
    308 /***********************************************************************
    309  *      DllRegisterServer (QUARTZ.@)
     307                const CLSID* pclsid,const IID* piid,void** ppv)
     308{
     309        *ppv = NULL;
     310        if ( IsEqualCLSID( &IID_IUnknown, piid ) ||
     311             IsEqualCLSID( &IID_IClassFactory, piid ) )
     312        {
     313                return IClassFactory_Alloc( pclsid, ppv );
     314        }
     315
     316        return CLASS_E_CLASSNOTAVAILABLE;
     317}
     318
     319/***********************************************************************
     320 *              DllRegisterServer (QUARTZ.@)
    310321 */
    311322
    312323HRESULT WINAPI QUARTZ_DllRegisterServer( void )
    313324{
    314     FIXME( "(): stub\n" );
    315     return E_FAIL;
    316 }
    317 
    318 /***********************************************************************
    319  *      DllUnregisterServer (QUARTZ.@)
     325        FIXME( "(): stub\n" );
     326        return E_FAIL;
     327}
     328
     329/***********************************************************************
     330 *              DllUnregisterServer (QUARTZ.@)
    320331 */
    321332
    322333HRESULT WINAPI QUARTZ_DllUnregisterServer( void )
    323334{
    324     FIXME( "(): stub\n" );
    325     return E_FAIL;
    326 }
    327 
     335        FIXME( "(): stub\n" );
     336        return E_FAIL;
     337}
     338
     339
     340
Note: See TracChangeset for help on using the changeset viewer.