[Client] Compile-time option ENABLE_RECEIVE_POSITION

Enables or disables the -l option at compile-time.
This commit is contained in:
Matteo Cypriani 2012-01-10 12:21:24 +01:00
parent a81b539a05
commit c9c82211d8
2 changed files with 33 additions and 7 deletions

View File

@ -39,15 +39,18 @@ XCFLAGS = $(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG = -fPIC PICFLAG = -fPIC
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\" OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
OWLPSFLAGS += -D DEBUG OWLPSFLAGS += -D DEBUG
LIBS = -L$(LIBOWLPS_DIR) -lowlps \ OWLPSFLAGS += -D ENABLE_RECEIVE_POSITION \
-L$(LIBOWLPSCLIENT_DIR) -lowlps-client \
-L$(LIBOWLPSRESULTREADER_DIR) -lowlps-resultreader -L$(LIBOWLPSRESULTREADER_DIR) -lowlps-resultreader
LIBS = -L$(LIBOWLPS_DIR) -lowlps \
-L$(LIBOWLPSCLIENT_DIR) -lowlps-client
OS := $(shell uname) OS := $(shell uname)
ifeq ("$(OS)", "Linux") ifeq ("$(OS)", "Linux")
LIBS += -lrt LIBS += -lrt
endif endif
LDFLAGS = $(LIBS) $(OWLPSFLAGS)
STATIC_LIBS = STATIC_LIBS =
@ -63,7 +66,7 @@ all : dynamic static
%: %.c %: %.c
%: %.o %: %.o
$(CC) $(LDFLAGS) $(STRIPFLAGS) $(XCFLAGS) -o $@ $^ $(LIBS) $(CC) $(STRIPFLAGS) $(XCFLAGS) -o $@ $^ $(LDFLAGS)
%.static: %.o %.static: %.o
$(CC) $(STRIPFLAGS) $(XCFLAGS) -o $@ $^ \ $(CC) $(STRIPFLAGS) $(XCFLAGS) -o $@ $^ \
$(LDFLAGS) $(LIBS) $(STATIC_LIBS) -static $(LDFLAGS) $(LIBS) $(STATIC_LIBS) -static

View File

@ -3,7 +3,10 @@
*/ */
#include <owlps-client.h> #include <owlps-client.h>
#include <owlps-resultreader.h>
#ifdef ENABLE_RECEIVE_POSITION
# include <owlps-resultreader.h>
#endif // ENABLE_RECEIVE_POSITION
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -42,7 +45,9 @@ void print_configuration(void) ;
void create_socket(void) ; void create_socket(void) ;
void make_packet(void) ; void make_packet(void) ;
void send_request(void) ; void send_request(void) ;
#ifdef ENABLE_RECEIVE_POSITION
int receive_position(void) ; int receive_position(void) ;
#endif // ENABLE_RECEIVE_POSITION
void print_usage(void) ; void print_usage(void) ;
void print_version(void) ; void print_version(void) ;
@ -122,8 +127,10 @@ int main(int argc, char *argv[])
close(sockfd) ; close(sockfd) ;
#ifdef ENABLE_RECEIVE_POSITION
if (options.listening_port > 0) if (options.listening_port > 0)
ret = receive_position() ; ret = receive_position() ;
#endif // ENABLE_RECEIVE_POSITION
return ret ; return ret ;
} }
@ -187,6 +194,7 @@ void parse_main_options(int argc, char **argv)
strncpy(options.dest_ip, optarg, INET_ADDRSTRLEN) ; strncpy(options.dest_ip, optarg, INET_ADDRSTRLEN) ;
break ; break ;
case 'l' : case 'l' :
#ifdef ENABLE_RECEIVE_POSITION
/* Facultative getopt options do not handle separated values /* Facultative getopt options do not handle separated values
* (like -l <port>), so we have to test separately. * (like -l <port>), so we have to test separately.
*/ */
@ -207,6 +215,11 @@ void parse_main_options(int argc, char **argv)
++optind ; ++optind ;
} }
} }
#else // ENABLE_RECEIVE_POSITION
fprintf(stderr, "Warning! The program was compiled without"
" enabling the -l option (receive the position from"
" the positioning server).\n") ;
#endif // ENABLE_RECEIVE_POSITION
break ; break ;
case 'n' : case 'n' :
options.nb_pkt = strtoul(optarg, NULL, 0) ; options.nb_pkt = strtoul(optarg, NULL, 0) ;
@ -477,6 +490,7 @@ void make_packet()
#ifdef ENABLE_RECEIVE_POSITION
/* /*
* Receives a position computed by the infrastructure. * Receives a position computed by the infrastructure.
* Note that it is currently not guaranteed that the received result * Note that it is currently not guaranteed that the received result
@ -503,6 +517,7 @@ int receive_position()
return 0 ; return 0 ;
} }
#endif // ENABLE_RECEIVE_POSITION
@ -550,8 +565,8 @@ void print_usage()
"\t-D\t\tDaemon mode. Useful only in flood mode.\n" "\t-D\t\tDaemon mode. Useful only in flood mode.\n"
"\t-l [port]\tWait for the computed position and display it." "\t-l [port]\tWait for the computed position and display it."
" The Optional argument <port> allows to specify the listening" " The Optional argument <port> allows to specify the listening"
" port (default: %d).\n" " port (default: %d). Available only if the program was"
, " compiled with the option ENABLE_RECEIVE_POSITION.\n",
program_name, program_name,
program_name, program_name,
OWL_DEFAULT_REQUEST_PORT, OWL_DEFAULT_REQUEST_PORT,
@ -569,11 +584,19 @@ void print_version()
{ {
printf("This is OwlPS Client, part of the Open Wireless" printf("This is OwlPS Client, part of the Open Wireless"
" Positioning System project.\n" " Positioning System project.\n"
"Version: %s.\n", "Version: %s.\n"
"Compilation-time options:\n"
"\tOption -l: %s.\n",
#ifdef OWLPS_VERSION #ifdef OWLPS_VERSION
OWLPS_VERSION OWLPS_VERSION
#else // OWLPS_VERSION #else // OWLPS_VERSION
"unknown version" "unknown version"
#endif // OWLPS_VERSION #endif // OWLPS_VERSION
,
#ifdef ENABLE_RECEIVE_POSITION
"YES"
#else // ENABLE_RECEIVE_POSITION
"NO"
#endif // ENABLE_RECEIVE_POSITION
) ; ) ;
} }