diff options
author | Gabor X Toth <*@tg-x.net> | 2015-05-07 12:15:32 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2015-05-07 12:15:32 +0000 |
commit | a5edf8ac9f03a368c87ea6163994d4ac3d62af06 (patch) | |
tree | 4daeaa2561d3edf5c0a6f2298054970e27928a0b /src/include | |
parent | 26dbd65eff8dc627697a1ee5c3b755c2951ac013 (diff) | |
download | gnunet-a5edf8ac9f03a368c87ea6163994d4ac3d62af06.tar.gz gnunet-a5edf8ac9f03a368c87ea6163994d4ac3d62af06.zip |
client_manager: add API for async operations
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_client_manager_lib.h | 91 | ||||
-rw-r--r-- | src/include/gnunet_common.h | 40 |
2 files changed, 131 insertions, 0 deletions
diff --git a/src/include/gnunet_client_manager_lib.h b/src/include/gnunet_client_manager_lib.h index 6623c2ba1..4b267c98f 100644 --- a/src/include/gnunet_client_manager_lib.h +++ b/src/include/gnunet_client_manager_lib.h | |||
@@ -249,6 +249,97 @@ GNUNET_CLIENT_MANAGER_set_user_context_ (struct GNUNET_CLIENT_MANAGER_Connection | |||
249 | GNUNET_CLIENT_MANAGER_set_user_context_ (mgr, ctx, sizeof (*ctx)) | 249 | GNUNET_CLIENT_MANAGER_set_user_context_ (mgr, ctx, sizeof (*ctx)) |
250 | 250 | ||
251 | 251 | ||
252 | /** | ||
253 | * Get a unique operation ID to distinguish between asynchronous requests. | ||
254 | * | ||
255 | * @param mgr | ||
256 | * Client manager connection. | ||
257 | * | ||
258 | * @return Operation ID to use. | ||
259 | */ | ||
260 | uint64_t | ||
261 | GNUNET_CLIENT_MANAGER_op_get_next_id (struct GNUNET_CLIENT_MANAGER_Connection *mgr); | ||
262 | |||
263 | |||
264 | /** | ||
265 | * Find operation by ID. | ||
266 | * | ||
267 | * @param mgr | ||
268 | * Client manager connection. | ||
269 | * @param op_id | ||
270 | * Operation ID to look up. | ||
271 | * @param[out] result_cb | ||
272 | * If an operation was found, its result callback is returned here. | ||
273 | * @param[out] cls | ||
274 | * If an operation was found, its closure is returned here. | ||
275 | * | ||
276 | * @return #GNUNET_YES if an operation was found, | ||
277 | * #GNUNET_NO if not found. | ||
278 | */ | ||
279 | int | ||
280 | GNUNET_CLIENT_MANAGER_op_find (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | ||
281 | uint64_t op_id, | ||
282 | GNUNET_ResultCallback *result_cb, | ||
283 | void **cls); | ||
284 | |||
285 | |||
286 | /** | ||
287 | * Add a new operation. | ||
288 | * | ||
289 | * @param mgr | ||
290 | * Client manager connection. | ||
291 | * @param result_cb | ||
292 | * Function to call with the result of the operation. | ||
293 | * @param cls | ||
294 | * Closure for @a result_cb. | ||
295 | * | ||
296 | * @return ID of the new operation. | ||
297 | */ | ||
298 | uint64_t | ||
299 | GNUNET_CLIENT_MANAGER_op_add (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | ||
300 | GNUNET_ResultCallback result_cb, | ||
301 | void *cls); | ||
302 | |||
303 | |||
304 | /** | ||
305 | * Call the result callback and remove the operation. | ||
306 | * | ||
307 | * @param mgr | ||
308 | * Client manager connection. | ||
309 | * @param op_id | ||
310 | * Operation ID. | ||
311 | * @param result_code | ||
312 | * Result of the operation. | ||
313 | * @param data | ||
314 | * Data result of the operation. | ||
315 | * @param data_size | ||
316 | * Size of @a data. | ||
317 | * | ||
318 | * @return #GNUNET_YES if the operation was found and removed, | ||
319 | * #GNUNET_NO if the operation was not found. | ||
320 | */ | ||
321 | int | ||
322 | GNUNET_CLIENT_MANAGER_op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | ||
323 | uint64_t op_id, int64_t result_code, | ||
324 | const void *data, uint16_t data_size); | ||
325 | |||
326 | |||
327 | /** | ||
328 | * Cancel an operation. | ||
329 | * | ||
330 | * @param mgr | ||
331 | * Client manager connection. | ||
332 | * @param op_id | ||
333 | * Operation ID. | ||
334 | * | ||
335 | * @return #GNUNET_YES if the operation was found and removed, | ||
336 | * #GNUNET_NO if the operation was not found. | ||
337 | */ | ||
338 | int | ||
339 | GNUNET_CLIENT_MANAGER_op_cancel (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | ||
340 | uint64_t op_id); | ||
341 | |||
342 | |||
252 | #if 0 /* keep Emacsens' auto-indent happy */ | 343 | #if 0 /* keep Emacsens' auto-indent happy */ |
253 | { | 344 | { |
254 | #endif | 345 | #endif |
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 880fc1fee..6a02190cc 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h | |||
@@ -248,6 +248,29 @@ struct GNUNET_MessageHeader | |||
248 | 248 | ||
249 | }; | 249 | }; |
250 | 250 | ||
251 | |||
252 | /** | ||
253 | * Answer from service to client about last operation. | ||
254 | */ | ||
255 | struct GNUNET_OperationResultMessage | ||
256 | { | ||
257 | struct GNUNET_MessageHeader header; | ||
258 | |||
259 | uint32_t reserved GNUNET_PACKED; | ||
260 | |||
261 | /** | ||
262 | * Operation ID. | ||
263 | */ | ||
264 | uint64_t op_id GNUNET_PACKED; | ||
265 | |||
266 | /** | ||
267 | * Status code for the operation. | ||
268 | */ | ||
269 | uint64_t result_code GNUNET_PACKED; | ||
270 | |||
271 | /* Followed by data. */ | ||
272 | }; | ||
273 | |||
251 | GNUNET_NETWORK_STRUCT_END | 274 | GNUNET_NETWORK_STRUCT_END |
252 | 275 | ||
253 | /** | 276 | /** |
@@ -273,6 +296,23 @@ typedef void | |||
273 | (*GNUNET_ContinuationCallback) (void *cls); | 296 | (*GNUNET_ContinuationCallback) (void *cls); |
274 | 297 | ||
275 | 298 | ||
299 | /** | ||
300 | * Function called with the result of an asynchronous operation. | ||
301 | * | ||
302 | * @param cls | ||
303 | * Closure. | ||
304 | * @param result_code | ||
305 | * Result code for the operation. | ||
306 | * @param data | ||
307 | * Data result for the operation. | ||
308 | * @param data_size | ||
309 | * Size of @a data. | ||
310 | */ | ||
311 | typedef void | ||
312 | (*GNUNET_ResultCallback) (void *cls, int64_t result_code, | ||
313 | const void *data, uint16_t data_size); | ||
314 | |||
315 | |||
276 | /* ****************************** logging ***************************** */ | 316 | /* ****************************** logging ***************************** */ |
277 | 317 | ||
278 | /** | 318 | /** |