Functions to create new backend and usage of it in existing backends
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 2 Aug 2008 02:23:25 +0000 (23:23 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 2 Aug 2008 02:23:25 +0000 (23:23 -0300)
backend/files/giochannel.c
backend/gio/gio.c
include/atompub/backend.h
src/backend.c

index f4e876a..e8a4bb7 100644 (file)
@@ -20,7 +20,8 @@
 #include <glib.h>
 #include <atompub/atom.h>
 
-gchar *giochannel_iri_to_filename (AtomCtx *ctx, IRI *iri)
+static gchar *
+giochannel_iri_to_filename (AtomCtx *ctx, IRI *iri)
 {
   gchar *root = atom_config_get_str (ctx, "giochannel", "root");
   gchar *path = iri_get_path (iri);
@@ -29,7 +30,8 @@ gchar *giochannel_iri_to_filename (AtomCtx *ctx, IRI *iri)
   return filename;
 }
 
-Atom * giochannel_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+static Atom *
+giochannel_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
 {
   gchar *filename;
   GIOChannel *channel;
@@ -58,3 +60,13 @@ Atom * giochannel_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
   g_free (data);
   return atom;
 }
+
+AtomBackend *
+giochannel_backend (void)
+{
+  AtomBackend *backend;
+  backend = atom_backend_new ();
+  atom_backend_retrieve_resource_set (backend,
+                                     giochannel_atom_retrieve_resource);
+  return backend;
+}
index 1157753..9a7244a 100644 (file)
@@ -21,7 +21,8 @@
 #include <gio/gio.h>
 #include <atompub/atom.h>
 
-GFile *gio_iri_to_file (AtomCtx *ctx, IRI *iri)
+static GFile *
+gio_iri_to_file (AtomCtx *ctx, IRI *iri)
 {
   gchar *root = atom_config_get_str (ctx, "gio", "root");
   gchar *path = iri_get_path (iri);
@@ -32,7 +33,8 @@ GFile *gio_iri_to_file (AtomCtx *ctx, IRI *iri)
   return file;
 }
 
-Atom * gio_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+static Atom *
+gio_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
 {
   GFile *file;
   GError *error = NULL;
@@ -52,3 +54,12 @@ Atom * gio_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
   g_free (data);
   return atom;
 }
+
+AtomBackend *
+gio_backend (void)
+{
+  AtomBackend *backend;
+  backend = atom_backend_new ();
+  atom_backend_retrieve_resource_set (backend, gio_atom_retrieve_resource);
+  return backend;
+}
index ef553d9..a76c7b8 100644 (file)
@@ -26,6 +26,9 @@
 
 typedef struct _atom_backend AtomBackend;
 
+AtomBackend *atom_backend_new (void);
+void atom_backend_retrieve_resource_set (AtomBackend *,
+                                        Atom * (AtomCtx *, IRI *));
 Atom * atom_retrieve_resource (AtomCtx *, IRI *);
 AtomBackend * atom_backend (AtomCtx *);
 void atom_backend_set (AtomCtx *, AtomBackend *);
index c0f0162..04ff695 100644 (file)
@@ -24,6 +24,22 @@ struct _atom_backend
   Atom * (*retrieve_resource) (AtomCtx *, IRI *);
 };
 
+AtomBackend *
+atom_backend_new ()
+{
+  AtomBackend *backend;
+  backend = g_slice_new (AtomBackend);
+  backend->retrieve_resource = NULL;
+  return backend;
+}
+
+void
+atom_backend_retrieve_resource_set (AtomBackend *backend,
+                                   Atom *retrieve_resource (AtomCtx *,
+                                                            IRI *))
+{
+  backend->retrieve_resource = retrieve_resource;
+}
 
 Atom *
 atom_retrieve_resource (AtomCtx *ctx, IRI *iri)