[telepathy-mission-control/master] mcd-dbusprop: make mcd_dbusprop_set_property, get_property return a boolean

Simon McVittie simon.mcvittie at collabora.co.uk
Tue May 5 07:00:25 PDT 2009


It's generally bad practice for the only indication of error or not to be
whether a GError was written through a GError** - you're meant to be able
to pass NULL if you don't care which error it was, and still see whether
it's success or failure.
---
 src/mcd-dbusprop.c |   18 ++++++++++--------
 src/mcd-dbusprop.h |   20 ++++++++++----------
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/mcd-dbusprop.c b/src/mcd-dbusprop.c
index 4fb2d24..d0afb6e 100644
--- a/src/mcd-dbusprop.c
+++ b/src/mcd-dbusprop.c
@@ -68,7 +68,7 @@ get_interface_properties (TpSvcDBusProperties *object, const gchar *interface)
     return NULL;
 }
 
-void
+gboolean
 mcd_dbusprop_set_property (TpSvcDBusProperties *self,
 			   const gchar *interface_name,
 			   const gchar *property_name,
@@ -84,7 +84,7 @@ mcd_dbusprop_set_property (TpSvcDBusProperties *self,
     {
 	g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
 		     "invalid interface: %s", interface_name);
-	return;
+	return FALSE;
     }
 
     /* look for our property */
@@ -95,18 +95,19 @@ mcd_dbusprop_set_property (TpSvcDBusProperties *self,
     {
 	g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
 		     "invalid property: %s", property_name);
-	return;
+	return FALSE;
     }
 
     if (!property->setprop)
     {
 	g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
 		     "property %s cannot be written", property_name);
-	return;
+	return FALSE;
     }
     /* we pass property->name, because we know it's a static value and there
      * will be no need to care about its lifetime */
     property->setprop (self, property->name, value);
+    return TRUE;
 }
 
 void
@@ -130,7 +131,7 @@ dbusprop_set (TpSvcDBusProperties *self,
     tp_svc_dbus_properties_return_from_set (context);
 }
 
-void
+gboolean
 mcd_dbusprop_get_property (TpSvcDBusProperties *self,
 			   const gchar *interface_name,
 			   const gchar *property_name,
@@ -144,7 +145,7 @@ mcd_dbusprop_get_property (TpSvcDBusProperties *self,
     {
 	g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
 		     "invalid interface: %s", interface_name);
-	return;
+	return FALSE;
     }
 
     /* look for our property */
@@ -155,16 +156,17 @@ mcd_dbusprop_get_property (TpSvcDBusProperties *self,
     {
 	g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
 		     "invalid property: %s", property_name);
-	return;
+	return FALSE;
     }
 
     if (!property->getprop)
     {
 	g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
 		     "property %s cannot be read", property_name);
-	return;
+	return FALSE;
     }
     property->getprop (self, property_name, value);
+    return TRUE;
 }
 
 void
diff --git a/src/mcd-dbusprop.h b/src/mcd-dbusprop.h
index 4d671f4..a109454 100644
--- a/src/mcd-dbusprop.h
+++ b/src/mcd-dbusprop.h
@@ -77,16 +77,16 @@ void mcd_dbus_init_interfaces (GType g_define_type_id,
 
 void mcd_dbus_init_interfaces_instances (gpointer self);
 
-void mcd_dbusprop_set_property (TpSvcDBusProperties *self,
-				const gchar *interface_name,
-				const gchar *property_name,
-				const GValue *value,
-				GError **error);
-void mcd_dbusprop_get_property (TpSvcDBusProperties *self,
-				const gchar *interface_name,
-				const gchar *property_name,
-				GValue *value,
-				GError **error);
+gboolean mcd_dbusprop_set_property (TpSvcDBusProperties *self,
+                                    const gchar *interface_name,
+                                    const gchar *property_name,
+                                    const GValue *value,
+                                    GError **error);
+gboolean mcd_dbusprop_get_property (TpSvcDBusProperties *self,
+                                    const gchar *interface_name,
+                                    const gchar *property_name,
+                                    GValue *value,
+                                    GError **error);
 
 void dbusprop_set (TpSvcDBusProperties *self,
 		   const gchar *interface_name,
-- 
1.5.6.5




More information about the telepathy-commits mailing list