trace_list.c 1.97 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
/*
2
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2013
Jeroen Vreeken's avatar
Jeroen Vreeken committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
	Copyright Stichting C.A. Muller Radioastronomiestation, 2007

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

#include <stdio.h>
#include <stdlib.h>
22
#include <string.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
23
24
25
26
27
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

28
#include <trace/trace.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
29

30
31
static char *host = "localhost";
static int port = 10000;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
static void handler_interval(struct trace *trace, 
    struct timespec *interval, enum trace_interval_type type)
{
	printf("Server interval: %ld.%09ld, type: %s\n",
	    interval->tv_sec, interval->tv_nsec, 
	    enum_trace_interval_type2str(type));
}

static void handler_list_entry(struct trace *trace, 
    char *name, enum trace_value_type type, char *unit)
{
	printf("Trace name='%s', type=%s, unit='%s'\n", 
	    name, enum_trace_value_type2str(type), unit);
}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
47
48
49

int main(int argc, char **argv)
{
50
	struct trace *trace;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
51
	
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
	if (argc > 1) {
		host = argv[1];
	}
	if (argc > 2) {
		port = atoi(argv[2]);
	}
	printf("Trace list from %s:%d\n", host, port);

	trace = trace_open(host, port);
	trace->handler_interval = handler_interval;
	trace->handler_list_entry = handler_list_entry;

	while (trace_state_get(trace) == TRACE_STATE_CONNECTED) {
		fd_set fdrx;
		int high = 0;
		
Jeroen Vreeken's avatar
Jeroen Vreeken committed
68
69
		FD_ZERO(&fdrx);

70
71
72
73
74
75
		trace_fd_set(trace, &fdrx, &high);
		
		select(high + 1, &fdrx, NULL, NULL, NULL);
		
		trace_handle(trace, &fdrx);
	}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
76
77
78

	return 0;
}