Esempio n. 1
0
//Launch method, instead of having all this main basically...
void create_list()
{
	printf("Assembling list nodes...\n");

	//We're assembling all this, correctly malloc()ing,
	//instead of creating inside this function with struct
	//vars, which would only be scoped to this function.
	//
	//First, setup the root.  If anything else in this app needs this,
	//we'll pass it as a param, instead of using a global var.
	struct LinkNode *root_node = malloc(sizeof(struct LinkNode));
	root_node->node_val = 9;
	root_node->next_node = NULL;

	add_item_to_list(12, root_node);

	//Add an item and store a pointer to it for future deletion test
	struct LinkNode *node_to_delete = add_item_to_list(10, root_node);

	add_item_to_list(22, root_node);
	add_item_to_list(37, root_node);
	
	printf("\nIterate through nodes and print values...\n\n");
	print_list_values(root_node);
	
	printf("\nAdding value 55 to end of list...\n");
	add_item_to_list(55, root_node);

	printf("\nNow reading all values again...\n\n");
	print_list_values(root_node);

	printf("\nRemoving item with value 10 from the list\n");

	//Do removal...
	remove_item_from_list(node_to_delete, root_node);

	printf("\nNow reading all values again...\n\n");
	print_list_values(root_node);

	printf("\nAdding 2 new values: 66 and 77...\n");

	add_item_to_list(66, root_node);
	add_item_to_list(77, root_node);

	printf("\nGet count of nodes...\n");
	int node_count = count_list_nodes(root_node);
	printf("\nNode count: %d\n",node_count);

	printf("\nNow reading all values again...\n\n");
	print_list_values(root_node);

	printf("\nFree()ing list memory...\n\n");
	free_list_memory(&root_node);

	printf("\nNow reading all values again...\n\n");
	print_list_values(root_node);
}
Esempio n. 2
0
/* Permenantly evict a cache item from the cache list and destroying 
   its content */
void evict_cache_item(Cache_List *cache_list) {
	if (DEBUG_MODE) printf("    evict_cache_item():\n");
	Cache_Item *cache_item = remove_item_from_list(cache_list, 
			cache_list->tail);
	free(cache_item->content);
	free(cache_item->uri);
	free(cache_item);
	if (DEBUG_MODE) printf("    evict_cache_item() finish.\n");
}
Esempio n. 3
0
/* Use an already existed cached item */
void use_cache_item(Cache_List *cache_list, Cache_Item *cache_item, 
		void *usrbuf, unsigned int *size) 
{
	if (DEBUG_MODE) printf("    use_cache_item():\n");
	remove_item_from_list(cache_list, cache_item);
	insert_item_to_listhead(cache_list, cache_item);
	*size = cache_item->content_length;
	/* Copy the content data into user-buffer */
	memcpy(usrbuf, cache_item->content, *size);
	if (DEBUG_MODE) printf("    use_cache_item() finish.\n");
}