vdagentd: Cache monitor configuration and forward
[vd_agent/hramrach.git] / vdagent.c
blob8a30ebf77c122ae202e18428817f36203d1745f2
1 /* vdagent.c xorg-client to vdagentd (daemon).
3 Copyright 2010 Red Hat, Inc.
5 Red Hat Authors:
6 Hans de Goede <hdegoede@redhat.com>
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <errno.h>
27 #include <sys/select.h>
28 #include <spice/vd_agent.h>
30 #include "udscs.h"
31 #include "vdagentd-proto.h"
32 #include "vdagent-x11.h"
34 int daemon_read_complete(struct udscs_connection *conn,
35 struct udscs_message_header *header, const uint8_t *data)
37 switch (header->type) {
38 case VDAGENTD_MONITORS_CONFIG: {
39 VDAgentMonitorsConfig *mon_config = (VDAgentMonitorsConfig *)data;
40 VDAgentMonConfig *monitors = mon_config->monitors;
41 /* FIXME */
42 printf("monitors config, mon0: %dx%d\n", monitors[0].width, monitors[0].height);
43 break;
45 default:
46 fprintf(stderr, "Unknown message from vdagentd type: %d\n",
47 header->type);
49 return 0;
52 static void usage(FILE *fp)
54 fprintf(fp,
55 "vdagent -- spice agent xorg client\n"
56 "options:\n"
57 " -h print this text\n"
58 " -d print debug messages\n");
61 int main(int argc, char *argv[])
63 struct udscs_connection *client;
64 struct vdagent_x11 *x11;
65 fd_set readfds, writefds;
66 int c, n, nfds, x11_fd;
67 int verbose = 0;
69 for (;;) {
70 if (-1 == (c = getopt(argc, argv, "dh")))
71 break;
72 switch (c) {
73 case 'd':
74 verbose++;
75 break;
76 case 'h':
77 usage(stdout);
78 exit(0);
79 default:
80 usage(stderr);
81 exit(1);
85 client = udscs_connect(VDAGENTD_SOCKET, daemon_read_complete, NULL);
86 if (!client)
87 exit(1);
89 x11 = vdagent_x11_create(client, verbose);
90 if (!x11) {
91 udscs_destroy_connection(&client);
92 exit(1);
95 while (client) {
96 FD_ZERO(&readfds);
97 FD_ZERO(&writefds);
99 nfds = udscs_client_fill_fds(client, &readfds, &writefds);
100 x11_fd = vdagent_x11_get_fd(x11);
101 FD_SET(x11_fd, &readfds);
102 if (x11_fd >= nfds)
103 nfds = x11_fd + 1;
105 n = select(nfds, &readfds, &writefds, NULL, NULL);
106 if (n == -1) {
107 if (errno == EINTR)
108 continue;
109 perror("select");
110 exit(1);
113 if (FD_SET(x11_fd, &readfds))
114 vdagent_x11_do_read(x11);
115 udscs_client_handle_fds(&client, &readfds, &writefds);
118 vdagent_x11_destroy(x11);
120 return 0;