From 8aa9708471981997c43b84d64fc7ecfb20f9f55f Mon Sep 17 00:00:00 2001 From: Francesco Salvestrini Date: Sat, 13 Sep 2008 14:29:47 +0200 Subject: [PATCH] Added -t/--time-out option to client --- src/distribute.cxx | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/distribute.cxx b/src/distribute.cxx index 103e69a..33416db 100644 --- a/src/distribute.cxx +++ b/src/distribute.cxx @@ -41,14 +41,15 @@ void version(void) void help(void) { std::cout - << "Usage: " << PACKAGE << " [OPTION]... "<< std::endl - << std::endl - << "Options: " << std::endl - << " -j, --job=FILE use FILE as job to distribute" << std::endl - << " -h, --help print this help, then exit" << std::endl - << " -V, --version print version number, then exit" << std::endl - << std::endl - << "Report bugs to <" << PACKAGE_BUGREPORT << ">" << std::endl; + << "Usage: " << PACKAGE << " [OPTION]... "<< std::endl + << std::endl + << "Options: " << std::endl + << " -t, --time-out=TIME start time-out (seconds)" << std::endl + << " -j, --job=FILE use FILE as job to distribute" << std::endl + << " -h, --help print this help, then exit" << std::endl + << " -V, --version print version number, then exit" << std::endl + << std::endl + << "Report bugs to <" << PACKAGE_BUGREPORT << ">" << std::endl; } void hint(const std::string & message) @@ -63,7 +64,8 @@ void hint(const std::string & message) int main(int argc, char * argv[]) { try { - std::string job; + int time_out = 0; // XXX FIXME: Change to a constant + std::string job = ""; // XXX FIXME: Change to a constant int c; int digit_optind = 0; @@ -72,19 +74,34 @@ int main(int argc, char * argv[]) int option_index = 0; static struct option long_options[] = { - { "job", 1, 0, 'j' }, - { "version", 0, 0, 'V' }, - { "help", 0, 0, 'h' }, - { 0, 0, 0, 0 } + { "job", 1, 0, 'j' }, + { "time-out", 1, 0, 't' }, + { "version", 0, 0, 'V' }, + { "help", 0, 0, 'h' }, + { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "j:Vh", + c = getopt_long(argc, argv, "t:j:Vh", long_options, &option_index); if (c == -1) { break; } switch (c) { + case 't': + // + // XXX FIXME: + // The current solution is ugly. + // Add modifiers (s, m, h) to + // this option in order to use + // different time granularity. + // + time_out = atoi(optarg); + if (time_out < 0) { + hint("Wrong time-out value"); + return 1; + } + break; case 'j': job = optarg; break; @@ -104,7 +121,8 @@ int main(int argc, char * argv[]) } } - TRACE(LVL_DEBUG, "Job = '%s'\n", job.c_str()); + TRACE(LVL_DEBUG, "Time out = '%d'\n", time_out); + TRACE(LVL_DEBUG, "Job = '%s'\n", job.c_str()); // Do the supposed work MISSING_CODE(); -- 2.11.4.GIT