exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_sleep.c (2836B)


      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/taler_json_lib.h"
     25 #include <gnunet/gnunet_curl_lib.h>
     26 #include "taler/taler_testing_lib.h"
     27 
     28 
     29 /**
     30  * State for a "sleep" CMD.
     31  */
     32 struct SleepState
     33 {
     34 
     35   /**
     36    * How long should we sleep?
     37    */
     38   unsigned int duration;
     39 };
     40 
     41 
     42 /**
     43  * No traits to offer, just provide a stub to be called when
     44  * some CMDs iterates through the list of all the commands.
     45  *
     46  * @param cls closure.
     47  * @param[out] ret result.
     48  * @param trait name of the trait.
     49  * @param index index number of the trait to return.
     50  * @return #GNUNET_OK on success.
     51  */
     52 static int
     53 sleep_traits (void *cls,
     54               const void **ret,
     55               const char *trait,
     56               unsigned int index)
     57 {
     58   (void) cls;
     59   (void) ret;
     60   (void) trait;
     61   (void) index;
     62   return GNUNET_NO;
     63 }
     64 
     65 
     66 /**
     67  * Run the command.
     68  *
     69  * @param cls closure.
     70  * @param cmd the command to execute.
     71  * @param is the interpreter state.
     72  */
     73 static void
     74 sleep_run (void *cls,
     75            const struct TALER_TESTING_Command *cmd,
     76            struct TALER_TESTING_Interpreter *is)
     77 {
     78   struct SleepState *ss = cls;
     79 
     80   sleep (ss->duration);
     81   TALER_TESTING_interpreter_next (is);
     82 }
     83 
     84 
     85 /**
     86  * Cleanup the state from a "sleep" CMD.
     87  *
     88  * @param cls closure.
     89  * @param cmd the command which is being cleaned up.
     90  */
     91 static void
     92 sleep_cleanup (void *cls,
     93                const struct TALER_TESTING_Command *cmd)
     94 {
     95   struct SleepState *ss = cls;
     96 
     97   (void) cmd;
     98   GNUNET_free (ss);
     99 }
    100 
    101 
    102 /**
    103  * Sleep for @a duration_s seconds.
    104  *
    105  * @param label command label.
    106  * @param duration_s number of seconds to sleep
    107  * @return the command.
    108  */
    109 struct TALER_TESTING_Command
    110 TALER_TESTING_cmd_sleep (const char *label,
    111                          unsigned int duration_s)
    112 {
    113   struct SleepState *ss;
    114 
    115   ss = GNUNET_new (struct SleepState);
    116   ss->duration = duration_s;
    117 
    118   {
    119     struct TALER_TESTING_Command cmd = {
    120       .cls = ss,
    121       .label = label,
    122       .run = &sleep_run,
    123       .cleanup = &sleep_cleanup,
    124       .traits = &sleep_traits
    125     };
    126 
    127     return cmd;
    128   }
    129 }
    130 
    131 
    132 /* end of testing_api_cmd_sleep.c  */