From 7123f02e82ca4a0ec334c678894fbfc58c881262 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 12 Apr 2011 22:45:18 +0200 Subject: [PATCH] [Aggregator] Print version info with -V --- owlps-aggregator/Makefile | 7 ++++++- owlps-aggregator/owlps-aggregator.h | 3 ++- owlps-aggregator/owlps-aggregatord.c | 26 ++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/owlps-aggregator/Makefile b/owlps-aggregator/Makefile index f5bf98a..74abb2a 100644 --- a/owlps-aggregator/Makefile +++ b/owlps-aggregator/Makefile @@ -1,3 +1,8 @@ +# Source version +ifndef OWLPS_VERSION + OWLPS_VERSION = $$(git describe || echo 'UNKNOWN_VERSION') +endif + # RĂ©pertoire d'installation PREFIX=/usr/local INSTALL_DIR= $(PREFIX)/bin @@ -25,7 +30,7 @@ CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes -O -I$(LIBOWLPS_DIR) DEPFLAGS=-MMD XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS) PICFLAG=-fPIC -#OWLPSFLAGS = +OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\" LIBS = -pthread -lconfuse -L$(LIBOWLPS_DIR) -lowlps LDFLAGS = $(LIBS) $(OWLPSFLAGS) diff --git a/owlps-aggregator/owlps-aggregator.h b/owlps-aggregator/owlps-aggregator.h index b4bba4b..0060b59 100644 --- a/owlps-aggregator/owlps-aggregator.h +++ b/owlps-aggregator/owlps-aggregator.h @@ -11,7 +11,7 @@ /* Arguments & program configuration */ -#define OPTIONS "Aa:c:C:f:hi:k:K:l:o:p:t:v" // getopt string +#define OPTIONS "Aa:c:C:f:hi:k:K:l:o:p:t:vV" // getopt string #define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-aggregator.conf" #define DEFAULT_AGGREGATE_TIMEOUT 1500 // milliseconds #define DEFAULT_KEEP_TIMEOUT 3000 // milliseconds @@ -112,5 +112,6 @@ void order_send(ap_list *ap) ; void free_ap_list(void) ; void print_usage(void) ; +void print_version(void) ; #endif // _OWLPS_AGGREGATOR_H_ diff --git a/owlps-aggregator/owlps-aggregatord.c b/owlps-aggregator/owlps-aggregatord.c index ec42c38..e98a408 100644 --- a/owlps-aggregator/owlps-aggregatord.c +++ b/owlps-aggregator/owlps-aggregatord.c @@ -190,7 +190,7 @@ void parse_config_file(int argc, char **argv) char *config_file = NULL ; // Configuration file name - // Option -f specifies a config file, -h exits the + // Option -f specifies a config file, options -h and -V exit the // program, so we search for them first int opt ; while ((opt = getopt(argc, argv, OPTIONS)) != -1) @@ -204,6 +204,9 @@ void parse_config_file(int argc, char **argv) case 'h' : print_usage() ; exit(0) ; + case 'V' : + print_version() ; + exit(0) ; } } @@ -1239,9 +1242,12 @@ void print_usage() " [-K ap_keep_timeout]" " [-C ap_check_interval]" "\n" + "\t%s -h\n" + "\t%s -V\n" "Main options:\n" "\t-h\t\tPrint this help.\n" + "\t-V\t\tShow version information.\n" "\t-f config_file\tUse 'config_file' instead of the default" " configuration file (%s).\n" "\t-v\t\tBe verbose (print detailed info on each received" @@ -1260,7 +1266,7 @@ void print_usage() " treated (default: %d).\n" "\t-t aggregate_timeout\tRequests are stored during" " 'aggregate_timeout' milliseconds before to be grouped" - " (default: %d ms).\n" + " (default: %d ms).\n" "\t-k keep_timeout\t\tAggregated requests are kept during" " 'keep_timeout' milliseconds (default: %d ms).\n" "\t-c check_interval\tTime between two checks of the stored" @@ -1276,6 +1282,8 @@ void print_usage() " checks of the stored APs (default: %d ms).\n" , program_name, + program_name, + program_name, DEFAULT_CONFIG_FILE, POSITIONER_DEFAULT_IP, POSITIONER_DEFAULT_PORT, @@ -1288,3 +1296,17 @@ void print_usage() DEFAULT_AP_CHECK_INTERVAL ) ; } + + +void print_version() +{ + printf("This is OwlPS Aggregator, part of the Open Wireless" + " Positioning System project.\n" + "Version: %s.\n", +#ifdef OWLPS_VERSION + OWLPS_VERSION +#else // OWLPS_VERSION + "unknown version" +#endif // OWLPS_VERSION + ) ; +}