2011-08-18 23:10:49 +02:00
|
|
|
/*
|
|
|
|
* This is a simple program to demonstrate the use of
|
|
|
|
* libowlps-resultreader-udp.
|
|
|
|
* It must be linked against libowlps and its dependencies
|
|
|
|
* (see the Makefile).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "owlps-resultreader-udp.h"
|
|
|
|
|
2011-08-20 11:10:12 +02:00
|
|
|
#include <signal.h>
|
2011-08-18 23:10:49 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2011-08-20 11:10:12 +02:00
|
|
|
struct sigaction action ; // Signal handler structure
|
2011-08-18 23:10:49 +02:00
|
|
|
owl_result *result ;
|
|
|
|
int sockfd ;
|
|
|
|
|
2011-08-20 11:10:12 +02:00
|
|
|
/* Set up signal handlers */
|
|
|
|
action.sa_flags = 0 ;
|
|
|
|
sigemptyset(&action.sa_mask) ;
|
|
|
|
action.sa_handler = owl_sigint_handler ;
|
|
|
|
sigaction(SIGINT, &action, NULL) ;
|
|
|
|
action.sa_handler = owl_sigterm_handler ;
|
|
|
|
sigaction(SIGTERM, &action, NULL) ;
|
|
|
|
|
|
|
|
/* Open the socket */
|
2011-08-20 19:28:31 +02:00
|
|
|
sockfd = owl_create_udp_listening_socket(OWL_DEFAULT_RESULT_PORT) ;
|
2011-08-18 23:10:49 +02:00
|
|
|
if (sockfd < 0)
|
|
|
|
return 1 ;
|
|
|
|
|
2011-08-20 11:10:12 +02:00
|
|
|
/* Read loop */
|
2011-08-20 19:28:31 +02:00
|
|
|
owl_run = owl_true ;
|
2011-08-20 11:10:12 +02:00
|
|
|
while (owl_run)
|
2011-08-18 23:10:49 +02:00
|
|
|
{
|
2011-08-20 08:57:29 +02:00
|
|
|
if (! (result = owl_receive_position(sockfd)))
|
2011-08-18 23:10:49 +02:00
|
|
|
return 1 ;
|
|
|
|
owl_print_result(result) ;
|
|
|
|
owl_free_result(result) ;
|
|
|
|
printf("--------------\n") ;
|
|
|
|
}
|
|
|
|
|
2011-08-20 11:10:12 +02:00
|
|
|
/* Cleaning */
|
2011-08-18 23:10:49 +02:00
|
|
|
close(sockfd) ;
|
|
|
|
|
|
|
|
return 0 ;
|
|
|
|
}
|