Changeset 6710 for trunk/src/quartz/complist.c
- Timestamp:
- Sep 15, 2001, 11:28:23 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/quartz/complist.c
r6649 r6710 1 /* $Id: complist.c,v 1.2 2001-09-05 13:36:34 bird Exp $ */2 1 /* 3 2 * List of components. (for internal use) … … 25 24 struct QUARTZ_CompList 26 25 { 27 QUARTZ_CompListItem* pFirst; 28 QUARTZ_CompListItem* pLast; 26 QUARTZ_CompListItem* pFirst; 27 QUARTZ_CompListItem* pLast; 28 CRITICAL_SECTION csList; 29 29 }; 30 30 31 31 struct QUARTZ_CompListItem 32 32 { 33 IUnknown* punk; 34 QUARTZ_CompListItem* pNext; 35 QUARTZ_CompListItem* pPrev; 33 IUnknown* punk; 34 QUARTZ_CompListItem* pNext; 35 QUARTZ_CompListItem* pPrev; 36 void* pvData; 37 DWORD dwDataLen; 36 38 }; 37 39 … … 39 41 QUARTZ_CompList* QUARTZ_CompList_Alloc( void ) 40 42 { 41 QUARTZ_CompList* pList; 42 43 pList = (QUARTZ_CompList*)QUARTZ_AllocMem( sizeof(QUARTZ_CompList) ); 44 if ( pList != NULL ) 45 { 46 /* construct. */ 47 pList->pFirst = NULL; 48 pList->pLast = NULL; 49 } 50 51 return pList; 43 QUARTZ_CompList* pList; 44 45 pList = (QUARTZ_CompList*)QUARTZ_AllocMem( sizeof(QUARTZ_CompList) ); 46 if ( pList != NULL ) 47 { 48 /* construct. */ 49 pList->pFirst = NULL; 50 pList->pLast = NULL; 51 52 InitializeCriticalSection( &pList->csList ); 53 } 54 55 return pList; 52 56 } 53 57 54 58 void QUARTZ_CompList_Free( QUARTZ_CompList* pList ) 55 59 { 56 QUARTZ_CompListItem* pCur; 57 QUARTZ_CompListItem* pNext; 58 59 if ( pList != NULL ) 60 { 61 pCur = pList->pFirst; 62 while ( pCur != NULL ) 63 { 64 pNext = pCur->pNext; 65 if ( pCur->punk != NULL ) 66 IUnknown_Release( pCur->punk ); 67 QUARTZ_FreeMem( pCur ); 68 pCur = pNext; 69 } 70 QUARTZ_FreeMem( pList ); 71 } 72 } 73 74 QUARTZ_CompList* QUARTZ_CompList_Dup( QUARTZ_CompList* pList ) 75 { 76 QUARTZ_CompList* pNewList; 77 QUARTZ_CompListItem* pCur; 78 HRESULT hr; 79 80 pNewList = QUARTZ_CompList_Alloc(); 81 if ( pNewList == NULL ) 82 return NULL; 83 84 pCur = pList->pFirst; 85 while ( pCur != NULL ) 86 { 87 if ( pCur->punk != NULL ) 88 { 89 hr = QUARTZ_CompList_AddComp( pNewList, pCur->punk ); 90 if ( FAILED(hr) ) 91 { 92 QUARTZ_CompList_Free( pNewList ); 93 return NULL; 94 } 95 } 96 pCur = pCur->pNext; 97 } 98 99 return pNewList; 100 } 101 102 HRESULT QUARTZ_CompList_AddComp( QUARTZ_CompList* pList, IUnknown* punk ) 103 { 104 QUARTZ_CompListItem* pItem; 105 106 pItem = (QUARTZ_CompListItem*)QUARTZ_AllocMem( sizeof(QUARTZ_CompListItem) ); 107 if ( pItem == NULL ) 108 return E_OUTOFMEMORY; /* out of memory. */ 109 pItem->punk = punk; IUnknown_AddRef(punk); 110 111 if ( pList->pFirst != NULL ) 112 pList->pFirst->pPrev = pItem; 113 else 114 pList->pLast = pItem; 115 pList->pFirst = pItem; 116 pItem->pNext = pList->pFirst; 117 pItem->pPrev = NULL; 118 119 return S_OK; 60 QUARTZ_CompListItem* pCur; 61 QUARTZ_CompListItem* pNext; 62 63 if ( pList != NULL ) 64 { 65 pCur = pList->pFirst; 66 while ( pCur != NULL ) 67 { 68 pNext = pCur->pNext; 69 if ( pCur->punk != NULL ) 70 IUnknown_Release( pCur->punk ); 71 if ( pCur->pvData != NULL ) 72 QUARTZ_FreeMem( pCur->pvData ); 73 QUARTZ_FreeMem( pCur ); 74 pCur = pNext; 75 } 76 77 DeleteCriticalSection( &pList->csList ); 78 79 QUARTZ_FreeMem( pList ); 80 } 81 } 82 83 void QUARTZ_CompList_Lock( QUARTZ_CompList* pList ) 84 { 85 EnterCriticalSection( &pList->csList ); 86 } 87 88 void QUARTZ_CompList_Unlock( QUARTZ_CompList* pList ) 89 { 90 LeaveCriticalSection( &pList->csList ); 91 } 92 93 QUARTZ_CompList* QUARTZ_CompList_Dup( 94 const QUARTZ_CompList* pList, BOOL fDupData ) 95 { 96 QUARTZ_CompList* pNewList; 97 const QUARTZ_CompListItem* pCur; 98 HRESULT hr; 99 100 pNewList = QUARTZ_CompList_Alloc(); 101 if ( pNewList == NULL ) 102 return NULL; 103 104 pCur = pList->pFirst; 105 while ( pCur != NULL ) 106 { 107 if ( pCur->punk != NULL ) 108 { 109 if ( fDupData ) 110 hr = QUARTZ_CompList_AddComp( 111 pNewList, pCur->punk, 112 pCur->pvData, pCur->dwDataLen ); 113 else 114 hr = QUARTZ_CompList_AddComp( 115 pNewList, pCur->punk, NULL, 0 ); 116 if ( FAILED(hr) ) 117 { 118 QUARTZ_CompList_Free( pNewList ); 119 return NULL; 120 } 121 } 122 pCur = pCur->pNext; 123 } 124 125 return pNewList; 126 } 127 128 HRESULT QUARTZ_CompList_AddComp( 129 QUARTZ_CompList* pList, IUnknown* punk, 130 const void* pvData, DWORD dwDataLen ) 131 { 132 QUARTZ_CompListItem* pItem; 133 134 pItem = (QUARTZ_CompListItem*)QUARTZ_AllocMem( sizeof(QUARTZ_CompListItem) ); 135 if ( pItem == NULL ) 136 return E_OUTOFMEMORY; /* out of memory. */ 137 138 pItem->pvData = NULL; 139 pItem->dwDataLen = 0; 140 if ( pvData != NULL ) 141 { 142 pItem->pvData = (void*)QUARTZ_AllocMem( dwDataLen ); 143 if ( pItem->pvData == NULL ) 144 { 145 QUARTZ_FreeMem( pItem ); 146 return E_OUTOFMEMORY; 147 } 148 memcpy( pItem->pvData, pvData, dwDataLen ); 149 pItem->dwDataLen = dwDataLen; 150 } 151 152 pItem->punk = punk; IUnknown_AddRef(punk); 153 154 if ( pList->pFirst != NULL ) 155 pList->pFirst->pPrev = pItem; 156 else 157 pList->pLast = pItem; 158 pItem->pNext = pList->pFirst; 159 pList->pFirst = pItem; 160 pItem->pPrev = NULL; 161 162 return S_OK; 120 163 } 121 164 122 165 HRESULT QUARTZ_CompList_RemoveComp( QUARTZ_CompList* pList, IUnknown* punk ) 123 166 { 124 QUARTZ_CompListItem* pCur; 125 126 pCur = QUARTZ_CompList_SearchComp( pList, punk ); 127 if ( pCur == NULL ) 128 return S_FALSE; /* already removed. */ 129 130 /* remove from list. */ 131 if ( pCur->pNext != NULL ) 132 pCur->pNext->pPrev = pCur->pPrev; 133 else 134 pList->pLast = pCur->pPrev; 135 if ( pCur->pPrev != NULL ) 136 pCur->pPrev->pNext = pCur->pNext; 137 else 138 pList->pFirst = pCur->pNext; 139 140 /* release this item. */ 141 if ( pCur->punk != NULL ) 142 IUnknown_Release( pCur->punk ); 143 QUARTZ_FreeMem( pCur ); 144 145 return S_OK; 167 QUARTZ_CompListItem* pCur; 168 169 pCur = QUARTZ_CompList_SearchComp( pList, punk ); 170 if ( pCur == NULL ) 171 return S_FALSE; /* already removed. */ 172 173 /* remove from list. */ 174 if ( pCur->pNext != NULL ) 175 pCur->pNext->pPrev = pCur->pPrev; 176 else 177 pList->pLast = pCur->pPrev; 178 if ( pCur->pPrev != NULL ) 179 pCur->pPrev->pNext = pCur->pNext; 180 else 181 pList->pFirst = pCur->pNext; 182 183 /* release this item. */ 184 if ( pCur->punk != NULL ) 185 IUnknown_Release( pCur->punk ); 186 if ( pCur->pvData != NULL ) 187 QUARTZ_FreeMem( pCur->pvData ); 188 QUARTZ_FreeMem( pCur ); 189 190 return S_OK; 146 191 } 147 192 148 193 QUARTZ_CompListItem* QUARTZ_CompList_SearchComp( 149 QUARTZ_CompList* pList, IUnknown* punk ) 150 { 151 QUARTZ_CompListItem* pCur; 152 153 pCur = pList->pFirst; 154 while ( pCur != NULL ) 155 { 156 if ( pCur->punk == punk ) 157 return pCur; 158 pCur = pCur->pNext; 159 } 160 161 return NULL; 194 QUARTZ_CompList* pList, IUnknown* punk ) 195 { 196 QUARTZ_CompListItem* pCur; 197 198 pCur = pList->pFirst; 199 while ( pCur != NULL ) 200 { 201 if ( pCur->punk == punk ) 202 return pCur; 203 pCur = pCur->pNext; 204 } 205 206 return NULL; 207 } 208 209 QUARTZ_CompListItem* QUARTZ_CompList_SearchData( 210 QUARTZ_CompList* pList, const void* pvData, DWORD dwDataLen ) 211 { 212 QUARTZ_CompListItem* pCur; 213 214 pCur = pList->pFirst; 215 while ( pCur != NULL ) 216 { 217 if ( pCur->dwDataLen == dwDataLen && 218 !memcmp( pCur->pvData, pvData, dwDataLen ) ) 219 return pCur; 220 pCur = pCur->pNext; 221 } 222 223 return NULL; 162 224 } 163 225 164 226 QUARTZ_CompListItem* QUARTZ_CompList_GetFirst( 165 166 { 167 227 QUARTZ_CompList* pList ) 228 { 229 return pList->pFirst; 168 230 } 169 231 170 232 QUARTZ_CompListItem* QUARTZ_CompList_GetNext( 171 172 { 173 233 QUARTZ_CompList* pList, QUARTZ_CompListItem* pPrev ) 234 { 235 return pPrev->pNext; 174 236 } 175 237 176 238 IUnknown* QUARTZ_CompList_GetItemPtr( QUARTZ_CompListItem* pItem ) 177 239 { 178 return pItem->punk; 179 } 240 return pItem->punk; 241 } 242 243 const void* QUARTZ_CompList_GetDataPtr( QUARTZ_CompListItem* pItem ) 244 { 245 return pItem->pvData; 246 } 247 248 DWORD QUARTZ_CompList_GetDataLength( QUARTZ_CompListItem* pItem ) 249 { 250 return pItem->dwDataLen; 251 }
Note:
See TracChangeset
for help on using the changeset viewer.