2 Copyright (C) 2009 Red Hat, Inc.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 #ifndef __MAIN_CHANNEL_H__
19 #define __MAIN_CHANNEL_H__
22 #include <spice/vd_agent.h>
23 #include "common/marshaller.h"
25 #include "red_channel.h"
27 // TODO: Defines used to calculate receive buffer size, and also by reds.c
28 // other options: is to make a reds_main_consts.h, to duplicate defines.
29 #define REDS_AGENT_WINDOW_SIZE 10
30 #define REDS_NUM_INTERNAL_AGENT_MESSAGES 1
32 // approximate max receive message size for main channel
33 #define RECEIVE_BUF_SIZE \
34 (4096 + (REDS_AGENT_WINDOW_SIZE + REDS_NUM_INTERNAL_AGENT_MESSAGES) * SPICE_AGENT_MAX_DATA_SIZE)
36 typedef struct MainChannel {
38 uint8_t recv_buf[RECEIVE_BUF_SIZE];
39 RedsMigSpice mig_target; // TODO: add refs and release (afrer all clients completed migration in one way or the other?)
40 int num_clients_mig_wait;
44 MainChannel *main_channel_init(void);
45 RedClient *main_channel_get_client_by_link_id(MainChannel *main_chan, uint32_t link_id);
46 /* This is a 'clone' from the reds.h Channel.link callback to allow passing link_id */
47 MainChannelClient *main_channel_link(MainChannel *, RedClient *client,
48 RedsStream *stream, uint32_t link_id, int migration, int num_common_caps,
49 uint32_t *common_caps, int num_caps, uint32_t *caps);
50 void main_channel_close(MainChannel *main_chan); // not destroy, just socket close
51 void main_channel_push_mouse_mode(MainChannel *main_chan, int current_mode, int is_client_mouse_allowed);
52 void main_channel_push_agent_connected(MainChannel *main_chan);
53 void main_channel_push_agent_disconnected(MainChannel *main_chan);
54 void main_channel_client_push_agent_tokens(MainChannelClient *mcc, uint32_t num_tokens);
55 void main_channel_client_push_agent_data(MainChannelClient *mcc, uint8_t* data, size_t len,
56 spice_marshaller_item_free_func free_data, void *opaque);
57 void main_channel_client_start_net_test(MainChannelClient *mcc);
58 // TODO: huge. Consider making a reds_* interface for these functions
59 // and calling from main.
60 void main_channel_push_init(MainChannelClient *mcc, int display_channels_hint,
61 int current_mouse_mode, int is_client_mouse_allowed, int multi_media_time,
63 void main_channel_push_notify(MainChannel *main_chan, const char *msg);
64 void main_channel_client_push_notify(MainChannelClient *mcc, const char *msg);
65 void main_channel_push_multi_media_time(MainChannel *main_chan, int time);
66 int main_channel_getsockname(MainChannel *main_chan, struct sockaddr *sa, socklen_t *salen);
67 int main_channel_getpeername(MainChannel *main_chan, struct sockaddr *sa, socklen_t *salen);
68 uint32_t main_channel_client_get_link_id(MainChannelClient *mcc);
71 * return TRUE if network test had been completed successfully.
72 * If FALSE, bitrate_per_sec is set to MAX_UINT64 and the roundtrip is set to 0
74 int main_channel_client_is_network_info_initialized(MainChannelClient *mcc);
75 int main_channel_client_is_low_bandwidth(MainChannelClient *mcc);
76 uint64_t main_channel_client_get_bitrate_per_sec(MainChannelClient *mcc);
77 uint64_t main_channel_client_get_roundtrip_ms(MainChannelClient *mcc);
79 int main_channel_is_connected(MainChannel *main_chan);
80 RedChannelClient* main_channel_client_get_base(MainChannelClient* mcc);
82 /* switch host migration */
83 void main_channel_migrate_switch(MainChannel *main_chan, RedsMigSpice *mig_target);
85 /* semi seamless migration */
87 /* returns the number of clients that we are waiting for their connection.
88 * try_seamless = 'true' when the seamless-migration=on in qemu command line */
89 int main_channel_migrate_connect(MainChannel *main_channel, RedsMigSpice *mig_target,
91 void main_channel_migrate_cancel_wait(MainChannel *main_chan);
92 /* returns the number of clients for which SPICE_MSG_MAIN_MIGRATE_END was sent*/
93 int main_channel_migrate_src_complete(MainChannel *main_chan, int success);
94 void main_channel_migrate_dst_complete(MainChannelClient *mcc);
95 void main_channel_push_name(MainChannelClient *mcc, const char *name);
96 void main_channel_push_uuid(MainChannelClient *mcc, const uint8_t uuid[16]);