EXPORT void CleanIndicatorsList(List **ppList) { ListItem* handle; IndicatorSubscribers *pTempInd = NULL; handle = CreateIterator(*ppList); //for each indicator struct- clean the subscribers list and free the IndicatorSubscribers struct: handle = Iterator_GetNext(*ppList, handle, (void**)&pTempInd); while (handle != NULL) { List_Clear(&(pTempInd->subscribersList)); List_Finalize(&(pTempInd->subscribersList)); free(pTempInd); pTempInd = NULL; handle = Iterator_GetNext(*ppList, handle, (void**)&pTempInd); } FreeIterator(*ppList); List_Clear(*ppList); List_Finalize(*ppList); free(*ppList); (*ppList) = NULL; }
static void ListPermutations(string str) { setADT set; iteratorADT iterator; string s; set = NewPtrSet(StringCmpFn); RecursivePermute(str, 0, set); iterator = NewIterator(set); while (StepIterator(iterator, &s)) { printf("%s\n", s); } FreeIterator(iterator); }
static void ListCmdFn(cmdScannerADT cs) { symtabADT table; string key, value; iteratorADT iterator; CheckForExtraTokens(cs); table = GetCommandData(cs); iterator = NewIterator(table); while (StepIterator(iterator, &key)) { value = Lookup(table, key); printf("%s = %s\n", key, value); } FreeIterator(iterator); }
//find the relevant InidicatorsSubscribers Item. //bCreateNew - boolean which indicate to create a new entry to the specific id if not exist EXPORT IndicatorSubscribers *GetIndicatorSubscribers(List *pList, UINT32 indication_id, BOOL bCreateNew) { ListItem* handle; IndicatorSubscribers *pTempInd = NULL; if(pList == NULL) { return NULL; } handle = CreateIterator(pList); handle = Iterator_GetNext(pList, handle, (void**)&pTempInd); while (handle != NULL) { if(pTempInd->id == indication_id)//this is the Item { FreeIterator(pList); return pTempInd; } handle = Iterator_GetNext(pList, handle, (void**)&pTempInd); } FreeIterator(pList); if (TRUE == bCreateNew) { //No such indicator list for the specific id - generate new one pTempInd = (IndicatorSubscribers*)malloc(sizeof(IndicatorSubscribers)); pTempInd->id = indication_id; List_Init(&(pTempInd->subscribersList), TRUE); List_AddItem(pList, pTempInd); return pTempInd; } return NULL; }
D_MOBILE *get_char(D_MOBILE * ch, char *argument) { D_MOBILE *wch; ITERATOR *pIter; char arg[MIL]; // char buf[MSL]; pIter = AllocIterator(dmobile_list); while ((wch = (D_MOBILE *) NextInList(pIter)) != NULL) { if (wch == ch) continue; else if (str_cmp(arg,wch->name)) return wch; else return NULL; } FreeIterator(pIter); return NULL; }
TweetSeq FindByFav(Database* db, uint32_t favs) { TweetSeq tws; tws.length = 0; tws.seq = NULL; Tweet tmp; DatabaseItr *i = GetIterator(db); while(GetNextTweet(i, &tmp) == 0) { // Percorre todos os tweets ativos if(tmp.favs == favs) { // Filtra pela qtd. de FAVs tws.seq = realloc(tws.seq, (tws.length + 1) * sizeof(Tweet)); // Aumenta o vetor FATAL(tws.seq, 1); tws.seq[tws.length] = tmp; // Copia para o vetor ++(tws.length); // Ajusta o contador } else { FreeTweet(&tmp); } } FreeIterator(i); return tws; }
TweetSeq FindByUser(Database *db, const char *user) { TweetSeq tws; tws.length = 0; tws.seq = NULL; Tweet tmp; DatabaseItr *i = GetIterator(db); while(GetNextTweet(i, &tmp) == 0) { // Percorre todos os tweets ativos if(strcmp(user, tmp.user) == 0) { // Filtra apenas os com user desejado tws.seq = realloc(tws.seq, (tws.length + 1) * sizeof(Tweet)); // Aumenta o vetor FATAL(tws.seq, 1); tws.seq[tws.length] = tmp; // Copia para o vetor ++(tws.length); // Ajusta o contador } else { FreeTweet(&tmp); } } FreeIterator(i); return tws; }
int main(int argc, char** argv) { TREE pTree = AllocTree(NULL); void *pContents; ITERATOR pIter; int nChoice = 0, nKey; while (nChoice != -1) { printf("1: Insert\n"); printf("2: Remove\n"); printf("3: Print\n"); printf("4: Print all keys\n"); printf("5: Print all keys reverse\n"); printf("6: Mass insert\n"); printf("7: Mass remove\n"); printf("Else: Quit\n\n"); BTSCAN("%d", &nChoice); switch(nChoice) { case 1: printf("Key: "); BTSCAN("%d", &nKey); Insert(nKey, "temp", pTree); break; case 2: printf("Key: "); BTSCAN("%d", &nKey); Remove(nKey, pTree); break; case 3: printf("Key: " ); BTSCAN("%d", &nKey); pContents = Search(nKey, pTree); if (pContents != NULL) { printf("Contents: %s\n", pContents); } else { printf("Not found\n"); } break; case 4: pIter = AllocIterator(); Attach(pIter, pTree); while ((pContents = Next(pIter)) != NULL) { printf("Contents: %d\n", pContents); } Detach(pIter); FreeIterator(pIter); break; case 5: pIter = AllocIterator(); AttachEnd(pIter, pTree); while ((pContents = Next(pIter)) != NULL) { printf("Contents: %d\n", pContents); } Detach(pIter); FreeIterator(pIter); break; case 6: for (nKey = 100; nKey > 0; nKey--) { Insert(nKey, "temp", pTree); } break; case 7: for (nKey = 100; nKey > 0; nKey--) { Remove(nKey, pTree); } break; default: nChoice = -1; break; } printf("\n"); } return 0; }
// This function go over the specific list (L4 SS or status SS) and send all its registered targets the indication. // Can be used as the InternalHandler with Messenger_PostRequest EXPORT void SendIndicationToSubscribers( UINT32 internalRequestID, void *_buffer, UINT32 bufferLength ) { SendIndData *buffer = _buffer; ListItem* handle; L5_TARGET_ID targetID; // Instead of storing a pointer in the 'pData' field of the ListItem, the indicator ID is stored there. // Since the size of a pointer may be larger than the size of an L5_TARGET_ID, a pointer needs to be used // with Iterator_GetNext() to store the indicator ID, before copying the value to an L5_TARGET_ID. void *data; L5_RESULT res; IndicatorSubscribers *indSubscribers; List tempList; UNREFERENCED_PARAMETER(bufferLength); //TODO: use FailedDeliveryIndication if available to notify on send failure. // go over the list and send indications to all targets indSubscribers = GetIndicatorSubscribers(buffer->pSubscribersList, buffer->indication_id, FALSE); TRACE(TR_MOD_WRAPPER_LOGS, TR_SEV_DEBUG,"SendIndicationToSubscribers(IN) - internalRequestID=%d, indSubscribers=%d, pSubscribersList=%d, indication_id=%d", internalRequestID ,indSubscribers, buffer->pSubscribersList, buffer->indication_id); if ((NULL != indSubscribers) && (0 != List_Length(&(indSubscribers->subscribersList)))) { // Build temp list List_Init(&tempList, FALSE); handle = CreateIterator(&(indSubscribers->subscribersList)); handle = Iterator_GetNext(&(indSubscribers->subscribersList), handle, (void**)(&data)); while (handle != NULL) { List_AddItem(&tempList, data); handle = Iterator_GetNext(&(indSubscribers->subscribersList), handle, (void**)(&data)); } FreeIterator(&(indSubscribers->subscribersList)); //iterate the temp list and send the targets indication: handle = CreateIterator(&tempList); handle = Iterator_GetNext(&tempList, handle, (void**)(&data)); while (handle != NULL) { targetID = (L5_TARGET_ID) data; //in case we are working with remote DnD, we want to send the trace and monitor indications //only to the DnD agent if(((L3_L4_OPCODE_REPORT_MONITOR_EVACUATE != wimaxll_le16_to_cpu(*((UINT16 *)buffer->indication_buffer))) && (L3_L4_OPCODE_REPORT_TRACE_EVACUATE != wimaxll_le16_to_cpu(*((UINT16 *)buffer->indication_buffer)))) || (L5_TARGET_DND_AGENT == targetID)) { TRACE(TR_MOD_WRAPPER_LOGS, TR_SEV_DEBUG,"SendIndicationToSubscribers - senderL5Conn=0x%x, targetID=%d, internalRequestID=%d", buffer->senderL5Conn, targetID, internalRequestID); res = buffer->pSenderFuncs->pfnSendReceiveMessage( buffer->senderL5Conn, targetID, internalRequestID, buffer->indication_buffer, buffer->indication_buffer_size, NULL, NULL, NULL); if ( L5_RESULT_ID_NOT_FOUND == res) { Indications_RemoveSubscriber(indSubscribers , targetID); } } handle = Iterator_GetNext(&tempList, handle, (void**)(&data)); // TODO - XXX - check L5_COMMON_UTILS_IsTargetNotExist // TODO - XXX - check res // TODO - XXX - check responseID } FreeIterator(&tempList); //free the temp list items: List_Clear(&tempList); List_Finalize(&tempList); } else { TRACE(TR_MOD_WRAPPER_LOGS, TR_SEV_DEBUG,"SendIndicationToSubscribers - no subscribers"); } }