Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
void ListSuite_TestClear( ListSuiteData* data ) {
   Index idx;

   for( idx = 0; idx < NUM_ITEMS; idx++ ) {
      List_Append( data->list, &data->arrayData[idx] );
   }
   List_Clear( data->list );
   pcu_check_true( data->list->nItems == 0 );
   List_Clear( data->list );
   pcu_check_true( data->list->nItems == 0 );
}
Exemplo n.º 3
0
void freeModelList(void)
{
    if(!modellist)
    {
        return;
    }
    List_Clear(modellist);
    free(modellist);
    modellist = NULL;
}
Exemplo n.º 4
0
static void List_Assign(var self, var obj) {
    struct List* l = self;

    List_Clear(self);

    l->type = implements_method(obj, Iter, iter_type) ? iter_type(obj) : Ref;
    l->tsize = size(l->type);

    size_t nargs = len(obj);
    for (size_t i = 0; i < nargs; i++) {
        List_Push(self, get(obj, $I(i)));
    }

}
Exemplo n.º 5
0
int main()
{
    List *a;
    int v;
    List_Foreach_Variable;

    a = List_CreateNew(4);
    if(0==a) {
        printf("Create New list failed!\n");
        return 0;
    }

    v=0;
    List_PushBack(a,(void*)&v);
    v=1;
    List_PushBack(a,(void*)&v);
    v=2;
    List_PushBack(a,(void*)&v);
    v=3;
    List_PushBack(a,(void*)&v);
    v=4;
    List_PushBack(a,(void*)&v);
    v=5;
    List_PushBack(a,(void*)&v);
    List_PushBack(a,(void*)&v);

    int val;

    List_Foreach(a) {
        val = *(int*)List_Foreach_Value;
        if(2==val) {
            List_Foreach_RmCurNode;
            continue;
        }
        printf("%d----------\n",val);
    }

    val = 2;

    printf("size of list %d\n",List_Count(a));
    printf("value size of list %d\n",List_ValueCount(a,(void*)&val));
    printf("index of \'%d\' is %d\n",val,List_Indexof(a,&val));

    List_Clear(a);

    return 0;
}
Exemplo n.º 6
0
int main(void)
{
    List* list = List_Create();

    int i = 0;
    int j = 1;
    int k = 2;

    List_Insert(list, &i, 0);
    List_Insert(list, &j, 1);
    List_Insert(list, &k, 2);

    List_Clear(list);

    List_Destroy(list);

    return 0;
}
Exemplo n.º 7
0
void Instruction_Clear(Instruction * pins) {
	if(pins->theVal) {
		ScriptVariant_Clear(pins->theVal);
		free((void *) pins->theVal);
	}
	if(pins->theVal2) {
		ScriptVariant_Clear(pins->theVal2);
		free((void *) pins->theVal2);
	}
	if(pins->theRefList) {
		List_Clear(pins->theRefList);
		free(pins->theRefList);
	}
	if(pins->Label)
		free(pins->Label);
	if(pins->theToken)
		free(pins->theToken);
	if(pins->theSolidListOfRefList)
		freeSolidList(pins->theSolidListOfRefList);
	memset(pins, 0, sizeof(Instruction));
}
Exemplo n.º 8
0
/*-----------------------------------------------------------------------
| Let l1 be l1 and l2 be l2
| Split l2 off from the front of l1:    final l2,l1 = original l1
|
| Split l1 into l2: objects of l1 up to and including Curs object
|               l1: objects of l1 after Curs
| Any original contents of l2 are freed.
| List_Spilt(l1, l2, NULL) splits l1 before the first object so l1 gets all.
| The elements themselves are not moved.
 ------------------------------------------------------------------------*/
void
APIENTRY
List_SplitAfter(
                LIST l1,
                LIST l2,
                LPVOID Curs
                )
{
    LIST pit;

    if ((l1==NULL) || (l2==NULL)) {
        TRACE_ERROR("Bug: List_SplitAfter bogus list.  Continuing...", FALSE);
        return;
    }
    if (l2->pitNext!=l2) {
        List_Clear(l2);
    };
    if (Curs!=NULL) {
        MOVEBACK(Curs)
        pit = (LIST)Curs;
        /* Curs had better be an item in l1! l2 had better be created! */
        if (pit==l1) {
            l1->bOK = FALSE;
            l2->bOK = FALSE;
            return;
        }
        if (pit->pitNext==l1) {
            /* transfer whole of l2 to l1 */
            SwitchLists(l2,l1);
            return;
        }
        l2->pitPrev = pit;
        l2->pitNext = l1->pitNext;
        l1->pitNext = pit->pitNext;
        pit->pitNext = l2;
        l2->pitNext->pitPrev = l2;
        l1->pitNext->pitPrev = l1;
    }
}
Exemplo n.º 9
0
/*----------------------------------------------------------------------
| Split l2 off from the back of l1:  final l1,l2 = original l1
|
| Split l1 into l1: objects of l1 up to but not including Curs object
|               l2: objects of l1 from Curs onwards
| Any original contants of l2 are freed.
| List_Spilt(l1, l2, NULL) splits l1 after the last object so l1 gets all.
| The elements themselves are not moved.
 -----------------------------------------------------------------------*/
void
APIENTRY
List_SplitBefore(
                 LIST l1,
                 LIST l2,
                 LPVOID Curs
                 )
{
    LIST pit;

    if ((l1==NULL) || (l2==NULL)) {
        TRACE_ERROR("Bug: List_SplitBefore bogus list.  Continuing...", FALSE);
        return;
    }
    if (l2->pitNext!=l2) {
        List_Clear(l2);
    }
    if (Curs!=NULL) {
        MOVEBACK(Curs)
        pit = (LIST)Curs;
        /* Curs had better be an item in L1! L2 had better be created! */
        if (pit==l1) {
            l1->bOK = FALSE;
            l2->bOK = FALSE;
            return;
        }
        if (pit->pitPrev==l1) {
            SwitchLists(l2,l1);
            return;
        }
        l2->pitNext = pit;
        l2->pitPrev = l1->pitPrev;
        l1->pitPrev = pit->pitPrev;
        pit->pitPrev = l2;
        l2->pitPrev->pitNext = l2;
        l1->pitPrev->pitNext = l1;
    }
}
Exemplo n.º 10
0
/*销毁一个新的链表*/
void List_Delete(list_t *pList)
{
    if(0==pList) return;
    List_Clear(pList);
    LIST_FREE(pList);
}
Exemplo n.º 11
0
int main() {

	List list, list2;
	size_t dummy = 0x1234;
	int i = 0;

	Node *test;

	List_Init(&list);
	assert(list.last == NULL);
	assert(list.first == NULL);
	assert(list.size == 0);
	assert(list.index == 0);


	List_InsertAfter(&list, (void *) dummy, int2str(++i));
	assert(list.current == list.first);
	assert(list.current == list.last);
	assert(list.last != NULL);
	assert(list.first != NULL);
	assert(list.last->next == NULL);
	assert(list.first->prev == NULL);

	assert(list.size == i);
	assert(eq(list.current->name, "1"));

	List_InsertAfter(&list, (void *) dummy, int2str(++i));
	assert(list.current->prev == list.first);
	assert(list.current == list.last);
	assert(list.last->next == NULL);
	assert(list.first->prev == NULL);
	assert(list.size == i);
	assert(eq(list.current->name, "2"));

	List_InsertAfter(&list, (void *) dummy, int2str(++i));
	assert(list.current->prev->prev == list.first);
	assert(list.current == list.last);
	assert(list.last->next == NULL);
	assert(list.first->prev == NULL);
	assert(list.size == i);
	assert(eq(list.current->name, "3"));

	List_Remove(&list);
	assert(list.current->prev == list.first);
	assert(list.current == list.last);
	assert(list.last->next == NULL);
	assert(list.first->prev == NULL);
	assert(list.size == i - 1);
	assert(eq(list.current->name, "2"));

	List_InsertBefore(&list, (void *) dummy, int2str(++i));
	assert(list.current != list.last);
	assert(list.current->next == list.last);

	assert(list.last->next == NULL);
	assert(list.first->prev == NULL);
	assert(list.size == i - 1);
	assert(eq(list.current->name, "4"));
	assert(eq(list.last->name, "2"));

	List_GotoFirst(&list);
	List_InsertBefore(&list, (void *) dummy, int2str(++i));
	assert(list.current == list.first);
	assert(list.last->next == NULL);
	assert(list.first->prev == NULL);
	assert(list.size == i - 1);
	assert(eq(list.current->name, "5"));
	assert(eq(list.last->name, "2"));

	List_InsertAfter(&list, (void *) dummy, int2str(++i));
	assert(list.current == list.first->next);
	assert(list.current->prev == list.first);
	assert(list.current->next->prev == list.current);
	assert(list.last->next == NULL);
	assert(list.first->prev == NULL);
	assert(list.size == i - 1);
	assert(eq(list.current->name, "6"));
	assert(eq(list.last->name, "2"));

	List_GotoFirst(&list);
	assert(list.current == list.first);
	test = list.first->next;
	List_Remove(&list);
	assert(list.first == test);
	assert(list.current == list.first);
	assert(list.last->next == NULL);
	assert(list.first->prev == NULL);
	assert(list.size == i - 2);
	//assert(eq(list.current->name, "7"));
	assert(eq(list.last->name, "2"));

	List_GotoFirst(&list);
	assert(list.current == list.first);

	List_Copy(&list2, &list);
	assert(list2.size == list.size);
	assert(list2.current == list2.first);
	assert(eq(list2.last->name, "2"));

	List_GotoLast(&list);
	assert(list.current == list.last);

	List_Copy(&list2, &list);
	assert(list2.current == list2.last);
	assert(list2.size == list.size);
	assert(list2.index == list.index);
	assert(list2.index == 0);
	assert(eq(list2.last->name, "2"));
	assert(eq(list2.last->name, list.last->name));
	assert(eq(list2.first->name, list.first->name));
	assert(eq(list2.current->name, list.current->name));
	assert(eq(list2.current->prev->name, list.current->prev->name));
	assert(list2.current->next == list.current->next);
	assert(list.current->next == 0);
	List_GotoFirst(&list);
	assert(!eq(list2.current->name, list.current->name));
	List_GotoFirst(&list2);
	assert(eq(list2.current->name, list.current->name));
	assert(list.current == list.first);
	assert(list.current->prev == NULL);
	assert(list2.current->prev == NULL);


	List_InsertAfter(&list, (void *) 0xDEADBEEF, int2str(++i));
	assert(list.first->next->value == (void *) 0xDEADBEEF);
	assert(list.current = list.first->next);

	List_InsertAfter(&list, (void *) dummy, int2str(++i));

	List_InsertBefore(&list, (void *) dummy, int2str(++i));
	List_InsertBefore(&list, (void *) dummy, int2str(++i));
	List_InsertBefore(&list, (void *) dummy, int2str(++i));
	assert(list.size == i - 2);	// i = 11
	List_GotoFirst(&list);
	List_GotoNext(&list);
	List_GotoPrevious(&list);

	List_GotoLast(&list);

	test = list.last;
	assert(list.current == list.last);

	List_Remove(&list);
	assert(list.last != test);
	assert(list.current == list.last);

	List_Remove(&list);
	assert(list.current == list.last);

	List_Remove(&list);
	assert(list.current == list.last);

	List_Remove(&list);

	assert(list.current == list.last);
	assert(list.size == i - 6);

	List_GotoPrevious(&list);
	List_GotoPrevious(&list);
	List_GotoPrevious(&list);

	assert(List_Retrieve(&list) == (void *) 0xDEADBEEF);
	List_Remove(&list);
	assert(!List_Includes(&list, (void *) 0xDEADBEEF));
	assert(list.size == i - 7);

	List_GotoLast(&list);
	List_InsertAfter(&list, (void *) 0xDEADBEEF, int2str(++i));

#ifdef USE_INDEX
	List_CreateIndices(&list);
	assert(list.mindices);
	assert(List_GetIndex(&list) == list.size - 1);
	assert(List_GetNodeIndex(&list, list.first) == 0);
	assert(List_GetNodeIndex(&list, list.last->prev) == list.size - 2);
	assert(List_GetNodeIndex(&list, list.last->prev->prev) == list.size - 3);
	assert(list.mindices[ptrhash((void *) 0xDEADBEEF)]);
#endif
	assert(List_Includes(&list, (void *) 0xDEADBEEF));

	assert(list.current == list.last);
	assert(List_Retrieve(&list) == (void *) 0xDEADBEEF);

	List_Update(&list, (void *) 0xDEADC0DE);
	assert(list.current == list.last);
	assert(List_Retrieve(&list) == (void *) 0xDEADC0DE);
	assert(!List_Includes(&list, (void *) 0xDEADBEEF));
	assert(List_Includes(&list, (void *) 0xDEADC0DE));
#ifdef USE_INDEX
	assert(list.mindices);
	assert(list.mindices[ptrhash((void *) 0xDEADC0DE)]);
#endif
	List_Remove(&list);
	assert(!List_Includes(&list, (void *) 0xDEADC0DE));
#ifdef USE_INDEX
	assert(list.mindices);
	assert(ptrhash((void *) dummy) != ptrhash((void *) 0xDEADC0DE));
	assert(ptrhash((void *) dummy) != ptrhash((void *) 0xDEADBEEF));
	// disable temporary
	assert(list.mindices[ptrhash((void *) 0xDEADC0DE)]);
	assert(list.mindices[ptrhash((void *) 0xDEADC0DE)]->nodes[0] == NULL);
	assert(list.mindices[ptrhash((void *) 0xDEADC0DE)]->used == 0);
	// dead beef was updated, so used must be still 1
	assert(list.mindices[ptrhash((void *) 0xDEADBEEF)]);
	assert(list.mindices[ptrhash((void *) 0xDEADBEEF)]->nodes[0] == NULL);
	assert(list.mindices[ptrhash((void *) 0xDEADBEEF)]->used == 1);
#endif

	List_Clear(&list);
	assert(list.size == 0);
	List_Init(&list);
	i = 0;

	List_InsertBefore(&list, (void *) dummy, int2str(++i));
	List_InsertBefore(&list, (void *) dummy, int2str(++i));
	List_InsertBefore(&list, (void *) dummy, int2str(++i));
	assert(list.size == 3);
	List_Remove(&list);
	List_Remove(&list);
	List_Remove(&list);
	List_Remove(&list);
	List_GotoFirst(&list);

	List_Clear(&list);

	// testing the order of removal is equivalent to gotonext
	List_Init(&list);
	List_InsertAfter(&list, (void *) 1, NULL);
	List_InsertAfter(&list, (void *) 2, NULL);
	List_InsertAfter(&list, (void *) 3, NULL);
	List_InsertAfter(&list, (void *) 4, NULL);
	List_GotoFirst(&list);
	assert(list.current->value == (void *) 1);
	List_GotoNext(&list);
	assert(list.current->value == (void *) 2);
	List_GotoNext(&list);
	assert(list.current->value == (void *) 3);
	List_GotoNext(&list);
	assert(list.current->value == (void *) 4);
	assert(list.current == list.last);
	List_GotoFirst(&list);
	assert(list.current->value == (void *) 1);
	List_Remove(&list);
	assert(list.current->value == (void *) 2);
	List_Remove(&list);
	assert(list.current->value == (void *) 3);
	List_Remove(&list);
	assert(list.current->value == (void *) 4);
	assert(list.current == list.last);
	List_Remove(&list);
	assert(list.current == list.last);
	assert(list.current == list.first);
	assert(list.current == NULL);


	freemem();
	return 0;
}
Exemplo n.º 12
0
static void List_Del(var self) {
    struct List* l = self;
    List_Clear(self);
}
Exemplo n.º 13
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");
	}
}