GNUnet  0.19.3
op.c File Reference

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

#include "platform.h"
#include <inttypes.h>
#include "gnunet_util_lib.h"
Include dependency graph for op.c:

Go to the source code of this file.

Data Structures

struct  OperationListItem
 
struct  GNUNET_OP_Handle
 Operations handle. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-op", __VA_ARGS__)
 

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...
 
static struct OperationListItemop_find (struct GNUNET_OP_Handle *h, uint64_t op_id)
 Find operation by ID. 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...
 
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). 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 op.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-op", __VA_ARGS__)

Definition at line 34 of file op.c.

Function Documentation

◆ op_find()

static struct OperationListItem* op_find ( struct GNUNET_OP_Handle h,
uint64_t  op_id 
)
static

Find operation by ID.

Parameters
hOperations handle.
op_idOperation ID to look up.
Returns
Operation, or NULL if not found.

Definition at line 132 of file op.c.

134 {
135  struct OperationListItem *op;
136 
137  for (op = h->op_head; NULL != op; op = op->next)
138  if (op->op_id == op_id)
139  return op;
140  return NULL;
141 }
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_ARM_Operation * next
This is a doubly-linked list.
Definition: arm_api.c:45
uint64_t op_id
Operation ID.
Definition: op.c:44

References h, GNUNET_ARM_Operation::next, op, and OperationListItem::op_id.

Referenced by GNUNET_OP_get(), and op_result().

Here is the caller graph for this function:

◆ op_result()

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 
)
static

Remove an operation, and call its result callback (unless it was cancelled).

Parameters
hOperations handle.
op_idOperation ID.
result_codeResult of the operation.
dataData result of the operation.
data_sizeSize of data.
[out]ctxUser context.
cancelIs the operation cancelled? GNUNET_NO Not cancelled, result callback is called. GNUNET_YES Cancelled, result callback is not called.
Returns
GNUNET_YES if the operation was found and removed, GNUNET_NO if the operation was not found.

Definition at line 246 of file op.c.

253 {
254  if (0 == op_id)
255  return GNUNET_NO;
256 
257  struct OperationListItem *op = op_find (h, op_id);
258  if (NULL == op)
259  {
261  "Could not find operation #%" PRIu64 "\n", op_id);
262  return GNUNET_NO;
263  }
264 
265  if (NULL != ctx)
266  *ctx = op->ctx;
267 
268  GNUNET_CONTAINER_DLL_remove (h->op_head,
269  h->op_tail,
270  op);
271 
272  if ((GNUNET_YES != cancel) &&
273  (NULL != op->result_cb))
274  op->result_cb (op->cls,
275  result_code, data,
276  data_size);
277  GNUNET_free (op);
278  return GNUNET_YES;
279 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t data
The data value.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_free(ptr)
Wrapper around free.
#define LOG(kind,...)
Definition: op.c:34
static struct OperationListItem * op_find(struct GNUNET_OP_Handle *h, uint64_t op_id)
Find operation by ID.
Definition: op.c:132

References ctx, data, data_size, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_NO, GNUNET_YES, h, LOG, op, op_find(), and OperationListItem::op_id.

Referenced by cadet_disconnect_adapter(), dht_da(), dht_disconnect(), dht_disconnect_adapter(), fs_disconnect_adapter(), GNUNET_OP_remove(), GNUNET_OP_result(), nse_disconnect_adapter(), rps_disconnect_adapter(), stat_disconnect_adapter(), statistics_da(), and stats_da().

Here is the call graph for this function:
Here is the caller graph for this function: