mirror of
https://github.com/hmaxnl/netex.git
synced 2025-01-18 15:34:20 +01:00
[ADD] Double linked list for holding app loggers.
This commit is contained in:
parent
63fa472d8c
commit
4c9c547e62
|
@ -14,6 +14,7 @@ target_link_directories(netex PUBLIC ${CURSES_INCLUDE_DIR})
|
||||||
|
|
||||||
target_include_directories(netex PRIVATE ${CMAKE_SOURCE_DIR}/src/net/include)
|
target_include_directories(netex PRIVATE ${CMAKE_SOURCE_DIR}/src/net/include)
|
||||||
|
|
||||||
|
add_subdirectory(collections)
|
||||||
add_subdirectory(include)
|
add_subdirectory(include)
|
||||||
add_subdirectory(logging)
|
add_subdirectory(logging)
|
||||||
add_subdirectory(str)
|
add_subdirectory(str)
|
||||||
|
|
2
src/net/collections/CMakeLists.txt
Normal file
2
src/net/collections/CMakeLists.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
target_sources(netex PUBLIC
|
||||||
|
"list.c")
|
63
src/net/collections/list.c
Normal file
63
src/net/collections/list.c
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#include <errno.h>
|
||||||
|
#include "netex.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
#include "list.h"
|
||||||
|
|
||||||
|
list_node * insert_end(list_node* list, void* data)
|
||||||
|
{
|
||||||
|
list_node* node = (list_node*)malloc(sizeof(list_node));
|
||||||
|
if (node == NULL)
|
||||||
|
{
|
||||||
|
int error = errno;
|
||||||
|
//Failed -> log
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
node->data = data;
|
||||||
|
node->previous = NULL;
|
||||||
|
node->next = NULL;
|
||||||
|
|
||||||
|
if (list != NULL)
|
||||||
|
{
|
||||||
|
if (list->next == NULL)
|
||||||
|
list->next = node;
|
||||||
|
list_node* current = list->next;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (current->next == NULL)
|
||||||
|
{
|
||||||
|
current->next = node;
|
||||||
|
node->previous = current;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current = current->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete_node(list_node* node)
|
||||||
|
{
|
||||||
|
if (node == NULL)
|
||||||
|
return;
|
||||||
|
node->previous->next = node->next;
|
||||||
|
node->next->previous = node->previous;
|
||||||
|
free(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void iterate_list(list_node* list, bool forward, int (*iterFunc)(const void*))
|
||||||
|
{
|
||||||
|
if (list == NULL || iterFunc == NULL)
|
||||||
|
return;
|
||||||
|
list_node * current = list;
|
||||||
|
while (current != NULL)
|
||||||
|
{
|
||||||
|
if (iterFunc(current->data) == 1)
|
||||||
|
break;
|
||||||
|
if (forward)
|
||||||
|
current = current->next;
|
||||||
|
else
|
||||||
|
current = current->previous;
|
||||||
|
}
|
||||||
|
}
|
14
src/net/include/list.h
Normal file
14
src/net/include/list.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef NETEX_LIST_H
|
||||||
|
#define NETEX_LIST_H
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct list_node
|
||||||
|
{
|
||||||
|
void* data;
|
||||||
|
struct list_node* previous;
|
||||||
|
struct list_node* next;
|
||||||
|
} list_node;
|
||||||
|
|
||||||
|
void iterate_list(list_node* list, bool forward, int (*iterFunc)(const void*));
|
||||||
|
|
||||||
|
#endif //NETEX_LIST_H
|
|
@ -1,5 +1,6 @@
|
||||||
#ifndef LOG_H
|
#ifndef LOG_H
|
||||||
#define LOG_H
|
#define LOG_H
|
||||||
|
#include "list.h"
|
||||||
|
|
||||||
enum log_level
|
enum log_level
|
||||||
{
|
{
|
||||||
|
@ -16,7 +17,8 @@ typedef struct app_logger_info
|
||||||
char* executable_name;
|
char* executable_name;
|
||||||
int log_file_max_size;
|
int log_file_max_size;
|
||||||
enum log_level max_log_level;
|
enum log_level max_log_level;
|
||||||
/// logger list/linked list/array?
|
list_node* loggers;
|
||||||
|
|
||||||
} app_logger_info;
|
} app_logger_info;
|
||||||
|
|
||||||
typedef struct logger
|
typedef struct logger
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "netex.h"
|
#include "netex.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
bool canLog = true;
|
bool canLog = true;
|
||||||
app_logger_info* default_app_log = NULL;
|
app_logger_info* default_app_log = NULL;
|
||||||
|
@ -10,11 +12,22 @@ app_logger_info* initialize_log(char* logPath, char* executable, int maxFileSize
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int shutdown_logger(const void* data)
|
||||||
|
{
|
||||||
|
logger* logger = (struct logger*)data;
|
||||||
|
logger->app_logger = NULL;
|
||||||
|
logger->name = NULL;
|
||||||
|
free(logger);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
void shutdown_log(app_logger_info* appLogger)
|
void shutdown_log(app_logger_info* appLogger)
|
||||||
{
|
{
|
||||||
canLog = false;
|
canLog = false;
|
||||||
|
iterate_list(appLogger->loggers, true, &shutdown_logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger* create_logger(app_logger_info* appLogger, char* name)
|
logger* create_logger(app_logger_info* appLogger, char* name)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user