aboutsummaryrefslogtreecommitdiff
path: root/src/util/op.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/op.c')
-rw-r--r--src/util/op.c157
1 files changed, 78 insertions, 79 deletions
diff --git a/src/util/op.c b/src/util/op.c
index 8fca7553e..20a0d3b0d 100644
--- a/src/util/op.c
+++ b/src/util/op.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file 22 * @file
@@ -30,10 +30,9 @@
30#include "platform.h" 30#include "platform.h"
31#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "util-op", __VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from(kind, "util-op", __VA_ARGS__)
34 34
35struct OperationListItem 35struct OperationListItem {
36{
37 struct OperationListItem *prev; 36 struct OperationListItem *prev;
38 struct OperationListItem *next; 37 struct OperationListItem *next;
39 38
@@ -63,8 +62,7 @@ struct OperationListItem
63 * Operations handle. 62 * Operations handle.
64 */ 63 */
65 64
66struct GNUNET_OP_Handle 65struct GNUNET_OP_Handle {
67{
68 /** 66 /**
69 * First operation in the linked list. 67 * First operation in the linked list.
70 */ 68 */
@@ -86,9 +84,9 @@ struct GNUNET_OP_Handle
86 * Create new operations handle. 84 * Create new operations handle.
87 */ 85 */
88struct GNUNET_OP_Handle * 86struct GNUNET_OP_Handle *
89GNUNET_OP_create () 87GNUNET_OP_create()
90{ 88{
91 return GNUNET_new (struct GNUNET_OP_Handle); 89 return GNUNET_new(struct GNUNET_OP_Handle);
92} 90}
93 91
94 92
@@ -96,9 +94,9 @@ GNUNET_OP_create ()
96 * Destroy operations handle. 94 * Destroy operations handle.
97 */ 95 */
98void 96void
99GNUNET_OP_destroy (struct GNUNET_OP_Handle *h) 97GNUNET_OP_destroy(struct GNUNET_OP_Handle *h)
100{ 98{
101 GNUNET_free (h); 99 GNUNET_free(h);
102} 100}
103 101
104 102
@@ -111,7 +109,7 @@ GNUNET_OP_destroy (struct GNUNET_OP_Handle *h)
111 * @return Operation ID to use. 109 * @return Operation ID to use.
112 */ 110 */
113uint64_t 111uint64_t
114GNUNET_OP_get_next_id (struct GNUNET_OP_Handle *h) 112GNUNET_OP_get_next_id(struct GNUNET_OP_Handle *h)
115{ 113{
116 return ++h->last_op_id; 114 return ++h->last_op_id;
117} 115}
@@ -128,8 +126,8 @@ GNUNET_OP_get_next_id (struct GNUNET_OP_Handle *h)
128 * @return Operation, or NULL if not found. 126 * @return Operation, or NULL if not found.
129 */ 127 */
130static struct OperationListItem * 128static struct OperationListItem *
131op_find (struct GNUNET_OP_Handle *h, 129op_find(struct GNUNET_OP_Handle *h,
132 uint64_t op_id) 130 uint64_t op_id)
133{ 131{
134 struct OperationListItem *op; 132 struct OperationListItem *op;
135 133
@@ -158,23 +156,24 @@ op_find (struct GNUNET_OP_Handle *h,
158 * #GNUNET_NO if not found. 156 * #GNUNET_NO if not found.
159 */ 157 */
160int 158int
161GNUNET_OP_get (struct GNUNET_OP_Handle *h, 159GNUNET_OP_get(struct GNUNET_OP_Handle *h,
162 uint64_t op_id, 160 uint64_t op_id,
163 GNUNET_ResultCallback *result_cb, 161 GNUNET_ResultCallback *result_cb,
164 void **cls, 162 void **cls,
165 void **ctx) 163 void **ctx)
166{ 164{
167 struct OperationListItem *op = op_find (h, op_id); 165 struct OperationListItem *op = op_find(h, op_id);
166
168 if (NULL != op) 167 if (NULL != op)
169 { 168 {
170 if (NULL != result_cb) 169 if (NULL != result_cb)
171 *result_cb = op->result_cb; 170 *result_cb = op->result_cb;
172 if (NULL != cls) 171 if (NULL != cls)
173 *cls = op->cls; 172 *cls = op->cls;
174 if (NULL != ctx) 173 if (NULL != ctx)
175 *ctx = op->ctx; 174 *ctx = op->ctx;
176 return GNUNET_YES; 175 return GNUNET_YES;
177 } 176 }
178 return GNUNET_NO; 177 return GNUNET_NO;
179} 178}
180 179
@@ -194,24 +193,24 @@ GNUNET_OP_get (struct GNUNET_OP_Handle *h,
194 * @return ID of the new operation. 193 * @return ID of the new operation.
195 */ 194 */
196uint64_t 195uint64_t
197GNUNET_OP_add (struct GNUNET_OP_Handle *h, 196GNUNET_OP_add(struct GNUNET_OP_Handle *h,
198 GNUNET_ResultCallback result_cb, 197 GNUNET_ResultCallback result_cb,
199 void *cls, 198 void *cls,
200 void *ctx) 199 void *ctx)
201{ 200{
202 struct OperationListItem *op; 201 struct OperationListItem *op;
203 202
204 op = GNUNET_new (struct OperationListItem); 203 op = GNUNET_new(struct OperationListItem);
205 op->op_id = GNUNET_OP_get_next_id (h); 204 op->op_id = GNUNET_OP_get_next_id(h);
206 op->result_cb = result_cb; 205 op->result_cb = result_cb;
207 op->cls = cls; 206 op->cls = cls;
208 op->ctx = ctx; 207 op->ctx = ctx;
209 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, 208 GNUNET_CONTAINER_DLL_insert_tail(h->op_head,
210 h->op_tail, 209 h->op_tail,
211 op); 210 op);
212 LOG (GNUNET_ERROR_TYPE_DEBUG, 211 LOG(GNUNET_ERROR_TYPE_DEBUG,
213 "%p Added operation #%" PRIu64 "\n", 212 "%p Added operation #%" PRIu64 "\n",
214 h, op->op_id); 213 h, op->op_id);
215 return op->op_id; 214 return op->op_id;
216} 215}
217 216
@@ -241,38 +240,38 @@ GNUNET_OP_add (struct GNUNET_OP_Handle *h,
241 * #GNUNET_NO if the operation was not found. 240 * #GNUNET_NO if the operation was not found.
242 */ 241 */
243static int 242static int
244op_result (struct GNUNET_OP_Handle *h, 243op_result(struct GNUNET_OP_Handle *h,
245 uint64_t op_id, 244 uint64_t op_id,
246 int64_t result_code, 245 int64_t result_code,
247 const void *data, 246 const void *data,
248 uint16_t data_size, 247 uint16_t data_size,
249 void **ctx, 248 void **ctx,
250 uint8_t cancel) 249 uint8_t cancel)
251{ 250{
252 if (0 == op_id) 251 if (0 == op_id)
253 return GNUNET_NO; 252 return GNUNET_NO;
254 253
255 struct OperationListItem *op = op_find (h, op_id); 254 struct OperationListItem *op = op_find(h, op_id);
256 if (NULL == op) 255 if (NULL == op)
257 { 256 {
258 LOG (GNUNET_ERROR_TYPE_WARNING, 257 LOG(GNUNET_ERROR_TYPE_WARNING,
259 "Could not find operation #%" PRIu64 "\n", op_id); 258 "Could not find operation #%" PRIu64 "\n", op_id);
260 return GNUNET_NO; 259 return GNUNET_NO;
261 } 260 }
262 261
263 if (NULL != ctx) 262 if (NULL != ctx)
264 *ctx = op->ctx; 263 *ctx = op->ctx;
265 264
266 GNUNET_CONTAINER_DLL_remove (h->op_head, 265 GNUNET_CONTAINER_DLL_remove(h->op_head,
267 h->op_tail, 266 h->op_tail,
268 op); 267 op);
269 268
270 if ( (GNUNET_YES != cancel) && 269 if ((GNUNET_YES != cancel) &&
271 (NULL != op->result_cb) ) 270 (NULL != op->result_cb))
272 op->result_cb (op->cls, 271 op->result_cb(op->cls,
273 result_code, data, 272 result_code, data,
274 data_size); 273 data_size);
275 GNUNET_free (op); 274 GNUNET_free(op);
276 return GNUNET_YES; 275 return GNUNET_YES;
277} 276}
278 277
@@ -297,17 +296,17 @@ op_result (struct GNUNET_OP_Handle *h,
297 * #GNUNET_NO if the operation was not found. 296 * #GNUNET_NO if the operation was not found.
298 */ 297 */
299int 298int
300GNUNET_OP_result (struct GNUNET_OP_Handle *h, 299GNUNET_OP_result(struct GNUNET_OP_Handle *h,
301 uint64_t op_id, 300 uint64_t op_id,
302 int64_t result_code, 301 int64_t result_code,
303 const void *data, 302 const void *data,
304 uint16_t data_size, 303 uint16_t data_size,
305 void **ctx) 304 void **ctx)
306{ 305{
307 LOG (GNUNET_ERROR_TYPE_DEBUG, 306 LOG(GNUNET_ERROR_TYPE_DEBUG,
308 "%p Received result for operation #%" PRIu64 ": %" PRId64 " (size: %u)\n", 307 "%p Received result for operation #%" PRIu64 ": %" PRId64 " (size: %u)\n",
309 h, op_id, result_code, data_size); 308 h, op_id, result_code, data_size);
310 return op_result (h, op_id, result_code, data, data_size, ctx, GNUNET_NO); 309 return op_result(h, op_id, result_code, data, data_size, ctx, GNUNET_NO);
311} 310}
312 311
313 312
@@ -323,11 +322,11 @@ GNUNET_OP_result (struct GNUNET_OP_Handle *h,
323 * #GNUNET_NO if the operation was not found. 322 * #GNUNET_NO if the operation was not found.
324 */ 323 */
325int 324int
326GNUNET_OP_remove (struct GNUNET_OP_Handle *h, 325GNUNET_OP_remove(struct GNUNET_OP_Handle *h,
327 uint64_t op_id) 326 uint64_t op_id)
328{ 327{
329 LOG (GNUNET_ERROR_TYPE_DEBUG, 328 LOG(GNUNET_ERROR_TYPE_DEBUG,
330 "%p Cancelling operation #%" PRIu64 "\n", 329 "%p Cancelling operation #%" PRIu64 "\n",
331 h, op_id); 330 h, op_id);
332 return op_result (h, op_id, 0, NULL, 0, NULL, GNUNET_YES); 331 return op_result(h, op_id, 0, NULL, 0, NULL, GNUNET_YES);
333} 332}