[Spice-devel] [PATCH spice-gtk 06/15] webdav: move initialization to session

Jonathon Jongsma jjongsma at redhat.com
Tue Nov 25 14:49:03 PST 2014


On Tue, 2014-11-25 at 14:19 +0100, Marc-André Lureau wrote:
> Use session accessors to initialize the webdav server
> ---
>  gtk/channel-webdav.c     | 24 +++++-------------------
>  gtk/spice-session-priv.h |  2 ++
>  gtk/spice-session.c      | 23 +++++++++++++++++++++++
>  3 files changed, 30 insertions(+), 19 deletions(-)
> 
> diff --git a/gtk/channel-webdav.c b/gtk/channel-webdav.c
> index dbb8730..94f3ef3 100644
> --- a/gtk/channel-webdav.c
> +++ b/gtk/channel-webdav.c
> @@ -694,19 +694,14 @@ end:
>      g_object_unref(gaddr);
>  }
>  
> -static PhodavServer* webdav_server_new(SpiceSession *session)
> +G_GNUC_INTERNAL
> +PhodavServer* channel_webdav_server_new(SpiceSession *session)

I find this name a little inconsistent. Generally the first part of the
function name indicates the type of object that this method belongs to.
So I'd expect channel_webdav_server_new() to take a SpiceWebdavChannel*
as its first argument, but it takes a SpiceSession* instead. So it seems
that spice_session_webdav_server_new() would be a more appropriate name?
Maybe even move it along to spice-session.c since its only caller just
got moved there?

Looks fine otherwise.


>  {
>      PhodavServer *dav;
>      SoupServer *server;
>      SoupSocket *listener;
> -    int i;
> -
> -    g_warn_if_fail(!session->priv->webdav);
>  
>      dav = phodav_server_new(0, spice_session_get_shared_dir(session));
> -    session->priv->webdav = dav;
> -    for (i = 0; i < sizeof(session->priv->webdav_magic); i++)
> -        session->priv->webdav_magic[i] = g_random_int_range(0, 255);
>  
>      server = phodav_server_get_soup_server(dav);
>      listener = soup_server_get_listener(server);
> @@ -723,21 +718,12 @@ static PhodavServer* phodav_server_get(SpiceSession *session, gint *port)
>      g_return_val_if_fail(SPICE_IS_SESSION(session), NULL);
>  
>  #ifdef USE_PHODAV
> -    PhodavServer *self = NULL;
> -    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
> -
> -    g_static_mutex_lock(&mutex);
> -    self = session->priv->webdav;
> -    if (self == NULL) {
> -        self = webdav_server_new(session);
> -        phodav_server_run(self);
> -    }
> -    g_static_mutex_unlock(&mutex);
> +    PhodavServer *server = spice_session_get_webdav_server(session);
>  
>      if (port)
> -        *port = phodav_server_get_port(self);
> +        *port = phodav_server_get_port(server);
>  
> -    return self;
> +    return server;
>  #else
>      g_return_val_if_reached(NULL);
>  #endif
> diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
> index 5a63536..5136c2d 100644
> --- a/gtk/spice-session-priv.h
> +++ b/gtk/spice-session-priv.h
> @@ -178,6 +178,8 @@ gboolean spice_session_get_usbredir_enabled(SpiceSession *session);
>  
>  #define WEBDAV_MAGIC_SIZE 16
>  const guint8* spice_session_get_webdav_magic(SpiceSession *session);
> +PhodavServer *spice_session_get_webdav_server(SpiceSession *session);
> +PhodavServer* channel_webdav_server_new(SpiceSession *session);
>  guint spice_session_get_display_channels_count(SpiceSession *session);
>  void spice_session_set_migration_copy(SpiceSession *session, gboolean copy);
>  void spice_session_set_main_channel(SpiceSession *session, SpiceChannel *channel);
> diff --git a/gtk/spice-session.c b/gtk/spice-session.c
> index 5dd6f0f..04979a1 100644
> --- a/gtk/spice-session.c
> +++ b/gtk/spice-session.c
> @@ -2379,6 +2379,29 @@ const guint8* spice_session_get_webdav_magic(SpiceSession *session)
>  }
>  
>  G_GNUC_INTERNAL
> +PhodavServer* spice_session_get_webdav_server(SpiceSession *session)
> +{
> +    g_return_val_if_fail(SPICE_IS_SESSION(session), NULL);
> +
> +#ifdef USE_PHODAV
> +    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
> +    int i;
> +
> +    g_static_mutex_lock(&mutex);
> +    if (!session->priv->webdav) {
> +        for (i = 0; i < sizeof(session->priv->webdav_magic); i++)
> +            session->priv->webdav_magic[i] = g_random_int_range(0, 255);
> +
> +        session->priv->webdav = channel_webdav_server_new(session);
> +        phodav_server_run(session->priv->webdav);
> +    }
> +    g_static_mutex_unlock(&mutex);
> +#endif
> +
> +    return session->priv->webdav;
> +}
> +
> +G_GNUC_INTERNAL
>  void spice_session_set_migration_copy(SpiceSession *session, gboolean copy)
>  {
>      g_return_if_fail(SPICE_IS_SESSION(session));




More information about the Spice-devel mailing list