summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/NetworkManagerUtils.c33
-rw-r--r--src/NetworkManagerUtils.h25
2 files changed, 58 insertions, 0 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index d78313df5..d5bb6c87f 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -110,6 +110,39 @@ _nm_utils_set_testing (NMUtilsTestFlags flags)
/*****************************************************************************/
+G_DEFINE_QUARK (nm-utils-error-quark, nm_utils_error)
+
+void
+nm_utils_error_set_cancelled (GError **error,
+ gboolean is_disposing,
+ const char *instance_name)
+{
+ if (is_disposing) {
+ g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_CANCELLED_DISPOSING,
+ "Disposing %s instance",
+ instance_name && *instance_name ? instance_name : "source");
+ } else {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
+ "Request cancelled");
+ }
+}
+
+gboolean
+nm_utils_error_is_cancelled (GError *error,
+ gboolean consider_is_disposing)
+{
+ if (error) {
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ return TRUE;
+ if ( consider_is_disposing
+ && g_error_matches (error, NM_UTILS_ERROR, NM_UTILS_ERROR_CANCELLED_DISPOSING))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/*****************************************************************************/
+
static GSList *_singletons = NULL;
static gboolean _singletons_shutdown = FALSE;
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index df4b35b14..3af93e5a0 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -89,6 +89,31 @@ GETTER (void) \
/*****************************************************************************/
+/**
+ * NMUtilsError:
+ * @NM_UTILS_ERROR_UNKNOWN: unknown or unclassified error
+ * @NM_UTILS_ERROR_CANCELLED_DISPOSING: when disposing an object that has
+ * pending aynchronous operations, the operation is cancelled with this
+ * error reason. Depending on the usage, this might indicate a bug because
+ * usually the target object should stay alive as long as there are pending
+ * operations.
+ */
+typedef enum {
+ NM_UTILS_ERROR_UNKNOWN = 0, /*< nick=Unknown >*/
+ NM_UTILS_ERROR_CANCELLED_DISPOSING, /*< nick=CancelledDisposing >*/
+} NMUtilsError;
+
+#define NM_UTILS_ERROR (nm_utils_error_quark ())
+GQuark nm_utils_error_quark (void);
+
+void nm_utils_error_set_cancelled (GError **error,
+ gboolean is_disposing,
+ const char *instance_name);
+gboolean nm_utils_error_is_cancelled (GError *error,
+ gboolean consider_is_disposing);
+
+/*****************************************************************************/
+
gboolean nm_ethernet_address_is_valid (gconstpointer addr, gssize len);
in_addr_t nm_utils_ip4_address_clear_host_address (in_addr_t addr, guint8 plen);