From ff8e56336574a168d427a993d666d9e038aacbaf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 Mar 2018 10:34:58 +0100 Subject: [PATCH] libnm: add nm-autoptr.h header "nm-autoptr.h" is done in a way that allows you to copy the header in your source tree to support older versions of libnm, that didn't contain the header yet. For example, we might want to use it in network-manager-applet, but we don't want to bump the libnm dependency to 1.11.2+ only to get this functionality. Note that G_DEFINE_AUTOPTR_CLEANUP_FUNC() was added in glib 2.43.4, and requires compiler support for the cleanup attribute. The compiler support is taken as given, because we rely on it already. However, NetworkManager and network-manager-applet still don't depend on a glib version recent enough to provide these macros. To actually use them (*inside*) NetworkManager/network-manager-applet, we either would have to bump the glib minimal dependency, or reimplement g_autoptr in /shared/nm-utils/nm-glib.h compat header. https://bugzilla.gnome.org/show_bug.cgi?id=794294 --- Makefile.am | 1 + libnm/NetworkManager.h | 2 + libnm/nm-autoptr.h | 85 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 libnm/nm-autoptr.h diff --git a/Makefile.am b/Makefile.am index 9d5d8e43ce..f52e1f0248 100644 --- a/Makefile.am +++ b/Makefile.am @@ -752,6 +752,7 @@ libnm_lib_h_pub_real = \ libnm/NetworkManager.h \ libnm/nm-access-point.h \ libnm/nm-active-connection.h \ + libnm/nm-autoptr.h \ libnm/nm-checkpoint.h \ libnm/nm-client.h \ libnm/nm-device-adsl.h \ diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h index 2bdd2ed9a1..e04911c677 100644 --- a/libnm/NetworkManager.h +++ b/libnm/NetworkManager.h @@ -108,6 +108,8 @@ #include "nm-vpn-service-plugin.h" #include "nm-wimax-nsp.h" +#include "nm-autoptr.h" + #undef __NETWORKMANAGER_H_INSIDE__ #endif /* __NETWORKMANAGER_H__ */ diff --git a/libnm/nm-autoptr.h b/libnm/nm-autoptr.h new file mode 100644 index 0000000000..e70d94aa54 --- /dev/null +++ b/libnm/nm-autoptr.h @@ -0,0 +1,85 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * Copyright 2018 Red Hat, Inc. + */ + +#ifndef __NM_AUTOPTR_H__ +#define __NM_AUTOPTR_H__ + +/** + * Note that you might use this header with older versions of libnm + * that do not yet ship this header. In that case, copy the header + * into your source tree. + **/ + +#include +#include + +#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMClient, g_object_unref) + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMConnection, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSetting, g_object_unref) + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSetting8021x, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingAdsl, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingBluetooth, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingBond, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingBridge, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingBridgePort, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingCdma, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingConnection, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingDcb, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingDummy, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingGeneric, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingGsm, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingInfiniband, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingIP4Config, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingIP6Config, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingIPConfig, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingIPTunnel, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingMacsec, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingMacvlan, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingOlpcMesh, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingOvsBridge, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingOvsInterface, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingOvsPatch, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingOvsPort, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingPpp, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingPppoe, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingProxy, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingSerial, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingTCConfig, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingTeam, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingTeamPort, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingTun, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingUser, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingVlan, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingVpn, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingVxlan, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingWimax, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingWired, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingWireless, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingWirelessSecurity, g_object_unref) + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMVpnPluginInfo, g_object_unref) + +#endif + +#endif /* __NM_AUTOPTR_H__ */