From 68e18c7f35b332a4fbfa1bec206706667681ce30 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 13 Jun 2015 15:16:17 +0200 Subject: added a wait command which should make automatic testing easier --- src/biruda.conf | 4 ++-- src/cli.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/biruda.conf b/src/biruda.conf index d7fae19..8ac2150 100644 --- a/src/biruda.conf +++ b/src/biruda.conf @@ -32,8 +32,8 @@ worker worker1 execution = direct - command = "./workertest 60" -# command = "workertest.exe 60" + command = "./workertest 10" +# command = "workertest.exe 10" } worker worker2 diff --git a/src/cli.c b/src/cli.c index 2a228db..2c4dde8 100644 --- a/src/cli.c +++ b/src/cli.c @@ -29,7 +29,10 @@ typedef enum { COMMAND, // command parsing START_WORKER, // worker commands expect a worker (and STOP_WORKER, // optionally an architecture and os parameter) - MESSAGES_WORKER + MESSAGES_WORKER, + WAIT // wait state, allow autodisp to work, but wait + // for commands for n seconds (handy in batches + // and for testing) } command_state_t; typedef enum { @@ -42,7 +45,7 @@ typedef enum { static char *commands[] = { "help", "quit", "status", "start", "stop", - "autodisp", "messages", NULL + "autodisp", "messages", "wait", NULL }; static bool print_colors = false; @@ -59,6 +62,8 @@ static int nof_worker_names = 0; static bool autodisp_toggle = false; +static unsigned int wait_time = 0; + static void cleanup_worker_names( ) { for( int i = 0; i < nof_worker_names; i++ ) { @@ -153,6 +158,10 @@ static void completion_func( const char *buf, linenoiseCompletions *lc ) linenoiseAddCompletion( lc, worker_names[i] ); } break; + + case WAIT: + // no completion + break; } } @@ -166,6 +175,7 @@ static void print_help( ) " stop - stop a worker manually\n" " messages - show output of workers\n" " autodisp - automatically show messages (toggle)\n" + " wait - wait n seconds before next command\n" ); } @@ -353,12 +363,26 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE case MESSAGES_WORKER: context = "worker"; break; + + case WAIT: + context = "wait"; + break; } if( autodisp_toggle ) { print_messages( ); } + if( command_state == WAIT && wait_time > 0 ) { + wait_time--; + if( wait_time == 0 ) { + command_state = COMMAND; + } else { + sleep( 1 ); + continue; + } + } + if( is_interactive ) { snprintf( prompt, sizeof( prompt ), "%s> ", context ); if( ( line = linenoise( prompt ) ) == NULL ) { @@ -371,6 +395,7 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE case START_WORKER: case STOP_WORKER: case MESSAGES_WORKER: + case WAIT: command_state = COMMAND; command_worker_state = WORKER_ILLEGAL; continue; @@ -429,6 +454,11 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE } else { print_error( "'autodisp' makes sense only in interactive mode." ); } + } else if( strncasecmp( line, "wait", 4 ) == 0 ) { + if( is_interactive ) { + puts( "Enter sleep time (in seconds):") ; + } + command_state = WAIT; } else if( strcmp( line, "" ) == 0 ) { // skip, handy if autodisp is on to show more messages } else { @@ -441,6 +471,8 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE start_worker( line ); command_state = COMMAND; command_worker_state = WORKER_ILLEGAL; + } else { + get_worker_data( ); } break; @@ -449,6 +481,8 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE stop_worker( line ); command_state = COMMAND; command_worker_state = WORKER_ILLEGAL; + } else { + get_worker_data( ); } break; @@ -457,8 +491,16 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE print_messages( ); command_state = COMMAND; command_worker_state = WORKER_ILLEGAL; + } else { + get_worker_data( ); } break; + + case WAIT: + wait_time = atoi( line ); + printf( "Sleeping for %d seconds\n", wait_time ); + break; + } } -- cgit v1.2.3-54-g00ecf