summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-06-13 13:19:59 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-06-13 13:19:59 +0200
commit5e88e1bf7ad98069e59557ec1aadfeeba90c4c45 (patch)
tree1368f3f54022056f9e7a75d63bb421020f160d9e
parent9821f4fcc5da36d24bc41186dccb12ed9f361662 (diff)
downloadbiruda-5e88e1bf7ad98069e59557ec1aadfeeba90c4c45.tar.gz
biruda-5e88e1bf7ad98069e59557ec1aadfeeba90c4c45.tar.bz2
more playing with cli and parameters for workers
-rw-r--r--src/cli.c60
1 files 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;
}
}