GNUnet  0.10.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 221 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().

222 {
224 
226  h->mq = GNUNET_CLIENT_connect(cfg,
227  "testbed-logger",
228  NULL,
230  h);
231  if (NULL == h->mq)
232  {
233  GNUNET_free(h);
234  return NULL;
235  }
236  return h;
237 }
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:900
#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:94
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 246 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().

247 {
248  if (NULL != h->flush_completion_task)
249  {
251  h->flush_completion_task = NULL;
252  }
253  if (0 != h->mq_len)
255  "Disconnect lost %u logger message[s]\n",
256  h->mq_len);
257  if (NULL != h->mq)
258  {
259  GNUNET_MQ_destroy(h->mq);
260  h->mq = NULL;
261  }
262  GNUNET_free(h);
263 }
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:821
#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:956
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 276 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().

279 {
280  if (NULL == h->mq)
281  return;
282  while (0 != size)
283  {
284  size_t fit_size = GNUNET_MIN(size,
285  BUFFER_SIZE - h->buse);
286  GNUNET_memcpy(&h->buf[h->buse],
287  data,
288  fit_size);
289  h->buse += fit_size;
290  data += fit_size;
291  size -= fit_size;
292  if (0 != size)
293  dispatch_buffer(h);
294  }
295 }
#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:66
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 306 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().

309 {
310  GNUNET_assert(NULL == h->cb);
311  h->cb = cb;
312  h->cb_cls = cb_cls;
313  if ((NULL == h->mq) ||
314  (0 == h->buse))
315  {
317  return;
318  }
319  dispatch_buffer(h);
320 }
#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 331 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().

332 {
333  if (NULL != h->flush_completion_task)
334  {
336  h->flush_completion_task = NULL;
337  }
338  h->cb = NULL;
339  h->cb_cls = NULL;
340 }
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:956
Here is the call graph for this function: