GNUnet  0.11.x
Typedefs | Functions
Testbed Logger service

Submit data to the testbed logger service. More...

Typedefs

typedef void(* GNUNET_TESTBED_LOGGER_FlushCompletion) (void *cls, size_t size)
 Functions of this type are called to notify a successful transmission of the message to the logger service. More...
 

Functions

struct GNUNET_TESTBED_LOGGER_HandleGNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Connect to the testbed logger service. More...
 
void GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h)
 Disconnect from the logger service. More...
 
void GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h, const void *data, size_t size)
 Send data to be logged to the logger service. More...
 
void GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, GNUNET_TESTBED_LOGGER_FlushCompletion cb, void *cb_cls)
 Flush the buffered data to the logger service. More...
 
void GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h)
 Cancel notification upon flush. More...
 

Detailed Description

Submit data to the testbed logger service.

Typedef Documentation

◆ GNUNET_TESTBED_LOGGER_FlushCompletion

typedef void(* GNUNET_TESTBED_LOGGER_FlushCompletion) (void *cls, size_t size)

Functions of this type are called to notify a successful transmission of the message to the logger service.

Parameters
clsthe closure given to GNUNET_TESTBED_LOGGER_send()
sizethe amount of data sent

Definition at line 79 of file gnunet_testbed_logger_service.h.

Function Documentation

◆ GNUNET_TESTBED_LOGGER_connect()

struct GNUNET_TESTBED_LOGGER_Handle* GNUNET_TESTBED_LOGGER_connect ( const struct GNUNET_CONFIGURATION_Handle cfg)

Connect to the testbed logger service.

Parameters
cfgconfiguration to use
Returns
the handle which can be used for sending data to the service; NULL upon any error

Definition at line 223 of file testbed_logger_api.c.

References GNUNET_CLIENT_connect(), GNUNET_free, GNUNET_new, h, GNUNET_TESTBED_LOGGER_Handle::mq, and mq_error_handler().

Referenced by core_init().

224 {
226 
228  h->mq = GNUNET_CLIENT_connect (cfg,
229  "testbed-logger",
230  NULL,
232  h);
233  if (NULL == h->mq)
234  {
235  GNUNET_free (h);
236  return NULL;
237  }
238  return h;
239 }
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_MQ_Handle * mq
Client connection.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We got disconnected from the logger.
Connection handle for the logger service.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_LOGGER_disconnect()

void GNUNET_TESTBED_LOGGER_disconnect ( struct GNUNET_TESTBED_LOGGER_Handle h)

Disconnect from the logger service.

Also cancels any pending send handles.

Parameters
hthe logger handle
hthe logger handle

Definition at line 248 of file testbed_logger_api.c.

References GNUNET_TESTBED_LOGGER_Handle::flush_completion_task, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), LOG, GNUNET_TESTBED_LOGGER_Handle::mq, and GNUNET_TESTBED_LOGGER_Handle::mq_len.

Referenced by handle_core_disconnect().

249 {
250  if (NULL != h->flush_completion_task)
251  {
253  h->flush_completion_task = NULL;
254  }
255  if (0 != h->mq_len)
257  "Disconnect lost %u logger message[s]\n",
258  h->mq_len);
259  if (NULL != h->mq)
260  {
261  GNUNET_MQ_destroy (h->mq);
262  h->mq = NULL;
263  }
264  GNUNET_free (h);
265 }
unsigned int mq_len
Number of entries in the MQ.
struct GNUNET_MQ_Handle * mq
Client connection.
struct GNUNET_SCHEDULER_Task * flush_completion_task
Task to call the flush completion callback.
#define LOG(kind,...)
Generic logging shorthand.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_LOGGER_write()

void GNUNET_TESTBED_LOGGER_write ( struct GNUNET_TESTBED_LOGGER_Handle h,
const void *  data,
size_t  size 
)

Send data to be logged to the logger service.

The data will be buffered and will be sent upon an explicit call to GNUNET_TESTBED_LOGGER_flush() or upon exceeding a threshold size.

Parameters
hthe logger handle
datathe data to send;
sizehow many bytes of data to send

Definition at line 278 of file testbed_logger_api.c.

References GNUNET_TESTBED_LOGGER_Handle::buf, BUFFER_SIZE, GNUNET_TESTBED_LOGGER_Handle::buse, dispatch_buffer(), GNUNET_memcpy, GNUNET_MIN, and GNUNET_TESTBED_LOGGER_Handle::mq.

Referenced by handle_p2p_estimate().

281 {
282  if (NULL == h->mq)
283  return;
284  while (0 != size)
285  {
286  size_t fit_size = GNUNET_MIN (size,
287  BUFFER_SIZE - h->buse);
288  GNUNET_memcpy (&h->buf[h->buse],
289  data,
290  fit_size);
291  h->buse += fit_size;
292  data += fit_size;
293  size -= fit_size;
294  if (0 != size)
295  dispatch_buffer (h);
296  }
297 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
size_t buse
How many bytes in buf are in use?
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
struct GNUNET_MQ_Handle * mq
Client connection.
static unsigned int size
Size of the "table".
Definition: peer.c:67
char buf[(GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GNUNET_MessageHeader))]
Local buffer for data to be transmitted.
static void dispatch_buffer(struct GNUNET_TESTBED_LOGGER_Handle *h)
Send the buffered data to the service.
uint32_t data
The data value.
#define BUFFER_SIZE
The size of the buffer we fill before sending out the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_LOGGER_flush()

void GNUNET_TESTBED_LOGGER_flush ( struct GNUNET_TESTBED_LOGGER_Handle h,
GNUNET_TESTBED_LOGGER_FlushCompletion  cb,
void *  cb_cls 
)

Flush the buffered data to the logger service.

Parameters
hthe logger handle
cbthe callback to call after the data is flushed
cb_clsthe closure for cb
hthe logger handle
cbthe callback to call after the data is flushed
cb_clsthe closure for the above callback

Definition at line 308 of file testbed_logger_api.c.

References GNUNET_TESTBED_LOGGER_Handle::buse, GNUNET_TESTBED_LOGGER_Handle::cb, GNUNET_TESTBED_LOGGER_Handle::cb_cls, dispatch_buffer(), GNUNET_assert, GNUNET_TESTBED_LOGGER_Handle::mq, and trigger_flush_notification().

Referenced by shutdown_task().

311 {
312  GNUNET_assert (NULL == h->cb);
313  h->cb = cb;
314  h->cb_cls = cb_cls;
315  if ((NULL == h->mq) ||
316  (0 == h->buse))
317  {
319  return;
320  }
321  dispatch_buffer (h);
322 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
GNUNET_TESTBED_LOGGER_FlushCompletion cb
Flush completion callback.
void * cb_cls
Closure for cb.
size_t buse
How many bytes in buf are in use?
struct GNUNET_MQ_Handle * mq
Client connection.
static void trigger_flush_notification(struct GNUNET_TESTBED_LOGGER_Handle *h)
Schedule the flush completion notification task.
static void dispatch_buffer(struct GNUNET_TESTBED_LOGGER_Handle *h)
Send the buffered data to the service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_LOGGER_flush_cancel()

void GNUNET_TESTBED_LOGGER_flush_cancel ( struct GNUNET_TESTBED_LOGGER_Handle h)

Cancel notification upon flush.

Should only be used when the flush completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already called.

Parameters
hthe logger handle

Definition at line 333 of file testbed_logger_api.c.

References GNUNET_TESTBED_LOGGER_Handle::cb, GNUNET_TESTBED_LOGGER_Handle::cb_cls, GNUNET_TESTBED_LOGGER_Handle::flush_completion_task, and GNUNET_SCHEDULER_cancel().

334 {
335  if (NULL != h->flush_completion_task)
336  {
338  h->flush_completion_task = NULL;
339  }
340  h->cb = NULL;
341  h->cb_cls = NULL;
342 }
GNUNET_TESTBED_LOGGER_FlushCompletion cb
Flush completion callback.
void * cb_cls
Closure for cb.
struct GNUNET_SCHEDULER_Task * flush_completion_task
Task to call the flush completion callback.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function: