]> mj.ucw.cz Git - libucw.git/blob - images/context.c
revising & testing image library
[libucw.git] / images / context.c
1 /*
2  *      Image Library -- Image contexts
3  *
4  *      (c) 2006 Pavel Charvat <pchar@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #undef LOCAL_DEBUG
11
12 #include "lib/lib.h"
13 #include "lib/bbuf.h"
14 #include "images/images.h"
15 #include "images/error.h"
16
17 #include <string.h>
18
19 void
20 image_context_init(struct image_context *ctx)
21 {
22   bzero(ctx, sizeof(*ctx));
23   bb_init(&ctx->msg_buf);
24   ctx->tracing_level = image_trace;
25   ctx->msg_callback = image_context_msg_default;
26 }
27
28 void
29 image_context_cleanup(struct image_context *ctx)
30 {
31   IMAGE_TRACE(ctx, 10, "Destroying image thread");
32   bb_done(&ctx->msg_buf);
33 }
34
35 void
36 image_context_msg_default(struct image_context *ctx)
37 {
38   log(ctx->msg_code >> 24, "%s", ctx->msg);
39 }
40
41 void
42 image_context_msg_silent(struct image_context *ctx UNUSED)
43 {
44 }
45
46 void
47 image_context_msg(struct image_context *ctx, uns code, char *msg, ...)
48 {
49   ctx->msg_code = code;
50   va_list args;
51   va_start(args, msg);
52   ctx->msg = bb_vprintf(&ctx->msg_buf, msg, args);
53   va_end(args);
54   ctx->msg_callback(ctx);
55 }
56
57 void
58 image_context_vmsg(struct image_context *ctx, uns code, char *msg, va_list args)
59 {
60   ctx->msg_code = code;
61   ctx->msg = bb_vprintf(&ctx->msg_buf, msg, args);
62   ctx->msg_callback(ctx);
63 }