aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/kerneldevice/mm-kernel-device-generic.c1
-rw-r--r--src/mm-plugin-manager.c1
-rw-r--r--src/mm-utils.c47
-rw-r--r--src/mm-utils.h14
5 files changed, 64 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index e80c10aa..05fc6d48 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -287,7 +287,7 @@ ModemManager_SOURCES = \
main.c \
mm-context.h \
mm-context.c \
- mm-utils.h \
+ mm-utils.h mm-utils.c \
mm-private-boxed-types.h \
mm-private-boxed-types.c \
mm-auth-provider.h \
diff --git a/src/kerneldevice/mm-kernel-device-generic.c b/src/kerneldevice/mm-kernel-device-generic.c
index d6798c6f..34285633 100644
--- a/src/kerneldevice/mm-kernel-device-generic.c
+++ b/src/kerneldevice/mm-kernel-device-generic.c
@@ -27,6 +27,7 @@
#include "mm-kernel-device-generic.h"
#include "mm-kernel-device-generic-rules.h"
#include "mm-log-object.h"
+#include "mm-utils.h"
#if !defined UDEVRULESDIR
# error UDEVRULESDIR is not defined
diff --git a/src/mm-plugin-manager.c b/src/mm-plugin-manager.c
index 6c9bdf1e..4e9f3008 100644
--- a/src/mm-plugin-manager.c
+++ b/src/mm-plugin-manager.c
@@ -28,6 +28,7 @@
#include "mm-plugin-manager.h"
#include "mm-plugin.h"
#include "mm-shared.h"
+#include "mm-utils.h"
#include "mm-log-object.h"
#define SHARED_PREFIX "libmm-shared"
diff --git a/src/mm-utils.c b/src/mm-utils.c
new file mode 100644
index 00000000..95fbb552
--- /dev/null
+++ b/src/mm-utils.c
@@ -0,0 +1,47 @@
+/* -*- 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:
+ *
+ * Singleton support imported from NetworkManager.
+ * (C) Copyright 2014 Red Hat, Inc.
+ *
+ * GPtrArray lookup with GEqualFunc imported from GLib 2.48
+ */
+
+#include "mm-utils.h"
+
+#if !GLIB_CHECK_VERSION(2,54,0)
+
+gboolean
+mm_ptr_array_find_with_equal_func (GPtrArray *haystack,
+ gconstpointer needle,
+ GEqualFunc equal_func,
+ guint *index_)
+{
+ guint i;
+
+ g_return_val_if_fail (haystack != NULL, FALSE);
+
+ if (equal_func == NULL)
+ equal_func = g_direct_equal;
+
+ for (i = 0; i < haystack->len; i++) {
+ if (equal_func (g_ptr_array_index (haystack, i), needle)) {
+ if (index_ != NULL)
+ *index_ = i;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+#endif
diff --git a/src/mm-utils.h b/src/mm-utils.h
index cdb123cd..613205a3 100644
--- a/src/mm-utils.h
+++ b/src/mm-utils.h
@@ -12,6 +12,8 @@
*
* Singleton support imported from NetworkManager.
* (C) Copyright 2014 Red Hat, Inc.
+ *
+ * GPtrArray lookup with GEqualFunc imported from GLib 2.48
*/
#ifndef MM_UTILS_H
@@ -78,4 +80,16 @@
} \
MM_DEFINE_SINGLETON_DESTRUCTOR(TYPE)
+
+#if !GLIB_CHECK_VERSION(2,54,0)
+
+/* Pointer Array lookup with a GEqualFunc, imported from GLib 2.54 */
+#define g_ptr_array_find_with_equal_func mm_ptr_array_find_with_equal_func
+gboolean mm_ptr_array_find_with_equal_func (GPtrArray *haystack,
+ gconstpointer needle,
+ GEqualFunc equal_func,
+ guint *index_);
+
+#endif
+
#endif /* MM_UTILS_H */