Commit Graph

62 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
ba065d1bdf char-device: Update documentation reference
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-06-25 16:09:34 +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
66dacecda9 char-device: Add a read method to simplify reading data
Avoid to pass throught SpiceCharDeviceInterface.
When data is read from device the device get marked as active.
This is coherent with what is done in red_char_device_read_from_device.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-06-23 12:49:26 +01:00
Frediano Ziglio
853a6df224 Avoid useless SPICE_CXX_GLIB_ALLOCATOR usage
Behaviour was already inherited.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Rope <jrope@redhat.com>
2020-06-04 09:34:12 +01:00
Frediano Ziglio
bd17418f9e char-device: Make RedCharDevice::write_retry private
Not meant to be called externally.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Rope <jrope@redhat.com>
2020-05-28 14:36:11 +01:00
Frediano Ziglio
62801ad9ac char-device: Remove obsolete declaration
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-05-05 05:14:53 +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
454b18fcae char-device: Convert some static functions to methods
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
26e6d15551 char-device: Prepare to move functions to methods
Move structure declaration at the end.

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
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
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
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
5bcfc2b5d5 char-device: Allow send_msg_to_client callback to be NULL
Mostly of the callback dealing with sent messages and tokens
can be NULL.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-19 12:33:16 +00:00
Frediano Ziglio
8ec691f056 char-device: Allow to more safely and quickly get device instance
This information is retrieved multiple time.
Avoid to use just g_object_get which is dynamic so potentially
unsafe and slow.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-16 15:06:44 +00:00
Frediano Ziglio
14fe2c3766 char-device: Don't use RedClient API
RedClient was an opaque structure for RedCharDevice.
It started to be used when RedsState started to contain all
the global state.
Make it opaque again using a new RedCharDeviceClientOpaque.
The RedCharDeviceClientOpaque define in the header allows users
of the class to override the type to get a more safe type
than RedClient.
The define at the beginning of C file is to make sure we don't
use the opaque type as a specific one.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-17 12:17:26 +01:00
Frediano Ziglio
f584a5d6b6 char-device: Allocate all write buffer in a single block
There are no much data other than the buffer, reduce the
allocations.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 11:57:24 +01:00
Frediano Ziglio
2160b1ea39 spicevmc: Remove reds parameter from spicevmc_device_disconnect
Unused.
Also the devices should be able to release themselves.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 10:59:00 +01:00
Frediano Ziglio
75879867b7 char-device: Remove unused red_char_device_destroy function
g_object_unref is directly used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 10:57:07 +01:00
Frediano Ziglio
a9af580a6e char-device: Fix some comments
Some function names where changed.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-06-02 14:44:58 +03: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
Frediano Ziglio
6bd9a486a9 stream-device: Separate declaration in a separate header
Move public declaration (stream_device_connect) from char-device.h
to a new stream-device.h.
Add type declaration for StreamDevice.
This allows to use the type outside the implementation file and makes it
easier to extend the interface without changing char-device.h header.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-03-08 10:58:46 +00:00
Frediano Ziglio
a0c184e89b stream-device: Add device to handle streaming
Add a stub device in guest.
The aim of this device is to make it possible for the guest to send a
stream through a DisplayChannel (in the sense of protocol channel).
This stub allows the guest to send some data and you can see some debug
lines of data arrived on host logs.

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
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
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
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
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
8340688c9d Change RedCharDevice::write_queue to GQueue
Change a couple more Rings to GQueue
2016-09-19 07:47:05 -05:00
Frediano Ziglio
6fbefcc3c3 Remove obsolete comment
AGENT_CONNECT with token count is implemented by agent_connected_tokens
message.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-01 16:21:07 +01:00
Frediano Ziglio
8a314520cc Fix some typos in comments
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-01 16:09:44 +01:00
Frediano Ziglio
3349610652 char-device: Update function names in documentation
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-18 00:24:37 +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
7c79c0f6a8 char-device: improved comment
- fix typo;
- simplify sentence.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-05-09 14:21:58 +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
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
e37f97a9f8 reds: Move RedsState typedef to red-common.h
This allows to stop using struct RedsState * rather than RedsState * in
headers which cannot include reds.h. This also allows to remove the
duplicate RedsState typedef in reds.h and reds-stream.h which is causing
issues with older gcc versions.
2016-04-06 10:30:00 +02:00
Christophe Fergeau
4d3c8bdb98 char-device: Remove duplicate typedef 2016-04-05 16:49:40 +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