GNUnet  0.10.x
Functions
gnunet_op_lib.h File Reference

Asynchronous operations; register callbacks for operations and call them when a response arrives. More...

#include "gnunet_util_lib.h"
Include dependency graph for gnunet_op_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct GNUNET_OP_HandleGNUNET_OP_create ()
 Create new operations handle. More...
 
void GNUNET_OP_destroy (struct GNUNET_OP_Handle *h)
 Destroy operations handle. More...
 
uint64_t GNUNET_OP_get_next_id (struct GNUNET_OP_Handle *h)
 Get a unique operation ID to distinguish between asynchronous requests. More...
 
int GNUNET_OP_get (struct GNUNET_OP_Handle *h, uint64_t op_id, GNUNET_ResultCallback *result_cb, void **cls, void **ctx)
 Find operation by ID. More...
 
uint64_t GNUNET_OP_add (struct GNUNET_OP_Handle *h, GNUNET_ResultCallback result_cb, void *cls, void *ctx)
 Add a new operation. More...
 
int GNUNET_OP_result (struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx)
 Call the result callback of an operation and remove it. More...
 
int GNUNET_OP_remove (struct GNUNET_OP_Handle *h, uint64_t op_id)
 Remove / cancel an operation. More...
 

Detailed Description

Asynchronous operations; register callbacks for operations and call them when a response arrives.

Author
Gabor X Toth

Definition in file gnunet_op_lib.h.

Function Documentation

◆ GNUNET_OP_create()

struct GNUNET_OP_Handle* GNUNET_OP_create ( )

Create new operations handle.

Definition at line 89 of file op.c.

References GNUNET_new.

90 {
91  return GNUNET_new (struct GNUNET_OP_Handle);
92 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Operations handle.
Definition: op.c:66

◆ GNUNET_OP_destroy()

void GNUNET_OP_destroy ( struct GNUNET_OP_Handle h)

Destroy operations handle.

Definition at line 99 of file op.c.

References GNUNET_free.

100 {
101  GNUNET_free (h);
102 }
#define GNUNET_free(ptr)
Wrapper around free.

◆ GNUNET_OP_get_next_id()

uint64_t GNUNET_OP_get_next_id ( struct GNUNET_OP_Handle h)

Get a unique operation ID to distinguish between asynchronous requests.

Parameters
hOperations handle.
Returns
Operation ID to use.

Definition at line 114 of file op.c.

References GNUNET_OP_Handle::last_op_id.

Referenced by GNUNET_OP_add().

115 {
116  return ++h->last_op_id;
117 }
uint64_t last_op_id
Last operation ID used.
Definition: op.c:81
Here is the caller graph for this function:

◆ GNUNET_OP_get()

int GNUNET_OP_get ( struct GNUNET_OP_Handle h,
uint64_t  op_id,
GNUNET_ResultCallback result_cb,
void **  cls,
void **  ctx 
)

Find operation by ID.

Parameters
hOperations handle.
op_idOperation ID to look up.
[out]result_cbIf an operation was found, its result callback is returned here.
[out]clsIf an operation was found, its closure is returned here.
[out]ctxUser context.
Returns
GNUNET_YES if an operation was found, GNUNET_NO if not found.
Parameters
hOperations handle.
op_idOperation ID to look up.
[out]result_cbIf an operation was found, its result callback is returned here.
[out]clsIf an operation was found, its closure is returned here.
[out]ctxIf an operation was found, its user context is returned here.
Returns
GNUNET_YES if an operation was found, GNUNET_NO if not found.

Definition at line 161 of file op.c.

References OperationListItem::cls, OperationListItem::ctx, GNUNET_NO, GNUNET_YES, op, op_find(), and OperationListItem::result_cb.

166 {
167  struct OperationListItem *op = op_find (h, op_id);
168  if (NULL != op)
169  {
170  if (NULL != result_cb)
171  *result_cb = op->result_cb;
172  if (NULL != cls)
173  *cls = op->cls;
174  if (NULL != ctx)
175  *ctx = op->ctx;
176  return GNUNET_YES;
177  }
178  return GNUNET_NO;
179 }
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
void * ctx
User context.
Definition: op.c:58
static struct OperationListItem * op_find(struct GNUNET_OP_Handle *h, uint64_t op_id)
Find operation by ID.
Definition: op.c:131
void * cls
Closure for result_cb.
Definition: op.c:53
uint64_t op_id
Operation ID.
Definition: op.c:43
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
GNUNET_ResultCallback result_cb
Continuation to invoke with the result of an operation.
Definition: op.c:48
Here is the call graph for this function:

◆ GNUNET_OP_add()

uint64_t GNUNET_OP_add ( struct GNUNET_OP_Handle h,
GNUNET_ResultCallback  result_cb,
void *  cls,
void *  ctx 
)

Add a new operation.

Parameters
hOperations handle.
result_cbFunction to call with the result of the operation.
clsClosure for result_cb.
ctxUser context.
Returns
ID of the new operation.

Definition at line 197 of file op.c.

References OperationListItem::cls, OperationListItem::ctx, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_OP_get_next_id(), LOG, op, GNUNET_OP_Handle::op_head, OperationListItem::op_id, GNUNET_OP_Handle::op_tail, and OperationListItem::result_cb.

201 {
202  struct OperationListItem *op;
203 
204  op = GNUNET_new (struct OperationListItem);
205  op->op_id = GNUNET_OP_get_next_id (h);
206  op->result_cb = result_cb;
207  op->cls = cls;
208  op->ctx = ctx;
210  h->op_tail,
211  op);
213  "%p Added operation #%" PRIu64 "\n",
214  h, op->op_id);
215  return op->op_id;
216 }
struct OperationListItem * op_tail
Last operation in the linked list.
Definition: op.c:76
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define LOG(kind,...)
Definition: op.c:33
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
void * ctx
User context.
Definition: op.c:58
uint64_t GNUNET_OP_get_next_id(struct GNUNET_OP_Handle *h)
Get a unique operation ID to distinguish between asynchronous requests.
Definition: op.c:114
void * cls
Closure for result_cb.
Definition: op.c:53
uint64_t op_id
Operation ID.
Definition: op.c:43
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
GNUNET_ResultCallback result_cb
Continuation to invoke with the result of an operation.
Definition: op.c:48
struct OperationListItem * op_head
First operation in the linked list.
Definition: op.c:71
Here is the call graph for this function:

◆ GNUNET_OP_result()

int GNUNET_OP_result ( struct GNUNET_OP_Handle h,
uint64_t  op_id,
int64_t  result_code,
const void *  data,
uint16_t  data_size,
void **  ctx 
)

Call the result callback of an operation and remove it.

Parameters
hOperations handle.
op_idOperation ID.
result_codeResult of the operation.
dataData result of the operation.
data_sizeSize of data.
[out]ctxUser context.
Returns
GNUNET_YES if the operation was found and removed, GNUNET_NO if the operation was not found.

Definition at line 300 of file op.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, LOG, and op_result().

306 {
308  "%p Received result for operation #%" PRIu64 ": %" PRId64 " (size: %u)\n",
309  h, op_id, result_code, data_size);
310  return op_result (h, op_id, result_code, data, data_size, ctx, GNUNET_NO);
311 }
static int op_result(struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx, uint8_t cancel)
Remove an operation, and call its result callback (unless it was cancelled).
Definition: op.c:244
#define GNUNET_NO
Definition: gnunet_common.h:81
#define LOG(kind,...)
Definition: op.c:33
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
uint64_t op_id
Operation ID.
Definition: op.c:43
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
Here is the call graph for this function:

◆ GNUNET_OP_remove()

int GNUNET_OP_remove ( struct GNUNET_OP_Handle h,
uint64_t  op_id 
)

Remove / cancel an operation.

Parameters
hOperations handle.
op_idOperation ID.
Returns
GNUNET_YES if the operation was found and removed, GNUNET_NO if the operation was not found.

Definition at line 326 of file op.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_YES, LOG, and op_result().

328 {
330  "%p Cancelling operation #%" PRIu64 "\n",
331  h, op_id);
332  return op_result (h, op_id, 0, NULL, 0, NULL, GNUNET_YES);
333 }
static int op_result(struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx, uint8_t cancel)
Remove an operation, and call its result callback (unless it was cancelled).
Definition: op.c:244
#define LOG(kind,...)
Definition: op.c:33
uint64_t op_id
Operation ID.
Definition: op.c:43
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function: