2 * List of components. (for internal use)
4 * Copyright (C) Hidenori TAKESHIMA <hidenori@a2.ctktv.ne.jp>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/obj_base.h"
28 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
31 #include "quartz_private.h"
36 struct QUARTZ_CompList
38 QUARTZ_CompListItem* pFirst;
39 QUARTZ_CompListItem* pLast;
40 CRITICAL_SECTION csList;
43 struct QUARTZ_CompListItem
46 QUARTZ_CompListItem* pNext;
47 QUARTZ_CompListItem* pPrev;
53 QUARTZ_CompList* QUARTZ_CompList_Alloc( void )
55 QUARTZ_CompList* pList;
57 pList = (QUARTZ_CompList*)QUARTZ_AllocMem( sizeof(QUARTZ_CompList) );
64 InitializeCriticalSection( &pList->csList );
70 void QUARTZ_CompList_Free( QUARTZ_CompList* pList )
72 QUARTZ_CompListItem* pCur;
73 QUARTZ_CompListItem* pNext;
78 while ( pCur != NULL )
81 if ( pCur->punk != NULL )
82 IUnknown_Release( pCur->punk );
83 if ( pCur->pvData != NULL )
84 QUARTZ_FreeMem( pCur->pvData );
85 QUARTZ_FreeMem( pCur );
89 DeleteCriticalSection( &pList->csList );
91 QUARTZ_FreeMem( pList );
95 void QUARTZ_CompList_Lock( QUARTZ_CompList* pList )
97 EnterCriticalSection( &pList->csList );
100 void QUARTZ_CompList_Unlock( QUARTZ_CompList* pList )
102 LeaveCriticalSection( &pList->csList );
105 QUARTZ_CompList* QUARTZ_CompList_Dup(
106 const QUARTZ_CompList* pList, BOOL fDupData )
108 QUARTZ_CompList* pNewList;
109 const QUARTZ_CompListItem* pCur;
112 pNewList = QUARTZ_CompList_Alloc();
113 if ( pNewList == NULL )
116 pCur = pList->pFirst;
117 while ( pCur != NULL )
119 if ( pCur->punk != NULL )
122 hr = QUARTZ_CompList_AddComp(
123 pNewList, pCur->punk,
124 pCur->pvData, pCur->dwDataLen );
126 hr = QUARTZ_CompList_AddComp(
127 pNewList, pCur->punk, NULL, 0 );
130 QUARTZ_CompList_Free( pNewList );
140 static QUARTZ_CompListItem* QUARTZ_CompList_AllocComp(
141 QUARTZ_CompList* pList, IUnknown* punk,
142 const void* pvData, DWORD dwDataLen )
144 QUARTZ_CompListItem* pItem;
146 pItem = (QUARTZ_CompListItem*)QUARTZ_AllocMem( sizeof(QUARTZ_CompListItem) );
150 pItem->pvData = NULL;
151 pItem->dwDataLen = 0;
152 if ( pvData != NULL )
154 pItem->pvData = (void*)QUARTZ_AllocMem( dwDataLen );
155 if ( pItem->pvData == NULL )
157 QUARTZ_FreeMem( pItem );
160 memcpy( pItem->pvData, pvData, dwDataLen );
161 pItem->dwDataLen = dwDataLen;
164 pItem->punk = punk; IUnknown_AddRef(punk);
169 HRESULT QUARTZ_CompList_AddComp(
170 QUARTZ_CompList* pList, IUnknown* punk,
171 const void* pvData, DWORD dwDataLen )
173 QUARTZ_CompListItem* pItem;
175 pItem = QUARTZ_CompList_AllocComp( pList, punk, pvData, dwDataLen );
177 return E_OUTOFMEMORY;
179 if ( pList->pFirst != NULL )
180 pList->pFirst->pPrev = pItem;
182 pList->pLast = pItem;
183 pItem->pNext = pList->pFirst;
184 pList->pFirst = pItem;
190 HRESULT QUARTZ_CompList_AddTailComp(
191 QUARTZ_CompList* pList, IUnknown* punk,
192 const void* pvData, DWORD dwDataLen )
194 QUARTZ_CompListItem* pItem;
196 pItem = QUARTZ_CompList_AllocComp( pList, punk, pvData, dwDataLen );
198 return E_OUTOFMEMORY;
200 if ( pList->pLast != NULL )
201 pList->pLast->pNext = pItem;
203 pList->pFirst = pItem;
204 pItem->pPrev = pList->pLast;
205 pList->pLast = pItem;
211 HRESULT QUARTZ_CompList_RemoveComp( QUARTZ_CompList* pList, IUnknown* punk )
213 QUARTZ_CompListItem* pCur;
215 pCur = QUARTZ_CompList_SearchComp( pList, punk );
217 return S_FALSE; /* already removed. */
219 /* remove from list. */
220 if ( pCur->pNext != NULL )
221 pCur->pNext->pPrev = pCur->pPrev;
223 pList->pLast = pCur->pPrev;
224 if ( pCur->pPrev != NULL )
225 pCur->pPrev->pNext = pCur->pNext;
227 pList->pFirst = pCur->pNext;
229 /* release this item. */
230 if ( pCur->punk != NULL )
231 IUnknown_Release( pCur->punk );
232 if ( pCur->pvData != NULL )
233 QUARTZ_FreeMem( pCur->pvData );
234 QUARTZ_FreeMem( pCur );
239 QUARTZ_CompListItem* QUARTZ_CompList_SearchComp(
240 QUARTZ_CompList* pList, IUnknown* punk )
242 QUARTZ_CompListItem* pCur;
244 pCur = pList->pFirst;
245 while ( pCur != NULL )
247 if ( pCur->punk == punk )
255 QUARTZ_CompListItem* QUARTZ_CompList_SearchData(
256 QUARTZ_CompList* pList, const void* pvData, DWORD dwDataLen )
258 QUARTZ_CompListItem* pCur;
260 pCur = pList->pFirst;
261 while ( pCur != NULL )
263 if ( pCur->dwDataLen == dwDataLen &&
264 !memcmp( pCur->pvData, pvData, dwDataLen ) )
272 QUARTZ_CompListItem* QUARTZ_CompList_GetFirst(
273 QUARTZ_CompList* pList )
275 return pList->pFirst;
278 QUARTZ_CompListItem* QUARTZ_CompList_GetLast(
279 QUARTZ_CompList* pList )
284 QUARTZ_CompListItem* QUARTZ_CompList_GetNext(
285 QUARTZ_CompList* pList, QUARTZ_CompListItem* pPrev )
290 QUARTZ_CompListItem* QUARTZ_CompList_GetPrev(
291 QUARTZ_CompList* pList, QUARTZ_CompListItem* pNext )
296 IUnknown* QUARTZ_CompList_GetItemPtr( QUARTZ_CompListItem* pItem )
301 const void* QUARTZ_CompList_GetDataPtr( QUARTZ_CompListItem* pItem )
303 return pItem->pvData;
306 DWORD QUARTZ_CompList_GetDataLength( QUARTZ_CompListItem* pItem )
308 return pItem->dwDataLen;