Commit Graph

3432 Commits

Author SHA1 Message Date
Frediano Ziglio
0807ccea59 cursor-channel-client: Move all public functions to methods
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
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
fdedbe9e94 dcc-send: Avoid to call DISPLAY_CHANNEL_CLIENT to cast
It's useless now, it's always a DisplayChannelClient, pass the
right type.

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
2ffa7d00c6 inputs-channel-client: Improve encapsulation for InputsChannelClient
Move most inputs_channel_client_* functions inside the class.
This also helps preparing handle_migrate_data to be virtual.

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
851696a645 red-channel-client: Preparation, rename send_item to avoid clash
We will use this name for a virtual function from 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
1ac616c4a3 Use utils.hpp for allocating/removing priv field
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
b86f6e9a53 utils: Add red::unique_ptr
red::unique_link will be used to manage "priv" fields.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
61affed2a2 red-channel-client: Better private initialisation
Initialise RedChannelClientPrivate fields from the new
constructor instead from RedChannelClient.
Also change some fields to constants (actually many of them).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
2023bb3767 red-channel-client: Remove "self"
It was left unchanged to reduce diff.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
d8e5838054 red-channel-client: Move all functions to methods
Improve incapsulation.
The only not mechanical change is the addition of timer_add to
make timer settings a bit more type safe.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
78193dff16 red-channel-capabilities: Removed unused stuff from RedChannelCapabilities
Not used anymore

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
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
Frediano Ziglio
38cd152952 automake: Link with C++ linker
If automake sees no C++ files in the source it assumes have to
use C linker settings not linking C++ library.
This was not a problem as code did not use C++ libraries but next
patch will use pure virtual function call.
It could be provided but as later we will use RTTI use C++ library.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
6e14b6bc99 Reimplement video-codes update with no GObject signals
This is in preparation to remove GObjects, as signals require them.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
69fbef6fff Add RedChannel::(un)ref for reference counting and use them
This will reduce code to avoid gobject and make code less
type unsafe.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
3a05720eaa Introduce some utilities for C++
red::add_ref will be used to increment a reference counter
and return the object pointer.

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
2b078c44d7 Remove COMMON_GRAPHICS_CHANNEL where possible
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +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
Frediano Ziglio
e788e6e476 Remove conversion warnings
Use casts to avoid all that warning.
They should go away once you use more type safe types.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
17a7251e56 Remove warnings about combining GParamFlags types
C++ thread enum a bit more safely than C not allowing to combine
them. Avoid warning combining them and passing to functions
expecting enums.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
d8b1519c35 Remove -Wliteral-suffix warnings
Avoids warnings like

main-channel-client.cpp:538:27: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
    "net test: latency %f ms, bitrate %"G_GUINT64_FORMAT" bps (%f Mbps)%s",
    ^

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
2561f1db94 Avoid conversion warnings calling Windows sockets
Some Windows socket functions accepts char* instead of classic void*
causing some warning. Force the cast.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
e54224730e Change string check
In C++ GLib add function declaration (function parameters).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
6db395dc74 Make sure empty structure are ABI compatible
Empty structure are not really portable however adding
an zero size array seems to be the way to have a zero
size structure portably.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
2f7474427b Do not leave not initialized fields in the middle
Some old GNU compilers does not allow this (like CentOS 7 one)

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
e0b395fb68 Declare exported functions as C
Allows to be used by both C and C++ code.
So to leave part of the code in C and part move to C++.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
238f53d702 Declare public exported functions as C
Allows to link externally from a C program.
This will allow C++ code to respect C ABI.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
505b90e179 Avoid double definitions
In C++ that code would define variable twice giving error.
Define only one.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
48adb67c13 Fix order of initializers
C++ complaints if they are not in the order of
declaration.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
81c04623ea Avoid to use reserved C++ keywords
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
7b36374170 Adjust some warnings
Remove -Werror and add -fpermissive, this will allow to compile C code with
a GNU C++ compiler.

Ignore warnings as our code use some feature like empty arrays.

Remove warnings not available in C++.

Bump GLIB_VERSION_MAX_ALLOWED to reduce the warning, looks like the
GLib headers for C++ are not able to handle them correctly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
c4b4b967fb Allows C++ to be used in sources
Enable C++ compiler

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
bea4ad66b9 char-device: Remove pool handling
Memory pool handling does not give much but make code more complex.
Current implementation tends to only increasing buffer sizes
leading to potential cases where most of the allocated memory is
not used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
1fbb58ac52 Fix compatibility with SOL_TCP and Darwin
Under Darwin SOL_TCP is not defined. Use IPPROTO_TCP instead.
Other part of SPICE server uses this constant instead already.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-20 15:17:59 +01:00
Frediano Ziglio
717ed19a8b Constify display_channel_update_monitors_config config parameter
No reason to change the structure.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-04-20 14:47:34 +01:00