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

102 {
103  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
105  void *cb_cls;
106  size_t bw;
107 
108  h->flush_completion_task = NULL;
109  bw = h->bwrote;
110  h->bwrote = 0;
111  cb = h->cb;
112  h->cb = NULL;
113  cb_cls = h->cb_cls;
114  h->cb_cls = NULL;
115  if (NULL != cb)
116  cb(cb_cls, bw);
117 }
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 126 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().

127 {
128  if (NULL != h->flush_completion_task)
132  h);
133 }
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:1264
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:956
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 173 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().

174 {
175  struct GNUNET_MessageHeader *msg;
176  struct GNUNET_MQ_Envelope *env;
177 
178  env = GNUNET_MQ_msg_extra(msg,
179  h->buse,
181  GNUNET_memcpy(&msg[1],
182  h->buf,
183  h->buse);
184  h->bwrote += h->buse;
185  h->buse = 0;
186  h->mq_len++;
188  &notify_sent,
189  h);
190  GNUNET_MQ_send(h->mq,
191  env);
192 }
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:772
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:351
#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 151 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().

152 {
153  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
154 
155  h->mq_len--;
156  if ((0 == h->mq_len) &&
157  (NULL != h->cb))
158  {
159  if (0 == h->buse)
161  else
162  dispatch_buffer(h);
163  }
164 }
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 202 of file testbed_logger_api.c.

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

Referenced by GNUNET_TESTBED_LOGGER_connect().

204 {
205  struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
206 
207  GNUNET_break(0);
208  GNUNET_MQ_destroy(h->mq);
209  h->mq = NULL;
210 }
#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:821
Here is the call graph for this function:
Here is the caller graph for this function: