Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx> --- src/admin/libvirt-admin.c | 2 +- src/admin/libvirt_admin_private.syms | 2 +- src/datatypes.c | 36 ++++++++++++++++++---------- src/datatypes.h | 13 +++++----- src/rpc/gendispatch.pl | 1 + 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/admin/libvirt-admin.c b/src/admin/libvirt-admin.c index eccad1d0fc..56c63ea6e6 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_clear_object(&client); return 0; } diff --git a/src/admin/libvirt_admin_private.syms b/src/admin/libvirt_admin_private.syms index cfdaba330d..e402635872 100644 --- a/src/admin/libvirt_admin_private.syms +++ b/src/admin/libvirt_admin_private.syms @@ -34,8 +34,8 @@ xdr_admin_server_set_threadpool_parameters_args; xdr_admin_server_update_tls_files_args; # datatypes.h +vir_adm_client_get_type; vir_adm_server_get_type; -virAdmClientClass; virAdmConnectClass; virAdmConnectCloseCallbackDataRegister; virAdmConnectCloseCallbackDataReset; diff --git a/src/datatypes.c b/src/datatypes.c index cfdb9f9650..83028708da 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 virAdmClientDispose(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->dispose = virAdmClientDispose; +} G_DEFINE_TYPE(virAdmServer, vir_adm_server, G_TYPE_OBJECT); static void virAdmServerDispose(GObject *obj); @@ -121,7 +134,6 @@ virDataTypesOnceInit(void) DECLARE_CLASS_LOCKABLE(virAdmConnect); DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData); - DECLARE_CLASS(virAdmClient); #undef DECLARE_CLASS_COMMON #undef DECLARE_CLASS_LOCKABLE @@ -1228,30 +1240,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) +virAdmClientDispose(GObject *obj) { - virAdmClientPtr clt = obj; + virAdmClientPtr clt = VIR_ADM_CLIENT(obj); VIR_DEBUG("release client clt=%p, id=%llu", clt, clt->id); g_clear_object(&clt->srv); + + G_OBJECT_CLASS(vir_adm_client_parent_class)->finalize(obj); } diff --git a/src/datatypes.h b/src/datatypes.h index dee21068b3..482ad0274c 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 (_clt == NULL || \ !VIR_IS_ADM_SERVER(_clt->srv) || \ !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 (_clt == NULL || \ !VIR_IS_ADM_SERVER(_clt->srv) || \ !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 diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index a9152198d7..fa5340d5e8 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -194,6 +194,7 @@ sub get_conn_method { } my %gobject_impl = ( + virAdmClient => 1, virAdmServer => 1, ); -- 2.25.3