- code cleaned up
This commit is contained in:
parent
c3dc864eaa
commit
d794bcdb08
|
@ -29,13 +29,13 @@
|
|||
|
||||
#include "allocator.h"
|
||||
|
||||
#ifdef LEAK_DETECTIVE
|
||||
|
||||
#ifdef LEAK_DETECTIVE
|
||||
|
||||
typedef union memory_hdr_t memory_hdr_t;
|
||||
|
||||
/**
|
||||
* Header of each allocated memory area.
|
||||
* @brief Header of each allocated memory area.
|
||||
*
|
||||
* Ideas stolen from pluto's defs.c.
|
||||
*
|
||||
|
@ -43,28 +43,29 @@ typedef union memory_hdr_t memory_hdr_t;
|
|||
*/
|
||||
union memory_hdr_t {
|
||||
/**
|
||||
* Informations
|
||||
* Informations.
|
||||
*/
|
||||
struct {
|
||||
/**
|
||||
* Filename withing memory was allocated
|
||||
* Filename withing memory was allocated.
|
||||
*/
|
||||
const char *filename;
|
||||
/**
|
||||
* Line number in given file
|
||||
* Line number in given file.
|
||||
*/
|
||||
size_t line;
|
||||
/**
|
||||
* Allocated memory size. Needed for reallocation
|
||||
* Allocated memory size. Needed for reallocation.
|
||||
*/
|
||||
size_t size_of_memory;
|
||||
/**
|
||||
* Link to the previous and next memory area
|
||||
* Link to the previous and next memory area.
|
||||
*/
|
||||
memory_hdr_t *older, *newer;
|
||||
} info;
|
||||
/**
|
||||
* force maximal alignment ?
|
||||
* Force maximal alignment ?
|
||||
*
|
||||
*/
|
||||
unsigned long junk;
|
||||
};
|
||||
|
@ -100,13 +101,11 @@ struct private_allocator_t
|
|||
* returns an empty data area filled with zeros.
|
||||
*
|
||||
* @param this private_allocator_t object
|
||||
* @param bytes number of bytes to allocate
|
||||
* @param bytes number of bytes to allocate
|
||||
* @param file filename from which the memory is allocated
|
||||
* @param line line number in specific file
|
||||
* @param use_mutex if FALSE no mutex is used for allocation
|
||||
* @return
|
||||
* - pointer to allocated memory area
|
||||
* - NULL if out of ressources
|
||||
* @return pointer to allocated memory area
|
||||
*/
|
||||
void * (*allocate_special) (private_allocator_t *this,size_t bytes, char * file,int line, bool use_mutex);
|
||||
};
|
||||
|
@ -256,7 +255,6 @@ static void * clone_bytes(allocator_t *allocator,void * to_clone, size_t bytes,
|
|||
return new_space;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of allocator_t.clone_chunk.
|
||||
*/
|
||||
|
@ -327,7 +325,7 @@ static private_allocator_t allocator = {
|
|||
allocator_t *global_allocator = &(allocator.public);
|
||||
|
||||
/*
|
||||
* alloc function for gmp
|
||||
* Alloc function for gmp.
|
||||
*/
|
||||
void *gmp_alloc(size_t bytes)
|
||||
{
|
||||
|
@ -335,14 +333,14 @@ void *gmp_alloc(size_t bytes)
|
|||
}
|
||||
|
||||
/*
|
||||
* realloc function for gmp
|
||||
* Realloc function for gmp.
|
||||
*/
|
||||
void *gmp_realloc(void *old, size_t old_bytes, size_t new_bytes)
|
||||
{
|
||||
return global_allocator->reallocate(global_allocator, old, new_bytes, "[ gmp internal ]", 0);
|
||||
}
|
||||
/*
|
||||
* free function for gmp
|
||||
* Free function for gmp.
|
||||
*/
|
||||
void gmp_free(void *ptr, size_t bytes)
|
||||
{
|
||||
|
@ -359,9 +357,8 @@ void allocator_init()
|
|||
|
||||
#else /* !LEAK_DETECTION */
|
||||
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
* Described in header.
|
||||
*/
|
||||
chunk_t allocator_alloc_as_chunk(size_t bytes)
|
||||
{
|
||||
|
@ -377,7 +374,7 @@ chunk_t allocator_alloc_as_chunk(size_t bytes)
|
|||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
* Described in header.
|
||||
*/
|
||||
void * allocator_realloc(void * old, size_t newsize)
|
||||
{
|
||||
|
@ -386,7 +383,7 @@ void * allocator_realloc(void * old, size_t newsize)
|
|||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
* Described in header.
|
||||
*/
|
||||
void * allocator_clone_bytes(void * pointer, size_t size)
|
||||
{
|
||||
|
@ -400,9 +397,8 @@ void * allocator_clone_bytes(void * pointer, size_t size)
|
|||
return (data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Described in header
|
||||
* Described in header.
|
||||
*/
|
||||
chunk_t allocator_clone_chunk(chunk_t chunk)
|
||||
{
|
||||
|
@ -420,7 +416,7 @@ chunk_t allocator_clone_chunk(chunk_t chunk)
|
|||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
* Described in header.
|
||||
*/
|
||||
void allocator_free_chunk(chunk_t *chunk)
|
||||
{
|
||||
|
@ -429,5 +425,4 @@ void allocator_free_chunk(chunk_t *chunk)
|
|||
chunk->len = 0;
|
||||
}
|
||||
|
||||
|
||||
#endif /* LEAK_DETECTION */
|
||||
|
|
|
@ -32,10 +32,8 @@
|
|||
/**
|
||||
* Macro to allocate a special type.
|
||||
*
|
||||
* @param thing object on which a sizeof is performed
|
||||
* @return
|
||||
* - Pointer to allocated memory
|
||||
* - NULL if out of ressources.
|
||||
* @param thing object on which a sizeof is performed
|
||||
* @return pointer to allocated memory
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
|
@ -44,10 +42,8 @@
|
|||
/**
|
||||
* Macro to allocate a special type as chunk_t.
|
||||
*
|
||||
* @param thing object on which a sizeof is performed
|
||||
* @return
|
||||
* - chunk_t pointing to allocated memory if successful
|
||||
* - chunk_t containing empty pointer if out of ressources
|
||||
* @param thing object on which a sizeof is performed
|
||||
* @return chunk_t pointing to allocated memory
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
|
@ -68,16 +64,14 @@
|
|||
* Allocates memory with LEAK_DETECTION and
|
||||
* returns an empty data area filled with zeros.
|
||||
*
|
||||
* @warning Use this function not directly, only with assigned macros
|
||||
* @warning Use this function not directly, only with assigned macros
|
||||
* #allocator_alloc and #allocator_alloc_thing.
|
||||
*
|
||||
* @param this allocator_t object
|
||||
* @param bytes number of bytes to allocate
|
||||
* @param file filename from which the memory is allocated
|
||||
* @param line line number in specific file
|
||||
* @return
|
||||
* - pointer to allocated memory area
|
||||
* - NULL if out of ressources
|
||||
* @return pointer to allocated memory area
|
||||
*/
|
||||
void * (*allocate) (allocator_t *this,size_t bytes, char * file,int line);
|
||||
|
||||
|
@ -85,7 +79,7 @@
|
|||
* Allocates memory with LEAK_DETECTION and
|
||||
* returns an chunk pointing to an empy data area filled with zeros.
|
||||
*
|
||||
* @warning Use this function not directly, only with assigned
|
||||
* @warning Use this function not directly, only with assigned
|
||||
* macros #allocator_alloc_as_chunk and
|
||||
* #allocator_alloc_thing_as_chunk.
|
||||
*
|
||||
|
@ -93,9 +87,7 @@
|
|||
* @param bytes number of bytes to allocate
|
||||
* @param file filename from which the memory is allocated
|
||||
* @param line line number in specific file
|
||||
* @return
|
||||
* - pointer to allocated memory area
|
||||
* - NULL if out of ressources
|
||||
* @return pointer to allocated memory area
|
||||
*/
|
||||
chunk_t (*allocate_as_chunk) (allocator_t *this,size_t bytes, char * file,int line);
|
||||
|
||||
|
@ -103,7 +95,7 @@
|
|||
* Reallocates memory with LEAK_DETECTION and
|
||||
* returns an empty data area filled with zeros.
|
||||
*
|
||||
* @warning Use this function not directly, only with assigned macro
|
||||
* @warning Use this function not directly, only with assigned macro
|
||||
* #allocator_realloc.
|
||||
*
|
||||
* @param this allocator_t object
|
||||
|
@ -111,16 +103,14 @@
|
|||
* @param bytes number of bytes to allocate
|
||||
* @param file filename from which the memory is allocated
|
||||
* @param line line number in specific file
|
||||
* @return
|
||||
* - pointer to reallocated memory area
|
||||
* - NULL if out of ressources
|
||||
* @return pointer to reallocated memory area
|
||||
*/
|
||||
void * (*reallocate) (allocator_t *this,void * old, size_t bytes, char * file, int line);
|
||||
|
||||
/**
|
||||
* Clones memory with LEAK_DETECTION and returns a cloned data area.
|
||||
*
|
||||
* @warning Use this function not directly, only with assigned macro
|
||||
* @warning Use this function not directly, only with assigned macro
|
||||
* #allocator_clone_bytes.
|
||||
*
|
||||
* @param this allocator_t object
|
||||
|
@ -128,9 +118,7 @@
|
|||
* @param bytes number of bytes to allocate
|
||||
* @param file filename from which the memory is allocated
|
||||
* @param line line number in specific file
|
||||
* @return
|
||||
* - pointer to reallocated memory area if successful
|
||||
* - NULL if out of ressources
|
||||
* @return pointer to reallocated memory area
|
||||
*/
|
||||
void * (*clone_bytes) (allocator_t *this,void * to_clone, size_t bytes, char * file, int line);
|
||||
|
||||
|
@ -144,9 +132,7 @@
|
|||
* @param chunk chunk to clone
|
||||
* @param file filename from which the memory is allocated
|
||||
* @param line line number in specific file
|
||||
* @return
|
||||
* - pointer to reallocated memory area if successful
|
||||
* - NULL if out of ressources
|
||||
* @return pointer to reallocated memory
|
||||
*/
|
||||
chunk_t (*clone_chunk) (allocator_t *this, chunk_t chunk, char * file, int line);
|
||||
|
||||
|
@ -154,7 +140,7 @@
|
|||
* Frees memory with LEAK_DETECTION.
|
||||
*
|
||||
* @warning Use this function not directly, only with assigned macro
|
||||
* #allocator_free.
|
||||
* #allocator_free.
|
||||
*
|
||||
* @param this allocator_t object
|
||||
* @param pointer pointer to the data area to free
|
||||
|
@ -165,7 +151,7 @@
|
|||
* Report memory leaks to stderr.
|
||||
*
|
||||
* @warning Use this function not directly, only with assigned macro
|
||||
* #report_memory_leaks
|
||||
* #report_memory_leaks
|
||||
*
|
||||
* @param this allocator_t object
|
||||
*/
|
||||
|
@ -176,8 +162,7 @@
|
|||
/**
|
||||
* @brief Initialize the allocator.
|
||||
*
|
||||
* Setup the allocator (currently set
|
||||
* allocation functions for libgmp)
|
||||
* Setup the allocator (set allocation functions for libgmp)
|
||||
*/
|
||||
void allocator_init();
|
||||
|
||||
|
@ -219,17 +204,16 @@
|
|||
/**
|
||||
* Macro to clone some memory.
|
||||
*
|
||||
* See #allocator_t.*clone_bytes for description.
|
||||
* See #allocator_t.*clone_bytes for description.
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
#define allocator_clone_bytes(old,bytes) (global_allocator->clone_bytes(global_allocator,old,bytes,__FILE__, __LINE__))
|
||||
|
||||
|
||||
/**
|
||||
* Macro to clone a chunk and its contents
|
||||
*
|
||||
* See #allocator_t.clone_chunk for description.
|
||||
* See #allocator_t.clone_chunk for description.
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
|
@ -243,6 +227,7 @@
|
|||
* @ingroup utils
|
||||
*/
|
||||
#define allocator_free(pointer) (global_allocator->free_pointer(global_allocator,pointer))
|
||||
|
||||
/**
|
||||
* Macro to free a chunk.
|
||||
*/
|
||||
|
@ -251,6 +236,7 @@
|
|||
(chunk)->ptr = NULL; \
|
||||
(chunk)->len = 0; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Macro to report memory leaks.
|
||||
*
|
||||
|
@ -260,6 +246,7 @@
|
|||
*/
|
||||
#define report_memory_leaks(void) (global_allocator->report_memory_leaks(global_allocator))
|
||||
#else
|
||||
|
||||
/**
|
||||
* Macro to allocate some memory.
|
||||
*
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
#include <utils/allocator.h>
|
||||
|
||||
|
||||
/**
|
||||
* String mappings for id_type_t.
|
||||
*/
|
||||
|
@ -44,7 +43,6 @@ mapping_t id_type_m[] = {
|
|||
};
|
||||
|
||||
|
||||
|
||||
typedef struct private_identification_t private_identification_t;
|
||||
|
||||
/**
|
||||
|
@ -57,23 +55,23 @@ struct private_identification_t {
|
|||
identification_t public;
|
||||
|
||||
/**
|
||||
* string representation of this id
|
||||
* String representation of this ID.
|
||||
*/
|
||||
char *string;
|
||||
|
||||
/**
|
||||
* encoded representation of this id
|
||||
* Encoded representation of this ID.
|
||||
*/
|
||||
chunk_t encoded;
|
||||
|
||||
/**
|
||||
* type of this id
|
||||
* Type of this ID.
|
||||
*/
|
||||
id_type_t type;
|
||||
};
|
||||
|
||||
/**
|
||||
* implements identification_t.get_encoding
|
||||
* Implementation of identification_t.get_encoding.
|
||||
*/
|
||||
static chunk_t get_encoding(private_identification_t *this)
|
||||
{
|
||||
|
@ -81,7 +79,7 @@ static chunk_t get_encoding(private_identification_t *this)
|
|||
}
|
||||
|
||||
/**
|
||||
* implements identification_t.get_type
|
||||
* Implementation of identification_t.get_type.
|
||||
*/
|
||||
static id_type_t get_type(private_identification_t *this)
|
||||
{
|
||||
|
@ -89,7 +87,7 @@ static id_type_t get_type(private_identification_t *this)
|
|||
}
|
||||
|
||||
/**
|
||||
* implements identification_t.get_string
|
||||
* Implementation of identification_t.get_string.
|
||||
*/
|
||||
static char *get_string(private_identification_t *this)
|
||||
{
|
||||
|
@ -116,7 +114,7 @@ static bool equals (private_identification_t *this,private_identification_t *oth
|
|||
}
|
||||
|
||||
/**
|
||||
* implements identification_t.destroy
|
||||
* Implementation of identification_t.destroy.
|
||||
*/
|
||||
static void destroy(private_identification_t *this)
|
||||
{
|
||||
|
@ -126,13 +124,14 @@ static void destroy(private_identification_t *this)
|
|||
}
|
||||
|
||||
/*
|
||||
* Generic constructor used for the other twos
|
||||
* Generic constructor used for the other constructors.
|
||||
*
|
||||
* @return private_identification_t object
|
||||
*/
|
||||
static private_identification_t *identification_create()
|
||||
{
|
||||
private_identification_t *this = allocator_alloc_thing(private_identification_t);
|
||||
|
||||
/* assign methods */
|
||||
this->public.equals = (bool (*) (identification_t*,identification_t*))equals;
|
||||
this->public.get_encoding = (chunk_t (*) (identification_t*))get_encoding;
|
||||
this->public.get_type = (id_type_t (*) (identification_t*))get_type;
|
||||
|
|
|
@ -30,9 +30,11 @@
|
|||
typedef enum id_type_t id_type_t;
|
||||
|
||||
/**
|
||||
* @brief ID Types of a ID payload.
|
||||
* @brief ID Types in a ID payload.
|
||||
*
|
||||
* @see identification_t
|
||||
* @see
|
||||
* - identification_t
|
||||
* - id_payload_t
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
|
@ -83,7 +85,7 @@ enum id_type_t {
|
|||
};
|
||||
|
||||
/**
|
||||
* string amppings for id_type_t
|
||||
* String mappings for id_type_t.
|
||||
*/
|
||||
extern mapping_t id_type_m[];
|
||||
|
||||
|
@ -106,7 +108,7 @@ typedef struct identification_t identification_t;
|
|||
* - identification_create_from_string()
|
||||
* - identification_create_from_encoding()
|
||||
*
|
||||
* @todo Implement other types.
|
||||
* @todo Support for other ID types then ID_IPV4_ADDR.
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
|
@ -150,7 +152,6 @@ struct identification_t {
|
|||
*/
|
||||
bool (*equals) (identification_t *this,identification_t *other);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Destroys a identification_t object.
|
||||
*
|
||||
|
@ -178,7 +179,7 @@ identification_t * identification_create_from_string(id_type_t type, char *strin
|
|||
*
|
||||
* @param type type of this id, such as ID_IPV4_ADDR
|
||||
* @param encoded encoded bytes, such as from identification_t.get_encoding
|
||||
* @return created identification_t object
|
||||
* @return identification_t object
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
|
|
|
@ -31,9 +31,11 @@ typedef struct iterator_t iterator_t;
|
|||
* iterator_t defines an interface for iterating over collections.
|
||||
* It allows searching, deleting, updating and inserting.
|
||||
*
|
||||
* Thanks to JMP for iterator lessons :-)
|
||||
*
|
||||
* @b Constructors:
|
||||
* - via linked_list_t.create_iterator, or
|
||||
* - any other class which supports this interface
|
||||
* - any other class which supports the iterator_t interface
|
||||
*
|
||||
* @see linked_list_t
|
||||
*
|
||||
|
@ -44,8 +46,8 @@ struct iterator_t {
|
|||
/**
|
||||
* @brief Moves to the next element, if available.
|
||||
*
|
||||
* A newly created iterator doesn't point to any item,
|
||||
* call has_next first to point it to the first item.
|
||||
* A newly created iterator_t object doesn't point to any item.
|
||||
* Call iterator_t.has_next first to point it to the first item.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return
|
||||
|
@ -118,8 +120,8 @@ struct iterator_t {
|
|||
/**
|
||||
* @brief Resets the iterator position.
|
||||
*
|
||||
* After reset, the iterator stands NOT on an element.
|
||||
* A call to has_next is necessary to do any other operations
|
||||
* After reset, the iterator_t objects doesn't point to an element.
|
||||
* A call to iterator_t.has_next is necessary to do any other operations
|
||||
* with the resetted iterator.
|
||||
*
|
||||
* @param this calling object
|
||||
|
|
|
@ -27,35 +27,39 @@
|
|||
#include <utils/allocator.h>
|
||||
|
||||
|
||||
|
||||
typedef struct linked_list_element_t linked_list_element_t;
|
||||
|
||||
/**
|
||||
* @brief Element of the linked_list.
|
||||
* @brief Element in a linked list.
|
||||
*
|
||||
* This element holds a pointer to the value of the list item itself.
|
||||
* This element holds a pointer to the value it represents.
|
||||
*/
|
||||
struct linked_list_element_t {
|
||||
|
||||
/**
|
||||
* Value of a list item.
|
||||
*/
|
||||
void *value;
|
||||
|
||||
/**
|
||||
* previous list element
|
||||
* NULL if first element in list
|
||||
* Previous list element.
|
||||
*
|
||||
* NULL if first element in list.
|
||||
*/
|
||||
linked_list_element_t *previous;
|
||||
|
||||
/**
|
||||
* next list element
|
||||
* NULL if last element in list
|
||||
* Next list element.
|
||||
*
|
||||
* NULL if last element in list.
|
||||
*/
|
||||
linked_list_element_t *next;
|
||||
|
||||
/**
|
||||
* Destroys a linked_list_element object.
|
||||
*
|
||||
* @param linked_list_element_t calling object
|
||||
* @param linked_list_element_t calling object
|
||||
*/
|
||||
void (*destroy) (linked_list_element_t *this);
|
||||
};
|
||||
|
@ -73,8 +77,8 @@ static void linked_list_element_destroy(linked_list_element_t *this)
|
|||
*
|
||||
* @warning Only the pointer to the value is stored.
|
||||
*
|
||||
* @param[in] value value of item to be set
|
||||
* @return linked_list_element_t object
|
||||
* @param[in] value value of item to be set
|
||||
* @return linked_list_element_t object
|
||||
*/
|
||||
|
||||
linked_list_element_t *linked_list_element_create(void *value)
|
||||
|
@ -92,8 +96,9 @@ linked_list_element_t *linked_list_element_create(void *value)
|
|||
|
||||
|
||||
typedef struct private_linked_list_t private_linked_list_t;
|
||||
|
||||
/**
|
||||
* Private variables and functions of linked list.
|
||||
* Private data of a linked_list_t object.
|
||||
*
|
||||
*/
|
||||
struct private_linked_list_t {
|
||||
|
@ -582,7 +587,6 @@ static status_t get_at_position (private_linked_list_t *this,size_t position, vo
|
|||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of linked_list_t.get_last.
|
||||
*/
|
||||
|
@ -628,7 +632,6 @@ static void linked_list_destroy(private_linked_list_t *this)
|
|||
{
|
||||
void * value;
|
||||
/* Remove all list items before destroying list */
|
||||
|
||||
while (this->public.remove_first(&(this->public),&value) != NOT_FOUND)
|
||||
{
|
||||
/* values are not destroyed so memory leaks are possible
|
||||
|
@ -638,7 +641,7 @@ static void linked_list_destroy(private_linked_list_t *this)
|
|||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
* Described in header.
|
||||
*/
|
||||
linked_list_t *linked_list_create()
|
||||
{
|
||||
|
|
|
@ -37,7 +37,10 @@ typedef struct linked_list_t linked_list_t;
|
|||
* @b Costructors:
|
||||
* - linked_list_create()
|
||||
*
|
||||
* @see job_queue_t, event_queue_t, send_queue_t
|
||||
* @see
|
||||
* - job_queue_t
|
||||
* - event_queue_t
|
||||
* - send_queue_t
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
|
@ -57,7 +60,7 @@ struct linked_list_t {
|
|||
* @warning Created iterator_t object has to get destroyed by the caller.
|
||||
*
|
||||
* @param linked_list calling object
|
||||
* @param[in] forward iterator direction (TRUE: front to end)
|
||||
* @param forward iterator direction (TRUE: front to end)
|
||||
* @return new iterator_t object
|
||||
*/
|
||||
iterator_t * (*create_iterator) (linked_list_t *linked_list, bool forward);
|
||||
|
@ -66,7 +69,7 @@ struct linked_list_t {
|
|||
* @brief Inserts a new item at the beginning of the list.
|
||||
*
|
||||
* @param linked_list calling object
|
||||
* @param[in] item value to insert in list
|
||||
* @param[in] item item value to insert in list
|
||||
*/
|
||||
void (*insert_first) (linked_list_t *linked_list, void *item);
|
||||
|
||||
|
@ -74,7 +77,7 @@ struct linked_list_t {
|
|||
* @brief Removes the first item in the list and returns its value.
|
||||
*
|
||||
* @param linked_list calling object
|
||||
* @param[in] item returned value of first item
|
||||
* @param[out] item returned value of first item
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - NOT_FOUND, if list is empty
|
||||
|
@ -85,7 +88,7 @@ struct linked_list_t {
|
|||
* @brief Returns the value of the first list item without removing it.
|
||||
*
|
||||
* @param linked_list calling object
|
||||
* @param[out] item returned value of first item
|
||||
* @param[out] item item returned value of first item
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - NOT_FOUND, if list is empty
|
||||
|
@ -96,7 +99,7 @@ struct linked_list_t {
|
|||
* @brief Inserts a new item at the end of the list.
|
||||
*
|
||||
* @param linked_list calling object
|
||||
* @param[in] item value to insert into list
|
||||
* @param[in] item item value to insert into list
|
||||
*/
|
||||
void (*insert_last) (linked_list_t *linked_list, void *item);
|
||||
|
||||
|
@ -105,7 +108,7 @@ struct linked_list_t {
|
|||
*
|
||||
* @param linked_list calling object
|
||||
* @param position position starting at 0 to insert new entry
|
||||
* @param[in] item value to insert into list
|
||||
* @param[in] item item value to insert into list
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - INVALID_ARG if position not existing
|
||||
|
@ -117,7 +120,7 @@ struct linked_list_t {
|
|||
*
|
||||
* @param linked_list calling object
|
||||
* @param position position starting at 0 to remove entry from
|
||||
* @param[out] removed item will be stored at this location
|
||||
* @param[out] item removed item will be stored at this location
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - INVALID_ARG if position not existing
|
||||
|
@ -129,7 +132,7 @@ struct linked_list_t {
|
|||
*
|
||||
* @param linked_list calling object
|
||||
* @param position position starting at 0 to get entry from
|
||||
* @param[out] item will be stored at this location
|
||||
* @param[out] item item will be stored at this location
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - INVALID_ARG if position not existing
|
||||
|
@ -140,7 +143,7 @@ struct linked_list_t {
|
|||
* @brief Removes the last item in the list and returns its value.
|
||||
*
|
||||
* @param linked_list calling object
|
||||
* @param[out] item returned value of last item
|
||||
* @param[out] item item returned value of last item
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - NOT_FOUND if list is empty
|
||||
|
@ -151,7 +154,7 @@ struct linked_list_t {
|
|||
* @brief Returns the value of the last list item without removing it.
|
||||
*
|
||||
* @param linked_list calling object
|
||||
* @param[out] item returned value of last item
|
||||
* @param[out] item item returned value of last item
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - NOT_FOUND if list is empty
|
||||
|
@ -174,7 +177,7 @@ struct linked_list_t {
|
|||
/**
|
||||
* @brief Creates an empty linked list object.
|
||||
*
|
||||
* @return the created linked list.
|
||||
* @return linked_list_t object.
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
|
|
|
@ -33,18 +33,19 @@
|
|||
#include <utils/allocator.h>
|
||||
|
||||
/**
|
||||
* Maximum length of al log entry (only used for logger_s.log)
|
||||
* Maximum length of a log entry (only used for logger_s.log).
|
||||
*/
|
||||
#define MAX_LOG 8192
|
||||
|
||||
|
||||
typedef struct private_logger_t private_logger_t;
|
||||
|
||||
/**
|
||||
* @brief The logger object's private data.
|
||||
* @brief Private data of a logger_t object.
|
||||
*/
|
||||
struct private_logger_t {
|
||||
/**
|
||||
* Public data
|
||||
* Public data.
|
||||
*/
|
||||
logger_t public;
|
||||
/**
|
||||
|
@ -255,7 +256,6 @@ static void log_bytes(private_logger_t *this, logger_level_t loglevel, char *lab
|
|||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of logger_t.log_chunk.
|
||||
*/
|
||||
|
@ -264,7 +264,6 @@ static void log_chunk(logger_t *this, logger_level_t loglevel, char *label, chun
|
|||
this->log_bytes(this, loglevel, label, chunk->ptr, chunk->len);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of logger_t.enable_level.
|
||||
*/
|
||||
|
@ -297,11 +296,7 @@ logger_t *logger_create(char *logger_name, logger_level_t log_level, bool log_th
|
|||
{
|
||||
private_logger_t *this = allocator_alloc_thing(private_logger_t);
|
||||
|
||||
if (logger_name == NULL)
|
||||
{
|
||||
logger_name = "";
|
||||
}
|
||||
|
||||
/* public functions */
|
||||
this->public.log = (void(*)(logger_t*,logger_level_t,char*,...))logg;
|
||||
this->public.log_bytes = (void(*)(logger_t*, logger_level_t, char*,char*,size_t))log_bytes;
|
||||
this->public.log_chunk = log_chunk;
|
||||
|
@ -309,8 +304,14 @@ logger_t *logger_create(char *logger_name, logger_level_t log_level, bool log_th
|
|||
this->public.disable_level = (void(*)(logger_t*,logger_level_t))disable_level;
|
||||
this->public.destroy = (void(*)(logger_t*))destroy;
|
||||
|
||||
/* private functions */
|
||||
this->prepend_prefix = prepend_prefix;
|
||||
|
||||
if (logger_name == NULL)
|
||||
{
|
||||
logger_name = "";
|
||||
}
|
||||
|
||||
/* private variables */
|
||||
this->level = log_level;
|
||||
this->log_thread_id = log_thread_id;
|
||||
|
|
|
@ -33,9 +33,9 @@ typedef enum logger_level_t logger_level_t;
|
|||
/**
|
||||
* @brief Log Levels supported by the logger object.
|
||||
*
|
||||
* Logleves are devided in two types:
|
||||
* - One to specify the type log
|
||||
* - One to specify the detail-level of the log
|
||||
* Logleves are devided in two different kinds:
|
||||
* - levels to specify the type of the log
|
||||
* - levels to specify the detail-level of the log
|
||||
*
|
||||
* Use combinations of these to build detailed loglevels, such
|
||||
* as CONTROL|MORE fore a detailed cotrol level, or
|
||||
|
@ -85,6 +85,9 @@ typedef struct logger_t logger_t;
|
|||
/**
|
||||
* @brief Class to simplify logging.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - logger_create()
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
struct logger_t {
|
||||
|
@ -92,11 +95,11 @@ struct logger_t {
|
|||
/**
|
||||
* @brief Log an entry, using printf()-like params.
|
||||
*
|
||||
* The specefied loglevels must ALL be activated that
|
||||
* All specified loglevels must be activated that
|
||||
* the log is done.
|
||||
*
|
||||
* @param this logger_t object
|
||||
* @param loglevel or'ed set of loglevels
|
||||
* @param loglevel or'ed set of logger_level_t's
|
||||
* @param format printf like format string
|
||||
* @param ... printf like parameters
|
||||
*/
|
||||
|
@ -105,11 +108,11 @@ struct logger_t {
|
|||
/**
|
||||
* @brief Log some bytes, useful for debugging.
|
||||
*
|
||||
* The specefied loglevels must ALL be activated that
|
||||
* All specified loglevels must be activated that
|
||||
* the log is done.
|
||||
*
|
||||
* @param this logger_t object
|
||||
* @param loglevel or'ed set of loglevels
|
||||
* @param loglevel or'ed set of logger_level_t's
|
||||
* @param label a labeling name, logged with the bytes
|
||||
* @param bytes pointer to the bytes to dump
|
||||
* @param len number of bytes to dump
|
||||
|
@ -119,11 +122,11 @@ struct logger_t {
|
|||
/**
|
||||
* @brief Log a chunk, useful for debugging.
|
||||
*
|
||||
* The specefied loglevels must ALL be activated that
|
||||
* All specified loglevels must be activated that
|
||||
* the log is done.
|
||||
*
|
||||
* @param this logger_t object
|
||||
* @param loglevel or'ed set of loglevels
|
||||
* @param loglevel or'ed set of logger_level_t's
|
||||
* @param label a labeling name, logged with the bytes
|
||||
* @param chunk pointer to a chunk to log
|
||||
*/
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include <utils/allocator.h>
|
||||
#include <utils/linked_list.h>
|
||||
|
||||
/**
|
||||
* String mappings for logger_context_t
|
||||
*/
|
||||
mapping_t logger_context_t_mappings[] = {
|
||||
{PARSER, "PARSER"},
|
||||
{GENERATOR, "GENRAT"},
|
||||
|
@ -48,7 +51,7 @@ mapping_t logger_context_t_mappings[] = {
|
|||
};
|
||||
|
||||
/**
|
||||
* Maximum length of a logger name
|
||||
* Maximum length of a logger name in bytes.
|
||||
*/
|
||||
#define MAX_LOGGER_NAME 45
|
||||
|
||||
|
@ -65,7 +68,7 @@ struct private_logger_manager_t {
|
|||
logger_manager_t public;
|
||||
|
||||
/**
|
||||
* Managed loggers.
|
||||
* List of managed loggers.
|
||||
*/
|
||||
linked_list_t *loggers;
|
||||
|
||||
|
@ -93,7 +96,10 @@ struct private_logger_manager_t {
|
|||
* @param logger_level logger_level to set
|
||||
* @param enable enable specific level or disable it
|
||||
*/
|
||||
void (*set_logger_level) (private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level,bool enable);
|
||||
void (*set_logger_level) (private_logger_manager_t *this,
|
||||
logger_context_t context,
|
||||
logger_level_t logger_level,
|
||||
bool enable);
|
||||
|
||||
};
|
||||
|
||||
|
@ -107,17 +113,33 @@ typedef struct logger_levels_entry_t logger_levels_entry_t;
|
|||
* logger_t objects in specific context.
|
||||
*/
|
||||
struct logger_levels_entry_t {
|
||||
/**
|
||||
* Logger context.
|
||||
*/
|
||||
logger_context_t context;
|
||||
|
||||
/**
|
||||
* Logger level of logger context.
|
||||
*/
|
||||
logger_level_t level;
|
||||
};
|
||||
|
||||
|
||||
typedef struct loggers_entry_t loggers_entry_t;
|
||||
|
||||
/**
|
||||
* Entry in the loggers linked list.
|
||||
*
|
||||
* @todo Replace loggers_entry_t with logger_t and add get_context() function to logger_t class.
|
||||
*/
|
||||
struct loggers_entry_t {
|
||||
/**
|
||||
* Logger context.
|
||||
*/
|
||||
logger_context_t context;
|
||||
/**
|
||||
* Assigned logger
|
||||
*/
|
||||
logger_t *logger;
|
||||
};
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <utils/logger.h>
|
||||
|
||||
|
||||
typedef enum logger_context_t logger_context_t;
|
||||
|
||||
/**
|
||||
|
@ -53,17 +54,18 @@ enum logger_context_t {
|
|||
PRIME_POOL,
|
||||
};
|
||||
|
||||
|
||||
typedef struct logger_manager_t logger_manager_t;
|
||||
|
||||
/**
|
||||
* @brief Class to manage logger_t objects.
|
||||
*
|
||||
* The logger manager stores all loggers in a list and
|
||||
* The logger manager manages all logger_t object in a list and
|
||||
* allows their manipulation. Via a logger_context_t, the loglevel
|
||||
* of a specific logging type can be adjusted at runtime.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - logger_manager_create()
|
||||
* - logger_manager_create()
|
||||
*
|
||||
* @see logger_t
|
||||
*
|
||||
|
@ -81,18 +83,16 @@ struct logger_manager_t {
|
|||
*
|
||||
* @param this logger_manager_t object
|
||||
* @param context logger_context to use the logger for
|
||||
* @param[out] logger pointer to a a place where the new logger is stored
|
||||
* @param name name for the new logger. Context name is already included
|
||||
* and has not to be specified (so NULL is allowed)
|
||||
* @return logger_t object
|
||||
*/
|
||||
logger_t *(*create_logger) (logger_manager_t *this, logger_context_t context, char *name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Destroys a logger_t object which is not used anymore.
|
||||
*
|
||||
* @warning Objects of type logger_t which are not destroyed over function
|
||||
* Objects of type logger_t which are not destroyed over function
|
||||
* #logger_manager_t.destroy_logger are destroyed in logger_managers
|
||||
* destroy function.
|
||||
*
|
||||
|
@ -111,21 +111,21 @@ struct logger_manager_t {
|
|||
logger_level_t (*get_logger_level) (logger_manager_t *this, logger_context_t context);
|
||||
|
||||
/**
|
||||
* Enables a logger_level of a specific context.
|
||||
* Enables a logger level of a specific context.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param context context to set level
|
||||
* @param logger_level logger_level to eanble
|
||||
* @param logger_level logger level to eanble
|
||||
*/
|
||||
void (*enable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
|
||||
|
||||
|
||||
/**
|
||||
* Disables a logger_level of a specific context.
|
||||
* Disables a logger level of a specific context.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param context context to set level
|
||||
* @param logger_level logger_level to disable
|
||||
* @param logger_level logger level to disable
|
||||
*/
|
||||
void (*disable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
|
||||
|
||||
|
@ -143,7 +143,7 @@ struct logger_manager_t {
|
|||
/**
|
||||
* @brief Constructor to create a logger_manager_t object.
|
||||
*
|
||||
* @param default_log_level default log level for a context
|
||||
* @param default_log_level default log level for all context
|
||||
* @return logger_manager_t object
|
||||
*
|
||||
* @ingroup utils
|
||||
|
|
Loading…
Reference in New Issue