[gupnp] Service: Return error if autoconnect fails



commit 1708847496c3bbc9ab7a3850a084102d9a27b768
Author: Jens Georg <mail jensge org>
Date:   Thu Dec 30 15:18:08 2021 +0100

    Service: Return error if autoconnect fails
    
    Instead of aborting with g_error

 libgupnp/gupnp-error.c   | 17 +++++++++++++++++
 libgupnp/gupnp-error.h   | 17 +++++++++++++++++
 libgupnp/gupnp-service.c |  6 +++++-
 3 files changed, 39 insertions(+), 1 deletion(-)
---
diff --git a/libgupnp/gupnp-error.c b/libgupnp/gupnp-error.c
index b30c971..94d0791 100644
--- a/libgupnp/gupnp-error.c
+++ b/libgupnp/gupnp-error.c
@@ -125,6 +125,23 @@ gupnp_service_introspection_error_quark (void)
         return quark;
 }
 
+/**
+ * GUPNP_SERVICE_ERROR:
+ *
+ * The #GQuark uniquely used by GUPnP Service errors.
+ *
+ * Returns: a #GQuark uniquely used by GUPnP Service creation errors.
+ */
+GQuark
+gupnp_service_error_quark (void)
+{
+        static GQuark quark = 0;
+
+        if (!quark)
+                quark = g_quark_from_static_string ("gupnp-service-error");
+
+        return quark;
+}
 
 /* Soup status code => GUPnPServerError */
 static int
diff --git a/libgupnp/gupnp-error.h b/libgupnp/gupnp-error.h
index d3a7a43..2baa4ff 100644
--- a/libgupnp/gupnp-error.h
+++ b/libgupnp/gupnp-error.h
@@ -141,6 +141,23 @@ typedef enum
 {
         GUPNP_SERVICE_INTROSPECTION_ERROR_OTHER,
 } GUPnPServiceIntrospectionError;
+
+
+GQuark
+gupnp_service_error_quark (void) G_GNUC_CONST;
+
+#define GUPNP_SERVICE_ERROR                                      \
+(gupnp_service_introspection_error_quark ())
+
+/**
+ * GUPnPServiceError:
+ * @GUPNP_SERVICE_ERROR_AUTOCONNECT@: [method@GUPnP.Service.signals_autoconnect] failed
+ */
+typedef enum
+{
+        GUPNP_SERVICE_ERROR_AUTOCONNECT,
+} GUPnPServiceError;
+
 G_END_DECLS
 
 #endif /* GUPNP_ERROR_H */
diff --git a/libgupnp/gupnp-service.c b/libgupnp/gupnp-service.c
index 212b972..53811dd 100644
--- a/libgupnp/gupnp-service.c
+++ b/libgupnp/gupnp-service.c
@@ -1804,7 +1804,11 @@ gupnp_service_signals_autoconnect (GUPnPService *service,
         /* Get a handle on the main executable -- use this to find symbols */
         module = g_module_open (NULL, 0);
         if (module == NULL) {
-                g_error ("Failed to open module: %s", g_module_error ());
+                g_warning ("Failed to open module: %s", g_module_error ());
+                g_set_error (error,
+                             GUPNP_SERVICE_ERROR,
+                             GUPNP_SERVICE_ERROR_AUTOCONNECT,
+                             "Failed to open module: %s", g_module_error ());
 
                 return;
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]