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

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

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 }
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:99
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 128 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().

129 {
130  if (NULL != 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:1280
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:966
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.

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

176 {
177  struct GNUNET_MessageHeader *msg;
178  struct GNUNET_MQ_Envelope *env;
179 
180  env = GNUNET_MQ_msg_extra (msg,
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 }
size_t bwrote
Number of bytes wrote since last flush.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#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_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
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 153 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().

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 }
GNUNET_TESTBED_LOGGER_FlushCompletion cb
Flush completion callback.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
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 204 of file testbed_logger_api.c.

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

Referenced by GNUNET_TESTBED_LOGGER_connect().

206 {
207  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
208 
209  GNUNET_break (0);
210  GNUNET_MQ_destroy (h->mq);
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...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
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: