GNUnet  0.20.0
testbed_logger_api.c File Reference

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

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
 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.

◆ BUFFER_SIZE

#define BUFFER_SIZE
Value:
(GNUNET_MAX_MESSAGE_SIZE - sizeof(struct \
GNUNET_MessageHeader))
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...

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

Definition at line 42 of file testbed_logger_api.c.

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 103 of file testbed_logger_api.c.

104 {
105  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
107  void *cb_cls;
108  size_t bw;
109 
110  h->flush_completion_task = NULL;
111  bw = h->bwrote;
112  h->bwrote = 0;
113  cb = h->cb;
114  h->cb = NULL;
115  cb_cls = h->cb_cls;
116  h->cb_cls = NULL;
117  if (NULL != cb)
118  cb (cb_cls, bw);
119 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_BIO_WriteHandle * bw
handle to the file to write the load statistics to
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...
Connection handle for the logger service.
GNUNET_TESTBED_LOGGER_FlushCompletion cb
Flush completion callback.
void * cb_cls
Closure for cb.

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

Referenced by trigger_flush_notification().

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 128 of file testbed_logger_api.c.

129 {
130  if (NULL != h->flush_completion_task)
131  GNUNET_SCHEDULER_cancel (h->flush_completion_task);
132  h->flush_completion_task
134  h);
135 }
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:1299
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
static void call_flush_completion(void *cls)
Task to call the flush completion notification.

References call_flush_completion(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), and h.

Referenced by GNUNET_TESTBED_LOGGER_flush(), and notify_sent().

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 175 of file testbed_logger_api.c.

176 {
177  struct GNUNET_MessageHeader *msg;
178  struct GNUNET_MQ_Envelope *env;
179 
181  h->buse,
183  GNUNET_memcpy (&msg[1],
184  h->buf,
185  h->buse);
186  h->bwrote += h->buse;
187  h->buse = 0;
188  h->mq_len++;
190  &notify_sent,
191  h);
192  GNUNET_MQ_send (h->mq,
193  env);
194 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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:304
#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:63
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:638
#define GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG
Message for TESTBED LOGGER.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
Header for all communications.
static void notify_sent(void *cls)
MQ successfully sent a message.

References env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), h, GNUNET_ARM_Handle::mq, msg, and notify_sent().

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

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 153 of file testbed_logger_api.c.

154 {
155  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
156 
157  h->mq_len--;
158  if ((0 == h->mq_len) &&
159  (NULL != h->cb))
160  {
161  if (0 == h->buse)
163  else
164  dispatch_buffer (h);
165  }
166 }
static void dispatch_buffer(struct GNUNET_TESTBED_LOGGER_Handle *h)
Send the buffered data to the service.
static void trigger_flush_notification(struct GNUNET_TESTBED_LOGGER_Handle *h)
Schedule the flush completion notification task.

References dispatch_buffer(), h, and trigger_flush_notification().

Referenced by dispatch_buffer().

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 204 of file testbed_logger_api.c.

206 {
207  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
208 
209  GNUNET_break (0);
211  h->mq = NULL;
212 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683

References GNUNET_break, GNUNET_MQ_destroy(), h, and GNUNET_ARM_Handle::mq.

Referenced by GNUNET_TESTBED_LOGGER_connect().

Here is the call graph for this function:
Here is the caller graph for this function: