From 842308eb541ecf78391addc0b6778f8f1daab1e4 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 16 Nov 2014 10:25:04 +0100 Subject: some docu added parser callback for worker execution mode --- INSTALL | 1 + README | 6 +++++- src/biruda.c | 27 ++++++++++++++++++++++++++- src/biruda.conf | 2 ++ src/worker.c | 8 ++++++++ src/worker.h | 6 ++++++ 6 files changed, 48 insertions(+), 2 deletions(-) diff --git a/INSTALL b/INSTALL index f334659..0fd38f2 100644 --- a/INSTALL +++ b/INSTALL @@ -11,6 +11,7 @@ from the AUR: * nanomsg * json-c * libdaemon + * libmicrohttpd Centos 7 -------- diff --git a/README b/README index c87887a..017f210 100644 --- a/README +++ b/README @@ -34,9 +34,13 @@ Requirements https://github.com/json-c/json-c/wiki * glib2: for direct execution of children in the worker http://www.gtk.org/ -* libdaemon: for daemonizing support on Unix * linenoise: lightweight editline/readline replacement for the baruda client 'bcli' + https://github.com/antirez/linenoise + (integrated) +* http-tiny: simple web client library, used by the 'cli' to talk to the master. + http://www.demailly.com/~dl/http-tiny-1.2.tar.gz (integrated) +* libdaemon: for daemonizing support on Unix Other projects -------------- diff --git a/src/biruda.c b/src/biruda.c index 3934d55..1ec8d5a 100644 --- a/src/biruda.c +++ b/src/biruda.c @@ -68,6 +68,19 @@ static int test_config( const struct gengetopt_args_info *args_info ) return 0; } +static int conf_parse_worker_execution( cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result ) +{ + if( strcmp( value, "direct" ) == 0 ) { + *(worker_execution_mode_t *)result = WORKER_EXECUTION_DIRECT; + } else { + cfg_error( cfg, "invalid value for worker execution mode option '%s': %s", + cfg_opt_name( opt ), value ); + return -1; + } + + return 0; +} + static int read_config( const char *filename, cfg_t **cfg ) { cfg_opt_t opts_master[] = { @@ -82,6 +95,8 @@ static int read_config( const char *filename, cfg_t **cfg ) cfg_opt_t opts_worker[] = { CFG_STR( "control", 0, CFGF_NODEFAULT ), + CFG_INT_CB( "execution", WORKER_EXECUTION_DIRECT, CFGF_NONE, conf_parse_worker_execution ), + CFG_STR( "command", NULL, CFGF_NONE ), CFG_END( ) }; @@ -142,12 +157,22 @@ static void print_config( struct gengetopt_args_info *args_info, cfg_t *cfg ) unsigned int nof_workers = cfg_size( cfg, "worker" ); if( nof_workers > 0 ) { - printf( "Workers:\n" ); + puts( "Workers:\n" ); for( unsigned int i = 0; i < nof_workers; i++ ) { cfg_t *worker_cfg = cfg_getnsec( cfg, "worker", i ); printf( " Worker %s:\n", cfg_title( worker_cfg ) ); printf( " Control channel: %s\n", cfg_getstr( worker_cfg, "control" ) ); + printf( " Execution mode: %s\n", worker_exection_mode_str( cfg_getint( worker_cfg, "execution" ) ) ); + if( cfg_getint( worker_cfg, "execution" ) == WORKER_EXECUTION_DIRECT ) { + char *command = cfg_getstr( worker_cfg, "command" ); + if( command != NULL ) { + printf( " Command: %s\n", cfg_getstr( worker_cfg, "command" ) ); + } else { + printf( " No command configured\n" ); + } + } + puts( "" ); } puts( "" ); } diff --git a/src/biruda.conf b/src/biruda.conf index 51da929..ac98a9f 100644 --- a/src/biruda.conf +++ b/src/biruda.conf @@ -19,6 +19,8 @@ worker worker1 # control = "ipc:///tmp/biruda.ipc" # control = "inproc://control" control = "tcp://localhost:5555" + execution = direct + command = "workertest" } worker worker2 diff --git a/src/worker.c b/src/worker.c index 7c538d2..54e3982 100644 --- a/src/worker.c +++ b/src/worker.c @@ -4,6 +4,14 @@ #include +const char *worker_exection_mode_str( worker_execution_mode_t mode ) +{ + switch( mode ) { + case WORKER_EXECUTION_DIRECT: return "direct"; + default: return ""; + } +} + int worker_init( const char *control ) { //~ gboolean ret = g_spawn_async_with_pipes( NULL, diff --git a/src/worker.h b/src/worker.h index d0ca595..151aa77 100644 --- a/src/worker.h +++ b/src/worker.h @@ -1,6 +1,12 @@ #ifndef _BIRUDA_WORKER_HEADER_INCLUDED #define _BIRUDA_WORKER_HEADER_INCLUDED +typedef enum { + WORKER_EXECUTION_DIRECT +} worker_execution_mode_t; + +const char *worker_exection_mode_str( worker_execution_mode_t mode ); + int worker_init( const char *control ); void worker_terminate( ); int worker_free( ); -- cgit v1.2.3-54-g00ecf