2 * List of components. (for internal use)
4 * hidenori@a2.ctktv.ne.jp
12 #include "wine/obj_base.h"
14 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(quartz
);
17 #include "quartz_private.h"
22 struct QUARTZ_CompList
24 QUARTZ_CompListItem
* pFirst
;
25 QUARTZ_CompListItem
* pLast
;
26 CRITICAL_SECTION csList
;
29 struct QUARTZ_CompListItem
32 QUARTZ_CompListItem
* pNext
;
33 QUARTZ_CompListItem
* pPrev
;
39 QUARTZ_CompList
* QUARTZ_CompList_Alloc( void )
41 QUARTZ_CompList
* pList
;
43 pList
= (QUARTZ_CompList
*)QUARTZ_AllocMem( sizeof(QUARTZ_CompList
) );
50 InitializeCriticalSection( &pList
->csList
);
56 void QUARTZ_CompList_Free( QUARTZ_CompList
* pList
)
58 QUARTZ_CompListItem
* pCur
;
59 QUARTZ_CompListItem
* pNext
;
64 while ( pCur
!= NULL
)
67 if ( pCur
->punk
!= NULL
)
68 IUnknown_Release( pCur
->punk
);
69 if ( pCur
->pvData
!= NULL
)
70 QUARTZ_FreeMem( pCur
->pvData
);
71 QUARTZ_FreeMem( pCur
);
75 DeleteCriticalSection( &pList
->csList
);
77 QUARTZ_FreeMem( pList
);
81 void QUARTZ_CompList_Lock( QUARTZ_CompList
* pList
)
83 EnterCriticalSection( &pList
->csList
);
86 void QUARTZ_CompList_Unlock( QUARTZ_CompList
* pList
)
88 LeaveCriticalSection( &pList
->csList
);
91 QUARTZ_CompList
* QUARTZ_CompList_Dup(
92 const QUARTZ_CompList
* pList
, BOOL fDupData
)
94 QUARTZ_CompList
* pNewList
;
95 const QUARTZ_CompListItem
* pCur
;
98 pNewList
= QUARTZ_CompList_Alloc();
99 if ( pNewList
== NULL
)
102 pCur
= pList
->pFirst
;
103 while ( pCur
!= NULL
)
105 if ( pCur
->punk
!= NULL
)
108 hr
= QUARTZ_CompList_AddComp(
109 pNewList
, pCur
->punk
,
110 pCur
->pvData
, pCur
->dwDataLen
);
112 hr
= QUARTZ_CompList_AddComp(
113 pNewList
, pCur
->punk
, NULL
, 0 );
116 QUARTZ_CompList_Free( pNewList
);
126 static QUARTZ_CompListItem
* QUARTZ_CompList_AllocComp(
127 QUARTZ_CompList
* pList
, IUnknown
* punk
,
128 const void* pvData
, DWORD dwDataLen
)
130 QUARTZ_CompListItem
* pItem
;
132 pItem
= (QUARTZ_CompListItem
*)QUARTZ_AllocMem( sizeof(QUARTZ_CompListItem
) );
136 pItem
->pvData
= NULL
;
137 pItem
->dwDataLen
= 0;
138 if ( pvData
!= NULL
)
140 pItem
->pvData
= (void*)QUARTZ_AllocMem( dwDataLen
);
141 if ( pItem
->pvData
== NULL
)
143 QUARTZ_FreeMem( pItem
);
146 memcpy( pItem
->pvData
, pvData
, dwDataLen
);
147 pItem
->dwDataLen
= dwDataLen
;
150 pItem
->punk
= punk
; IUnknown_AddRef(punk
);
155 HRESULT
QUARTZ_CompList_AddComp(
156 QUARTZ_CompList
* pList
, IUnknown
* punk
,
157 const void* pvData
, DWORD dwDataLen
)
159 QUARTZ_CompListItem
* pItem
;
161 pItem
= QUARTZ_CompList_AllocComp( pList
, punk
, pvData
, dwDataLen
);
163 return E_OUTOFMEMORY
;
165 if ( pList
->pFirst
!= NULL
)
166 pList
->pFirst
->pPrev
= pItem
;
168 pList
->pLast
= pItem
;
169 pItem
->pNext
= pList
->pFirst
;
170 pList
->pFirst
= pItem
;
176 HRESULT
QUARTZ_CompList_AddTailComp(
177 QUARTZ_CompList
* pList
, IUnknown
* punk
,
178 const void* pvData
, DWORD dwDataLen
)
180 QUARTZ_CompListItem
* pItem
;
182 pItem
= QUARTZ_CompList_AllocComp( pList
, punk
, pvData
, dwDataLen
);
184 return E_OUTOFMEMORY
;
186 if ( pList
->pLast
!= NULL
)
187 pList
->pLast
->pNext
= pItem
;
189 pList
->pFirst
= pItem
;
190 pItem
->pPrev
= pList
->pLast
;
191 pList
->pLast
= pItem
;
197 HRESULT
QUARTZ_CompList_RemoveComp( QUARTZ_CompList
* pList
, IUnknown
* punk
)
199 QUARTZ_CompListItem
* pCur
;
201 pCur
= QUARTZ_CompList_SearchComp( pList
, punk
);
203 return S_FALSE
; /* already removed. */
205 /* remove from list. */
206 if ( pCur
->pNext
!= NULL
)
207 pCur
->pNext
->pPrev
= pCur
->pPrev
;
209 pList
->pLast
= pCur
->pPrev
;
210 if ( pCur
->pPrev
!= NULL
)
211 pCur
->pPrev
->pNext
= pCur
->pNext
;
213 pList
->pFirst
= pCur
->pNext
;
215 /* release this item. */
216 if ( pCur
->punk
!= NULL
)
217 IUnknown_Release( pCur
->punk
);
218 if ( pCur
->pvData
!= NULL
)
219 QUARTZ_FreeMem( pCur
->pvData
);
220 QUARTZ_FreeMem( pCur
);
225 QUARTZ_CompListItem
* QUARTZ_CompList_SearchComp(
226 QUARTZ_CompList
* pList
, IUnknown
* punk
)
228 QUARTZ_CompListItem
* pCur
;
230 pCur
= pList
->pFirst
;
231 while ( pCur
!= NULL
)
233 if ( pCur
->punk
== punk
)
241 QUARTZ_CompListItem
* QUARTZ_CompList_SearchData(
242 QUARTZ_CompList
* pList
, const void* pvData
, DWORD dwDataLen
)
244 QUARTZ_CompListItem
* pCur
;
246 pCur
= pList
->pFirst
;
247 while ( pCur
!= NULL
)
249 if ( pCur
->dwDataLen
== dwDataLen
&&
250 !memcmp( pCur
->pvData
, pvData
, dwDataLen
) )
258 QUARTZ_CompListItem
* QUARTZ_CompList_GetFirst(
259 QUARTZ_CompList
* pList
)
261 return pList
->pFirst
;
264 QUARTZ_CompListItem
* QUARTZ_CompList_GetLast(
265 QUARTZ_CompList
* pList
)
270 QUARTZ_CompListItem
* QUARTZ_CompList_GetNext(
271 QUARTZ_CompList
* pList
, QUARTZ_CompListItem
* pPrev
)
276 QUARTZ_CompListItem
* QUARTZ_CompList_GetPrev(
277 QUARTZ_CompList
* pList
, QUARTZ_CompListItem
* pNext
)
282 IUnknown
* QUARTZ_CompList_GetItemPtr( QUARTZ_CompListItem
* pItem
)
287 const void* QUARTZ_CompList_GetDataPtr( QUARTZ_CompListItem
* pItem
)
289 return pItem
->pvData
;
292 DWORD
QUARTZ_CompList_GetDataLength( QUARTZ_CompListItem
* pItem
)
294 return pItem
->dwDataLen
;