From a978c195a8b0cbf9ff1330ab8c6af1deb79a8b83 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 02:11:20 -0400 Subject: trying new config mode --- src/survive.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'src/survive.c') diff --git a/src/survive.c b/src/survive.c index bafacad..e075423 100755 --- a/src/survive.c +++ b/src/survive.c @@ -50,7 +50,7 @@ static void *button_servicer(void * context) { OGLockSema(ctx->buttonQueue.buttonservicesem); - if (ctx->isClosing) + if (ctx->state != SURVIVE_RUNNING) { // we're shutting down. Close. return NULL; @@ -104,7 +104,9 @@ void survive_verify_FLT_size(uint32_t user_size) { } } -SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) { +SurviveContext * survive_init_internal( SurviveInitData * initdata ) +{ + #ifdef RUNTIME_SYMNUM if( !did_runtime_symnum ) { @@ -121,18 +123,17 @@ SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) MANUAL_DRIVER_REGISTRATION(PoserDaveOrtho) MANUAL_DRIVER_REGISTRATION(PoserDummy) MANUAL_DRIVER_REGISTRATION(DriverRegHTCVive) - #endif - int r = 0; - int i = 0; SurviveContext * ctx = calloc( 1, sizeof( SurviveContext ) ); - ctx->isClosing = 0; + ctx->state = SURVIVE_STOPPED; ctx->global_config_values = malloc( sizeof(config_group) ); ctx->lh_config = malloc( sizeof(config_group) * NUM_LIGHTHOUSES); + //initdata + // ->argc ->argp init_config_group(ctx->global_config_values,10); init_config_group(&ctx->lh_config[0],10); init_config_group(&ctx->lh_config[1],10); @@ -144,12 +145,18 @@ SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) ctx->faultfunction = survivefault; ctx->notefunction = survivenote; - ctx->lightproc = survive_default_light_process; ctx->imuproc = survive_default_imu_process; ctx->angleproc = survive_default_angle_process; ctx->lighthouseposeproc = survive_default_lighthouse_pose_process; - ctx->configfunction = configFunc ? configFunc : survive_default_htc_config_process; + ctx->configfunction = survive_default_htc_config_process; + return ctx; +} + +int survive_startup( SurviveContext * ctx ) +{ + int r = 0; + int i = 0; // initialize the button queue memset(&(ctx->buttonQueue), 0, sizeof(ctx->buttonQueue)); @@ -160,7 +167,6 @@ SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) survive_install_button_fn(ctx, NULL); survive_install_raw_pose_fn(ctx, NULL); - i = 0; const char * DriverName; //const char * PreferredPoser = config_read_str(ctx->global_config_values, "DefaultPoser", "PoserDummy"); @@ -190,8 +196,6 @@ SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) r = dd( ctx ); printf( "Driver %s reports status %d\n", DriverName, r ); } -printf( "REGISTERING DRIVERS\n" ); - //Apply poser to objects. for( i = 0; i < ctx->objs_ct; i++ ) { @@ -201,10 +205,12 @@ printf( "REGISTERING DRIVERS\n" ); // saving the config extra to make sure that the user has a config file they can change. config_save(ctx, "config.json"); + ctx->state = SURVIVE_RUNNING; - return ctx; + return 0; } + void survive_install_info_fn( SurviveContext * ctx, text_feedback_func fbp ) { if( fbp ) @@ -328,7 +334,7 @@ void survive_close( SurviveContext * ctx ) const char * DriverName; int r = 0; - ctx->isClosing = 1; + ctx->state = SURVIVE_CLOSING; // unlock/ post to button service semaphore so the thread can kill itself OGUnlockSema(ctx->buttonQueue.buttonservicesem); @@ -380,8 +386,15 @@ void survive_close( SurviveContext * ctx ) int survive_poll( struct SurviveContext * ctx ) { - int oldct = ctx->driver_ct; int i, r; + if( ctx->state = SURVIVE_STOPPED ) + { + r = survive_startup( ctx ); + if( r ) + return r; + } + + int oldct = ctx->driver_ct; for( i = 0; i < oldct; i++ ) { -- cgit v1.2.3 From 5aa20d099b9fe7539050a5baa4c70b678aeab64e Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 02:45:09 -0400 Subject: Moving things over... still todo: * Make functions for changing temp configs. * Make functions for config_read_str but where it checks the temp one first. * Parse command-line options. --- src/survive.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/survive.c') diff --git a/src/survive.c b/src/survive.c index e075423..327b7f8 100755 --- a/src/survive.c +++ b/src/survive.c @@ -104,7 +104,7 @@ void survive_verify_FLT_size(uint32_t user_size) { } } -SurviveContext * survive_init_internal( SurviveInitData * initdata ) +SurviveContext * survive_init_internal( int argc, char * const * argv ) { #ifdef RUNTIME_SYMNUM @@ -130,16 +130,19 @@ SurviveContext * survive_init_internal( SurviveInitData * initdata ) ctx->state = SURVIVE_STOPPED; ctx->global_config_values = malloc( sizeof(config_group) ); + ctx->temporary_config_values = malloc( sizeof(config_group) ); ctx->lh_config = malloc( sizeof(config_group) * NUM_LIGHTHOUSES); //initdata // ->argc ->argp init_config_group(ctx->global_config_values,10); + init_config_group(ctx->temporary_config_values,20); init_config_group(&ctx->lh_config[0],10); init_config_group(&ctx->lh_config[1],10); - config_read(ctx, "config.json"); - ctx->activeLighthouses = config_read_uint32(ctx->global_config_values, "LighthouseCount", 2); + config_read(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); + ctx->activeLighthouses = survive_config_readi( ctx, "lighthousecount", 2 ); + config_read_lighthouse(ctx->lh_config, &(ctx->bsd[0]), 0); config_read_lighthouse(ctx->lh_config, &(ctx->bsd[1]), 1); @@ -169,8 +172,8 @@ int survive_startup( SurviveContext * ctx ) const char * DriverName; - //const char * PreferredPoser = config_read_str(ctx->global_config_values, "DefaultPoser", "PoserDummy"); - const char * PreferredPoser = config_read_str(ctx->global_config_values, "DefaultPoser", "PoserTurveyTori"); + //const char * PreferredPoser = survive_config_reads(ctx->global_config_values, "defaultposer", "PoserDummy"); + const char * PreferredPoser = survive_config_reads( ctx, "defaultposer", "PoserTurveyTori"); PoserCB PreferredPoserCB = 0; const char * FirstPoser = 0; printf( "Available posers:\n" ); @@ -203,7 +206,7 @@ int survive_startup( SurviveContext * ctx ) } // saving the config extra to make sure that the user has a config file they can change. - config_save(ctx, "config.json"); + config_save(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); ctx->state = SURVIVE_RUNNING; @@ -364,9 +367,10 @@ void survive_close( SurviveContext * ctx ) } - config_save(ctx, "config.json"); + config_save(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); destroy_config_group(ctx->global_config_values); + destroy_config_group(ctx->temporary_config_values); destroy_config_group(ctx->lh_config); for (i = 0; i < ctx->objs_ct; i++) { @@ -379,6 +383,7 @@ void survive_close( SurviveContext * ctx ) free( ctx->drivermagics ); free( ctx->drivercloses ); free( ctx->global_config_values ); + free( ctx->temporary_config_values ); free( ctx->lh_config ); free( ctx ); -- cgit v1.2.3 From c44cca299fbea4196af125dfedd8e4d60f3ae0cc Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 19:48:25 -0400 Subject: Almost at a config interface. --- src/survive.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) (limited to 'src/survive.c') diff --git a/src/survive.c b/src/survive.c index 327b7f8..24bb7d3 100755 --- a/src/survive.c +++ b/src/survive.c @@ -106,7 +106,6 @@ void survive_verify_FLT_size(uint32_t user_size) { SurviveContext * survive_init_internal( int argc, char * const * argv ) { - #ifdef RUNTIME_SYMNUM if( !did_runtime_symnum ) { @@ -134,14 +133,58 @@ SurviveContext * survive_init_internal( int argc, char * const * argv ) ctx->lh_config = malloc( sizeof(config_group) * NUM_LIGHTHOUSES); //initdata - // ->argc ->argp init_config_group(ctx->global_config_values,10); init_config_group(ctx->temporary_config_values,20); init_config_group(&ctx->lh_config[0],10); init_config_group(&ctx->lh_config[1],10); - config_read(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); - ctx->activeLighthouses = survive_config_readi( ctx, "lighthousecount", 2 ); + //Process command-line parameters. + char * const * argvend = &argv[argc]; + char * const * av = argv+1; + int showhelp = 0; + for( ; av != argvend; av++ ) + { + if( (*av)[0] != '-' ) + showhelp = 1; + else + { + const char * vartoupdate = 0; + + switch( (*av)[1] ) + { + case '-': vartoupdate = &(*av)[2]; break; + case 'h': showhelp = 1; break; + case 'p': vartoupdate = "defaultposer"; break; + case 'l': vartoupdate = "lighthousecount"; break; + case 'c': vartoupdate = "configfile"; break; + default: + fprintf( stderr, "Error: unknown parameter %s\n", *av ); + showhelp = 1; + } + + if( vartoupdate ) + { + survive_configs( ctx, *av, SC_OVERRIDE, *(av+1) ); + av++; + } + } + } + if( showhelp ) + { + fprintf( stderr, "libsurvive - usage:\n" ); + fprintf( stderr, " --[parameter] [value] - sets parameter\n" ); + fprintf( stderr, " -h - shows help.\n" ); + fprintf( stderr, " -p [poser] - use a specific defaultposer.\n" ); + fprintf( stderr, " -l [lighthouse count] - use a specific number of lighthoses.\n" ); + fprintf( stderr, " -c [config file] - set config file\n" ); + fprintf( stderr, " -p [lighthouse count] - use a specific number of lighthoses.\n" ); + + //XXX: TODO: Should this just exit(-1)? + return 0; + } + + config_read(ctx, survive_configs( ctx, "configfile", SC_GET, "config.json" ) ); + ctx->activeLighthouses = survive_configi( ctx, "lighthousecount", SC_SETCONFIG, 2 ); config_read_lighthouse(ctx->lh_config, &(ctx->bsd[0]), 0); config_read_lighthouse(ctx->lh_config, &(ctx->bsd[1]), 1); @@ -173,7 +216,7 @@ int survive_startup( SurviveContext * ctx ) const char * DriverName; //const char * PreferredPoser = survive_config_reads(ctx->global_config_values, "defaultposer", "PoserDummy"); - const char * PreferredPoser = survive_config_reads( ctx, "defaultposer", "PoserTurveyTori"); + const char * PreferredPoser = survive_configs( ctx, "defaultposer", SC_SETCONFIG, "PoserTurveyTori"); PoserCB PreferredPoserCB = 0; const char * FirstPoser = 0; printf( "Available posers:\n" ); @@ -206,7 +249,7 @@ int survive_startup( SurviveContext * ctx ) } // saving the config extra to make sure that the user has a config file they can change. - config_save(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); + config_save(ctx, survive_configs( ctx, "configfile", SC_GET, "config.json" ) ); ctx->state = SURVIVE_RUNNING; @@ -367,7 +410,7 @@ void survive_close( SurviveContext * ctx ) } - config_save(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); + config_save(ctx, survive_configs( ctx, "configfile", SC_GET, "config.json" ) ); destroy_config_group(ctx->global_config_values); destroy_config_group(ctx->temporary_config_values); -- cgit v1.2.3 From 0996cfcee351bfd665f48a205d2f7fe37dec336c Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 22:00:55 -0400 Subject: Fix configuration system and fix race condition in survive_vive. --- src/survive.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/survive.c') diff --git a/src/survive.c b/src/survive.c index 24bb7d3..05c66d7 100755 --- a/src/survive.c +++ b/src/survive.c @@ -164,13 +164,22 @@ SurviveContext * survive_init_internal( int argc, char * const * argv ) if( vartoupdate ) { - survive_configs( ctx, *av, SC_OVERRIDE, *(av+1) ); - av++; + if( av+1 == argvend ) + { + fprintf( stderr, "Error: expected parameter after %s\n", *av ); + showhelp = 1; + } + else + { + survive_configs( ctx, *av+2, SC_OVERRIDE|SC_SET, *(av+1) ); + av++; + } } } } if( showhelp ) { + //Can't use SV_ERROR here since we don't have a context to send to yet. fprintf( stderr, "libsurvive - usage:\n" ); fprintf( stderr, " --[parameter] [value] - sets parameter\n" ); fprintf( stderr, " -h - shows help.\n" ); @@ -178,8 +187,6 @@ SurviveContext * survive_init_internal( int argc, char * const * argv ) fprintf( stderr, " -l [lighthouse count] - use a specific number of lighthoses.\n" ); fprintf( stderr, " -c [config file] - set config file\n" ); fprintf( stderr, " -p [lighthouse count] - use a specific number of lighthoses.\n" ); - - //XXX: TODO: Should this just exit(-1)? return 0; } @@ -435,7 +442,7 @@ void survive_close( SurviveContext * ctx ) int survive_poll( struct SurviveContext * ctx ) { int i, r; - if( ctx->state = SURVIVE_STOPPED ) + if( ctx->state == SURVIVE_STOPPED ) { r = survive_startup( ctx ); if( r ) -- cgit v1.2.3 From 8e65bc97327b27014fc9507374a20bfc468e06ee Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 18 Mar 2018 21:44:58 -0600 Subject: Took out installation after users could install hooks --- src/survive.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/survive.c') diff --git a/src/survive.c b/src/survive.c index 05c66d7..f0c24f5 100755 --- a/src/survive.c +++ b/src/survive.c @@ -217,8 +217,6 @@ int survive_startup( SurviveContext * ctx ) // start the thread to process button data ctx->buttonservicethread = OGCreateThread(button_servicer, ctx); - survive_install_button_fn(ctx, NULL); - survive_install_raw_pose_fn(ctx, NULL); const char * DriverName; -- cgit v1.2.3