shared: move NM_UTILS_ERROR to shared-utils
authorThomas Haller <thaller@redhat.com>
Fri, 18 Mar 2016 12:59:57 +0000 (13:59 +0100)
committerThomas Haller <thaller@redhat.com>
Sat, 26 Mar 2016 11:10:53 +0000 (12:10 +0100)
NM_UTILS_ERROR is our way to say, that we don't care about
the GError domain and code. nmcli sometimes passes domain "1"
and code "0" to g_set_error(), which could be considered
a bug.

We usually don't care about the error but only about the error
message, so let's have a universally available error quark around.

shared/nm-shared-utils.c
shared/nm-shared-utils.h
src/nm-core-utils.c
src/nm-core-utils.h

index b80b9f2..57b979b 100644 (file)
@@ -101,3 +101,36 @@ _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 ma
 }
 
 /*****************************************************************************/
+
+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;
+}
+
+/*****************************************************************************/
index 943e467..2942fe9 100644 (file)
@@ -28,4 +28,29 @@ gint64 _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gi
 
 /******************************************************************************/
 
+/**
+ * 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);
+
+/******************************************************************************/
+
 #endif /* __NM_SHARED_UTILS_H__ */
index 1a6d00f..b98b6e8 100644 (file)
@@ -109,39 +109,6 @@ _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;
 
index 2fb5273..f77b43e 100644 (file)
@@ -91,31 +91,6 @@ 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);
-
-/*****************************************************************************/
-
 gint nm_utils_ascii_str_to_bool (const char *str,
                                  gint default_value);