From 5e88e1bf7ad98069e59557ec1aadfeeba90c4c45 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 13 Jun 2015 13:19:59 +0200 Subject: more playing with cli and parameters for workers --- src/cli.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/src/cli.c b/src/cli.c index 63def10..2a228db 100644 --- a/src/cli.c +++ b/src/cli.c @@ -32,6 +32,14 @@ typedef enum { MESSAGES_WORKER } command_state_t; +typedef enum { + WORKER_ILLEGAL, // not in a worker related state + WORKER_NAME, // name of the worker + WORKER_OS, // in case there is more than one worker with that name + WORKER_ARCH, // architecture, if still ambiguos + WORKER_EXECUTE // all data, execute worker command now +} command_worker_state_t; + static char *commands[] = { "help", "quit", "status", "start", "stop", "autodisp", "messages", NULL @@ -43,6 +51,8 @@ static bool is_interactive = false; static command_state_t command_state = COMMAND; +static command_worker_state_t command_worker_state = WORKER_ILLEGAL; + static char *worker_names[MAX_WORKERS]; static int nof_worker_names = 0; @@ -139,7 +149,6 @@ static void completion_func( const char *buf, linenoiseCompletions *lc ) case STOP_WORKER: case MESSAGES_WORKER: get_workers( ); - print_workers( ); for( int i = 0; i < nof_worker_names; i++ ) { linenoiseAddCompletion( lc, worker_names[i] ); } @@ -278,6 +287,25 @@ static void stop_worker( const char *worker_name ) } } +static void get_worker_data( ) +{ + switch( command_worker_state ) { + case WORKER_NAME: + get_workers( ); + print_workers( ); + command_worker_state = WORKER_EXECUTE; + break; + + case WORKER_EXECUTE: + case WORKER_ILLEGAL: + case WORKER_ARCH: + case WORKER_OS: + /* later */ + print_error( "ERROR: internal worker state error" ); + break; + } +} + #endif #ifdef _WIN32 @@ -344,6 +372,7 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE case STOP_WORKER: case MESSAGES_WORKER: command_state = COMMAND; + command_worker_state = WORKER_ILLEGAL; continue; } break; @@ -383,10 +412,16 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE print_status( ); } else if( strncasecmp( line, "start", 5 ) == 0 ) { command_state = START_WORKER; + command_worker_state = WORKER_NAME; + get_worker_data( ); } else if( strncasecmp( line, "stop", 5 ) == 0 ) { command_state = STOP_WORKER; + command_worker_state = WORKER_NAME; + get_worker_data( ); } else if( strncasecmp( line, "messages", 8 ) == 0 ) { command_state = MESSAGES_WORKER; + command_worker_state = WORKER_NAME; + get_worker_data( ); } else if( strncasecmp( line, "autodisp", 8 ) == 0 ) { if( is_interactive ) { autodisp_toggle = !autodisp_toggle; @@ -400,20 +435,29 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE print_error( "Bad command '%s'.", line ); } break; - + case START_WORKER: - start_worker( line ); - command_state = COMMAND; + if( command_worker_state == WORKER_EXECUTE ) { + start_worker( line ); + command_state = COMMAND; + command_worker_state = WORKER_ILLEGAL; + } break; case STOP_WORKER: - stop_worker( line ); - command_state = COMMAND; + if( command_worker_state == WORKER_EXECUTE ) { + stop_worker( line ); + command_state = COMMAND; + command_worker_state = WORKER_ILLEGAL; + } break; case MESSAGES_WORKER: - print_messages( ); - command_state = COMMAND; + if( command_worker_state == WORKER_EXECUTE ) { + print_messages( ); + command_state = COMMAND; + command_worker_state = WORKER_ILLEGAL; + } break; } } -- cgit v1.2.3-54-g00ecf