117 lines
2.2 KiB
C
117 lines
2.2 KiB
C
|
|
#include "ctx.h"
|
||
|
|
|
||
|
|
#include "diag.h"
|
||
|
|
#include "write.h"
|
||
|
|
|
||
|
|
#include <ivy/diag.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <string.h>
|
||
|
|
|
||
|
|
enum ivy_status ivy_diag_ctx_create(struct ivy_diag_ctx **out)
|
||
|
|
{
|
||
|
|
struct ivy_diag_ctx *ctx = malloc(sizeof *ctx);
|
||
|
|
if (!ctx) {
|
||
|
|
return IVY_ERR_NO_MEMORY;
|
||
|
|
}
|
||
|
|
|
||
|
|
memset(ctx, 0x0, sizeof *ctx);
|
||
|
|
|
||
|
|
*out = ctx;
|
||
|
|
return IVY_OK;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ivy_diag_ctx_destroy(struct ivy_diag_ctx *ctx)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
enum ivy_status ivy_diag_set_line_source(
|
||
|
|
struct ivy_diag_ctx *ctx, struct ivy_line_source *src)
|
||
|
|
{
|
||
|
|
ctx->ctx_line_source = src;
|
||
|
|
return IVY_OK;
|
||
|
|
}
|
||
|
|
|
||
|
|
enum ivy_status ivy_diag_ctx_set_class_definitions(
|
||
|
|
struct ivy_diag_ctx *ctx, const struct ivy_diag_class *classes,
|
||
|
|
size_t nr_classes)
|
||
|
|
{
|
||
|
|
ctx->ctx_classes = classes;
|
||
|
|
ctx->ctx_nr_classes = nr_classes;
|
||
|
|
return IVY_OK;
|
||
|
|
}
|
||
|
|
|
||
|
|
enum ivy_status ivy_diag_ctx_set_msg_definitions(
|
||
|
|
struct ivy_diag_ctx *ctx, const struct ivy_diag_msg *msgs, size_t nr_msgs)
|
||
|
|
{
|
||
|
|
ctx->ctx_msg = msgs;
|
||
|
|
ctx->ctx_nr_msg = nr_msgs;
|
||
|
|
return IVY_OK;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ivy_diag_ctx_write(
|
||
|
|
struct ivy_diag_ctx *ctx, enum ivy_diag_format format,
|
||
|
|
struct ivy_diag_stream *stream)
|
||
|
|
{
|
||
|
|
b_queue_iterator it;
|
||
|
|
b_queue_foreach (&it, &ctx->ctx_diags) {
|
||
|
|
struct ivy_diag *diag
|
||
|
|
= b_unbox(struct ivy_diag, it.entry, diag_entry);
|
||
|
|
diag_write(ctx, diag, format, stream);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
struct ivy_diag *ivy_diag_ctx_create_diag(
|
||
|
|
struct ivy_diag_ctx *ctx, unsigned long diag_class)
|
||
|
|
{
|
||
|
|
struct ivy_diag *out = malloc(sizeof *out);
|
||
|
|
if (!out) {
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
memset(out, 0x0, sizeof *out);
|
||
|
|
out->diag_class = diag_class;
|
||
|
|
out->diag_parent = ctx;
|
||
|
|
|
||
|
|
b_queue_push_back(&ctx->ctx_diags, &out->diag_entry);
|
||
|
|
|
||
|
|
return out;
|
||
|
|
}
|
||
|
|
|
||
|
|
const struct ivy_diag_class *diag_ctx_get_class(
|
||
|
|
struct ivy_diag_ctx *ctx, unsigned long class_id)
|
||
|
|
{
|
||
|
|
if (!ctx->ctx_classes) {
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (class_id >= ctx->ctx_nr_classes) {
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
const struct ivy_diag_class *out = &ctx->ctx_classes[class_id];
|
||
|
|
if (out->c_type == IVY_DIAG_NONE || !out->c_title) {
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
return out;
|
||
|
|
}
|
||
|
|
|
||
|
|
const struct ivy_diag_msg *diag_ctx_get_msg(
|
||
|
|
struct ivy_diag_ctx *ctx, unsigned long msg_id)
|
||
|
|
{
|
||
|
|
if (!ctx->ctx_msg) {
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (msg_id >= ctx->ctx_nr_msg) {
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
const struct ivy_diag_msg *out = &ctx->ctx_msg[msg_id];
|
||
|
|
if (!out->msg_content) {
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
return out;
|
||
|
|
}
|