Commit 57ab9fd6 authored by Thomas Haller's avatar Thomas Haller

core/dbus: rework creating numbered D-Bus export path by putting counter into class

I dislike the static hash table to cache the integer counter for
numbered paths. Let's instead cache the counter at the class instance
itself -- since the class contains the information how the export
path should be exported.

However, we cannot use a plain integer field inside the class structure,
because the class is copied between derived classes. For example,
NMDeviceEthernet and NMDeviceBridge both get a copy of the NMDeviceClass
instance. Hence, the class doesn't contain the counter directly, but
a pointer to one counter that can be shared between sibling classes.
parent 1e535789
...@@ -15269,7 +15269,7 @@ nm_device_class_init (NMDeviceClass *klass) ...@@ -15269,7 +15269,7 @@ nm_device_class_init (NMDeviceClass *klass)
g_type_class_add_private (object_class, sizeof (NMDevicePrivate)); g_type_class_add_private (object_class, sizeof (NMDevicePrivate));
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/Devices"); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/Devices");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_device, dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_device,
&nm_interface_info_device_statistics); &nm_interface_info_device_statistics);
......
...@@ -1391,7 +1391,7 @@ nm_wifi_ap_class_init (NMWifiAPClass *ap_class) ...@@ -1391,7 +1391,7 @@ nm_wifi_ap_class_init (NMWifiAPClass *ap_class)
GObjectClass *object_class = G_OBJECT_CLASS (ap_class); GObjectClass *object_class = G_OBJECT_CLASS (ap_class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (ap_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (ap_class);
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH_ACCESS_POINT); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH_ACCESS_POINT);
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_access_point); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_access_point);
object_class->get_property = get_property; object_class->get_property = get_property;
......
...@@ -2127,7 +2127,7 @@ nm_dns_manager_class_init (NMDnsManagerClass *klass) ...@@ -2127,7 +2127,7 @@ nm_dns_manager_class_init (NMDnsManagerClass *klass)
object_class->finalize = finalize; object_class->finalize = finalize;
object_class->get_property = get_property; object_class->get_property = get_property;
dbus_object_class->export_path = NM_DBUS_PATH "/DnsManager"; dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_STATIC (NM_DBUS_PATH "/DnsManager");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dns_manager); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dns_manager);
dbus_object_class->export_on_construction = TRUE; dbus_object_class->export_on_construction = TRUE;
......
...@@ -1447,7 +1447,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) ...@@ -1447,7 +1447,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
g_type_class_add_private (ac_class, sizeof (NMActiveConnectionPrivate)); g_type_class_add_private (ac_class, sizeof (NMActiveConnectionPrivate));
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/ActiveConnection"); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/ActiveConnection");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_active_connection); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_active_connection);
object_class->get_property = get_property; object_class->get_property = get_property;
......
...@@ -558,7 +558,7 @@ nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class) ...@@ -558,7 +558,7 @@ nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class)
GObjectClass *object_class = G_OBJECT_CLASS (checkpoint_class); GObjectClass *object_class = G_OBJECT_CLASS (checkpoint_class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (checkpoint_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (checkpoint_class);
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/Checkpoint"); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/Checkpoint");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_checkpoint); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_checkpoint);
object_class->dispose = dispose; object_class->dispose = dispose;
......
...@@ -56,36 +56,32 @@ G_DEFINE_ABSTRACT_TYPE (NMDBusObject, nm_dbus_object, G_TYPE_OBJECT); ...@@ -56,36 +56,32 @@ G_DEFINE_ABSTRACT_TYPE (NMDBusObject, nm_dbus_object, G_TYPE_OBJECT);
static char * static char *
_create_export_path (NMDBusObjectClass *klass) _create_export_path (NMDBusObjectClass *klass)
{ {
const char *class_export_path, *p; nm_assert (NM_IS_DBUS_OBJECT_CLASS (klass));
static GHashTable *prefix_counters; nm_assert (klass->export_path.path);
guint64 *counter;
#if NM_MORE_ASSERTS
class_export_path = klass->export_path; {
const char *p;
nm_assert (class_export_path);
p = strchr (klass->export_path.path, '%');
p = strchr (class_export_path, '%'); if (klass->export_path.int_counter) {
if (p) { nm_assert (p);
if (G_UNLIKELY (!prefix_counters)) nm_assert (p[1] == 'l');
prefix_counters = g_hash_table_new (nm_str_hash, g_str_equal); nm_assert (p[2] == 'l');
nm_assert (p[3] == 'u');
nm_assert (p[1] == 'l'); nm_assert (p[4] == '\0');
nm_assert (p[2] == 'l'); } else
nm_assert (p[3] == 'u'); nm_assert (!p);
nm_assert (p[4] == '\0'); }
#endif
counter = g_hash_table_lookup (prefix_counters, class_export_path);
if (!counter) {
counter = g_slice_new0 (guint64);
g_hash_table_insert (prefix_counters, (char *) class_export_path, counter);
}
if (klass->export_path.int_counter) {
NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral") NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
return g_strdup_printf (class_export_path, (unsigned long long) (++(*counter))); return g_strdup_printf (klass->export_path.path,
++(*klass->export_path.int_counter));
NM_PRAGMA_WARNING_REENABLE NM_PRAGMA_WARNING_REENABLE
} }
return g_strdup (klass->export_path.path);
return g_strdup (class_export_path);
} }
/** /**
......
...@@ -32,6 +32,38 @@ void nm_dbus_object_set_quitting (void); ...@@ -32,6 +32,38 @@ void nm_dbus_object_set_quitting (void);
/*****************************************************************************/ /*****************************************************************************/
typedef struct {
const char *path;
/* if path is of type NM_DBUS_EXPORT_PATH_NUMBERED(), we need a
* per-class counter when generating a new numbered path.
*
* Each NMDBusObjectClass instance has a shallow clone of the NMDBusObjectClass parent
* instance in every derived type. Hence we cannot embed the counter there directly,
* because it must be shared, e.g. between NMDeviceBond and NMDeviceEthernet.
* Make int_counter a pointer to the actual counter that is used by ever sibling
* class. */
long long unsigned *int_counter;
} NMDBusExportPath;
#define NM_DBUS_EXPORT_PATH_STATIC(basepath) \
({ \
((NMDBusExportPath) { \
.path = ""basepath"", \
}); \
})
#define NM_DBUS_EXPORT_PATH_NUMBERED(basepath) \
({ \
static long long unsigned _int_counter = 0; \
((NMDBusExportPath) { \
.path = ""basepath"/%llu", \
.int_counter = &_int_counter, \
}); \
})
/*****************************************************************************/
/* "org.freedesktop.NetworkManager.Device.Statistics" is a special interface, /* "org.freedesktop.NetworkManager.Device.Statistics" is a special interface,
* because although it has a legacy PropertiesChanged signal, it only notifies * because although it has a legacy PropertiesChanged signal, it only notifies
* about properties that actually exist on that interface. That is, because it * about properties that actually exist on that interface. That is, because it
...@@ -82,7 +114,7 @@ struct _NMDBusObject { ...@@ -82,7 +114,7 @@ struct _NMDBusObject {
typedef struct { typedef struct {
GObjectClass parent; GObjectClass parent;
const char *export_path; NMDBusExportPath export_path;
const NMDBusInterfaceInfoExtended *const*interface_infos; const NMDBusInterfaceInfoExtended *const*interface_infos;
......
...@@ -23,10 +23,6 @@ ...@@ -23,10 +23,6 @@
/*****************************************************************************/ /*****************************************************************************/
#define NM_EXPORT_PATH_NUMBERED(basepath) ""basepath"/%llu"
/*****************************************************************************/
struct _NMDBusInterfaceInfoExtended; struct _NMDBusInterfaceInfoExtended;
struct _NMDBusMethodInfoExtended; struct _NMDBusMethodInfoExtended;
......
...@@ -167,7 +167,7 @@ nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class) ...@@ -167,7 +167,7 @@ nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class)
object_class->get_property = get_property; object_class->get_property = get_property;
object_class->finalize = finalize; object_class->finalize = finalize;
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP4Config"); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP4Config");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dhcp4_config); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dhcp4_config);
dbus_object_class->export_on_construction = TRUE; dbus_object_class->export_on_construction = TRUE;
......
...@@ -165,7 +165,7 @@ nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class) ...@@ -165,7 +165,7 @@ nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class)
object_class->get_property = get_property; object_class->get_property = get_property;
object_class->finalize = finalize; object_class->finalize = finalize;
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP6Config"); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP6Config");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dhcp6_config); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dhcp6_config);
dbus_object_class->export_on_construction = TRUE; dbus_object_class->export_on_construction = TRUE;
......
...@@ -3240,7 +3240,7 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class) ...@@ -3240,7 +3240,7 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
GObjectClass *object_class = G_OBJECT_CLASS (config_class); GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (config_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (config_class);
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/IP4Config"); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/IP4Config");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_ip4_config); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_ip4_config);
object_class->get_property = get_property; object_class->get_property = get_property;
......
...@@ -2800,7 +2800,7 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class) ...@@ -2800,7 +2800,7 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
GObjectClass *object_class = G_OBJECT_CLASS (config_class); GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (config_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (config_class);
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/IP6Config"); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/IP6Config");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_ip6_config); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_ip6_config);
object_class->get_property = get_property; object_class->get_property = get_property;
......
...@@ -7047,7 +7047,7 @@ nm_manager_class_init (NMManagerClass *manager_class) ...@@ -7047,7 +7047,7 @@ nm_manager_class_init (NMManagerClass *manager_class)
GObjectClass *object_class = G_OBJECT_CLASS (manager_class); GObjectClass *object_class = G_OBJECT_CLASS (manager_class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (manager_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (manager_class);
dbus_object_class->export_path = NM_DBUS_PATH; dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_STATIC (NM_DBUS_PATH);
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_manager); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_manager);
object_class->constructed = constructed; object_class->constructed = constructed;
......
...@@ -1419,7 +1419,7 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) ...@@ -1419,7 +1419,7 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class)
object_class->get_property = get_property; object_class->get_property = get_property;
object_class->set_property = set_property; object_class->set_property = set_property;
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/PPP"); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/PPP");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_ppp); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_ppp);
obj_properties[PROP_PARENT_IFACE] = obj_properties[PROP_PARENT_IFACE] =
......
...@@ -1687,7 +1687,7 @@ nm_agent_manager_class_init (NMAgentManagerClass *agent_manager_class) ...@@ -1687,7 +1687,7 @@ nm_agent_manager_class_init (NMAgentManagerClass *agent_manager_class)
GObjectClass *object_class = G_OBJECT_CLASS (agent_manager_class); GObjectClass *object_class = G_OBJECT_CLASS (agent_manager_class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (agent_manager_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (agent_manager_class);
dbus_object_class->export_path = NM_DBUS_PATH_AGENT_MANAGER; dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_STATIC (NM_DBUS_PATH_AGENT_MANAGER);
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_agent_manager); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_agent_manager);
object_class->constructed = constructed; object_class->constructed = constructed;
......
...@@ -3181,7 +3181,7 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *klass) ...@@ -3181,7 +3181,7 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *klass)
g_type_class_add_private (klass, sizeof (NMSettingsConnectionPrivate)); g_type_class_add_private (klass, sizeof (NMSettingsConnectionPrivate));
dbus_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH_SETTINGS); dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH_SETTINGS);
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_settings_connection); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_settings_connection);
object_class->constructed = constructed; object_class->constructed = constructed;
......
...@@ -2080,7 +2080,7 @@ nm_settings_class_init (NMSettingsClass *class) ...@@ -2080,7 +2080,7 @@ nm_settings_class_init (NMSettingsClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class); GObjectClass *object_class = G_OBJECT_CLASS (class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (class);
dbus_object_class->export_path = NM_DBUS_PATH_SETTINGS; dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_STATIC (NM_DBUS_PATH_SETTINGS);
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_settings); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_settings);
object_class->get_property = get_property; object_class->get_property = get_property;
......
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