]> mj.ucw.cz Git - libucw.git/blob - images/context.c
Merge with git+ssh://git.ucw.cz/projects/sherlock/GIT/sherlock.git#v3.11
[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   msg(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   va_list args;
50   va_start(args, msg);
51   image_context_vmsg(ctx, code, msg, args);
52   va_end(args);
53 }
54
55 void
56 image_context_vmsg(struct image_context *ctx, uns code, char *msg, va_list args)
57 {
58   ctx->msg_code = code;
59   ctx->msg = bb_vprintf(&ctx->msg_buf, msg, args);
60   ctx->msg_callback(ctx);
61 }