testing_api_cmd_sleep.c (2864B)
1 /* 2 This file is part of TALER 3 (C) 2018 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 3, or 8 (at your option) any later version. 9 10 TALER 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 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with TALER; see the file COPYING. If not, see 17 <http://www.gnu.org/licenses/> 18 */ 19 /** 20 * @file testing/testing_api_cmd_sleep.c 21 * @brief command(s) to sleep for a bit 22 * @author Christian Grothoff 23 */ 24 #include "taler/platform.h" 25 #include "taler/taler_json_lib.h" 26 #include <gnunet/gnunet_curl_lib.h> 27 #include "taler/taler_testing_lib.h" 28 29 30 /** 31 * State for a "sleep" CMD. 32 */ 33 struct SleepState 34 { 35 36 /** 37 * How long should we sleep? 38 */ 39 unsigned int duration; 40 }; 41 42 43 /** 44 * No traits to offer, just provide a stub to be called when 45 * some CMDs iterates through the list of all the commands. 46 * 47 * @param cls closure. 48 * @param[out] ret result. 49 * @param trait name of the trait. 50 * @param index index number of the trait to return. 51 * @return #GNUNET_OK on success. 52 */ 53 static int 54 sleep_traits (void *cls, 55 const void **ret, 56 const char *trait, 57 unsigned int index) 58 { 59 (void) cls; 60 (void) ret; 61 (void) trait; 62 (void) index; 63 return GNUNET_NO; 64 } 65 66 67 /** 68 * Run the command. 69 * 70 * @param cls closure. 71 * @param cmd the command to execute. 72 * @param is the interpreter state. 73 */ 74 static void 75 sleep_run (void *cls, 76 const struct TALER_TESTING_Command *cmd, 77 struct TALER_TESTING_Interpreter *is) 78 { 79 struct SleepState *ss = cls; 80 81 sleep (ss->duration); 82 TALER_TESTING_interpreter_next (is); 83 } 84 85 86 /** 87 * Cleanup the state from a "sleep" CMD. 88 * 89 * @param cls closure. 90 * @param cmd the command which is being cleaned up. 91 */ 92 static void 93 sleep_cleanup (void *cls, 94 const struct TALER_TESTING_Command *cmd) 95 { 96 struct SleepState *ss = cls; 97 98 (void) cmd; 99 GNUNET_free (ss); 100 } 101 102 103 /** 104 * Sleep for @a duration_s seconds. 105 * 106 * @param label command label. 107 * @param duration_s number of seconds to sleep 108 * @return the command. 109 */ 110 struct TALER_TESTING_Command 111 TALER_TESTING_cmd_sleep (const char *label, 112 unsigned int duration_s) 113 { 114 struct SleepState *ss; 115 116 ss = GNUNET_new (struct SleepState); 117 ss->duration = duration_s; 118 119 { 120 struct TALER_TESTING_Command cmd = { 121 .cls = ss, 122 .label = label, 123 .run = &sleep_run, 124 .cleanup = &sleep_cleanup, 125 .traits = &sleep_traits 126 }; 127 128 return cmd; 129 } 130 } 131 132 133 /* end of testing_api_cmd_sleep.c */