summaryrefslogtreecommitdiff
path: root/gtk/channel-base.c
blob: 097f0120e745887b49e685d2a4d30018eeae0bb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
#include "spice-client.h"
#include "spice-common.h"

#include "spice-channel-priv.h"

void spice_channel_handle_set_ack(SpiceChannel *channel, spice_msg_in *in)
{
    spice_channel *c = channel->priv;
    SpiceMsgSetAck* ack = spice_msg_in_parsed(in);
    spice_msg_out *out = spice_msg_out_new(channel, SPICE_MSGC_ACK_SYNC);
    SpiceMsgcAckSync sync = {
        .generation = ack->generation,
    };

    c->message_ack_window = c->message_ack_count = ack->window;
    c->marshallers->msgc_ack_sync(out->marshaller, &sync);
    spice_msg_out_send(out);
    spice_msg_out_put(out);
}

void spice_channel_handle_ping(SpiceChannel *channel, spice_msg_in *in)
{
    spice_channel *c = channel->priv;
    SpiceMsgPing *ping = spice_msg_in_parsed(in);
    spice_msg_out *pong = spice_msg_out_new(channel, SPICE_MSGC_PONG);

    c->marshallers->msgc_pong(pong->marshaller, ping);
    spice_msg_out_send(pong);
    spice_msg_out_put(pong);
}

void spice_channel_handle_notify(SpiceChannel *channel, spice_msg_in *in)
{
    spice_channel *c = channel->priv;
    static const char* severity_strings[] = {"info", "warn", "error"};
    static const char* visibility_strings[] = {"!", "!!", "!!!"};

    SpiceMsgNotify *notify = spice_msg_in_parsed(in);
    const char *severity   = "?";
    const char *visibility = "?";
    const char *message_str = NULL;

    if (notify->severity <= SPICE_NOTIFY_SEVERITY_ERROR) {
        severity = severity_strings[notify->severity];
    }
    if (notify->visibilty <= SPICE_NOTIFY_VISIBILITY_HIGH) {
        visibility = visibility_strings[notify->visibilty];
    }

    if (notify->message_len &&
        notify->message_len <= in->dpos - sizeof(*notify)) {
        message_str = (char*)notify->message;
    }

    fprintf(stderr, "%s: channel %s -- %s%s #%u%s%.*s\n", __FUNCTION__,
            c->name, severity, visibility, notify->what,
            message_str ? ": " : "", notify->message_len,
            message_str ? message_str : "");
}