2 * Copyright (C) 2007 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
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.
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.
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.
20 #include <atompub/atom.h>
29 AtomFrontend *frontend;
38 ctx = g_slice_new (AtomCtx);
40 ctx->config_data = NULL;
43 ctx->bemap = g_hash_table_new_full (g_str_hash, g_str_equal,
45 ctx->femap = g_hash_table_new_full (g_str_hash, g_str_equal,
51 atom_ctx_delete (AtomCtx *ctx)
54 atom_error_delete (ctx->error);
56 atom_backend_delete (ctx->backend);
58 atom_frontend_delete (ctx->frontend);
60 g_hash_table_destroy (ctx->bemap);
62 g_hash_table_destroy (ctx->femap);
63 g_slice_free (AtomCtx, ctx);
67 atom_error_set (AtomCtx *ctx, AtomError *error)
70 atom_error_delete (ctx->error);
75 atom_error_get (AtomCtx *ctx)
81 atom_config_data (AtomCtx *ctx)
83 return ctx->config_data;
87 atom_config_data_set (AtomCtx *ctx, void *data)
89 ctx->config_data = data;
93 atom_backend (AtomCtx *ctx)
99 atom_backend_set (AtomCtx *ctx, AtomBackend *backend)
101 ctx->backend = backend;
105 atom_frontend (AtomCtx *ctx)
107 return ctx->frontend;
111 atom_frontend_set (AtomCtx *ctx, AtomFrontend *frontend)
113 ctx->frontend = frontend;
117 atom_map_backend_requests (AtomCtx *ctx, char **reqs,
118 AtomEntry **entries, size_t len)
121 for (i = 0; i < len; i++)
123 char *key = g_strdup (atom_entry_id (entries[i]));
124 char *val = g_strdup (reqs[i]);
125 g_hash_table_replace (ctx->bemap, key, val);
130 atom_map_frontend_requests (AtomCtx *ctx, char **reqs,
131 AtomEntry **entries, size_t len)
134 for (i = 0; i < len; i++)
136 char *key = g_strdup (reqs[i]);
137 char *val = g_strdup (atom_entry_id (entries[i]));
138 g_hash_table_replace (ctx->femap, key, val);
143 atom_id_new_from_frontend (AtomCtx *ctx, char * req)
146 if (g_hash_table_lookup_extended (ctx->femap, req, NULL, &id))
147 return atom_id_new (id);
152 atom_id_to_backend (AtomCtx *ctx, AtomID *id)
154 char *key = atom_id_string (id);
156 if (g_hash_table_lookup_extended (ctx->bemap, key, NULL, &val))