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 222 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().

223 {
225 
227  h->mq = GNUNET_CLIENT_connect (cfg,
228  "testbed-logger",
229  NULL,
231  h);
232  if (NULL == h->mq)
233  {
234  GNUNET_free (h);
235  return NULL;
236  }
237  return h;
238 }
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:901
#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 247 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().

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

280 {
281  if (NULL == h->mq)
282  return;
283  while (0 != size)
284  {
285  size_t fit_size = GNUNET_MIN (size,
286  BUFFER_SIZE - h->buse);
287  GNUNET_memcpy (&h->buf[h->buse],
288  data,
289  fit_size);
290  h->buse += fit_size;
291  data += fit_size;
292  size -= fit_size;
293  if (0 != size)
294  dispatch_buffer (h);
295  }
296 }
size_t buse
How many bytes in buf are in use?
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
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 307 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().

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

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