#include #include #include #include #include "mlp_priv.h" mlp_context *mlp_context_new(){ mlp_debug(2, "-> Context new") ; mlp_context *ctx = MLP_MALLOC(mlp_context) ; ctx->error = MLP_OK ; ctx->error_msg = NULL ; mlp_debug(2, "<- Context new") ; return ctx ; } void mlp_context_delete(mlp_context *ctx){ if (ctx != NULL){ mlp_debug(2, "-> Context delete") ; if (ctx->error_msg != NULL){ free(ctx->error_msg) ; } free(ctx) ; mlp_debug(2, "<- Context delete") ; } } int mlp_context_has_error(const mlp_context *ctx){ return (ctx->error == MLP_OK ? 0 : 1) ; } mlp_error mlp_context_get_error(const mlp_context *ctx){ return ctx->error ; } const char *mlp_context_get_error_msg(const mlp_context *ctx){ return ctx->error_msg ; } void mlp_context_set_error(mlp_context *ctx, mlp_error err, const char *fmt, ...){ mlp_context_clear_error(ctx) ; ctx->error = err ; if (fmt != NULL){ va_list va ; va_start(va, fmt) ; char *msg = (char *)malloc(MLP_MAX_ERROR_MSG_LENGTH * sizeof(char)) ; vsnprintf(msg, MLP_MAX_ERROR_MSG_LENGTH - 1, fmt, va) ; va_end(va) ; ctx->error_msg = msg ; } } void mlp_context_clear_error(mlp_context *ctx){ ctx->error = MLP_OK ; if (ctx->error_msg != NULL){ free(ctx->error_msg) ; ctx->error_msg = NULL ; } }