GNUnet  0.17.6
Data Structures | Macros | Functions
op.c File Reference

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

#include <inttypes.h>
#include "platform.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 33 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 131 of file op.c.

133 {
134  struct OperationListItem *op;
135 
136  for (op = h->op_head; NULL != op; op = op->next)
137  if (op->op_id == op_id)
138  return op;
139  return NULL;
140 }
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:43

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 245 of file op.c.

252 {
253  if (0 == op_id)
254  return GNUNET_NO;
255 
256  struct OperationListItem *op = op_find (h, op_id);
257  if (NULL == op)
258  {
260  "Could not find operation #%" PRIu64 "\n", op_id);
261  return GNUNET_NO;
262  }
263 
264  if (NULL != ctx)
265  *ctx = op->ctx;
266 
267  GNUNET_CONTAINER_DLL_remove (h->op_head,
268  h->op_tail,
269  op);
270 
271  if ((GNUNET_YES != cancel) &&
272  (NULL != op->result_cb))
273  op->result_cb (op->cls,
274  result_code, data,
275  data_size);
276  GNUNET_free (op);
277  return GNUNET_YES;
278 }
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
Definition: gnunet_common.h:98
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_free(ptr)
Wrapper around free.
#define LOG(kind,...)
Definition: op.c:33
static struct OperationListItem * op_find(struct GNUNET_OP_Handle *h, uint64_t op_id)
Find operation by ID.
Definition: op.c:131

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: