diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-09-11 19:22:12 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:20 +0100 |
commit | 27e1d97aca340877db8f2b2181406b3ed8c06a5f (patch) | |
tree | e3017ebb9e432ee90606c01780a34d2135fb7316 /src | |
parent | a3ace206b08998e80891e783abbd2d7ca5add297 (diff) |
port-probe: new cache of Port Probe results
Whenever a plugin has probed for some information in a given port, that data
should be available for any other plugin wanting it during its own probing
process. This new cache of Port Probe results allows to easily retrieve the
already probed information.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/mm-port-probe-cache.c | 80 | ||||
-rw-r--r-- | src/mm-port-probe-cache.h | 30 |
3 files changed, 112 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 5ad5cec0..4c08b736 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -134,6 +134,8 @@ modem_manager_SOURCES = \ mm-port-probe.c \ mm-port-probe-at-command.h \ mm-port-probe-at-command.c \ + mm-port-probe-cache.h \ + mm-port-probe-cache.c \ mm-plugin.c \ mm-plugin.h \ mm-plugin-base.c \ diff --git a/src/mm-port-probe-cache.c b/src/mm-port-probe-cache.c new file mode 100644 index 00000000..113b5774 --- /dev/null +++ b/src/mm-port-probe-cache.c @@ -0,0 +1,80 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details: + * + * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org> + */ + +#include <glib.h> + +#include "mm-port-probe.h" +#include "mm-port-probe-cache.h" + +/* Cache of port probing objects */ +static GHashTable *cache; + +static gchar * +get_key (GUdevDevice *port) +{ + return g_strdup_printf ("%s%s", + g_udev_device_get_subsystem (port), + g_udev_device_get_name (port)); +} + +MMPortProbe * +mm_port_probe_cache_get (GUdevDevice *port, + const gchar *physdev_path, + const gchar *driver) +{ + MMPortProbe *probe = NULL; + gchar *key; + + key = get_key (port); + + if (G_UNLIKELY (!cache)) { + cache = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_object_unref); + } else { + probe = g_hash_table_lookup (cache, key); + } + + if (!probe) { + probe = mm_port_probe_new (port, physdev_path, driver); + g_hash_table_insert (cache, key, probe); + key = NULL; + } + + g_free (key); + return g_object_ref (probe); +} + +void +mm_port_probe_cache_remove (GUdevDevice *port) +{ + MMPortProbe *probe = NULL; + gchar *key; + + if (G_UNLIKELY (!cache)) + return; + + key = get_key (port); + probe = g_hash_table_lookup (cache, key); + if (probe) { + mm_port_probe_run_cancel (probe); + g_object_unref (probe); + } + g_hash_table_remove (cache, key); + g_free (key); +} + + diff --git a/src/mm-port-probe-cache.h b/src/mm-port-probe-cache.h new file mode 100644 index 00000000..86e8ab92 --- /dev/null +++ b/src/mm-port-probe-cache.h @@ -0,0 +1,30 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details: + * + * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org> + */ + +#ifndef MM_PORT_PROBE_CACHE_H +#define MM_PORT_PROBE_CACHE_H + +#include <glib.h> + +#include "mm-port-probe.h" + +MMPortProbe *mm_port_probe_cache_get (GUdevDevice *port, + const gchar *physdev_path, + const gchar *driver); + +void mm_port_probe_cache_remove (GUdevDevice *port); + +#endif /* MM_PORT_PROBE_CACHE_H */ + |