File: cursor-channel-client.cpp

package info (click to toggle)
spice 0.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,460 kB
  • sloc: ansic: 43,305; cpp: 30,185; sh: 5,342; python: 3,040; makefile: 844
file content (98 lines) | stat: -rw-r--r-- 3,053 bytes parent folder | download | duplicates (3)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
   Copyright (C) 2009-2016 Red Hat, Inc.

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

   This library 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
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>

#include <common/generated_server_marshallers.h>

#include "common-graphics-channel.h"
#include "red-channel-client.h"
#include "cache-item.h"
#include "cursor-channel.h"
#include "cursor-channel-client.h"

#define CLIENT_CURSOR_CACHE_SIZE 256

#define CURSOR_CACHE_HASH_SHIFT 8
#define CURSOR_CACHE_HASH_SIZE (1 << CURSOR_CACHE_HASH_SHIFT)
#define CURSOR_CACHE_HASH_MASK (CURSOR_CACHE_HASH_SIZE - 1)
#define CURSOR_CACHE_HASH_KEY(id) ((id) & CURSOR_CACHE_HASH_MASK)
#define CURSOR_CLIENT_TIMEOUT 30000000000ULL //nano

struct CursorChannelClientPrivate
{
    SPICE_CXX_GLIB_ALLOCATOR

    RedCacheItem *cursor_cache[CURSOR_CACHE_HASH_SIZE];
    Ring cursor_cache_lru = { nullptr, nullptr };
    long cursor_cache_available = 0;
};

#define CLIENT_CURSOR_CACHE
#include "cache-item.tmpl.cpp"
#undef CLIENT_CURSOR_CACHE

void CursorChannelClient::reset_cursor_cache()
{
    red_cursor_cache_reset(this, CLIENT_CURSOR_CACHE_SIZE);
}

void CursorChannelClient::on_disconnect()
{
    reset_cursor_cache();
}

void CursorChannelClient::migrate()
{
    pipe_add_type(RED_PIPE_ITEM_TYPE_INVAL_CURSOR_CACHE);
    RedChannelClient::migrate();
}

CursorChannelClient::CursorChannelClient(RedChannel *channel,
                                         RedClient *client,
                                         RedStream *stream,
                                         RedChannelCapabilities *caps):
    CommonGraphicsChannelClient(channel, client, stream, caps)
{
    ring_init(&priv->cursor_cache_lru);
    priv->cursor_cache_available = CLIENT_CURSOR_CACHE_SIZE;
}

CursorChannelClient* cursor_channel_client_new(CursorChannel *cursor, RedClient *client, RedStream *stream,
                                               int mig_target,
                                               RedChannelCapabilities *caps)
{
    auto rcc =
        red::make_shared<CursorChannelClient>(cursor, client, stream, caps);

    if (!rcc->init()) {
        return nullptr;
    }
    cursor->set_during_target_migrate(mig_target);

    return rcc.get();
}

RedCacheItem* CursorChannelClient::cache_find(uint64_t id)
{
    return red_cursor_cache_find(this, id);
}

int CursorChannelClient::cache_add(uint64_t id, size_t size)
{
    return red_cursor_cache_add(this, id, size);
}