summaryrefslogtreecommitdiff
path: root/src/nm-dbus-object.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-03-13 10:14:06 +0100
committerThomas Haller <thaller@redhat.com>2018-03-13 11:29:18 +0100
commit57ab9fd60fc9ec3ab7bc3fcef40b1f003d614162 (patch)
tree6a1e175ab577236f566de1993a8a20ca87fb31a9 /src/nm-dbus-object.c
parent1e535789cfd8dbc94da1e4f6393d27ccc2a209fc (diff)
downloadNetworkManager-57ab9fd60fc9ec3ab7bc3fcef40b1f003d614162.tar.gz
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.
Diffstat (limited to 'src/nm-dbus-object.c')
-rw-r--r--src/nm-dbus-object.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/src/nm-dbus-object.c b/src/nm-dbus-object.c
index b8670041fb..cd3a23509e 100644
--- a/src/nm-dbus-object.c
+++ b/src/nm-dbus-object.c
@@ -56,36 +56,32 @@ G_DEFINE_ABSTRACT_TYPE (NMDBusObject, nm_dbus_object, G_TYPE_OBJECT);
static char *
_create_export_path (NMDBusObjectClass *klass)
{
- const char *class_export_path, *p;
- static GHashTable *prefix_counters;
- guint64 *counter;
-
- class_export_path = klass->export_path;
-
- nm_assert (class_export_path);
-
- p = strchr (class_export_path, '%');
- if (p) {
- if (G_UNLIKELY (!prefix_counters))
- prefix_counters = g_hash_table_new (nm_str_hash, g_str_equal);
-
- nm_assert (p[1] == 'l');
- nm_assert (p[2] == 'l');
- nm_assert (p[3] == 'u');
- nm_assert (p[4] == '\0');
-
- 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);
- }
+ nm_assert (NM_IS_DBUS_OBJECT_CLASS (klass));
+ nm_assert (klass->export_path.path);
+
+#if NM_MORE_ASSERTS
+ {
+ const char *p;
+
+ p = strchr (klass->export_path.path, '%');
+ if (klass->export_path.int_counter) {
+ nm_assert (p);
+ nm_assert (p[1] == 'l');
+ nm_assert (p[2] == 'l');
+ nm_assert (p[3] == 'u');
+ nm_assert (p[4] == '\0');
+ } else
+ nm_assert (!p);
+ }
+#endif
+ if (klass->export_path.int_counter) {
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
}
-
- return g_strdup (class_export_path);
+ return g_strdup (klass->export_path.path);
}
/**