GNUnet  0.11.x
Data Structures | Functions
testing_api_cmd_hello_world_birth.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
Include dependency graph for testing_api_cmd_hello_world_birth.c:

Go to the source code of this file.

Data Structures

struct  HelloWorldBirthState
 

Functions

static void hello_world_birth_cleanup (void *cls)
 
static int hello_world_birth_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 
static void hello_world_birth_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 Run the "hello world" CMD. More...
 
int GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd, char **what_am_i)
 Offer data from trait. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world_birth (const char *label, struct GNUNET_TIME_Absolute *now)
 Create command. More...
 

Function Documentation

◆ hello_world_birth_cleanup()

static void hello_world_birth_cleanup ( void *  cls)
static
Parameters
clsclosure
cmdcurrent CMD being cleaned up.

Definition at line 43 of file testing_api_cmd_hello_world_birth.c.

44 {
45  struct HelloWorldBirthState *hbs = cls;
47  "Finished birth of %s\n",
48  hbs->what_am_i);
49 }
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_INFO

References GNUNET_ERROR_TYPE_INFO, GNUNET_log, and HelloWorldBirthState::what_am_i.

◆ hello_world_birth_traits()

static int hello_world_birth_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static
Parameters
clsclosure.
[out]retresult
traitname of the trait.
indexindex number of the object to offer.
Returns
GNUNET_OK on success.

Definition at line 62 of file testing_api_cmd_hello_world_birth.c.

66 {
67  struct HelloWorldBirthState *hbs = cls;
68  const char *what_am_i = hbs->what_am_i;
69 
70  struct GNUNET_TESTING_Trait traits[] = {
71  {
72  .index = 0,
73  .trait_name = "what_am_i",
74  .ptr = (const void *) what_am_i,
75  },
77  };
78 
79  return GNUNET_TESTING_get_trait (traits,
80  ret,
81  trait,
82  index);
83 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Extract a trait.
unsigned int index
Index number associated with the trait.

References GNUNET_TESTING_get_trait(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, ret, and HelloWorldBirthState::what_am_i.

Here is the call graph for this function:

◆ hello_world_birth_run()

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

Run the "hello world" CMD.

Parameters
clsclosure.
cmdCMD being run.
isinterpreter state.

Definition at line 94 of file testing_api_cmd_hello_world_birth.c.

96 {
97  struct HelloWorldBirthState *hbs = cls;
98  struct GNUNET_TIME_Relative relative;
99 
100  relative = GNUNET_TIME_absolute_get_difference (*hbs->date,
102 
103  if (0 == relative.rel_value_us % 10)
104  {
105  hbs->what_am_i = "creature!";
106  }
107  else if (0 == relative.rel_value_us % 2)
108  {
109  hbs->what_am_i = "girl!";
110  }
111  else
112  {
113  hbs->what_am_i = "boy!";
114  }
115 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:248
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_TIME_Absolute * date

References HelloWorldBirthState::date, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_difference(), GNUNET_TIME_Relative::rel_value_us, and HelloWorldBirthState::what_am_i.

Here is the call graph for this function:

◆ GNUNET_TESTING_get_trait_what_am_i()

int GNUNET_TESTING_get_trait_what_am_i ( const struct GNUNET_TESTING_Command cmd,
char **  what_am_i 
)

Offer data from trait.

Parameters
cmdcommand to extract the message from.
ptpointer to message.
Returns
GNUNET_OK on success.

Definition at line 126 of file testing_api_cmd_hello_world_birth.c.

128 {
129  return cmd->traits (cmd->cls,
130  (const void **) what_am_i,
131  "what_am_i",
132  (unsigned int) 0);
133 }
enum GNUNET_GenericReturnValue(* traits)(void *cls, const void **ret, const char *trait, unsigned int index)
Extract information from a command that is useful for other commands.
void * cls
Closure for all commands with command-specific context information.

Referenced by hello_world_run().

Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_hello_world_birth()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world_birth ( const char *  label,
struct GNUNET_TIME_Absolute now 
)

Create command.

Parameters
labelname for command.
nowwhen the command was started.
Returns
command.

Definition at line 126 of file testing_api_cmd_hello_world_birth.c.

146 {
147  struct HelloWorldBirthState *hbs;
148 
149  hbs = GNUNET_new (struct HelloWorldBirthState);
150  hbs->date = now;
151 
152  struct GNUNET_TESTING_Command cmd = {
153  .cls = hbs,
154  .label = label,
155  .run = &hello_world_birth_run,
156  .cleanup = &hello_world_birth_cleanup,
157  .traits = &hello_world_birth_traits
158  };
159 
160  return cmd;
161 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A command to be run by the interpreter.
const char * label
Label for the command.
static void hello_world_birth_cleanup(void *cls)
static int hello_world_birth_traits(void *cls, const void **ret, const char *trait, unsigned int index)
static void hello_world_birth_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the "hello world" CMD.

References GNUNET_TESTING_Command::cls, and GNUNET_TESTING_Command::traits.