Commit 38e3819b authored by Dan Williams's avatar Dan Williams

libnm-util: clean up setting registration

Make setting type registration less icky; instead of having the
connection register all the settings, have the settings themselves
register that information at library load time.  Putting this sort
of thing in G_DEFINE_TYPE_WITH_CODE is apparently more standard
than the home-rolled stuff we had before.  Also document the
priority stuff so when adding new settings, people know what
priority to use.

(cleanups by jklimes)
parent 1277f998
......@@ -74,4 +74,13 @@ p##_get_type (void) \
}
#endif
#if !GLIB_CHECK_VERSION(2,34,0)
static inline void
g_type_ensure (GType type)
{
if (G_UNLIKELY (type == (GType)-1))
g_error ("can't happen");
}
#endif
#endif /* NM_GLIB_COMPAT_H */
This diff is collapsed.
......@@ -81,7 +81,12 @@ nm_setting_802_1x_error_quark (void)
return quark;
}
G_DEFINE_TYPE (NMSetting8021x, nm_setting_802_1x, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSetting8021x, nm_setting_802_1x, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_802_1X_SETTING_NAME,
g_define_type_id,
2,
NM_SETTING_802_1X_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_802_1X)
#define NM_SETTING_802_1X_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_802_1X, NMSetting8021xPrivate))
......
......@@ -55,7 +55,12 @@ nm_setting_adsl_error_quark (void)
return quark;
}
G_DEFINE_TYPE (NMSettingAdsl, nm_setting_adsl, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingAdsl, nm_setting_adsl, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_ADSL_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_ADSL_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_ADSL)
#define NM_SETTING_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_ADSL, NMSettingAdslPrivate))
......
......@@ -32,6 +32,7 @@
#include "nm-setting-bluetooth.h"
#include "nm-setting-cdma.h"
#include "nm-setting-gsm.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-bluetooth
......@@ -62,7 +63,12 @@ nm_setting_bluetooth_error_quark (void)
}
G_DEFINE_TYPE (NMSettingBluetooth, nm_setting_bluetooth, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingBluetooth, nm_setting_bluetooth, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_BLUETOOTH_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_BLUETOOTH_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BLUETOOTH)
#define NM_SETTING_BLUETOOTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BLUETOOTH, NMSettingBluetoothPrivate))
......
......@@ -30,6 +30,7 @@
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-bond
......@@ -58,7 +59,12 @@ nm_setting_bond_error_quark (void)
}
G_DEFINE_TYPE (NMSettingBond, nm_setting_bond, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingBond, nm_setting_bond, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_BOND_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_BOND_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BOND)
#define NM_SETTING_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BOND, NMSettingBondPrivate))
......
......@@ -54,7 +54,12 @@ nm_setting_cdma_error_quark (void)
}
G_DEFINE_TYPE (NMSettingCdma, nm_setting_cdma, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingCdma, nm_setting_cdma, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_CDMA_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_CDMA_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CDMA)
#define NM_SETTING_CDMA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CDMA, NMSettingCdmaPrivate))
......
......@@ -28,6 +28,7 @@
#include "nm-dbus-glib-types.h"
#include "nm-param-spec-specialized.h"
#include "nm-setting-connection.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-connection
......@@ -58,7 +59,12 @@ nm_setting_connection_error_quark (void)
}
G_DEFINE_TYPE (NMSettingConnection, nm_setting_connection, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingConnection, nm_setting_connection, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_CONNECTION_SETTING_NAME,
g_define_type_id,
0,
NM_SETTING_CONNECTION_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CONNECTION)
#define NM_SETTING_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CONNECTION, NMSettingConnectionPrivate))
......
......@@ -56,7 +56,12 @@ nm_setting_gsm_error_quark (void)
}
G_DEFINE_TYPE (NMSettingGsm, nm_setting_gsm, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingGsm, nm_setting_gsm, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_GSM_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_GSM_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_GSM)
#define NM_SETTING_GSM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_GSM, NMSettingGsmPrivate))
......
......@@ -25,6 +25,7 @@
#include "nm-setting-infiniband.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-infiniband
......@@ -52,7 +53,12 @@ nm_setting_infiniband_error_quark (void)
return quark;
}
G_DEFINE_TYPE (NMSettingInfiniband, nm_setting_infiniband, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingInfiniband, nm_setting_infiniband, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_INFINIBAND_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_INFINIBAND_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_INFINIBAND)
#define NM_SETTING_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_INFINIBAND, NMSettingInfinibandPrivate))
......
......@@ -31,7 +31,7 @@
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
#include "nm-setting-private.h"
/**
......@@ -63,7 +63,12 @@ nm_setting_ip4_config_error_quark (void)
G_DEFINE_BOXED_TYPE (NMIP4Address, nm_ip4_address, nm_ip4_address_dup, nm_ip4_address_unref)
G_DEFINE_BOXED_TYPE (NMIP4Route, nm_ip4_route, nm_ip4_route_dup, nm_ip4_route_unref)
G_DEFINE_TYPE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_IP4_CONFIG_SETTING_NAME,
g_define_type_id,
4,
NM_SETTING_IP4_CONFIG_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG)
#define NM_SETTING_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP4_CONFIG, NMSettingIP4ConfigPrivate))
......
......@@ -30,6 +30,7 @@
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-ip6-config
......@@ -60,7 +61,12 @@ nm_setting_ip6_config_error_quark (void)
G_DEFINE_BOXED_TYPE (NMIP6Address, nm_ip6_address, nm_ip6_address_dup, nm_ip6_address_unref)
G_DEFINE_BOXED_TYPE (NMIP6Route, nm_ip6_route, nm_ip6_route_dup, nm_ip6_route_unref)
G_DEFINE_TYPE (NMSettingIP6Config, nm_setting_ip6_config, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingIP6Config, nm_setting_ip6_config, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_IP6_CONFIG_SETTING_NAME,
g_define_type_id,
4,
NM_SETTING_IP6_CONFIG_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP6_CONFIG)
#define NM_SETTING_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP6_CONFIG, NMSettingIP6ConfigPrivate))
......
......@@ -35,6 +35,7 @@
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
GQuark
nm_setting_olpc_mesh_error_quark (void)
......@@ -48,7 +49,12 @@ nm_setting_olpc_mesh_error_quark (void)
static void nm_setting_olpc_mesh_init (NMSettingOlpcMesh *setting);
G_DEFINE_TYPE (NMSettingOlpcMesh, nm_setting_olpc_mesh, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingOlpcMesh, nm_setting_olpc_mesh, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_OLPC_MESH_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_OLPC_MESH_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_OLPC_MESH)
#define NM_SETTING_OLPC_MESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_OLPC_MESH, NMSettingOlpcMeshPrivate))
......
......@@ -24,6 +24,7 @@
*/
#include "nm-setting-ppp.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-ppp
......@@ -54,7 +55,12 @@ nm_setting_ppp_error_quark (void)
}
G_DEFINE_TYPE (NMSettingPPP, nm_setting_ppp, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingPPP, nm_setting_ppp, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_PPP_SETTING_NAME,
g_define_type_id,
3,
NM_SETTING_PPP_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PPP)
#define NM_SETTING_PPP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PPP, NMSettingPPPPrivate))
......
......@@ -56,7 +56,12 @@ nm_setting_pppoe_error_quark (void)
}
G_DEFINE_TYPE (NMSettingPPPOE, nm_setting_pppoe, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingPPPOE, nm_setting_pppoe, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_PPPOE_SETTING_NAME,
g_define_type_id,
3,
NM_SETTING_PPPOE_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PPPOE)
#define NM_SETTING_PPPOE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PPPOE, NMSettingPPPOEPrivate))
......
......@@ -21,11 +21,23 @@
#ifndef NM_SETTING_PRIVATE_H
#define NM_SETTING_PRIVATE_H
#include "nm-glib-compat.h"
#define NM_SETTING_SECRET_FLAGS_ALL \
(NM_SETTING_SECRET_FLAG_NONE | \
NM_SETTING_SECRET_FLAG_AGENT_OWNED | \
NM_SETTING_SECRET_FLAG_NOT_SAVED | \
NM_SETTING_SECRET_FLAG_NOT_REQUIRED)
void _nm_register_setting (const char *name,
const GType type,
const guint32 priority,
const GQuark error_quark);
/* Ensure the setting's GType is registered at library load time */
#define NM_SETTING_REGISTER_TYPE(x) \
static void __attribute__((constructor)) register_setting (void) \
{ g_type_init (); g_type_ensure (x); }
#endif /* NM_SETTING_PRIVATE_H */
......@@ -27,6 +27,7 @@
#include "nm-setting-serial.h"
#include "nm-glib-compat.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-serial
......@@ -57,7 +58,12 @@ nm_setting_serial_error_quark (void)
}
G_DEFINE_TYPE (NMSettingSerial, nm_setting_serial, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingSerial, nm_setting_serial, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_SERIAL_SETTING_NAME,
g_define_type_id,
2,
NM_SETTING_SERIAL_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_SERIAL)
#define NM_SETTING_SERIAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_SERIAL, NMSettingSerialPrivate))
......
......@@ -30,6 +30,7 @@
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-connection.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-vlan
......@@ -57,7 +58,12 @@ nm_setting_vlan_error_quark (void)
return quark;
}
G_DEFINE_TYPE (NMSettingVlan, nm_setting_vlan, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingVlan, nm_setting_vlan, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_VLAN_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_VLAN_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_VLAN)
#define NM_SETTING_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VLAN, NMSettingVlanPrivate))
......
......@@ -64,7 +64,12 @@ nm_setting_vpn_error_quark (void)
}
G_DEFINE_TYPE (NMSettingVPN, nm_setting_vpn, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingVPN, nm_setting_vpn, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_VPN_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_VPN_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_VPN)
#define NM_SETTING_VPN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VPN, NMSettingVPNPrivate))
......
......@@ -26,6 +26,7 @@
#include "nm-setting-wimax.h"
#include "nm-param-spec-specialized.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-wimax
......@@ -54,7 +55,12 @@ nm_setting_wimax_error_quark (void)
}
G_DEFINE_TYPE (NMSettingWimax, nm_setting_wimax, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingWimax, nm_setting_wimax, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_WIMAX_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_WIMAX_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIMAX)
#define NM_SETTING_WIMAX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIMAX, NMSettingWimaxPrivate))
......
......@@ -33,6 +33,7 @@
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-wired
......@@ -61,7 +62,12 @@ nm_setting_wired_error_quark (void)
}
G_DEFINE_TYPE (NMSettingWired, nm_setting_wired, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingWired, nm_setting_wired, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_WIRED_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_WIRED_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRED)
#define NM_SETTING_WIRED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRED, NMSettingWiredPrivate))
......
......@@ -75,7 +75,12 @@ nm_setting_wireless_security_error_quark (void)
}
G_DEFINE_TYPE (NMSettingWirelessSecurity, nm_setting_wireless_security, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingWirelessSecurity, nm_setting_wireless_security, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
g_define_type_id,
2,
NM_SETTING_WIRELESS_SECURITY_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRELESS_SECURITY)
#define NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS_SECURITY, NMSettingWirelessSecurityPrivate))
......
......@@ -34,6 +34,7 @@
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-wireless
......@@ -62,7 +63,12 @@ nm_setting_wireless_error_quark (void)
}
G_DEFINE_TYPE (NMSettingWireless, nm_setting_wireless, NM_TYPE_SETTING)
G_DEFINE_TYPE_WITH_CODE (NMSettingWireless, nm_setting_wireless, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_WIRELESS_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_WIRELESS_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRELESS)
#define NM_SETTING_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessPrivate))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment