Re: [PATCH 14/36] admin: convert virAdmClient to GObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2020-04-03 at 17:15 +0200, Rafael Fonseca wrote:
> Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
> ---
>  src/admin/libvirt-admin.c            |  2 +-
>  src/admin/libvirt_admin_private.syms |  1 -
>  src/datatypes.c                      | 36 ++++++++++++++++++------
> ----
>  src/datatypes.h                      | 13 +++++-----
>  4 files changed, 31 insertions(+), 21 deletions(-)
> 
> diff --git a/src/admin/libvirt-admin.c b/src/admin/libvirt-admin.c
> index ed7a57cbbb..6f86de4360 100644
> --- a/src/admin/libvirt-admin.c
> +++ b/src/admin/libvirt-admin.c
> @@ -676,7 +676,7 @@ int virAdmClientFree(virAdmClientPtr client)
>  
>      virCheckAdmClientReturn(client, -1);
>  
> -    virObjectUnref(client);
> +    g_object_unref(client);
>      return 0;
>  }
>  
> diff --git a/src/admin/libvirt_admin_private.syms
> b/src/admin/libvirt_admin_private.syms
> index 270fa43995..9ba4b68932 100644
> --- a/src/admin/libvirt_admin_private.syms
> +++ b/src/admin/libvirt_admin_private.syms
> @@ -34,7 +34,6 @@ xdr_admin_server_set_threadpool_parameters_args;
>  xdr_admin_server_update_tls_files_args;
>  
>  # datatypes.h
> -virAdmClientClass;
>  virAdmConnectClass;
>  virAdmConnectCloseCallbackDataRegister;
>  virAdmConnectCloseCallbackDataReset;
> diff --git a/src/datatypes.c b/src/datatypes.c
> index d6afaf89ad..68fc216ffa 100644
> --- a/src/datatypes.c
> +++ b/src/datatypes.c
> @@ -71,8 +71,21 @@ virClassPtr virAdmConnectCloseCallbackDataClass;
>  static void virAdmConnectDispose(void *obj);
>  static void virAdmConnectCloseCallbackDataDispose(void *obj);
>  
> -virClassPtr virAdmClientClass;
> -static void virAdmClientDispose(void *obj);
> +G_DEFINE_TYPE(virAdmClient, vir_adm_client, G_TYPE_OBJECT);
> +static void virAdmClientFinalize(GObject *obj);
> +
> +static void
> +vir_adm_client_init(virAdmClient *clt G_GNUC_UNUSED)
> +{
> +}
> +
> +static void
> +vir_adm_client_class_init(virAdmClientClass *klass)
> +{
> +    GObjectClass *obj = G_OBJECT_CLASS(klass);
> +
> +    obj->finalize = virAdmClientFinalize;
> +}
>  
>  G_DEFINE_TYPE(virAdmServer, vir_adm_server, G_TYPE_OBJECT);
>  static void virAdmServerFinalize(GObject *obj);
> @@ -119,7 +132,6 @@ virDataTypesOnceInit(void)
>  
>      DECLARE_CLASS_LOCKABLE(virAdmConnect);
>      DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData);
> -    DECLARE_CLASS(virAdmClient);
>  
>  #undef DECLARE_CLASS_COMMON
>  #undef DECLARE_CLASS_LOCKABLE
> @@ -1216,30 +1228,28 @@ virAdmClientPtr
>  virAdmGetClient(virAdmServerPtr srv, const unsigned long long id,
>                  unsigned long long timestamp, unsigned int
> transport)
>  {
> -    virAdmClientPtr ret = NULL;
> +    g_autoptr(virAdmClient) ret = NULL;
>  
>      if (virDataTypesInitialize() < 0)
> -        goto error;
> +        return NULL;
>  
> -    if (!(ret = virObjectNew(virAdmClientClass)))
> -        goto error;
> +    ret = VIR_ADM_CLIENT(g_object_new(VIR_TYPE_ADM_CLIENT, NULL));
>  
>      ret->id = id;
>      ret->timestamp = timestamp;
>      ret->transport = transport;
>      ret->srv = g_object_ref(srv);
>  
> -    return ret;
> - error:
> -    virObjectUnref(ret);
> -    return NULL;
> +    return g_steal_pointer(&ret);
>  }
>  
>  static void
> -virAdmClientDispose(void *obj)
> +virAdmClientFinalize(GObject *obj)
>  {
> -    virAdmClientPtr clt = obj;
> +    virAdmClientPtr clt = VIR_ADM_CLIENT(obj);
>      VIR_DEBUG("release client clt=%p, id=%llu", clt, clt->id);
>  
>      g_object_unref(clt->srv);
> +
> +    G_OBJECT_CLASS(vir_adm_client_parent_class)->finalize(obj);
>  }
> diff --git a/src/datatypes.h b/src/datatypes.h
> index 20b64ca788..4e9f338f8b 100644
> --- a/src/datatypes.h
> +++ b/src/datatypes.h
> @@ -46,10 +46,11 @@ extern virClassPtr virStorageVolClass;
>  extern virClassPtr virStoragePoolClass;
>  
>  extern virClassPtr virAdmConnectClass;
> -extern virClassPtr virAdmClientClass;
>  
>  #define VIR_TYPE_ADM_SERVER vir_adm_server_get_type()
>  G_DECLARE_FINAL_TYPE(virAdmServer, vir_adm_server, VIR, ADM_SERVER,
> GObject);
> +#define VIR_TYPE_ADM_CLIENT vir_adm_client_get_type()
> +G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
> GObject);
>  
>  #define virCheckConnectReturn(obj, retval) \
>      do { \
> @@ -447,8 +448,8 @@ G_DECLARE_FINAL_TYPE(virAdmServer,
> vir_adm_server, VIR, ADM_SERVER, GObject);
>  
>  #define virCheckAdmClientReturn(obj, retval) \
>      do { \
> -        virAdmClientPtr _clt = (obj); \
> -        if (!virObjectIsClass(_clt, virAdmClientClass) || \
> +        virAdmClientPtr _clt = VIR_ADM_CLIENT(obj); \
> +        if (!G_IS_OBJECT(_clt) || !(G_OBJECT_TYPE(_clt) ==
> VIR_TYPE_ADM_CLIENT) || \

Same comments here about the casting macro as in the previous patch.

>              !G_IS_OBJECT(_clt->srv) || !(G_OBJECT_TYPE(_clt->srv) ==
> VIR_TYPE_ADM_SERVER) || \
>              !virObjectIsClass(_clt->srv->conn, virAdmConnectClass))
> { \
>              virReportErrorHelper(VIR_FROM_THIS,
> VIR_ERR_INVALID_CONN, \
> @@ -460,8 +461,8 @@ G_DECLARE_FINAL_TYPE(virAdmServer,
> vir_adm_server, VIR, ADM_SERVER, GObject);
>      } while (0)
>  #define virCheckAdmClientGoto(obj, label) \
>      do { \
> -        virAdmClientPtr _clt = (obj); \
> -        if (!virObjectIsClass(_clt, virAdmClientClass) || \
> +        virAdmClientPtr _clt = VIR_ADM_CLIENT(obj); \
> +        if (!G_IS_OBJECT(_clt) || !(G_OBJECT_TYPE(_clt) ==
> VIR_TYPE_ADM_CLIENT) || \
>              !G_IS_OBJECT(_clt->srv) || !(G_OBJECT_TYPE(_clt->srv) ==
> VIR_TYPE_ADM_SERVER) || \
>              !virObjectIsClass(_clt->srv->conn, virAdmConnectClass))
> { \
>              virReportErrorHelper(VIR_FROM_THIS,
> VIR_ERR_INVALID_CONN, \
> @@ -588,7 +589,7 @@ struct _virAdmServer {
>   * Internal structure associated to a client connected to daemon
>   */
>  struct _virAdmClient {
> -    virObject parent;
> +    GObject parent;
>      virAdmServerPtr srv;            /* pointer to the server client
> is
>                                       * connected to, which also
> holds a
>                                       * reference back to the admin
> connection




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux