Changeset 6710 for trunk/src/quartz/main.c
- Timestamp:
- Sep 15, 2001, 11:28:23 AM (24 years ago)
- 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 3 1 #include "config.h" 4 2 … … 20 18 #include "sysclock.h" 21 19 #include "memalloc.h" 20 #include "devenum.h" 21 #include "fmap.h" 22 #include "fmap2.h" 23 #include "seekpass.h" 22 24 23 25 24 26 typedef struct QUARTZ_CLASSENTRY 25 27 { 26 const CLSID*pclsid;27 QUARTZ_pCreateIUnknownpCreateIUnk;28 const CLSID* pclsid; 29 QUARTZ_pCreateIUnknown pCreateIUnk; 28 30 } QUARTZ_CLASSENTRY; 29 31 … … 38 40 static ICOM_VTABLE(IClassFactory) iclassfact = 39 41 { 40 41 42 43 44 45 42 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 43 IClassFactory_fnQueryInterface, 44 IClassFactory_fnAddRef, 45 IClassFactory_fnRelease, 46 IClassFactory_fnCreateInstance, 47 IClassFactory_fnLockServer 46 48 }; 47 49 48 50 typedef struct 49 51 { 50 51 52 DWORDref;53 54 52 /* IUnknown fields */ 53 ICOM_VFIELD(IClassFactory); 54 LONG ref; 55 /* IClassFactory fields */ 56 const QUARTZ_CLASSENTRY* pEntry; 55 57 } IClassFactoryImpl; 56 58 57 59 static const QUARTZ_CLASSENTRY QUARTZ_ClassList[] = 58 60 { 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 }, 63 69 }; 64 70 … … 70 76 void* QUARTZ_AllocObj( DWORD dwSize ) 71 77 { 72 void*pv;73 74 75 76 77 78 79 80 81 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; 82 88 } 83 89 84 90 void QUARTZ_FreeObj( void* pobj ) 85 91 { 86 87 88 89 92 EnterCriticalSection( &csHeap ); 93 HeapFree( hDLLHeap, 0, pobj ); 94 dwClassObjRef --; 95 LeaveCriticalSection( &csHeap ); 90 96 } 91 97 92 98 void* QUARTZ_AllocMem( DWORD dwSize ) 93 99 { 94 100 return HeapAlloc( hDLLHeap, 0, dwSize ); 95 101 } 96 102 97 103 void QUARTZ_FreeMem( void* pMem ) 98 104 { 99 105 HeapFree( hDLLHeap, 0, pMem ); 100 106 } 101 107 … … 105 111 IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) 106 112 { 107 108 109 110 111 112 113 114 115 116 117 118 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; 119 125 } 120 126 121 127 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface) 122 128 { 123 124 125 126 127 return ++(This->ref);129 ICOM_THIS(IClassFactoryImpl,iface); 130 131 TRACE("(%p)->()\n",This); 132 133 return InterlockedExchangeAdd(&(This->ref),1) + 1; 128 134 } 129 135 130 136 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface) 131 137 { 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; 140 148 } 141 149 142 150 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) 143 151 { 144 145 HRESULThr;146 IUnknown*punk;147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 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; 165 173 } 166 174 167 175 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock) 168 176 { 169 170 HRESULThr;171 172 FIXME("(%p)->(%d),stub!\n",This,dolock);173 174 175 176 177 178 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; 179 187 } 180 188 … … 183 191 static HRESULT IClassFactory_Alloc( const CLSID* pclsid, void** ppobj ) 184 192 { 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; 198 207 found: 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) 214 225 */ 215 226 static BOOL QUARTZ_InitProcess( void ) 216 227 { 217 218 219 220 221 222 223 224 225 226 227 228 } 229 230 /*********************************************************************** 231 * 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) 232 243 */ 233 244 static void QUARTZ_UninitProcess( void ) 234 245 { 235 236 237 238 239 240 241 242 243 244 245 } 246 247 /*********************************************************************** 248 * 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 249 260 */ 250 261 BOOL WINAPI QUARTZ_DllMain( 251 252 253 254 { 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 } 272 273 274 /*********************************************************************** 275 * 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.@) 276 287 * 277 288 * RETURNS … … 281 292 HRESULT WINAPI QUARTZ_DllCanUnloadNow(void) 282 293 { 283 HRESULThr;284 285 286 287 288 289 290 } 291 292 /*********************************************************************** 293 * 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.@) 294 305 */ 295 306 HRESULT WINAPI QUARTZ_DllGetClassObject( 296 297 { 298 299 300 301 302 303 304 305 306 } 307 308 /*********************************************************************** 309 * 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.@) 310 321 */ 311 322 312 323 HRESULT WINAPI QUARTZ_DllRegisterServer( void ) 313 324 { 314 315 316 } 317 318 /*********************************************************************** 319 * 325 FIXME( "(): stub\n" ); 326 return E_FAIL; 327 } 328 329 /*********************************************************************** 330 * DllUnregisterServer (QUARTZ.@) 320 331 */ 321 332 322 333 HRESULT WINAPI QUARTZ_DllUnregisterServer( void ) 323 334 { 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.