Commit Graph

24 Commits

Author SHA1 Message Date
Rosen Penev
e2848118bf clang-tidy: use C++ casting
Found with google-readability-casting

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-09-28 09:36:49 +01:00
Rosen Penev
51092046f7 Remove several usages of SPICE_N_ELEMENTS
It's simpler to just use a for range loop.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-23 10:01:39 +01:00
Frediano Ziglio
c5412b071a stream-channel: Fix compiler warning
This removes:

In function ‘stream_channel_get_supported_codecs’,
    inlined from ‘on_connect’ at ../server/stream-channel.cpp:364:60:
../server/stream-channel.cpp:326:31: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  326 |             out_codecs[num++] = codec;
      |                               ^
../server/stream-channel.cpp: In member function ‘on_connect’:
/usr/include/spice-1/spice/stream-device.h:209:13: note: destination object ‘codecs’ of size 0
  209 |     uint8_t codecs[0];
      |             ^

Reported by by Tomasz Kłoczko in
https://gitlab.freedesktop.org/spice/spice/-/issues/44

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 10:14:26 +01:00
Rosen Penev
5f8d49efaa clang-tidy: remove pointless move
Found with performance-move-const-arg

Allows better optimization as the compiler does not have to deal with an
rvalue reference. Especially in C++17 where std::move can prevent copy
elision.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-14 13:07:40 +01:00
Rosen Penev
8af176b15e clang-tidy: use nullptr
Found with modernize-use-nullptr

NULL in C++ is 0 whereas it is a void pointer in C. Avoids implicit
conversions.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-12 06:50:05 +01:00
Rosen Penev
944dc8662e clang-tidy: use auto
Found with modernize-use-auto

auto is shorter and can sometimes disambiguate pointer constness.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-11 07:44:42 +01:00
Rosen Penev
f64e61e44d clang-tidy: use override and remove virtual
Found with modernize-use-override

This can be useful as compilers can generate a compile time error when:
	The base class implementation function signature changes.
        The user has not created the override with the correct
	signature.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-09 08:20:06 +01:00
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
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
45e964dc5a red-pipe-item: Better encapsulate marshaller_unref_pipe_item
To avoid memory errors marshaller_unref_pipe_item should be
matched with a previous call to red_pipe_item_ref.
This is correctly done but to reduce the possibility of breaking
this rule move both referencing and unreferencing into a new
RedPipeItem::add_to_marshaller method.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:47:45 +01:00
Frediano Ziglio
724f23e4bd Use red::shared_ptr_counted for RedChannelClient
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
2bf72a5ce2 stream-channel: More incapsulation for StreamChannel
Put all functions into methods.
Separate public/private part.

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