Exemple #1
0
int
owlist_free_all
(
	OWList * list,
	void (* free_element) (void *)
)
{
	int return_code = 0 ;
	OWListIterator * iterator ;
	void * element ;

	iterator = owlist_iterator_new (list, OWLIST_WRITE) ;
	if (iterator != NULL)
	{
		while (owlist_iterator_next (iterator) == 0)
		{
			element = owlist_iterator_get (iterator) ;
			return_code |= owlist_iterator_remove (iterator) ;
			free_element (element) ;
			/* if free_element has a return code, it cannot be tested */
		}
		return_code |= owlist_iterator_free (iterator) ;
	}

	return_code |= owlist_free (list) ;

	return return_code ;
}
Exemple #2
0
int
owlist_contains
(
	OWList * list,
	const void * element,
	OWListCompare compare
)
{
	int return_code = -1 ;
	OWListIterator * iterator ;

	iterator = owlist_iterator_new (list, OWLIST_READ) ;
	if (iterator == NULL)
	{
		return -1 ;
	}

	while (owlist_iterator_next (iterator) == 0)
	{
		if (owlist_compare (iterator->current->element, element, compare) == 0)
		{
			return_code = 0 ;
			break ;
		}
	}

	if (owlist_iterator_free (iterator))
	{
		return -1 ;
	}

	return return_code ;
}
Exemple #3
0
int
owlist_remove_all
(
	OWList * list
)
{
	int return_code = 0 ;
	OWListIterator * iterator ;

	iterator = owlist_iterator_new (list, OWLIST_WRITE) ;
	if (iterator == NULL)
	{
		return -1 ;
	}

	while (owlist_iterator_next (iterator) == 0)
	{
		free (iterator->current) ;
	}

	if (owlist_iterator_free (iterator))
	{
		return_code = -1 ;
	}

	list->first = NULL ;
	list->last = NULL ;
	list->count = 0 ;

	return return_code ;
}
Exemple #4
0
void *
owlist_remove
(
	OWList * list,
	const void * element,
	OWListCompare compare
)
{
	void * found = NULL ;
	OWListIterator * iterator ;

	iterator = owlist_iterator_new (list, OWLIST_WRITE) ;
	if (iterator == NULL)
	{
		return NULL ;
	}

	while (owlist_iterator_next (iterator) == 0)
	{
		if (owlist_compare (iterator->current->element, element, compare) == 0)
		{
			found = iterator->current->element ;
			owlist_iterator_remove (iterator) ;
			break ;
		}
	}

	if (owlist_iterator_free (iterator))
	{
		return NULL ;
	}

	return found ;
}
Exemple #5
0
int
owlist_add
(
	OWList * list,
	const void * element,
	OWListCompare compare
)
{
	OWListIterator * iterator ;
	OWListNode * node ;

	/* write lock */
	iterator = owlist_iterator_new (list, OWLIST_WRITE) ;
	if (iterator == NULL)
	{
		return -1 ;
	}

	/* check if the element is already in the list */
	while (owlist_iterator_next (iterator) == 0)
	{
		if (owlist_compare (iterator->current->element, element, compare) == 0)
		{
			owlist_iterator_free (iterator) ;
			return -1 ;
		}
	}

	/* create a new node */
	node = malloc (sizeof (OWListNode)) ;
	if (node == NULL)
	{
		owlist_iterator_free (iterator) ;
		return -1 ;
	}
	node->element = (void *) element ;
	node->next = NULL ;

	/* add the node at the end of the list */
	if (list->first == NULL)
	{
		list->first = node ;
	}
	else
	{
		list->last->next = node ;
	}
	list->last = node ;
	list->count ++ ;

	/* write unlock */
	if (owlist_iterator_free (iterator))
	{
		return -1 ;
	}

	return 0 ;
}
Exemple #6
0
static OWSLSocket
transport_socket_get_next
(
	OWSLSocketType implementation,
	OWListIterator * list_iterator
)
{
	OWSLSocket found_socket = -1 ;
	OWSLSocket * socket ;
	while (owlist_iterator_next (list_iterator) == 0)
	{
		socket = owlist_iterator_get (list_iterator) ;
		if (owsl_type_get (* socket) == implementation)
		{
			found_socket = * socket ;
			break ;
		}
	}
	return found_socket ;
}