GNUnet  0.11.x
testing_api_cmd_hello_world.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2021 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
27 #include "gnunet_testing_ng_lib.h"
28 
30 {
31  char *message;
32  const char *birthLabel;
33 };
34 
35 
41 static void
43 {
44  struct HelloWorldState *hs = cls;
45 
47  "Cleaning up message %s\n",
48  hs->message);
49  GNUNET_free (hs);
50 }
51 
52 
62 static enum GNUNET_GenericReturnValue
63 hello_world_traits (void *cls,
64  const void **ret,
65  const char *trait,
66  unsigned int index)
67 {
68  return GNUNET_NO;
69 }
70 
71 
78 static void
79 hello_world_run (void *cls,
81 {
82  struct HelloWorldState *hs = cls;
83  const struct GNUNET_TESTING_Command *birth_cmd;
84 
86  "%s\n",
87  hs->message);
89  hs->birthLabel);
91  &hs->message);
93  "Now I am a %s\n",
94  hs->message);
95 }
96 
97 
107  const char *birthLabel,
108  char *message)
109 {
110  struct HelloWorldState *hs;
111 
112  hs = GNUNET_new (struct HelloWorldState);
113  hs->message = "Hello World, I was nobody!";
114  hs->birthLabel = birthLabel;
115  {
116  struct GNUNET_TESTING_Command cmd = {
117  .cls = hs,
118  .label = label,
119  .run = &hello_world_run,
120  .cleanup = &hello_world_cleanup,
121  .traits = &hello_world_traits
122  };
123 
124  return cmd;
125  }
126 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_NO
Definition: gnunet_common.h:94
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
int GNUNET_TESTING_get_trait_what_am_i(const struct GNUNET_TESTING_Command *cmd, char **what_am_i)
Offer data from trait.
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
A command to be run by the interpreter.
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
static enum GNUNET_GenericReturnValue hello_world_traits(void *cls, const void **ret, const char *trait, unsigned int index)
static void hello_world_cleanup(void *cls)
static void hello_world_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the "hello world" CMD.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world(const char *label, const char *birthLabel, char *message)
Create command.