e9d940ba118b5506900e43244404065cd48f4f0b
[cascardo/atompub.git] / src / ctx.c
1 /*
2  *  Copyright (C) 2007  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along
15  *  with this program; if not, write to the Free Software Foundation, Inc.,
16  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19
20 #include <atompub/atom.h>
21
22 #include <glib.h>
23
24 struct _atom_ctx
25 {
26   AtomError *error;
27   gpointer config_data;
28   AtomBackend *backend;
29 };
30
31 AtomCtx *
32 atom_ctx_new ()
33 {
34   AtomCtx *ctx;
35   ctx = g_slice_new (AtomCtx);
36   ctx->error = NULL;
37   ctx->config_data = NULL;
38   ctx->backend = NULL;
39   return ctx;
40 }
41
42 void
43 atom_ctx_delete (AtomCtx *ctx)
44 {
45   if (ctx->error)
46     atom_error_delete (ctx->error);
47   if (ctx->backend)
48     atom_backend_delete (ctx->backend);
49   g_slice_free (AtomCtx, ctx);
50 }
51
52 void
53 atom_error_set (AtomCtx *ctx, AtomError *error)
54 {
55   if (ctx->error)
56     atom_error_delete (ctx->error);
57   ctx->error = error;
58 }
59
60 AtomError *
61 atom_error_get (AtomCtx *ctx)
62 {
63   return ctx->error;
64 }
65
66 void *
67 atom_config_data (AtomCtx *ctx)
68 {
69   return ctx->config_data;
70 }
71
72 void
73 atom_config_data_set (AtomCtx *ctx, void *data)
74 {
75   ctx->config_data = data;
76 }
77
78 AtomBackend *
79 atom_backend (AtomCtx *ctx)
80 {
81   return ctx->backend;
82 }
83
84 void
85 atom_backend_set (AtomCtx *ctx, AtomBackend *backend)
86 {
87   ctx->backend = backend;
88 }