command_list.c 1.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
	Copyright Jeroen Vreeken (jeroen@vreeken.net), 2014

	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>
#include <unistd.h>
22
#include <string.h>
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include <command/command.h>
#include <dt_port_numbers.h>

static char *host = "localhost";
static int port = CONSOLE_COMMAND_PORT;

static void handler_list_entry(struct command *command, 
    char *name, enum command_value_type type, char *unit,
    int typec, enum command_ptype typev[])
{
	int i;
	
	printf("Command name='%s', type=%s, unit='%s'\n", 
	    name, enum_command_value_type2str(type), unit);
	for (i = 0; i < typec; i++) {
		printf("\tAccepts: %s\n", enum_command_ptype2str(typev[i]));
	}
}

int main(int argc, char **argv)
{
	struct command *command;
	
	if (argc > 1) {
		host = argv[1];
	}
	if (argc > 2) {
		port = atoi(argv[2]);
	}
	printf("Command list from %s:%d\n", host, port);

	command = command_open(host, port);
	command->handler_list_entry = handler_list_entry;

	while (command_state_get(command) != COMMAND_STATE_READY &&
	    command_state_get(command) != COMMAND_STATE_DISCONNECTED) {
		fd_set fdrx;
		int high = 0;
		
		FD_ZERO(&fdrx);

		command_fd_set(command, &fdrx, &high);
		
		select(high + 1, &fdrx, NULL, NULL, NULL);
		
		command_handle(command, &fdrx);
	}

	return 0;
}