diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-07-25 22:24:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-07-25 22:24:42 +0000 |
commit | c890b76cde9288a8d9f2faa3046fbb06341c8082 (patch) | |
tree | b2c072b5ad2fba45a6bf5856209963fbf37375c3 /src/datacache/plugin_datacache_template.c | |
parent | 2ec742c593419e3225fa87dcf44ca96fb62d62b5 (diff) | |
download | gnunet-c890b76cde9288a8d9f2faa3046fbb06341c8082.tar.gz gnunet-c890b76cde9288a8d9f2faa3046fbb06341c8082.zip |
towards datacache implementation
Diffstat (limited to 'src/datacache/plugin_datacache_template.c')
-rw-r--r-- | src/datacache/plugin_datacache_template.c | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/src/datacache/plugin_datacache_template.c b/src/datacache/plugin_datacache_template.c new file mode 100644 index 000000000..d1f162c17 --- /dev/null +++ b/src/datacache/plugin_datacache_template.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2006, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file datacache/plugin_datacache_template.c | ||
23 | * @brief template for an implementation of a database backend for the datacache | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #ifndef PLUGIN_DATACACHE_H | ||
27 | #define PLUGIN_DATACACHE_H | ||
28 | |||
29 | #include "plugin_datacache.h" | ||
30 | |||
31 | #ifdef __cplusplus | ||
32 | extern "C" | ||
33 | { | ||
34 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
35 | } | ||
36 | #endif | ||
37 | #endif | ||
38 | |||
39 | |||
40 | |||
41 | /** | ||
42 | * Context for all functions in this plugin. | ||
43 | */ | ||
44 | struct Plugin | ||
45 | { | ||
46 | /** | ||
47 | * Our execution environment. | ||
48 | */ | ||
49 | struct GNUNET_DATASTORE_PluginEnvironment *env; | ||
50 | }; | ||
51 | |||
52 | |||
53 | /** | ||
54 | * Store an item in the datastore. | ||
55 | * | ||
56 | * @param key key to store data under | ||
57 | * @param size number of bytes in data | ||
58 | * @param data data to store | ||
59 | * @param type type of the value | ||
60 | * @param discard_time when to discard the value in any case | ||
61 | * @return 0 on error, number of bytes used otherwise | ||
62 | */ | ||
63 | static uint32_t | ||
64 | template_plugin_put (void *cls, | ||
65 | const GNUNET_HashCode * key, | ||
66 | uint32_t size, | ||
67 | const char *data, | ||
68 | uint32_t type, | ||
69 | struct GNUNET_TIME_Absolute discard_time) | ||
70 | { | ||
71 | GNUNET_break (0); | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Iterate over the results for a particular key | ||
78 | * in the datastore. | ||
79 | * | ||
80 | * @param key | ||
81 | * @param type entries of which type are relevant? | ||
82 | * @param iter maybe NULL (to just count) | ||
83 | * @return the number of results found | ||
84 | */ | ||
85 | static unsigned int | ||
86 | template_plugin_get (void *cls, | ||
87 | const GNUNET_HashCode * key, | ||
88 | uint32_t type, | ||
89 | GNUNET_DATACACHE_Iterator iter, | ||
90 | void *iter_cls) | ||
91 | { | ||
92 | GNUNET_break (0); | ||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Delete the entry with the lowest expiration value | ||
99 | * from the datacache right now. | ||
100 | * | ||
101 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
102 | */ | ||
103 | static int | ||
104 | template_plugin_del (void *cls) | ||
105 | { | ||
106 | GNUNET_break (0); | ||
107 | return GNUNET_SYSERR; | ||
108 | } | ||
109 | |||
110 | |||
111 | /** | ||
112 | * Entry point for the plugin. | ||
113 | */ | ||
114 | void * | ||
115 | libgnunet_plugin_datacache_template_init (void *cls) | ||
116 | { | ||
117 | struct GNUNET_DATACACHE_PluginEnvironment *env = cls; | ||
118 | struct GNUNET_DATACACHE_PluginFunctions *api; | ||
119 | struct Plugin *plugin; | ||
120 | |||
121 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | ||
122 | plugin->env = env; | ||
123 | api = GNUNET_malloc (sizeof (struct GNUNET_DATACACHE_PluginFunctions)); | ||
124 | api->cls = plugin; | ||
125 | api->get = &template_plugin_get; | ||
126 | api->put = &template_plugin_put; | ||
127 | api->del = &template_plugin_del; | ||
128 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | ||
129 | "template", _("Template datacache running\n")); | ||
130 | return api; | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Exit point from the plugin. | ||
136 | */ | ||
137 | void * | ||
138 | libgnunet_plugin_datacache_template_done (void *cls) | ||
139 | { | ||
140 | struct GNUNET_DATACACHE_PluginFunctions *api = cls; | ||
141 | struct Plugin *plugin = api->cls; | ||
142 | |||
143 | GNUNET_free (plugin); | ||
144 | GNUNET_free (api); | ||
145 | return NULL; | ||
146 | } | ||
147 | |||
148 | |||
149 | |||
150 | /* end of plugin_datacache_template.c */ | ||
151 | |||