diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-12-07 13:16:08 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-12-07 13:16:08 +0100 |
commit | 9af266f6c4d44eb39754cc0e16cb7ca192addea0 (patch) | |
tree | 150c392c12ec33e8248a9751439b9fd4e15b70db /src/cli.c | |
parent | ea248471703cc71bb1d57c0dc2b7914983cf0127 (diff) | |
download | biruda-9af266f6c4d44eb39754cc0e16cb7ca192addea0.tar.gz biruda-9af266f6c4d44eb39754cc0e16cb7ca192addea0.tar.bz2 |
some better worker output reporting
Diffstat (limited to 'src/cli.c')
-rw-r--r-- | src/cli.c | 37 |
1 files changed, 35 insertions, 2 deletions
@@ -31,7 +31,7 @@ typedef enum { static char *commands[] = { "help", "quit", "status", "start", "stop", - "autodisp", NULL + "autodisp", "messages", NULL }; static bool print_colors = false; @@ -132,6 +132,7 @@ static void print_help( ) " status - status of the biruda network\n" " start - start a worker manually\n" " stop - stop a worker manually\n" + " messages - show output of workers\n" " autodisp - automatically show messages (toggle)\n" ); } @@ -194,6 +195,36 @@ static void print_status( ) free( data ); } +static void print_worker_output( const char *worker_name ) +{ + char url[128]; + snprintf( url, sizeof( url ), "worker?op=output&name=%s", worker_name ); + char *data = NULL; + int len; + http_retcode ret = http_get( url, &data, &len, NULL ); + if( ret == 200 ) { + if( strlen( data ) > 0 && data[len-1] == '\n' ) { + data[len-1] = '\0'; + len--; + } + if( strlen( data ) > 0 && data[len-1] == '\r' ) { + data[len-1] = '\0'; + } + print_answer( data ); + } else { + print_error( "ERROR: HTTP error %d", ret ); + } + free( data ); +} + +static void print_messages( ) +{ + get_workers( ); + for( int i = 0; i < nof_worker_names; i++ ) { + print_worker_output( worker_names[i] ); + } +} + static void start_worker( const char *worker_name ) { char url[128]; @@ -257,7 +288,7 @@ int start_interactive( bool colors, FILE *in ) } if( autodisp_toggle ) { - print_status( ); + print_messages( ); } if( is_interactive ) { @@ -313,6 +344,8 @@ int start_interactive( bool colors, FILE *in ) command_state = START_WORKER; } else if( strncasecmp( line, "stop", 5 ) == 0 ) { command_state = STOP_WORKER; + } else if( strncasecmp( line, "messages", 8 ) == 0 ) { + print_messages( ); } else if( strncasecmp( line, "autodisp", 8 ) == 0 ) { if( is_interactive ) { autodisp_toggle = !autodisp_toggle; |