Commit Graph

42 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
fa404f73d8 main-channel-client: Pass directly a RedPipeItem from VDI
Provides a base class to allows RedCharDeviceVDIPort to pass
a RedPipeItem to MainChannelClient instead of having to wrap
into another item.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:47:58 +01:00
Frediano Ziglio
d55c8837f8 red-pipe-item: Add and use a small utility class for easier initialization
Most of the times each class has an associated constant so
allows to be able to define the constant at declaration time.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:47:55 +01:00
Frediano Ziglio
a30df693cf red-pipe-item: Use inheritance on RedPipeItem
This allows to:
- reuse reference counting;
- avoid having to manually call g_free to release item memory;
- assure item is initialized;
- avoids some manual casts.

It will also allows to use smart pointers.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:47:53 +01:00
Frediano Ziglio
24c8692e5f Remove useless "common/ring.h" include
Not used directly by these source files.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-06-29 08:56:36 +01:00
Frediano Ziglio
0acf650afa reds: Remove not used preprocessor macros
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-06-27 06:29:53 +01:00
Frediano Ziglio
4a34111711 reds: Avoid a "end" label just to free password
"password" is pretty small, allocate on stack directly.
RSA is currently 1024 bits, that is more or less 128 bytes.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Kevin Pouget <kpouget@redhat.com>
2020-06-26 10:06:40 +01:00
Frediano Ziglio
69640d1054 reds: Remove useless label and goto statements
Not needed anymore.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-06-25 16:09:25 +01:00
Frediano Ziglio
a10e496c46 char-device: Remove "sin" parameter from read_one_msg_from_device
Not much used, can be retrieved from the class if needed.

There are some apparent test removal on reds.cpp.
The test "if (!reds->vdagent)" apparently disappeared but it's included in
the while.
reds->agent_dev cannot be NULL as SPICE server allows only one agent and we
are into a member of an object so it must be reds->agent_dev.get() == this.
As there's only an agent and as the interface (sin) is extracted from that
agent it must be reds->agent_dev.get() == sin->st and either reds->vdagent
== sin or reds->vdagent == NULL.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-06-23 12:49:43 +01:00
Frediano Ziglio
479a1a74a2 Reuse RedCharDevice::read
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-06-23 12:49:41 +01:00
Frediano Ziglio
8875e79c7c reds: Use socket_close instead of close
socket_close is mapped to close under Unix but under Windows
you should call closesocket instead so call socket_close which
will map to the proper close function on both environments.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-06-18 16:57:50 +01:00
Frediano Ziglio
f03d094942 reds: Remove usage of "this"
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@redhat.com>
2020-06-08 10:00:43 +01:00
Frediano Ziglio
ee4cf6a07c Fix compatibility with MSG_NOSIGNAL and Darwin
Darwin does not have MSG_NOSIGNAL but allows to set a SO_NOSIGPIPE
option to disable sending SIGPIPE writing to closed socket.
Note that *BSD has the SO_NOSIGPIPE option but does not affect all
write calls so instead continue to use MSG_NOSIGNAL instead on
that systems.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-19 10:01:47 +01:00
Frediano Ziglio
fd06625ba1 red-stream-device: Better encapsulation
Remove all members public, set correct access and create
missing methods.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
1e9205a3b8 char-device: Remove GObject from RedCharDevice
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +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
2b9e1dcd55 dispatcher: Reuse base reference counting for Dispatcher hierararchy
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
597461e443 Add and use red::make_shared
Allow to create an object already contained in a shared pointer
to avoid having not owned objects.

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
b28db35af5 reds: Make mig_wait_disconnect_clients a std::forward_list
In the meanwhile remove a leak on the program.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
9dcf937767 reds: Move qxl_instances to red::safe_list
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
1411383483 char-device: Automatically convert functions to methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
5f7aaf2a9a char-device: Remove define trick, won't work on C++
C++ check parameter type, not founding the functions at
link time.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
4233df686e reds: Move clients to safe_list
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
ec66702526 reds: Use red::safe_list instead of GList
Use an utility list.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
ab7486a9e8 main-channel-client: Automatically convert
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
9fd105e925 main-channel: Automatic convert functions to methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
cc86a7fb53 red-client: Automatically convert functions to methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
43c6bf91b7 reds: Remove a weak pointer usage
RedCharDevice can all be removed just calling unref, beside
the agent that needs special threatment.

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
164a333f99 Define and use (un)ref
Avoids g_object_(un)ref.
This in preparation to remove GObject.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
ea0d056bb7 char-device: Define and use (un)ref
Prepare to remove GObject.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
2d865a78da red-channel-client: Make start_connectivity_monitoring protected
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
9df07e3f20 inputs-channel: Make InputsChannel more encapsulated
Put functions into methods.

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
bd4b1caeb8 Use template to make adding timers/watches safer
Instead of forcibly cast functions cast only if data pointer and
function pointers match. This also allows to remove dangerous
casts all over the place.

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
08fab74cd7 Avoid useless downcast to RedChannelClient or RedChannel
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +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
e204677a43 Remove RED_CHANNEL_CLIENT where possible
Used Coccinelle:

@@
expression E;
@@

-RED_CHANNEL_CLIENT(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