X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=powersensordaemon%2Foptions.c;h=c0adddaf905a5f23d1ee6b2958e9edb274886e69;hp=3411f9d3fdc73275ae9822bd454a743c72588541;hb=1e3d3a58756a74fe837636bf7791926494778f4c;hpb=4e1a804cee8f1349967d65118bed03af60c6abdd diff --git a/powersensordaemon/options.c b/powersensordaemon/options.c index 3411f9d..c0addda 100644 --- a/powersensordaemon/options.c +++ b/powersensordaemon/options.c @@ -110,6 +110,22 @@ i++; \ } +#define PARSE_KEY_VALUE(SHORT, LONG, SEP, KV) \ + else if(!strcmp(str,SHORT) || !strcmp(str,LONG)) \ + { \ + if(argc < 1 || argv[i+1][0] == '-') \ + return i; \ + char* value = strchr(argv[i+1], SEP); \ + if(!value || value[1] == 0) \ + return i+1; \ + value[0] = 0; \ + value++; \ + if(key_value_storage_add(&KV, argv[i+1], value)) \ + return -2; \ + argc--; \ + i++; \ + } + int options_parse_hex_string(const char* hex, buffer_t* buffer) { if(!hex || !buffer) @@ -176,6 +192,8 @@ int options_parse(options_t* opt, int argc, char* argv[]) PARSE_STRING_PARAM("-s","--socket", opt->command_sock_) PARSE_STRING_PARAM("-p","--powerid-file", opt->powerid_file_) PARSE_STRING_PARAM("-a","--sampledev-file", opt->sampledev_file_) + PARSE_STRING_PARAM("-a","--sampledev-file", opt->sampledev_file_) + PARSE_KEY_VALUE("-A","--autosampledev", ',', opt->autosampledevs_) else return i; } @@ -229,6 +247,23 @@ int options_parse_post(options_t* opt) if(ret) return ret; } + + string_list_element_t* k = opt->autosampledevs_.keys_.first_; + string_list_element_t* v = opt->autosampledevs_.values_.first_; + while(k && v) { + if(!key_value_storage_find(&opt->sampledevs_, k->string_)) { + log_printf(ERROR, "sample dev '%s' not in file '%s'", k->string_, opt->sampledev_file_); + return -1; + } + if(atoi(v->string_) <= 0) { + log_printf(ERROR, "invalid rate '%s' for sample dev '%s'", v->string_, k->string_); + return -1; + } + k = k->next_; + v = v->next_; + } + + return 0; } void options_default(options_t* opt) @@ -250,6 +285,7 @@ void options_default(options_t* opt) key_value_storage_init(&opt->powerids_); opt->sampledev_file_ = NULL; key_value_storage_init(&opt->sampledevs_); + key_value_storage_init(&opt->autosampledevs_); } void options_clear(options_t* opt) @@ -279,6 +315,7 @@ void options_clear(options_t* opt) if(opt->sampledev_file_) free(opt->sampledev_file_); key_value_storage_clear(&opt->sampledevs_); + key_value_storage_clear(&opt->autosampledevs_); } void options_print_usage() @@ -297,6 +334,8 @@ void options_print_usage() printf(" [-s|--command-sock] the command socket e.g. /var/run/powersensordaemon/cmd.sock\n"); printf(" [-p|--powerid-file] file that contains the power ids\n"); printf(" [-a|--sampledev-file] file that contains all sample devices\n"); + printf(" [-A|--autosampledev] ,\n"); + printf(" automatic sample this devices, can be invoked several times\n"); } void options_print(options_t* opt) @@ -321,4 +360,5 @@ void options_print(options_t* opt) printf("sampledev_file: '%s'\n", opt->sampledev_file_); printf("sampledevs: \n"); key_value_storage_print(&opt->sampledevs_, " '", "' -> '", "'\n"); + key_value_storage_print(&opt->autosampledevs_, " '", "' -> '", "'\n"); }