Esempio n. 1
0
void logger_add_stream(struct logger *inst, struct logger_stream *stream) {
    logger_assert(NULL != inst);
    logger_assert(NULL != stream);

    if (true != logger_list_exist(&inst->stream_list, stream)) {
        logger_list_push(&inst->stream_list, stream, 0);
    }
}
Esempio n. 2
0
void _log_vwrite(struct logger *inst, const unsigned int level,
        const char *file_name,
        const char *function_name,
        const unsigned int line_number,
        const char *fmt, va_list args) {
    logger_assert(NULL != inst);
    logger_assert(NULL != fmt);

    __vlog_write(inst, level, file_name, function_name, line_number, fmt, args);
}
Esempio n. 3
0
void logger_remove_stream(struct logger *inst, struct logger_stream *stream) {
    logger_assert(NULL != inst);
    logger_assert(NULL != stream);

    struct logger_list_node *it = NULL;

    for (it = inst->stream_list.first; it != NULL; it = it->next) {
        if (it->object == stream) {
            logger_list_remove_node(&inst->stream_list, it);
            break;
        }
    }
}
Esempio n. 4
0
void logger_list_sort(struct logger_list *inst,
        logger_list_compare_t compare) {
    logger_assert(NULL != inst);

    if (inst->first == inst->last) {
        return;
    }

    struct logger_list_node *const last = inst->last->prev;
    struct logger_list_node *iit;
    struct logger_list_node *it;

    bool swap = true;
    void *object;
    int id;

    for (iit = inst->first; (NULL != iit) && (true == swap); iit = iit->next) {
        swap = false;
        for (it = inst->first; last != it; it = it->next) {
            if (true == compare(it->object, it->id,
                        it->next->object, it->next->id)) {
                /* Store */
                object = it->object;
                id = it->id;
                /* Left swap */
                it->object = it->next->object;
                it->id = it->next->id;
                /* Right swap */
                it->next->object = object;
                it->next->id = id;
                swap = true;
            }
        }
    }
}
Esempio n. 5
0
int logger_list_push(struct logger_list *inst, void *object, int id) {
    logger_assert(NULL != inst);

    struct logger_list_node *node =
        logger_memory_alloc(sizeof(struct logger_list_node));

    if (NULL == node) {
        return LOGGER_ERROR_NULL;
    }

    node->next = NULL;
    node->prev = NULL;
    node->object = object;
    node->id = id;

    if (NULL == inst->first) {
        inst->first = node;
        inst->last = node;
    } else {
        inst->last->next = node;
        node->prev = inst->last;
        inst->last = node;
    }

    return LOGGER_SUCCESS;
}
Esempio n. 6
0
void logger_get_options(struct logger *inst, union logger_options *options) {
    logger_assert(NULL != inst);

    if (NULL != options) {
        options->raw = inst->options.raw;
    }
}
Esempio n. 7
0
void logger_list_move(struct logger_list *inst,
        struct logger_list *list_to_move) {
    logger_assert(NULL != inst);
    logger_assert(NULL != list_to_move);

    if (NULL != list_to_move->first) {
        if (NULL != inst->first) {
            inst->last->next = list_to_move->first;
            inst->last = list_to_move->last;
        } else {
            inst->first = list_to_move->first;
            inst->last = list_to_move->last;
        }
        *list_to_move = LOGGER_LIST_INIT;
    }
}
int logger_stream_standard_error_flush(struct logger_stream *inst) {
    logger_assert(NULL != inst);

    inst->buffer[inst->index] = '\0';
    fputs(inst->buffer, stderr);

    return LOGGER_SUCCESS;
}
int logger_stream_standard_destroy(struct logger_stream *inst) {
    logger_assert(NULL != inst);

    logger_memory_free(inst->buffer);
    inst->buffer = NULL;
    inst->buffer_size = 0;

    return LOGGER_SUCCESS;
}
Esempio n. 10
0
void logger_set_options(struct logger *inst, union logger_options *options) {
    logger_assert(NULL != inst);

    if (NULL != options) {
        inst->options.raw = options->raw;
    } else {
        inst->options.raw = g_logger_default_options.raw;
    }
}
Esempio n. 11
0
char *logger_alloc_copy_string(const char *str) {
    logger_assert(NULL != str);

    size_t size = strnlen_s(str, RSIZE_MAX_STR);
    char *buffer = logger_memory_alloc(size + 1);
    if (NULL != buffer) {
        strncpy_s(buffer, RSIZE_MAX_STR, str, size);
        buffer[size] = '\0';
    }

    return buffer;
}
Esempio n. 12
0
bool logger_list_exist(struct logger_list *inst, void *object) {
    logger_assert(NULL != inst);

    struct logger_list_node *it;

    for (it = inst->first; it != NULL; it = it->next) {
        if (it->object == object) {
            return true;
        }
    }

    return false;
}
Esempio n. 13
0
void logger_list_clear(struct logger_list *inst) {
    logger_assert(NULL != inst);

    struct logger_list_node *it;
    struct logger_list_node *next;

    for (it = inst->first; it != NULL; it = next) {
        next = it->next;
        logger_memory_free(it);
    }

    *inst = LOGGER_LIST_INIT;
}
Esempio n. 14
0
void *logger_list_pop(struct logger_list *inst, int *id) {
    logger_assert(NULL != inst);

    void *object = NULL;
    struct logger_list_node *node = inst->first;

    if (NULL != node) {
        object = node->object;
        if (NULL != id) {
            *id = node->id;
        }
        logger_list_remove_node(inst, node);
    }

    return object;
}
int logger_stream_standard_create(struct logger_stream *inst) {
    logger_assert(NULL != inst);

    logger_memory_free(inst->buffer);
    /* Extend buffer size for null terminator character */
    inst->buffer = logger_memory_alloc(LOGGER_DEFAULT_STREAM_SIZE + 1);

    if (NULL != inst->buffer) {
        inst->buffer_size = LOGGER_DEFAULT_STREAM_SIZE;
    } else {
        inst->buffer_size = 0;
        return LOGGER_ERROR_NULL;
    }

    return LOGGER_SUCCESS;
}
Esempio n. 16
0
char *logger_alloc_fmt_string(const char *fmt, va_list args) {
    logger_assert(NULL != fmt);

    va_list args_copy;
    va_copy(args_copy, args);

    char *buffer = NULL;

    int size = vsnprintf(NULL, 0, fmt, args);
    if (size > 0) {
        buffer = logger_memory_alloc((size_t)size + 1);
        if (NULL != buffer) {
            vsnprintf(buffer, (size_t)size, fmt, args_copy);
        }
    }

    va_end(args_copy);
    return buffer;
}
Esempio n. 17
0
void _log_write(struct logger *inst, const unsigned int level,
        const char *file_name,
        const char *function_name,
        const unsigned int line_number,
        const char *message) {
    logger_assert(NULL != inst);

    size_t message_length = strnlen_s(message, RSIZE_MAX_STR);
    size_t size =  sizeof(struct logger_stream_message) + message_length + 1;

    struct logger_stream_message *msg = logger_memory_alloc(size);
    if (NULL == msg) {
        return;
    }

    memcpy_s(msg->message, message_length, message, message_length);
    msg->message[message_length] = '\0';

    __log_write(inst, level, file_name, function_name, line_number, msg, size);
}
Esempio n. 18
0
void logger_list_remove_node(struct logger_list *inst,
        struct logger_list_node *node) {
    logger_assert(NULL != inst);

    if ((NULL == inst->first) || (NULL == node)) return;

    if ((node == inst->first) && (node == inst->last)) {
        inst->first = NULL;
        inst->last = NULL;
    } else if (node == inst->first) {
        inst->first = node->next;
    } else if (node == inst->last) {
        inst->last = node->prev;
    } else {
        struct logger_list_node *after = node->next;
        struct logger_list_node *before = node->prev;

        after->prev = before;
        before->next = after;
    }

    logger_memory_free(node);
}
Esempio n. 19
0
void PARSER_Init(void)
{
	logger_assert("READY\r");
}
Esempio n. 20
0
void logger_list_init(struct logger_list *inst) {
    logger_assert(NULL != inst);

    *inst = LOGGER_LIST_INIT;
}
Esempio n. 21
0
bool logger_list_empty(struct logger_list *inst) {
    logger_assert(NULL != inst);

    return (inst->first == NULL) ? true : false;
}