2 * List of components. (for internal use)
4 * hidenori@a2.ctktv.ne.jp
14 #include "wine/obj_base.h"
17 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(quartz
);
20 #include "quartz_private.h"
25 struct QUARTZ_CompList
27 QUARTZ_CompListItem
* pFirst
;
28 QUARTZ_CompListItem
* pLast
;
29 CRITICAL_SECTION csList
;
32 struct QUARTZ_CompListItem
35 QUARTZ_CompListItem
* pNext
;
36 QUARTZ_CompListItem
* pPrev
;
42 QUARTZ_CompList
* QUARTZ_CompList_Alloc( void )
44 QUARTZ_CompList
* pList
;
46 pList
= (QUARTZ_CompList
*)QUARTZ_AllocMem( sizeof(QUARTZ_CompList
) );
53 InitializeCriticalSection( &pList
->csList
);
59 void QUARTZ_CompList_Free( QUARTZ_CompList
* pList
)
61 QUARTZ_CompListItem
* pCur
;
62 QUARTZ_CompListItem
* pNext
;
67 while ( pCur
!= NULL
)
70 if ( pCur
->punk
!= NULL
)
71 IUnknown_Release( pCur
->punk
);
72 if ( pCur
->pvData
!= NULL
)
73 QUARTZ_FreeMem( pCur
->pvData
);
74 QUARTZ_FreeMem( pCur
);
78 DeleteCriticalSection( &pList
->csList
);
80 QUARTZ_FreeMem( pList
);
84 void QUARTZ_CompList_Lock( QUARTZ_CompList
* pList
)
86 EnterCriticalSection( &pList
->csList
);
89 void QUARTZ_CompList_Unlock( QUARTZ_CompList
* pList
)
91 LeaveCriticalSection( &pList
->csList
);
94 QUARTZ_CompList
* QUARTZ_CompList_Dup(
95 const QUARTZ_CompList
* pList
, BOOL fDupData
)
97 QUARTZ_CompList
* pNewList
;
98 const QUARTZ_CompListItem
* pCur
;
101 pNewList
= QUARTZ_CompList_Alloc();
102 if ( pNewList
== NULL
)
105 pCur
= pList
->pFirst
;
106 while ( pCur
!= NULL
)
108 if ( pCur
->punk
!= NULL
)
111 hr
= QUARTZ_CompList_AddComp(
112 pNewList
, pCur
->punk
,
113 pCur
->pvData
, pCur
->dwDataLen
);
115 hr
= QUARTZ_CompList_AddComp(
116 pNewList
, pCur
->punk
, NULL
, 0 );
119 QUARTZ_CompList_Free( pNewList
);
129 HRESULT
QUARTZ_CompList_AddComp(
130 QUARTZ_CompList
* pList
, IUnknown
* punk
,
131 const void* pvData
, DWORD dwDataLen
)
133 QUARTZ_CompListItem
* pItem
;
135 pItem
= (QUARTZ_CompListItem
*)QUARTZ_AllocMem( sizeof(QUARTZ_CompListItem
) );
137 return E_OUTOFMEMORY
; /* out of memory. */
139 pItem
->pvData
= NULL
;
140 pItem
->dwDataLen
= 0;
141 if ( pvData
!= NULL
)
143 pItem
->pvData
= (void*)QUARTZ_AllocMem( dwDataLen
);
144 if ( pItem
->pvData
== NULL
)
146 QUARTZ_FreeMem( pItem
);
147 return E_OUTOFMEMORY
;
149 memcpy( pItem
->pvData
, pvData
, dwDataLen
);
150 pItem
->dwDataLen
= dwDataLen
;
153 pItem
->punk
= punk
; IUnknown_AddRef(punk
);
155 if ( pList
->pFirst
!= NULL
)
156 pList
->pFirst
->pPrev
= pItem
;
158 pList
->pLast
= pItem
;
159 pItem
->pNext
= pList
->pFirst
;
160 pList
->pFirst
= pItem
;
166 HRESULT
QUARTZ_CompList_RemoveComp( QUARTZ_CompList
* pList
, IUnknown
* punk
)
168 QUARTZ_CompListItem
* pCur
;
170 pCur
= QUARTZ_CompList_SearchComp( pList
, punk
);
172 return S_FALSE
; /* already removed. */
174 /* remove from list. */
175 if ( pCur
->pNext
!= NULL
)
176 pCur
->pNext
->pPrev
= pCur
->pPrev
;
178 pList
->pLast
= pCur
->pPrev
;
179 if ( pCur
->pPrev
!= NULL
)
180 pCur
->pPrev
->pNext
= pCur
->pNext
;
182 pList
->pFirst
= pCur
->pNext
;
184 /* release this item. */
185 if ( pCur
->punk
!= NULL
)
186 IUnknown_Release( pCur
->punk
);
187 if ( pCur
->pvData
!= NULL
)
188 QUARTZ_FreeMem( pCur
->pvData
);
189 QUARTZ_FreeMem( pCur
);
194 QUARTZ_CompListItem
* QUARTZ_CompList_SearchComp(
195 QUARTZ_CompList
* pList
, IUnknown
* punk
)
197 QUARTZ_CompListItem
* pCur
;
199 pCur
= pList
->pFirst
;
200 while ( pCur
!= NULL
)
202 if ( pCur
->punk
== punk
)
210 QUARTZ_CompListItem
* QUARTZ_CompList_SearchData(
211 QUARTZ_CompList
* pList
, const void* pvData
, DWORD dwDataLen
)
213 QUARTZ_CompListItem
* pCur
;
215 pCur
= pList
->pFirst
;
216 while ( pCur
!= NULL
)
218 if ( pCur
->dwDataLen
== dwDataLen
&&
219 !memcmp( pCur
->pvData
, pvData
, dwDataLen
) )
227 QUARTZ_CompListItem
* QUARTZ_CompList_GetFirst(
228 QUARTZ_CompList
* pList
)
230 return pList
->pFirst
;
233 QUARTZ_CompListItem
* QUARTZ_CompList_GetNext(
234 QUARTZ_CompList
* pList
, QUARTZ_CompListItem
* pPrev
)
239 IUnknown
* QUARTZ_CompList_GetItemPtr( QUARTZ_CompListItem
* pItem
)
244 const void* QUARTZ_CompList_GetDataPtr( QUARTZ_CompListItem
* pItem
)
246 return pItem
->pvData
;
249 DWORD
QUARTZ_CompList_GetDataLength( QUARTZ_CompListItem
* pItem
)
251 return pItem
->dwDataLen
;