Re: [PATCH 13/36] admin: convert virAdmServer 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                      | 42 ++++++++++++++++++------
> ----
>  src/datatypes.h                      | 20 +++++++------
>  4 files changed, 40 insertions(+), 25 deletions(-)
> 
> 

[snip]

> @@ -44,9 +46,11 @@ extern virClassPtr virStorageVolClass;
>  extern virClassPtr virStoragePoolClass;
>  
>  extern virClassPtr virAdmConnectClass;
> -extern virClassPtr virAdmServerClass;
>  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 virCheckConnectReturn(obj, retval) \
>      do { \
>          if (!virObjectIsClass(obj, virConnectClass)) { \
> @@ -419,8 +423,8 @@ extern virClassPtr virAdmClientClass;
>  
>  #define virCheckAdmServerReturn(obj, retval) \
>      do { \
> -        virAdmServerPtr _srv = (obj); \
> -        if (!virObjectIsClass(_srv, virAdmServerClass) || \
> +        virAdmServerPtr _srv = VIR_ADM_SERVER(obj); \
> +        if (!G_IS_OBJECT(_srv) || !(G_OBJECT_TYPE(_srv) ==
> VIR_TYPE_ADM_SERVER) || \

This additional check is unnecessary with GObject. The VIR_ADM_SERVER()
casting macro that is provided by G_DECLARE_FINAL_TYPE() does this
internally. This function already checks that the type of obj is
correct and castable. If the pointer is not castable to the type, it
emits a warning and returns NULL. So you can just check for (_srv ==
NULL).

>              !virObjectIsClass(_srv->conn, virAdmConnectClass)) { \
>              virReportErrorHelper(VIR_FROM_THIS,
> VIR_ERR_INVALID_CONN, \
>                                   __FILE__, __FUNCTION__, __LINE__, \
> @@ -431,8 +435,8 @@ extern virClassPtr virAdmClientClass;
>      } while (0)
>  #define virCheckAdmServerGoto(obj, label) \
>      do { \
> -        virAdmServerPtr _srv = (obj); \
> -        if (!virObjectIsClass(_srv, virAdmServerClass) || \
> +        virAdmServerPtr _srv = VIR_ADM_SERVER(obj); \
> +        if (!G_IS_OBJECT(_srv) || !(G_OBJECT_TYPE(_srv) ==
> VIR_TYPE_ADM_SERVER) || \

same here

>              !virObjectIsClass(_srv->conn, virAdmConnectClass)) { \
>              virReportErrorHelper(VIR_FROM_THIS,
> VIR_ERR_INVALID_CONN, \
>                                   __FILE__, __FUNCTION__, __LINE__, \
> @@ -445,7 +449,7 @@ extern virClassPtr virAdmClientClass;
>      do { \
>          virAdmClientPtr _clt = (obj); \
>          if (!virObjectIsClass(_clt, virAdmClientClass) || \
> -            !virObjectIsClass(_clt->srv, virAdmServerClass) || \
> +            !G_IS_OBJECT(_clt->srv) || !(G_OBJECT_TYPE(_clt->srv) ==
> VIR_TYPE_ADM_SERVER) || \

Here you should be able to use the macro VIR_IS_ADM_SERVER() that is
automatically provided by G_DECLARE_FINAL_TYPE().

>              !virObjectIsClass(_clt->srv->conn, virAdmConnectClass))
> { \
>              virReportErrorHelper(VIR_FROM_THIS,
> VIR_ERR_INVALID_CONN, \
>                                   __FILE__, __FUNCTION__, __LINE__, \
> @@ -458,7 +462,7 @@ extern virClassPtr virAdmClientClass;
>      do { \
>          virAdmClientPtr _clt = (obj); \
>          if (!virObjectIsClass(_clt, virAdmClientClass) || \
> -            !virObjectIsClass(_clt->srv, virAdmServerClass) || \
> +            !G_IS_OBJECT(_clt->srv) || !(G_OBJECT_TYPE(_clt->srv) ==
> VIR_TYPE_ADM_SERVER) || \

same here

>              !virObjectIsClass(_clt->srv->conn, virAdmConnectClass))
> { \
>              virReportErrorHelper(VIR_FROM_THIS,
> VIR_ERR_INVALID_CONN, \
>                                   __FILE__, __FUNCTION__, __LINE__, \
> @@ -573,7 +577,7 @@ struct _virAdmConnect {
>   * Internal structure associated to a daemon server
>   */
>  struct _virAdmServer {
> -    virObject parent;
> +    GObject parent;
>      virAdmConnectPtr conn;          /* pointer back to the admin
> connection */
>      char *name;                     /* the server external name */
>  };




[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