Commit Graph

66 Commits

Author SHA1 Message Date
Frediano Ziglio
7f57ff0186 Remove support for 64 bit pointers on protocol
Import "codegen: Remove support for --ptrsize" change from spice-common
and update code accordingly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-18 12:42:32 +00:00
Frediano Ziglio
98b8c725f2 Use proper format strings for spice_log
Formatting string should be compatible with GLib.
GLib uses formatting types compatible with GNU.
For Linux this is not an issue as both systems (like a printf) and
GLib one uses the same formatting type.  However on Windows they
differs potentially causing issues.
This is also make worse as GLib 2.58 changed format attribute from
__printf__ to gnu_printf (Microsoft compatibility formats like %I64d
are still supported but you'll get warnings using GCC/Clang
compilers).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-03-05 13:55:47 +00:00
Christophe Fergeau
dedc4184c9 char-device: Make send_tokens_to_client() optional
Only RedCharDeviceVDIPortClass implements this vfunc, rather than
forcing every classes deriving from RedCharDeviceClass to implement it,
red_char_device_send_tokens_to_client() can deal with it.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-02-08 17:25:46 +01:00
Eduardo Lima (Etrunko)
90ff154b36 Update usage of GObject private structures
New functions and macros have been added in glib 2.38 to better handle
this case.

c8de2b11bb/NEWS

G_TYPE_INSTANCE_GET_PRIVATE will be deprecated in GLib 2.58.

https://gitlab.gnome.org/GNOME/glib/merge_requests/7/commits

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-08 11:49:15 +00:00
Frediano Ziglio
1c523c90e4 char-device: Remove initial underscores from __red_char_device_write_buffer_get
Just cosmetic changes, the static function had underscores to
distinguish from the exported one which was recently renamed.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Lukáš Hrázký <lhrazky@redhat.com>
2018-11-08 10:22:17 +00:00
Lukáš Hrázký
e810b48fcd char-device: separate functions to get write buffer for client and server
Instead of having a single red_char_device_write_buffer_get function to
get both client and server buffers and decide by testing client == NULL,
have separate function for a client and for a server. The situation
should always be clear (you're either on the client or on the server
side) and you shouldn't need to parametrize that.

For the server case, add a use_token parameter instead of a separate
red_char_device_write_buffer_get_server_no_token function, as you may
want to parametrize that.

Signed-off-by: Lukáš Hrázký <lhrazky@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-11-08 08:08:28 +00:00
Christophe Fergeau
ed44faef04 Replace remaining spice_printerr() with g_warning()
The remaining occurrences of spice_printerr() are warnings when
something unexpected happens, they can be replaced with g_warning() so
that users of spice-server can redirect them with
g_log_set_default_handler().

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-28 13:21:48 +01:00
Christophe Fergeau
5dbd40129a Remove unneeded spice_printerr() calls
These calls seem to have been added for debugging for a very specific
purpose. At the very least, they should have been using g_debug() rather
than spice_printerr(). This commit removes these.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-28 13:21:22 +01:00
Frediano Ziglio
c0f1c65b30 char-device: Avoid possible invalid function pointer cast
This is reported by GCC 8.0.1 (Fedora 28).
Instead of doing a possible invalid cast destroy and create the
queue again.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-05-10 22:30:52 +01:00
Frediano Ziglio
33f33ccc51 char-device: Avoid to use unaligned memory
This causes some warnings with clang:

char-device.c:898:29: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
    write_to_dev_size_ptr = (uint32_t *)spice_marshaller_reserve_space(m, sizeof(uint32_t));
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
char-device.c:899:31: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
    write_to_dev_tokens_ptr = (uint32_t *)spice_marshaller_reserve_space(m, sizeof(uint32_t));
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This also fixes some minor endianness issue (on big endian machine
integers were not properly encoded).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2018-01-31 13:31:29 +00:00
Frediano Ziglio
7131e35300 char-device: Do not stop and clear interface on reset
Currently, red_char_device_reset() stops the device, clears all pending
messages, and clears its device instance. After this function is called,
the char device will not work again until it is assigned a new device
instance and restarted. This is fine for the vdagent char device, which
is currently the only user of this function. But for the stream device,
we want to be able to reset the char device to a working state (e.g.
clear all pending messages, etc) without stopping or disabling the char
device. So this function will now only reset the char device to a clean
working state, and the _stop() and _reset_dev_instance() calls will be
moved up to the caller.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-10-16 19:59:14 +01:00
Frediano Ziglio
4bab960c4e char-device: Use GLib memory functions
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-10-11 12:52:17 +01:00
Frediano Ziglio
930a1196e3 char-device: Allows to handle port events from any char device
From spice_server_port_event API you can send port events to
any char device. Although currently this is used only for "port"
devices implemented in spicevmc.c this will allow to support
such events using different objects.

This will be used for instance for a streaming device which
will be a specific SpicePort implementation.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-08-23 16:11:49 +01:00
Christophe Fergeau
1569d429b7 Remove use of spice_debug(NULL)
This is causing issues with potential improvements to the logging
system, and I've always found this usage a bit odd anyway.
Using spice_debug(""); was not possible as this triggers
-Wformat-zero-length warnings from our use of -Wall.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-06-15 16:40:25 +01:00
Christophe Fergeau
df43483f71 Introduce WriteBufferOrigin enum typedef
This use to be an anonymous enum, used as an int in
RedCharDeviceWriteBufferPrivate::origin.
Introducing a typedef clarifies what kind of value it's holding.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-04-28 16:59:25 +02:00
Christophe Fergeau
113b7c8f5e Make RedCharDeviceWriteBuffer::refs private
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-04-28 16:59:25 +02:00
Christophe Fergeau
76a06bdef8 Make RedCharDeviceWriteBuffer::token_price private
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-04-28 16:59:25 +02:00
Christophe Fergeau
8dc7505ae9 Make RedCharDeviceWriteBuffer::client private
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-04-28 16:59:25 +02:00
Christophe Fergeau
3fe4c661ef Make RedCharDeviceWriteBuffer::origin private
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-04-28 16:59:25 +02:00
Christophe Fergeau
968f3ab3e8 Add RedCharDeviceWriteBufferPrivate
This is intended to hold the fields that only char-device.c has a use
for, but for now this only adds the boilerplate for it, the next commit
will move the relevant field there.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-04-28 16:59:25 +02:00
Christophe Fergeau
6377b72d44 Use bool rather than int return values when appropriate
This commit changes all functions returning TRUE/FALSE from having an
'int' return value to 'bool'.
This way it's obvious that such a function is not going to return
anything else than TRUE or FALSE.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-03-09 18:39:29 +01:00
Frediano Ziglio
3613ead4d8 marshaller: rename _add_ref() to _add_by_ref()
The spice_marshaller_add_ref() family of functions is confusing since it
sounds like you're incrementing a reference on the marshaller. What it
is actually doing is adding a data buffer to the marshaller by reference
rather than by value. Changing the function names to _add_by_ref() makes
this clearer.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-12-08 14:05:04 +00:00
Frediano Ziglio
8da22558b7 Allows reds_core_timer_remove to accept NULL for timer
Most of the times the check is done externally
so moving inside the function reduce the code.
This is similar to the way free(3) works.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-11-30 17:35:41 +00:00
Jonathon Jongsma
e86f9521db char-device: add 'self' param to vfuncs
Add a 'self' parameter to all of the char device virtual functions so
that we don't have to play games with the 'opaque' pointer.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-11-14 14:30:47 +00:00
Jonathon Jongsma
bc8d967e67 Move RedClient to a separate file
Also move the RedClient struct out of the header to avoid accessing the
internals from other files.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-11-02 19:30:58 +00:00
Frediano Ziglio
5feb1d0379 Use a compatibility header to support GLib 2.28
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-10-18 09:52:28 +01:00
Jonathon Jongsma
21c6da814a Change RedCharDevicePrivate::clients to GList
More Ring cleanup. At the moment, we only support a single client, so
this is only a one-element list
2016-09-19 07:47:05 -05:00
Jonathon Jongsma
8340688c9d Change RedCharDevice::write_queue to GQueue
Change a couple more Rings to GQueue
2016-09-19 07:47:05 -05:00
Victor Toso
9df00ebdc8 char-device: fix mismatch of client tokens
As the tokens counter were not being reset you could enter in a
situation where client thinks it has more tokens then server which
would eventually lead to client's disconnection from 0c5eca97f1
onwards (before it was crashing).

It is easy to check the above situation if you track the amount of
tokens you have in the client and simply kill and restart the agent
while doing some file transfer: the client could reach more then 13
tokens which should not really be possible.

Based on patch from Frediano Ziglio <fziglio@redhat.com>

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-07 18:06:31 +01:00
Frediano Ziglio
02adcf354e Introduce SPICE_UPCAST macro
This was proposed by Christophe as improvement over some typesafe
patches.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-05-24 18:00:51 +01:00
Frediano Ziglio
ab69c3367f make red_pipe_item_unref more typesafe
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-21 04:11:12 +01:00
Frediano Ziglio
6433d94636 reset pointer to RedCharDeviceWriteBuffer calling red_char_device_write_buffer_release
This code make easier to be sure we don't have dangling pointers
resetting in the function which free the structure.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-05-10 16:53:33 +01:00
Frediano Ziglio
3f67f73c94 char-device: remove unused refs field
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-05-04 13:09:56 +01:00
Jonathon Jongsma
b9720d80e0 Rename PipeItem to RedPipeItem
Following internal type naming conventions

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-04-27 10:22:01 -05:00
Christophe Fergeau
64dc3ab244 Use weak gobject ref instead of reds_on_char_device_state_destroy
RedCharDevice implementation had to callback into reds.c in order to let
it know a char device was being destroyed. Now that RedCharDevice is a
gobject, a weak reference can be used instead allowing to remove that
coupling.

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-04-27 09:41:01 -05:00
Christophe Fergeau
d232e92794 Use GQueue for RedCharDevice::send_queue
There was an extra RedCharDeviceMsgToClientItem type whose only
purpose was to manage a linked list of items to send. GQueue has the
same purpose as this type in addition to being generic. As the length of
the send queue is tracked, a GQueue is more appropriate than a GList and
allow to remove RedCharDevice::send_queue_size.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-04-27 09:41:01 -05:00
Jonathon Jongsma
39b00dc71e char device: use _reset_dev_instance() to set 'sin'
Internally, use the method to set the 'sin' member variable so that we
don't have to duplicate the g_object_notify() calls, and there are
consistent debug statements whenever this value is modified. This also
means that we need to handle NULL arguments to this function.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-04-20 14:27:18 -05:00
Jonathon Jongsma
82024257b6 char device: use 'device' rather than 'state' for var names
Since the type name was changed, use variable names / debug statements
that are consistent with the new name.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-04-20 14:27:18 -05:00
Jonathon Jongsma
c28773f17a char-device: notify when device instance is changed
Since the device instance ("sin") is a gobject property, we should make
sure to notify when it changes, particularly since we do some
initialization in response to the "notify::sin" signal.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-04-20 14:27:18 -05:00
Christophe Fergeau
48e85a11c7 char-device: Remove RedCharDeviceClass::{un, }ref_msg_to_client
Now that client messages are always RedPipeItem, we don't need virtual
functions to know how to ref/unref them.
2016-04-15 11:14:36 -05:00
Christophe Fergeau
021d960471 char-device: Replace RedCharDeviceMsgToClient with PipeItem
Now that all derived classes use a type deriving from PipeItem for their
RedCharDeviceMsgToClient, we can make this explicit in the
RedCharDeviceClass vfuncs, and remove the RedCharDeviceMsgToClient
typedef.
2016-04-15 11:14:36 -05:00
Christophe Fergeau
0c6e51011b Move RedCharDeviceCallbacks into RedCharDeviceClass
This structure holding virtual function pointers was kept until now as a
RedCharDevice member in order to make the GObject conversion easier.
Now that all RedCharDevice children are converted to GObject, it can be
moved into RedCharDeviceClass.
2016-04-07 11:42:37 -05:00
Christophe Fergeau
87b6b9273d reds: Remove red_char_device_new()
Nothing is using it anymore now that CharDevice classes are
gobjectified.
2016-04-07 11:42:24 -05:00
Christophe Fergeau
852a9824a1 char-device: Fix property name in red_char_device_new()
This method will be removed in a subsequent commit, but for now it's
causing breakage since it's setting "reds" instead of "spice-server"
2016-04-06 10:30:00 +02:00
Christophe Fergeau
96bde4bf95 char-device: Make RedCharDevice a GObject
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-04-02 18:06:51 +01:00
Frediano Ziglio
77946c395b Rename some missing names related to RedCharDevice
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-04-01 14:40:44 +01:00
Frediano Ziglio
742612f34d Rename SpiceCharDeviceCallbacks to RedCharDeviceCallbacks
The structure is an internal one so should not have the Spice prefix
but use the Red one.

Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-04-01 14:33:54 +01:00
Jonathon Jongsma
a24ebcae89 Rename RedCharDevice functions
make the function names match the type names. So
spice_char_device_state_* becomes red_char_device_* and
spice_char_device_* also becomes red_char_device_*.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-04-01 11:59:46 +01:00
Jonathon Jongsma
0fd5b56be7 Rename SpiceCharDeviceClientState to RedCharDeviceClient
Make it consistent with the renamed RedCharDevice and the convention of
using 'Red' namespaces for internal types

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-04-01 11:59:44 +01:00
Jonathon Jongsma
b693eae580 Rename SpiceCharDeviceState to RedCharDevice
This is more consistent with internal type naming convention, and it
paves the way for a new char device GObject heirarchy

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-04-01 11:59:43 +01:00