[spice-server] char-device: Allow to more safely and quickly get device instance

Submitted by Frediano Ziglio on Sept. 18, 2019, 7:58 a.m.

Details

Message ID 20190918075809.5107-1-fziglio@redhat.com
State New
Headers show
Series "char-device: Allow to more safely and quickly get device instance" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Sept. 18, 2019, 7:58 a.m.
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>
---
 server/char-device.c | 5 +++++
 server/char-device.h | 2 ++
 2 files changed, 7 insertions(+)

Patch hide | download patch | download mbox

diff --git a/server/char-device.c b/server/char-device.c
index 03ac9907c..36e22dee3 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -1166,6 +1166,11 @@  SPICE_GNUC_VISIBLE void spice_server_port_event(SpiceCharDeviceInstance *sin, ui
     return klass->port_event(sin->st, event);
 }
 
+SpiceCharDeviceInstance *red_char_device_get_device_instance(RedCharDevice *dev)
+{
+    return dev->priv->sin;
+}
+
 static void
 red_char_device_init(RedCharDevice *self)
 {
diff --git a/server/char-device.h b/server/char-device.h
index 0a87045b7..830ca456d 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -243,6 +243,8 @@  RedCharDevice *spicevmc_device_connect(RedsState *reds,
                                        uint8_t channel_type);
 void spicevmc_device_disconnect(SpiceCharDeviceInstance *char_device);
 
+SpiceCharDeviceInstance *red_char_device_get_device_instance(RedCharDevice *dev);
+
 SpiceCharDeviceInterface *spice_char_device_get_interface(SpiceCharDeviceInstance *instance);
 
 #endif /* CHAR_DEVICE_H_ */

Comments

ping

> 
> 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>
> ---
>  server/char-device.c | 5 +++++
>  server/char-device.h | 2 ++
>  2 files changed, 7 insertions(+)
> 
> diff --git a/server/char-device.c b/server/char-device.c
> index 03ac9907c..36e22dee3 100644
> --- a/server/char-device.c
> +++ b/server/char-device.c
> @@ -1166,6 +1166,11 @@ SPICE_GNUC_VISIBLE void
> spice_server_port_event(SpiceCharDeviceInstance *sin, ui
>      return klass->port_event(sin->st, event);
>  }
>  
> +SpiceCharDeviceInstance *red_char_device_get_device_instance(RedCharDevice
> *dev)
> +{
> +    return dev->priv->sin;
> +}
> +
>  static void
>  red_char_device_init(RedCharDevice *self)
>  {
> diff --git a/server/char-device.h b/server/char-device.h
> index 0a87045b7..830ca456d 100644
> --- a/server/char-device.h
> +++ b/server/char-device.h
> @@ -243,6 +243,8 @@ RedCharDevice *spicevmc_device_connect(RedsState *reds,
>                                         uint8_t channel_type);
>  void spicevmc_device_disconnect(SpiceCharDeviceInstance *char_device);
>  
> +SpiceCharDeviceInstance *red_char_device_get_device_instance(RedCharDevice
> *dev);
> +
>  SpiceCharDeviceInterface
>  *spice_char_device_get_interface(SpiceCharDeviceInstance *instance);
>  
>  #endif /* CHAR_DEVICE_H_ */