From 267bb03899f29f558d020b6967c7f495834ab039 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sun, 12 Oct 2008 17:07:19 -0300 Subject: [PATCH] Create frontend structure with map_entries function --- atom/Makefile.am | 2 +- atom/ctx.c | 16 +++++++++ atom/frontend.c | 66 +++++++++++++++++++++++++++++++++++++ include/atompub/Makefile.am | 2 +- include/atompub/atom.h | 1 + include/atompub/frontend.h | 36 ++++++++++++++++++++ 6 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 atom/frontend.c create mode 100644 include/atompub/frontend.h diff --git a/atom/Makefile.am b/atom/Makefile.am index 9a1def6..28f1a27 100644 --- a/atom/Makefile.am +++ b/atom/Makefile.am @@ -1,6 +1,6 @@ lib_LTLIBRARIES = libatom.la libatom_la_SOURCES = id.c entry.c person.c feed.c resource.c \ - config.c ctx.c backend.c error.c + config.c ctx.c backend.c error.c frontend.c libatom_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS) libatom_la_CFLAGS += $(XML_CFLAGS) $(GIO_CFLAGS) libatom_la_LIBADD = $(GIO_LIBS) $(GLIB_LIBS) $(XML_LIBS) diff --git a/atom/ctx.c b/atom/ctx.c index a472dae..8519b31 100644 --- a/atom/ctx.c +++ b/atom/ctx.c @@ -26,6 +26,7 @@ struct _atom_ctx AtomError *error; gpointer config_data; AtomBackend *backend; + AtomFrontend *frontend; GHashTable *bemap; }; @@ -37,6 +38,7 @@ atom_ctx_new () ctx->error = NULL; ctx->config_data = NULL; ctx->backend = NULL; + ctx->frontend = NULL; ctx->bemap = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); return ctx; @@ -49,6 +51,8 @@ atom_ctx_delete (AtomCtx *ctx) atom_error_delete (ctx->error); if (ctx->backend) atom_backend_delete (ctx->backend); + if (ctx->frontend) + atom_frontend_delete (ctx->frontend); if (ctx->bemap) g_hash_table_destroy (ctx->bemap); g_slice_free (AtomCtx, ctx); @@ -92,6 +96,18 @@ atom_backend_set (AtomCtx *ctx, AtomBackend *backend) ctx->backend = backend; } +AtomFrontend * +atom_frontend (AtomCtx *ctx) +{ + return ctx->frontend; +} + +void +atom_frontend_set (AtomCtx *ctx, AtomFrontend *frontend) +{ + ctx->frontend = frontend; +} + void atom_map_backend_requests (AtomCtx *ctx, char **reqs, AtomEntry **entries, size_t len) diff --git a/atom/frontend.c b/atom/frontend.c new file mode 100644 index 0000000..778ffa1 --- /dev/null +++ b/atom/frontend.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2008 Thadeu Lima de Souza Cascardo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + + +#include + +#include + +#include + +struct _atom_frontend +{ + void (*map_entries) (AtomCtx *, char **, AtomEntry **, size_t); +}; + +AtomFrontend * +atom_frontend_new () +{ + AtomFrontend *frontend; + frontend = g_slice_new (AtomFrontend); + frontend->map_entries = NULL; + return frontend; +} + +void +atom_frontend_delete (AtomFrontend *frontend) +{ + g_slice_free (AtomFrontend, frontend); +} + +void +atom_frontend_map_entries_set (AtomFrontend *frontend, + void map_entries (AtomCtx *, + char **, + AtomEntry **, + size_t)) +{ + frontend->map_entries = map_entries; +} + +void +atom_frontend_map_entries (AtomCtx *ctx, char ** reqs, + AtomEntry ** entries, size_t len) +{ + AtomFrontend *frontend; + frontend = atom_frontend (ctx); + if (frontend && frontend->map_entries) + { + frontend->map_entries (ctx, reqs, entries, len); + } +} diff --git a/include/atompub/Makefile.am b/include/atompub/Makefile.am index 9e0f413..c30add5 100644 --- a/include/atompub/Makefile.am +++ b/include/atompub/Makefile.am @@ -1,4 +1,4 @@ pkginclude_HEADERS = atom.h config.h ctx.h entry.h person.h error.h feed.h \ id.h iri.h backend.h atom-glib.h error-glib.h atom-xml.h \ entry-xml.h person-xml.h feed-xml.h globals.h resource.h \ - map.h + map.h frontend.h diff --git a/include/atompub/atom.h b/include/atompub/atom.h index 162affc..6ac66f3 100644 --- a/include/atompub/atom.h +++ b/include/atompub/atom.h @@ -32,5 +32,6 @@ #include #include #include +#include #endif diff --git a/include/atompub/frontend.h b/include/atompub/frontend.h new file mode 100644 index 0000000..7e9ecc0 --- /dev/null +++ b/include/atompub/frontend.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2008 Thadeu Lima de Souza Cascardo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + + +#ifndef ATOMPUB_FRONTEND_H +#define ATOMPUB_FRONTEND_H + +#include + +typedef struct _atom_frontend AtomFrontend; + +AtomFrontend *atom_frontend_new (void); +void atom_frontend_delete (AtomFrontend *); +void atom_frontend_map_entries_set (AtomFrontend *, + void (AtomCtx *, char **, + AtomEntry **, size_t)); +void atom_map_entries (AtomCtx *, char **, AtomEntry **, size_t); +AtomFrontend * atom_frontend (AtomCtx *); +void atom_frontend_set (AtomCtx *, AtomFrontend *); + +#endif -- 2.20.1