Renamed retrieve_resource to retrieve_entry
[cascardo/atompub.git] / src / backend.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 #include <glib.h>
22
23 struct _atom_backend
24 {
25   AtomEntry * (*retrieve_entry) (AtomCtx *, IRI *);
26   void (*enumerate_entries) (AtomCtx *, AtomEntry ***, size_t *);
27 };
28
29 AtomBackend *
30 atom_backend_new ()
31 {
32   AtomBackend *backend;
33   backend = g_slice_new (AtomBackend);
34   backend->retrieve_entry = NULL;
35   backend->enumerate_entries = NULL;
36   return backend;
37 }
38
39 void
40 atom_backend_delete (AtomBackend *backend)
41 {
42   g_slice_free (AtomBackend, backend);
43 }
44
45 void
46 atom_backend_retrieve_entry_set (AtomBackend *backend,
47                                  AtomEntry *retrieve_entry (AtomCtx *,
48                                                             IRI *))
49 {
50   backend->retrieve_entry = retrieve_entry;
51 }
52
53 void
54 atom_backend_enumerate_entries_set (AtomBackend *backend,
55                                     void enumerate_entries (AtomCtx *,
56                                                             AtomEntry ***, size_t*))
57 {
58   backend->enumerate_entries = enumerate_entries;
59 }
60
61 AtomEntry *
62 atom_retrieve_entry (AtomCtx *ctx, IRI *iri)
63 {
64   AtomBackend *backend;
65   backend = atom_backend (ctx);
66   if (backend && backend->retrieve_entry)
67     return backend->retrieve_entry (ctx, iri);
68   return NULL;
69 }
70
71 void
72 atom_backend_enumerate_entries (AtomCtx *ctx, AtomEntry *** entries, size_t *len)
73 {
74   AtomBackend *backend;
75   backend = atom_backend (ctx);
76   if (backend && backend->enumerate_entries)
77     {
78       backend->enumerate_entries (ctx, entries, len);
79       return;
80     }
81 }
82
83 AtomFeed *
84 atom_retrieve_feed (AtomCtx *ctx)
85 {
86   AtomFeed *feed;
87   AtomEntry **entries;
88   size_t len;
89   atom_backend_enumerate_entries (ctx, &entries, &len);
90   feed = atom_feed_new ();
91   atom_feed_entry_append_array (feed, entries, len);
92   return feed;
93 }