Commit Graph

101 Commits

Author SHA1 Message Date
Frediano Ziglio
dd9b78fd78 Use smart pointers for RedPipeItem
Reduces usage of manual reference counting.
Avoids usage of new and use instead red::make_shared to both
create and own pipe items.
Use move semantic to reduce useless copies.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:48:08 +01:00
Frediano Ziglio
d8dccabb7d red-channel: Simplify some preprocessor macros
Just pass rest of the arguments.
Removes some extra semicolon.
This change also remove a specific GCC extension.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-06-19 14:24:48 +01:00
Frediano Ziglio
f6f998004b Wrap spice.h in order to do some adjustment
Instead of including spice.h directly include an header that wraps
it. This allows to remove the SPICE_SERVER_INTERNAL define.
Currently is used to rename SpiceCharDeviceInstance to RedCharDevice
and reduce its visibility to hidden. This remove some warnings
and some weird code in the source.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
5126e38367 Use shared_ptr implementation to handle reference counting
This allows to make easier the management of owning.
Reference counting is automatically updated based on shared
pointers modification.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
f4aefa728e Remove GObject from Dispatcher hierarchy
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
104aa6e1af Remove GObject from RedChannel
The patch seems pretty huge but mainly are mechanical steps:
- remove GObject declarations
- do not inherit from GObject
- add SPICE_CXX_GLIB_ALLOCATOR to avoid using C++ allocators
- CLASS_init and CLASS_constructor code goes into C++ constructor
- CLASS_dispose and CLASS_finalize code goes into C++ destructor
- g_object_new is replaced by new operator
- class members goes into virtual methods
- class parameters became argument to constructor
- use push-visibility.h and pop-visibility.h to limit visibility
- temporary use XXX_CAST for old GObject casts, they will
  be replaced
- g_object_get is replaced by accessors

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
435ea33540 Reduce C++ symbols visibility
This allows the compiler to do some more optimisations on the
produced binary.
To allows possible future portability include header/footer in
some helper header files.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
cf51158811 red-channel-client: Move handle_migrate_data_get_serial as a virtual function
Virtual functions cannot be null so use a return value instead
and return the serial using a reference.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
d5ea93d3a8 Make disconnect a virtual function
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
70367fd460 red-channel-client: Move handle_migrate_flush_mark as a virtual function
Note that the return value was removed as not used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
28a4fc5a10 red-channel-client: Move migrate as virtual method
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
2b04f644f6 red-channel-client: Move handle_migrate_data as virtual function
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
669df4fb38 red-channel-client: Make send_item a virtual function
The items are send from RedChannelClient so move the callback
to a virtual function in RedChannelClient instead of RedChannel.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
7720039ee0 red-channel-client: Move handle_message as a virtual function
The messages coming are from the client so it's a better place
to be in RedChannelClient instead of RedChannel.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
77af39d6b5 Update header style
Avoid typedef useless in C++.
Remove useless forward declarations.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
8671f659f4 Constify some methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
552c26b0a8 Move all red_channel_* functions in header as methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
874e745088 Move all red_channel_client_* functions in header as methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
3720e5a686 Remove RED_CHANNEL where possible
Used Coccinelle:

@@
expression E;
@@

-RED_CHANNEL(E)
+E

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
e6e6ded681 Use C++ IS-A relationship for RedChannelClient and RedChannel
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
d1023dc09e red-channel: Remove unneeded ring.h include
Not used in the header.
Also we reduced a lot the usage of these structures.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-04 13:53:30 +00:00
Frediano Ziglio
143c5b290f red-channel: Update some comment and function
red_channel_client_destroy is not called anymore from RedClient and
should not so update the comments.
red_channel_client_destroy, compared to other XXX_destroy functions
did not unreference the object but was just disconnecting the
client channel so use red_channel_client_disconnect instead.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-04 13:53:27 +00:00
Frediano Ziglio
789e8ce2c6 red-channel: Remove unused declaration
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-13 07:44:10 +01:00
Jonathon Jongsma
14403117b5 Make channel client callbacks virtual functions
Rather than having an API to register client callbacks for each channel
type, make them vfuncs.

Since the client callbacks are registered identically for each channel
of the same type, it doesn't make sense for to require these to be
registered separately for each object.  It's cleaner to have these be
per-class properties, so they've been converted to virtual functions.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
c4e26a54d0 Use new common demarshallers.h
Avoids mismatching duplicate declarations causing potentially
ABI incompatibilities.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-10-15 13:39:10 +01:00
Christophe Fergeau
2a97cec84c qxl: Remove red_channel_printerr()
It was only used twice, for what looks like adhoc debugging. This commit
removes it, similarly to what was done for some spice_printerr() calls.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-28 13:21:50 +01:00
Christophe Fergeau
47ca1f0da0 channel: Remove unused 3rd red_channel_register_client_cbs() arg
It was probably meant to be used as a "user_data" argument for the
various callbacks, but turns out not to be used.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-21 17:54:27 +01:00
Frediano Ziglio
223bfed649 Reuse SPICE_DECLARE_TYPE macro
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-11-21 08:38:44 +00:00
Christophe Fergeau
bf61342e9b channel: Introduce logging helpers
This commit adds red_channel_{debug,warning,printerr}() helpers which
will prepend the log message with "channel-name:id (%p)". It also
changes various locations which were doing this manually.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-10-23 20:29:31 +01:00
Christophe Fergeau
699a94ca8f utils: Introduce helpers to map channel types to names
spice_server_set_channel_security() is already mostly doing that. We can
make its code more generic, and introduce a red_channel_get_name()
method. This method will then be used to make debug messages more
readable by showing the actual channel name rather than its type as
an int.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-10-23 20:29:28 +01:00
Jonathon Jongsma
a5aa2a2261 Use standard "Red" namespace
The objects RedsStream and RedsSASL are currently using the namespace
"Reds" rather than the standard "Red" namespace used throughout the rest
of the project. Change these to be consistent. This also means changing
method names and some related enumeration types.

The files were also renamed to reflect the change:
  reds-stream.[ch] -> red-stream.[ch]

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-10-21 08:47:02 +01:00
Frediano Ziglio
7a3bfedfbe red-channel: Remove red_channel_init_outgoing_messages_window
This function does not make much sense anymore.
Is called by RedVmcChannel which doesn't use RedChannelClient ACKs
so the variable changed are not used.
Moreover, at red_vmc_channel_constructed() time, there will be no
clients yet, so red_channel_init_outgoing_messages() will be a no-op.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-10-12 16:37:14 +01:00
Christophe Fergeau
1e43272ba1 channel: Remove no longer used red_channel_apply_clients{_data,}
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-09-12 18:19:33 +02:00
Christophe Fergeau
685a6288f3 channel: Call red_channel_disconnect_if_pending_send() from red_channel_wait_all_sent()
red_channel_disconnect_if_pending_send() and red_channel_wait_all_sent() are
always called together, we can remove one of the 2 methods.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-09-12 18:19:33 +02:00
Jonathon Jongsma
5a1a6b24af RedChannel: Remove obsolete TODO comment
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-09-08 08:21:59 +01:00
Christophe Fergeau
92f1edf714 channel: Remove unused red_channel_min_pipe_size
This could have been removed as part of 6e6126e024.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Frediano Ziglio <fziglio@redhat.com>
2017-09-07 16:04:30 +02:00
Frediano Ziglio
bfaf660a05 red-channel: Do not push data calling red_channel_pipes_new_add_push
Now the push is done automatically when a PipeItem is added
(cfr commit 5c460de1a3
"worker: push data when clients can receive them"),
forcing a push cause only network fragmentation and is required
only if you are handling data in a loop instead of using the
default loop.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-09-06 11:39:03 +01:00
Frediano Ziglio
da3a5cc0ca red-channel: Add red_channel_pipes_add function
Considering that now RedPipeItem have reference counting
and that lot of items are just used to store constant
data to send, using reference counting instead of creating
different items for each client is easier to do.
So this new red_channel_pipes_add allows to add a single item
to all clients.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-09-06 11:39:03 +01:00
Christophe Fergeau
5dbfbb4d78 channel: Move RedChannel::on_disconnect to RedChannelClient
This vfunc only has a RedChannelClient * argument, and most of the time,
it operates on RedChannelClient, not on RedChannel. Moreover, the only
time it's used is from RedChannelClient. This commit moves the vfunc to
RedChannelClient, which seems like a better fit for it.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-08-31 15:51:57 +02:00
Frediano Ziglio
e3bff1eea4 Remove iterator from list iteration macros
Avoid to have to declare iterator and pass as an argument.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2017-08-21 12:54:47 +01:00
Jonathon Jongsma
1b18fd76d1 Remove unused red_channel_test_remote_common_cap()
This was a convenience function around
red_channel_client_test_remote_common_cap() that simply iterated over
each client (currently we only really support a single client anyway)
and returned TRUE only if all clients supported the capability. But
nobody ever called this wrapper function.
2017-04-07 15:08:43 -05:00
Christophe Fergeau
78c3dd4c18 Make various functions static
- glz_enc_dictionary_reset
- monitors_config_new
- red_channel_any_blocked
- red_channel_no_item_being_sent
- red_client_get_channel

are only used in the file where they are defined, so they can as well be
static.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-04-05 12:39:20 +02:00
Christophe Fergeau
bc5326b1ce Unify header guards
This changes the header guards in all .h files to follow this format:

/*
 * Licensing block
 */

/* ... */

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-03-30 18:17:20 +01: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
4f7fbb3113 red-channel: Move config_socket vfunc to RedChannelClient
config_socket is configuring the client stream socket.
As is responsibility of RedChannelClient to handle the stream
it make more sense to have the function in this object.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-03-08 16:55:43 +00:00
Frediano Ziglio
9af182b67a red-channel: Move alloc_recv_buf and release_recv_buf to RedChannelClient
These vfuncs are more appropriate in RedChannelClient.
The buffer they allocated are related to the client stream
which is managed directly by RedChannelClient.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-03-04 14:58:15 +00:00
Frediano Ziglio
5c0c9c6975 red-channel: Move byte statistic to RedChannelClient
As the counters are shared there is no reason why not
handling the byte count from RedChannelClient directly.
This remove a dependency and avoid some function calls.
The only visible difference at user level is that the
counters are created when a client connects.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-03-04 01:04:44 +00:00
Frediano Ziglio
afc4171c98 red-channel: Use RedChannelCapabilities directly to pass capabilities
For each channel there are two set of capabilities, one
for the common ones and one for the specific ones.
A single set were almost always passed using 2 arguments,
a number of elements and an array but then before using
these were converted to a GArray.
Use a single structure (already available) to pass all
channel capabilites using a single argument.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-03-02 15:34:58 +00:00
Frediano Ziglio
89a722ce03 red-channel: Separate RedChannelCapabilities
Add function to initialize and destroy this type.
Add GType type for boxing it.
These changes a in preparation for next patch.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-03-02 15:32:16 +00:00
Frediano Ziglio
ce06958fb8 Improve statistic code interface
Use new structures and functions to implement the statistics code.
Use inline functions instead of macros for increased type-safety.
If statistics are disabled, the structures and functions become
empty. This confines the configuration-specific #defines to the
statistics implementation itself and avoids the need for #defines in
the calling functions. This greatly reduces the chance of accidentally
breaking the build for one configuration or the other. The reds option
was removed from stat_inc_counter() as it was not used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-15 10:13:48 +00:00