Create frontend structure with map_entries function
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 12 Oct 2008 20:07:19 +0000 (17:07 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 12 Oct 2008 20:07:19 +0000 (17:07 -0300)
atom/Makefile.am
atom/ctx.c
atom/frontend.c [new file with mode: 0644]
include/atompub/Makefile.am
include/atompub/atom.h
include/atompub/frontend.h [new file with mode: 0644]

index 9a1def6..28f1a27 100644 (file)
@@ -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)
index a472dae..8519b31 100644 (file)
@@ -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 (file)
index 0000000..778ffa1
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  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 <atompub/atom.h>
+
+#include <glib.h>
+
+#include <string.h>
+
+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);
+    }
+}
index 9e0f413..c30add5 100644 (file)
@@ -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
index 162affc..6ac66f3 100644 (file)
@@ -32,5 +32,6 @@
 #include <atompub/resource.h>
 #include <atompub/backend.h>
 #include <atompub/map.h>
+#include <atompub/frontend.h>
 
 #endif
diff --git a/include/atompub/frontend.h b/include/atompub/frontend.h
new file mode 100644 (file)
index 0000000..7e9ecc0
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  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 <atompub/ctx.h>
+
+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