spice/server/inputs-channel-client.cpp
Frediano Ziglio 176970f3f1 red-channel-client: Remove GObject type
Make all RedChannelClient hierarchy a C++ class.
This allows to use virtual methods.
Added a normal contructor instead or properties and g_object_new.

As we remove GObject conversion macros I added a macro XXX_CAST
to create a function to replace the old macro.
They will be removed when more type safety is introduced.

There's a new SPICE_CXX_GLIB_ALLOCATOR macro in red-common.h.
This macro, added to a class define the class allocator allowing
to use, in this case, GLib for allocation. This to avoid C++ library
dependency and to initialize all structure to 0 (not all fields
are manually initialized, will be improved with more encapsulation).

Currently the methods are mainly public, access will be modified
when more encapsulation (all functions in method) are done.

Some classes are now defined in the header, C++ uses access to
limit accessibility but for efficiency and type safety/inline and
other features require types to be defined in the headers.

Some fields were moved from XxxPrivate structure to class, C++
has accessibility.

Many destructors are defined as protected to forbid the use of
stack, this as these objects uses internal reference counting
to have normal pointers. Maybe in the future pointers like
std::shared_ptr could be used instead.

Reference counting is now implemented very easily using atomic
operations.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00

91 lines
3.0 KiB
C++

/*
Copyright (C) 2009-2015 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 "inputs-channel-client.h"
#include "migration-protocol.h"
#include "red-channel-client.h"
XXX_CAST(RedChannelClient, InputsChannelClient, INPUTS_CHANNEL_CLIENT);
uint8_t *InputsChannelClient::alloc_recv_buf(uint16_t type, uint32_t size)
{
if (size > sizeof(recv_buf)) {
red_channel_warning(get_channel(), "error: too large incoming message");
return NULL;
}
return recv_buf;
}
void InputsChannelClient::release_recv_buf(uint16_t type, uint32_t size, uint8_t *msg)
{
}
void InputsChannelClient::on_disconnect()
{
inputs_release_keys(INPUTS_CHANNEL(get_channel()));
}
RedChannelClient* inputs_channel_client_create(RedChannel *channel,
RedClient *client,
RedStream *stream,
RedChannelCapabilities *caps)
{
auto rcc = new InputsChannelClient(channel, client, stream, caps);
if (!rcc->init()) {
delete rcc;
rcc = nullptr;
}
return rcc;
}
void inputs_channel_client_send_migrate_data(RedChannelClient *rcc,
SpiceMarshaller *m,
RedPipeItem *item)
{
InputsChannelClient *icc = INPUTS_CHANNEL_CLIENT(rcc);
rcc->init_send_data(SPICE_MSG_MIGRATE_DATA);
spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_INPUTS_MAGIC);
spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_INPUTS_VERSION);
spice_marshaller_add_uint16(m, icc->motion_count);
}
void inputs_channel_client_handle_migrate_data(InputsChannelClient *icc,
uint16_t motion_count)
{
icc->motion_count = motion_count;
for (; icc->motion_count >= SPICE_INPUT_MOTION_ACK_BUNCH;
icc->motion_count -= SPICE_INPUT_MOTION_ACK_BUNCH) {
icc->pipe_add_type(RED_PIPE_ITEM_MOUSE_MOTION_ACK);
}
}
void inputs_channel_client_on_mouse_motion(InputsChannelClient *icc)
{
InputsChannel *inputs_channel = INPUTS_CHANNEL(icc->get_channel());
if (++icc->motion_count % SPICE_INPUT_MOTION_ACK_BUNCH == 0 &&
!inputs_channel_is_src_during_migrate(inputs_channel)) {
icc->pipe_add_type(RED_PIPE_ITEM_MOUSE_MOTION_ACK);
icc->motion_count = 0;
}
}