GNUnet  0.10.x
Data Structures | Macros | Functions
testbed_logger_api.c File Reference

Client-side routines for communicating with the tesbted logger service. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testbed_logger_service.h"
Include dependency graph for testbed_logger_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_TESTBED_LOGGER_Handle
 Connection handle for the logger service. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "testbed-logger-api", __VA_ARGS__)
 Generic logging shorthand. More...
 
#define BUFFER_SIZE   (GNUNET_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader))
 The size of the buffer we fill before sending out the message. More...
 

Functions

static void call_flush_completion (void *cls)
 Task to call the flush completion notification. More...
 
static void trigger_flush_notification (struct GNUNET_TESTBED_LOGGER_Handle *h)
 Schedule the flush completion notification task. More...
 
static void dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h)
 Send the buffered data to the service. More...
 
static void notify_sent (void *cls)
 MQ successfully sent a message. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 We got disconnected from the logger. More...
 
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

Client-side routines for communicating with the tesbted logger service.

Author
Sree Harsha Totakura sreeh.nosp@m.arsh.nosp@m.a@tot.nosp@m.akur.nosp@m.a.in
Christian Grothoff

Definition in file testbed_logger_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "testbed-logger-api", __VA_ARGS__)

Generic logging shorthand.

Definition at line 35 of file testbed_logger_api.c.

Referenced by GNUNET_TESTBED_LOGGER_disconnect().

◆ BUFFER_SIZE

#define BUFFER_SIZE   (GNUNET_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader))

The size of the buffer we fill before sending out the message.

Definition at line 42 of file testbed_logger_api.c.

Referenced by GNUNET_TESTBED_LOGGER_write().

Function Documentation

◆ call_flush_completion()

static void call_flush_completion ( void *  cls)
static

Task to call the flush completion notification.

Parameters
clsthe logger handle

Definition at line 102 of file testbed_logger_api.c.

References bw, GNUNET_TESTBED_LOGGER_Handle::bwrote, GNUNET_TESTBED_LOGGER_Handle::cb, GNUNET_TESTBED_LOGGER_Handle::cb_cls, GNUNET_TESTBED_LOGGER_Handle::flush_completion_task, and h.

Referenced by trigger_flush_notification().

103 {
104  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
106  void *cb_cls;
107  size_t bw;
108 
109  h->flush_completion_task = NULL;
110  bw = h->bwrote;
111  h->bwrote = 0;
112  cb = h->cb;
113  h->cb = NULL;
114  cb_cls = h->cb_cls;
115  h->cb_cls = NULL;
116  if (NULL != cb)
117  cb (cb_cls, bw);
118 }
size_t bwrote
Number of bytes wrote since last flush.
struct GNUNET_BIO_WriteHandle * bw
hanlde to the file to write the load statistics to
GNUNET_TESTBED_LOGGER_FlushCompletion cb
Flush completion callback.
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 se...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
void * cb_cls
Closure for cb.
Connection handle for the logger service.
struct GNUNET_SCHEDULER_Task * flush_completion_task
Task to call the flush completion callback.
Here is the caller graph for this function:

◆ trigger_flush_notification()

static void trigger_flush_notification ( struct GNUNET_TESTBED_LOGGER_Handle h)
static

Schedule the flush completion notification task.

Parameters
hlogger handle

Definition at line 127 of file testbed_logger_api.c.

References call_flush_completion(), dispatch_buffer(), GNUNET_TESTBED_LOGGER_Handle::flush_completion_task, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), and h.

Referenced by GNUNET_TESTBED_LOGGER_flush(), and notify_sent().

128 {
129  if (NULL != h->flush_completion_task)
133  h);
134 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
struct GNUNET_SCHEDULER_Task * flush_completion_task
Task to call the flush completion callback.
static void call_flush_completion(void *cls)
Task to call the flush completion notification.
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:

◆ dispatch_buffer()

static void dispatch_buffer ( struct GNUNET_TESTBED_LOGGER_Handle h)
static

Send the buffered data to the service.

Parameters
hthe logger handle

Definition at line 174 of file testbed_logger_api.c.

References GNUNET_TESTBED_LOGGER_Handle::buf, GNUNET_TESTBED_LOGGER_Handle::buse, GNUNET_TESTBED_LOGGER_Handle::bwrote, env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_TESTBED_LOGGER_Handle::mq, GNUNET_TESTBED_LOGGER_Handle::mq_len, msg, and notify_sent().

Referenced by GNUNET_TESTBED_LOGGER_flush(), GNUNET_TESTBED_LOGGER_write(), notify_sent(), and trigger_flush_notification().

175 {
176  struct GNUNET_MessageHeader *msg;
177  struct GNUNET_MQ_Envelope *env;
178 
179  env = GNUNET_MQ_msg_extra (msg,
180  h->buse,
182  GNUNET_memcpy (&msg[1],
183  h->buf,
184  h->buse);
185  h->bwrote += h->buse;
186  h->buse = 0;
187  h->mq_len++;
189  &notify_sent,
190  h);
191  GNUNET_MQ_send (h->mq,
192  env);
193 }
size_t bwrote
Number of bytes wrote since last flush.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
size_t buse
How many bytes in buf are in use?
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
#define GNUNET_memcpy(dst, src, n)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
unsigned int mq_len
Number of entries in the MQ.
struct GNUNET_MQ_Handle * mq
Client connection.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
char buf[(GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GNUNET_MessageHeader))]
Local buffer for data to be transmitted.
static void notify_sent(void *cls)
MQ successfully sent a message.
Header for all communications.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
#define GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG
Message for TESTBED LOGGER.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_sent()

static void notify_sent ( void *  cls)
static

MQ successfully sent a message.

Parameters
clsour handle

Definition at line 152 of file testbed_logger_api.c.

References GNUNET_TESTBED_LOGGER_Handle::buse, GNUNET_TESTBED_LOGGER_Handle::cb, dispatch_buffer(), GNUNET_TESTBED_LOGGER_Handle::mq_len, and trigger_flush_notification().

Referenced by dispatch_buffer().

153 {
154  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
155 
156  h->mq_len--;
157  if ( (0 == h->mq_len) &&
158  (NULL != h->cb) )
159  {
160  if (0 == h->buse)
162  else
163  dispatch_buffer (h);
164  }
165 }
GNUNET_TESTBED_LOGGER_FlushCompletion cb
Flush completion callback.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
size_t buse
How many bytes in buf are in use?
unsigned int mq_len
Number of entries in the MQ.
Connection handle for the logger service.
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:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

We got disconnected from the logger.

Stop logging.

Parameters
clsthe struct GNUNET_TESTBED_LOGGER_Handle
errorerror code

Definition at line 203 of file testbed_logger_api.c.

References GNUNET_break, GNUNET_MQ_destroy(), and GNUNET_TESTBED_LOGGER_Handle::mq.

Referenced by GNUNET_TESTBED_LOGGER_connect().

205 {
206  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
207 
208  GNUNET_break (0);
209  GNUNET_MQ_destroy (h->mq);
210  h->mq = NULL;
211 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_MQ_Handle * mq
Client connection.
Connection handle for the logger service.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
Here is the call graph for this function:
Here is the caller graph for this function: