list.c File Reference

List module implementation file. More...

#include "list.h"
#include "memory.h"
#include "definitions.h"
#include "log_util.h"
Include dependency graph for list.c:

Go to the source code of this file.

Functions

E_MCL_ERROR_CODE mcl_list_initialize (mcl_list_t **list)
 Initializes a list with zero items in it. More...
 
E_MCL_ERROR_CODE mcl_list_add (mcl_list_t *list, void *data)
 Adds a new item to list. More...
 
E_MCL_ERROR_CODE mcl_list_next (mcl_list_t *list, mcl_list_node_t **node)
 Gets the next node from the list. More...
 
E_MCL_ERROR_CODE mcl_list_remove (mcl_list_t *list, mcl_list_node_t *node)
 Removes a node from the list. More...
 
E_MCL_ERROR_CODE mcl_list_remove_with_content (mcl_list_t *list, mcl_list_node_t *node, mcl_list_item_destroy_callback callback)
 Removes a node from the list and destroys the removed item with the provided callback function. More...
 
E_MCL_ERROR_CODE mcl_list_exist (mcl_list_t *list, const void *item_to_find, mcl_list_compare_callback compare_function, void **item)
 Searches item_to_find in the list. More...
 
void mcl_list_reset (mcl_list_t *list)
 Reset the current node to head node. More...
 
void mcl_list_destroy (mcl_list_t **list)
 Destroys the list. More...
 
void mcl_list_destroy_with_content (mcl_list_t **list, mcl_list_item_destroy_callback callback)
 Destroys the list and its items with a given callback function. More...
 
E_MCL_ERROR_CODE list_initialize (list_t **list)
 Initializes the list. More...
 
E_MCL_ERROR_CODE list_add (list_t *list, void *data)
 Adds a new list item. More...
 
E_MCL_ERROR_CODE list_remove_with_content (list_t *list, list_node_t *node, list_item_destroy_callback callback)
 Removes a node from the list and destroys the removed item with the provided callback function. More...
 
E_MCL_ERROR_CODE list_remove (list_t *list, list_node_t *node)
 Removes a node from the list. More...
 
list_node_tlist_next (list_t *list)
 Get the next node from the list. More...
 
void list_reset (list_t *list)
 Reset the current node to head node. More...
 
E_MCL_ERROR_CODE list_exist (list_t *list, const void *item_to_find, list_compare_callback compare_function, void **item)
 Searches item_to_find in the list. More...
 
void list_destroy_with_content (list_t **list, list_item_destroy_callback callback)
 To destroy the list and its items with a given callback function. More...
 
void list_destroy (list_t **list)
 To destroy the list. More...
 

Detailed Description

List module implementation file.


Date
Jul 20, 2016

Definition in file list.c.

Function Documentation

E_MCL_ERROR_CODE list_add ( list_t list,
void *  data 
)

Adds a new list item.

The received data pointer is added to the list. No new memory is allocated and no memory copy operations done. The lifetime of the data should be handled by the user.

Parameters
[in]listThe list to which the data is added.
[in]dataThe data to be added. Only data pointer will be kept in the list. No additional memory operation will perform.
Returns

Definition at line 159 of file list.c.

References ASSERT_CODE_MESSAGE, mcl_list_t::count, mcl_list_t::current, mcl_list_node_t::data, mcl_list_t::head, mcl_list_t::last, MCL_LIMIT_EXCEEDED, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_SIZE_MAX, MCL_VERBOSE, mcl_list_node_t::next, mcl_list_node_t::prev, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _store_add_data(), event_list_add_event(), mcl_data_source_configuration_add_data_point(), mcl_data_source_configuration_add_data_source(), mcl_list_add(), mcl_time_series_add_value(), mcl_time_series_new_value_set(), and string_split().

Here is the caller graph for this function:

void list_destroy ( list_t **  list)

To destroy the list.

For every node in the list, it frees the node but not the data it holds. After all nodes freed, it frees the list itself and sets it's value as NULL.

User needs to free all the data that the list is holding before destroying it!

Parameters
[in]listThe address of the pointer of the list to be destroyed.

Definition at line 409 of file list.c.

References list_destroy_with_content(), MCL_NULL, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_list_destroy().

Here is the call graph for this function:

Here is the caller graph for this function:

void list_destroy_with_content ( list_t **  list,
list_item_destroy_callback  callback 
)

To destroy the list and its items with a given callback function.

For every node in the list, it frees the node. The data of the node can also freed by given callback function. After all nodes freed, it frees the list itself and sets it's value as NULL.

Parameters
[in]listThe address of the pointer of the list to be destroyed.
[in]callbackThe callback function to destroy each node data within the list. If NULL no action will be performed.

Definition at line 373 of file list.c.

References mcl_list_t::count, mcl_list_node_t::data, DEBUG_ENTRY, DEBUG_LEAVE, mcl_list_t::head, MCL_DEBUG, MCL_FREE, MCL_NULL, and mcl_list_node_t::next.

Referenced by _destroy_data_source(), _destroy_value_set(), data_source_configuration_destroy(), event_list_destroy(), http_response_get_header(), list_destroy(), mcl_list_destroy_with_content(), mcl_store_destroy(), string_split(), and time_series_destroy().

Here is the caller graph for this function:

E_MCL_ERROR_CODE list_exist ( list_t list,
const void *  item_to_find,
list_compare_callback  compare_function,
void **  item 
)

Searches item_to_find in the list.

Parameters
[in]listTo search in.
[in]item_to_findTo search for.
[in]compare_functionCallback function to compare.
[out]itemIf item_to_find is found, then the node data where item_to_find exists returned with this parameter.
Returns
  • MCL_OK if item_to_find exists in the list.
  • MCL_FAIL if item_to_find doesn't exist in the list.

Definition at line 346 of file list.c.

References mcl_list_node_t::data, DEBUG_ENTRY, DEBUG_LEAVE, mcl_list_t::head, MCL_FAIL, MCL_NULL, MCL_OK, and mcl_list_node_t::next.

Referenced by mcl_list_exist(), and mcl_store_new_event().

Here is the caller graph for this function:

E_MCL_ERROR_CODE list_initialize ( list_t **  list)

Initializes the list.

Head, Last and Current pointers will be set to NULL. Count will be 0.

Parameters
[out]listWill point to the initialized list_t object.
Returns

Definition at line 139 of file list.c.

References ASSERT_CODE_MESSAGE, mcl_list_t::count, mcl_list_t::current, mcl_list_t::head, mcl_list_t::last, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _initialize_payload(), event_list_initialize(), mcl_data_source_configuration_add_data_source(), mcl_list_initialize(), mcl_store_initialize(), mcl_time_series_new_value_set(), string_split(), and time_series_initialize().

Here is the caller graph for this function:

list_node_t* list_next ( list_t list)

Get the next node from the list.

Last returned node is kept in list. This function can be called consequently to loop over the list. If there is no node left to return or the list is empty, this function returns NULL.

Parameters
[in]listThe list.
Returns
The next node in the list.

Definition at line 309 of file list.c.

References ASSERT_MESSAGE, mcl_list_t::current, mcl_list_t::head, MCL_NULL, mcl_list_node_t::next, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_data_source_configuration_data_points(), _add_data_source_configuration_data_sources(), _add_event_list(), _add_time_series_payload_values_array(), _add_time_series_value_sets(), _exchange_clear_sent_data_from_store(), _exchange_update_store_state(), and mcl_list_next().

Here is the caller graph for this function:

E_MCL_ERROR_CODE list_remove ( list_t list,
list_node_t node 
)

Removes a node from the list.

The node (list_node_t) will be freed but the data that it holds is not going to be freed. User needs to free the resource before it calls remove!

Parameters
[in]listThe list from which the node is removed.
[in]nodeThe node to be removed.
Returns

Definition at line 214 of file list.c.

References ASSERT_CODE_MESSAGE, mcl_list_t::count, mcl_list_t::current, mcl_list_t::head, mcl_list_t::last, MCL_ARRAY_IS_EMPTY, MCL_FREE, MCL_NULL, MCL_OK, MCL_VERBOSE, mcl_list_node_t::next, mcl_list_node_t::prev, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by list_remove_with_content(), and mcl_list_remove().

Here is the caller graph for this function:

E_MCL_ERROR_CODE list_remove_with_content ( list_t list,
list_node_t node,
list_item_destroy_callback  callback 
)

Removes a node from the list and destroys the removed item with the provided callback function.

The node (list_node_t) will be freed and the data that it holds is going to be destroyed by passing to the provided callback function. User needs to free the resource before it calls remove!

Parameters
[in]listThe list from which the node is removed.
[in]nodeThe node to be removed.
[in]callbackThe callback function to destroy the list item.
Returns

Definition at line 195 of file list.c.

References mcl_list_node_t::data, DEBUG_ENTRY, DEBUG_LEAVE, list_remove(), MCL_NULL, and MCL_OK.

Referenced by mcl_list_remove_with_content(), and store_data_remove().

Here is the call graph for this function:

Here is the caller graph for this function:

void list_reset ( list_t list)

Reset the current node to head node.

The goal here is to be able to loop over the list from it's beginning.

Parameters
[in]listThe list which is used to reset it's current node to it's head node.

Definition at line 329 of file list.c.

References mcl_list_t::current, mcl_list_t::head, MCL_NULL, MCL_VERBOSE, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_data_source_configuration_data_points(), _add_data_source_configuration_data_sources(), _add_event_list(), _add_time_series_payload_values_array(), _add_time_series_value_sets(), _exchange_update_store_state(), and mcl_list_reset().

Here is the caller graph for this function:

E_MCL_ERROR_CODE mcl_list_add ( mcl_list_t list,
void *  data 
)

Adds a new item to list.

A new list item pointed by data is added to the list. No new memory is allocated and no memory copy operations done. The lifetime of data should be handled by the caller of this function.

Parameters
[in]listThe list to which the data is added.
[in]dataThe pointer to the list item to be added.
Returns

Definition at line 32 of file list.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and list_add().

Here is the call graph for this function:

void mcl_list_destroy ( mcl_list_t **  list)

Destroys the list.

For every node in the list, it frees the node but not the data it holds. After all nodes freed, it frees the list itself and sets it's value to NULL.

User needs to free all the data that the list is holding before destroying it!

Parameters
[in]listThe address of the pointer of the list to be destroyed.

Definition at line 121 of file list.c.

References DEBUG_ENTRY, DEBUG_LEAVE, and list_destroy().

Here is the call graph for this function:

void mcl_list_destroy_with_content ( mcl_list_t **  list,
mcl_list_item_destroy_callback  callback 
)

Destroys the list and its items with a given callback function.

For every node in the list, it frees the node. The data of the node can also freed by given callback function. After all nodes freed, it frees the list itself and sets it's value to NULL.

Parameters
[in]listThe address of the pointer of the list to be destroyed.
[in]callbackThe callback function to destroy each node data within the list. If NULL no action will be performed.

Definition at line 130 of file list.c.

References DEBUG_ENTRY, DEBUG_LEAVE, and list_destroy_with_content().

Here is the call graph for this function:

E_MCL_ERROR_CODE mcl_list_exist ( mcl_list_t list,
const void *  item_to_find,
mcl_list_compare_callback  compare_function,
void **  item 
)

Searches item_to_find in the list.

Parameters
[in]listThe list to search in.
[in]item_to_findItem to search for.
[in]compare_functionCallback function used to compare.
[out]itemPointer to the item found.
Returns

Definition at line 96 of file list.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and list_exist().

Here is the call graph for this function:

E_MCL_ERROR_CODE mcl_list_initialize ( mcl_list_t **  list)

Initializes a list with zero items in it.

Parameters
[out]listInitialized mcl_list_t instance.
Returns

Definition at line 19 of file list.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and list_initialize().

Here is the call graph for this function:

E_MCL_ERROR_CODE mcl_list_next ( mcl_list_t list,
mcl_list_node_t **  node 
)

Gets the next node from the list.

Last returned node is kept in list. This function can be called consequently to loop over the list. If there is no node left to return or the list is empty, node will be NULL.

Parameters
[in]listThe list.
[out]nodeAddress of next node.
Returns

Definition at line 46 of file list.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, list_next(), MCL_FAIL, MCL_NULL, and MCL_OK.

Here is the call graph for this function:

E_MCL_ERROR_CODE mcl_list_remove ( mcl_list_t list,
mcl_list_node_t node 
)

Removes a node from the list.

The list node is removed from the list and its handle of type mcl_list_node_t will be freed but the data that it holds will not. User needs to free the resource before it calls remove!

Parameters
[in]listThe list from which the node is removed.
[in]nodeThe node to be removed.
Returns

Definition at line 67 of file list.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and list_remove().

Here is the call graph for this function:

E_MCL_ERROR_CODE mcl_list_remove_with_content ( mcl_list_t list,
mcl_list_node_t node,
mcl_list_item_destroy_callback  callback 
)

Removes a node from the list and destroys the removed item with the provided callback function.

The node (mcl_list_node_t) will be freed and the data that it holds is going to be destroyed by passing it to the provided callback function.

Parameters
[in]listThe list from which the node is removed.
[in]nodeThe node to be removed.
[in]callbackThe callback function to destroy the list item.
Returns

Definition at line 81 of file list.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and list_remove_with_content().

Here is the call graph for this function:

void mcl_list_reset ( mcl_list_t list)

Reset the current node to head node.

The goal here is to be able to loop over the list from it's beginning.

Parameters
[in]listThe list which is used to reset it's current node to it's head node.

Definition at line 112 of file list.c.

References DEBUG_ENTRY, DEBUG_LEAVE, and list_reset().

Here is the call graph for this function: