GNUnet 0.21.1
testing_api_cmd_barrier_reached.c File Reference

Command to signal barrier was reached. More...

Include dependency graph for testing_api_cmd_barrier_reached.c:

Go to the source code of this file.

Data Structures

struct  BarrierReachedState
 Struct with information for callbacks. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 

Functions

static void barrier_reached_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 Run the command. More...
 
static void barrier_reached_cleanup (void *cls)
 Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof. More...
 
static enum GNUNET_GenericReturnValue barrier_reached_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 Offer internal data from a "batch" CMD, to other commands. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached (const char *label, const char *barrier_label, unsigned int asynchronous_finish, unsigned int node_number, unsigned int running_on_master, GNUNET_TESTING_cmd_helper_write_cb write_message)
 Create command. More...
 

Detailed Description

Command to signal barrier was reached.

Author
t3sserakt

Definition in file testing_api_cmd_barrier_reached.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Generic logging shortcut.

Definition at line 37 of file testing_api_cmd_barrier_reached.c.

Function Documentation

◆ barrier_reached_run()

static void barrier_reached_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

Run the command.

Parameters
clsclosure.
isthe interpreter state.

Definition at line 90 of file testing_api_cmd_barrier_reached.c.

92{
93 struct BarrierReachedState *brs = cls;
94 struct GNUNET_TESTING_Barrier *barrier;
95 struct GNUNET_TESTING_Command *cmd =
97 struct CommandListEntry *cle;
98 size_t msg_length;
100 size_t name_len;
101
103 brs->barrier_name);
104 if (NULL == barrier)
105 {
106 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
107 barrier->name = brs->barrier_name;
109 barrier);
110 }
111 barrier->reached++;
113 {
114 GNUNET_assert (NULL != cmd);
117 barrier->name);
118 }
119 else if (GNUNET_NO == brs->asynchronous_finish)
120 {
121 cle = GNUNET_new (struct CommandListEntry);
122 cle->command = cmd;
124 barrier->cmds_tail,
125 cle);
127 "added cle for %p %s\n",
128 barrier,
129 barrier->name);
130 }
131
132 if (GNUNET_NO == brs->running_on_master)
133 {
134 char *terminator = "\0";
135
136 name_len = strlen (barrier->name);
137 msg_length = sizeof(struct GNUNET_TESTING_CommandBarrierReached)
138 + name_len + 1;
139 msg = GNUNET_malloc (msg_length);
140 msg->header.size = htons ((uint16_t) msg_length);
142 msg->node_number = brs->node_number;
143 memcpy (&msg[1], barrier->name, name_len + 1);
144 memcpy (&msg[name_len + 1],terminator,1);
145 brs->write_message ((struct GNUNET_MessageHeader *) msg, msg_length);
146 }
147}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_TESTING_Interpreter * is
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED
Struct with information for callbacks.
const char * barrier_name
The name of the barrier this commands wait (if finishing asynchronous) for or/and reaches.
unsigned int running_on_master
Is this cmd running on the master loop.
unsigned int asynchronous_finish
If this command will block.
GNUNET_TESTING_cmd_helper_write_cb write_message
Callback to write messages to the master loop.
struct GNUNET_TESTING_Command * command
Definition: testing.h:148
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
const char * name
Name of the barrier.
Definition: testing.h:182
struct CommandListEntry * cmds_tail
Tail of the DLL with local commands the barrier is attached too.
Definition: testing.h:172
struct CommandListEntry * cmds_head
Head of the DLL with local commands the barrier is attached too.
Definition: testing.h:167
unsigned int reached
Number of commands which reached this barrier.
Definition: testing.h:197
A command to be run by the interpreter.
bool asynchronous_finish
If "true", the interpreter should not immediately call finish, even if finish is non-NULL.
struct GNUNET_TESTING_Barrier * GNUNET_TESTING_get_barrier_(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Getting a barrier from the interpreter.
void GNUNET_TESTING_finish_barrier_(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Finish all "barrier reached" commands attached to this barrier.
bool GNUNET_TESTING_barrier_crossable_(struct GNUNET_TESTING_Barrier *barrier)
This function checks, if a barrier can be crossed, which actually means that the cmd representing the...
void GNUNET_TESTING_add_barrier_(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
Add a barrier to the loop.
#define LOG(kind,...)
Generic logging shortcut.
struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_get_current_command(struct GNUNET_TESTING_Interpreter *is)
Returns the actual running command.

References GNUNET_TESTING_Command::asynchronous_finish, BarrierReachedState::asynchronous_finish, BarrierReachedState::barrier_name, GNUNET_TESTING_Barrier::cmds_head, GNUNET_TESTING_Barrier::cmds_tail, CommandListEntry::command, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED, GNUNET_new, GNUNET_NO, GNUNET_TESTING_add_barrier_(), GNUNET_TESTING_barrier_crossable_(), GNUNET_TESTING_finish_barrier_(), GNUNET_TESTING_get_barrier_(), GNUNET_TESTING_interpreter_get_current_command(), GNUNET_YES, is, LOG, msg, GNUNET_TESTING_Barrier::name, BarrierReachedState::node_number, GNUNET_TESTING_Barrier::reached, BarrierReachedState::running_on_master, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, and BarrierReachedState::write_message.

Referenced by GNUNET_TESTING_cmd_barrier_reached().

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

◆ barrier_reached_cleanup()

static void barrier_reached_cleanup ( void *  cls)
static

Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof.

Parameters
clsclosure.

Definition at line 157 of file testing_api_cmd_barrier_reached.c.

158{
159 struct BarrierReachedState *brs = cls;
160
161 GNUNET_free (brs);
162}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free.

Referenced by GNUNET_TESTING_cmd_barrier_reached().

Here is the caller graph for this function:

◆ barrier_reached_traits()

static enum GNUNET_GenericReturnValue barrier_reached_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

Offer internal data from a "batch" CMD, to other commands.

Parameters
clsclosure.
[out]retresult.
traitname of the trait.
indexindex number of the object to offer.
Returns
GNUNET_OK on success.

Definition at line 175 of file testing_api_cmd_barrier_reached.c.

179{
180 struct BarrierReachedState *brs = cls;
181 struct GNUNET_TESTING_AsyncContext *ac = &brs->ac;
182
183 struct GNUNET_TESTING_Trait traits[] = {
186 };
187
188 return GNUNET_TESTING_get_trait (traits,
189 ret,
190 trait,
191 index);
192}
static int ret
Final status code.
Definition: gnunet-arm.c:94
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_async_context(struct GNUNET_TESTING_AsyncContext *value)
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
State each asynchronous command must have in its closure.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.

References BarrierReachedState::ac, GNUNET_TESTING_get_trait(), GNUNET_TESTING_make_trait_async_context(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, and ret.

Referenced by GNUNET_TESTING_cmd_barrier_reached().

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

◆ GNUNET_TESTING_cmd_barrier_reached()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached ( const char *  label,
const char *  barrier_label,
unsigned int  asynchronous_finish,
unsigned int  node_number,
unsigned int  running_on_master,
GNUNET_TESTING_cmd_helper_write_cb  write_message 
)

Create command.

If this command is executed the the process is signaling the master process that it reached a barrier.

Parameters
labelname for command.
barrier_labelThe name of the barrier we wait for (if finishing asynchronous) and which will be reached.
asynchronous_finishIf GNUNET_YES this command will not block.
node_numberThe global numer of the node the cmd runs on.
running_on_masterIs this cmd running on the master loop.
write_messageCallback to write messages to the master loop.
Returns
command.

Definition at line 207 of file testing_api_cmd_barrier_reached.c.

214{
215 struct BarrierReachedState *brs;
216
217 brs = GNUNET_new (struct BarrierReachedState);
218 brs->label = label;
219 brs->barrier_name = barrier_label;
228 &brs->ac);
229}
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command.
const char * label
The label of this command.
static void barrier_reached_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.
static enum GNUNET_GenericReturnValue barrier_reached_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "batch" CMD, to other commands.
static void barrier_reached_cleanup(void *cls)
Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof.

References BarrierReachedState::ac, BarrierReachedState::asynchronous_finish, BarrierReachedState::barrier_name, barrier_reached_cleanup(), barrier_reached_run(), barrier_reached_traits(), GNUNET_new, GNUNET_TESTING_command_new(), BarrierReachedState::label, BarrierReachedState::node_number, BarrierReachedState::running_on_master, write_message(), and BarrierReachedState::write_message.

Here is the call graph for this function: