[Galago-commits] r2319 - in trunk/libgalago: . libgalago tests

galago-commits at freedesktop.org galago-commits at freedesktop.org
Sat Nov 19 15:00:28 PST 2005


Author: chipx86
Date: 2005-11-19 15:00:10 -0800 (Sat, 19 Nov 2005)
New Revision: 2319

Added:
   trunk/libgalago/tests/get-property.c
Modified:
   trunk/libgalago/ChangeLog
   trunk/libgalago/libgalago/galago-core.c
   trunk/libgalago/libgalago/galago-person.c
   trunk/libgalago/libgalago/galago.h
   trunk/libgalago/tests/Makefile.am
Log:
- The values of a property are now encased in a D-BUS VARIANT type.
- Added a get-property tool.


Modified: trunk/libgalago/ChangeLog
===================================================================
--- trunk/libgalago/ChangeLog	2005-11-16 04:45:29 UTC (rev 2318)
+++ trunk/libgalago/ChangeLog	2005-11-19 23:00:10 UTC (rev 2319)
@@ -1,3 +1,13 @@
+Sat Nov 19 14:59:05 PST 2005  Christian Hammond <chipx86 at chipx86.com>
+
+	* libgalago/galago-core.c:
+	* libgalago/galago-person.c:
+	* libgalago/galago.h:
+	* tests/Makefile.am:
+	A tests/get-property.c:
+	  - The values of a property are now encased in a D-BUS VARIANT type.
+	  - Added a get-property tool.
+
 Tue Nov 15 19:57:04 PST 2005  Christian Hammond <chipx86 at chipx86.com>
 
 	* libgalago/galago-account.c:

Modified: trunk/libgalago/libgalago/galago-core.c
===================================================================
--- trunk/libgalago/libgalago/galago-core.c	2005-11-16 04:45:29 UTC (rev 2318)
+++ trunk/libgalago/libgalago/galago-core.c	2005-11-19 23:00:10 UTC (rev 2319)
@@ -570,31 +570,47 @@
 
 		if (person != NULL)
 		{
+			DBusMessageIter value_iter;
 			int arg_type;
 
 			dbus_message_iter_get_basic(&iter, &name);
 			dbus_message_iter_next(&iter);
 
+			dbus_message_iter_recurse(&iter, &value_iter);
+
 			arg_type = dbus_message_iter_get_arg_type(&iter);
 
-			if (arg_type == DBUS_TYPE_STRING)
+			switch (arg_type)
 			{
-				const char *value;
-				dbus_message_iter_get_basic(&iter, &value);
-				galago_person_set_property_string(person, name, value);
+				case DBUS_TYPE_STRING:
+				{
+					const char *value;
+					dbus_message_iter_get_basic(&value_iter, &value);
+					galago_person_set_property_string(person, name, value);
+					break;
+				}
+
+				case DBUS_TYPE_BOOLEAN:
+				{
+					gboolean value;
+					dbus_message_iter_get_basic(&value_iter, &value);
+					galago_person_set_property_bool(person, name, value);
+					break;
+				}
+
+				case DBUS_TYPE_UINT32:
+				{
+					dbus_uint32_t value;
+					dbus_message_iter_get_basic(&value_iter, &value);
+					galago_person_set_property_uint32(person, name, value);
+					break;
+				}
+
+				default:
+					galago_log_warning("Invalid property type %d passed to "
+									   "SetProperty\n", arg_type);
+					break;
 			}
-			else if (arg_type == DBUS_TYPE_BOOLEAN)
-			{
-				gboolean value;
-				dbus_message_iter_get_basic(&iter, &value);
-				galago_person_set_property_bool(person, name, value);
-			}
-			else if (arg_type == DBUS_TYPE_UINT32)
-			{
-				dbus_uint32_t value;
-				dbus_message_iter_get_basic(&iter, &value);
-				galago_person_set_property_uint32(person, name, value);
-			}
 		}
 	}
 	else if (dbus_message_is_signal(message, GALAGO_DBUS_PERSON_INTERFACE,

Modified: trunk/libgalago/libgalago/galago-person.c
===================================================================
--- trunk/libgalago/libgalago/galago-person.c	2005-11-16 04:45:29 UTC (rev 2318)
+++ trunk/libgalago/libgalago/galago-person.c	2005-11-19 23:00:10 UTC (rev 2319)
@@ -531,10 +531,8 @@
 
 		return (num_accounts > 0);
 	}
-	else
-	{
-		return (galago_person_get_accounts(person, query) != NULL);
-	}
+
+	return galago_person_get_accounts(person, query) != NULL;
 }
 
 GList *
@@ -764,8 +762,8 @@
 	value_type = galago_value_get_type(value);
 
 	g_return_if_fail(value_type == GALAGO_VALUE_TYPE_STRING  ||
-						  value_type == GALAGO_VALUE_TYPE_BOOLEAN ||
-						  IS_TYPE_INTEGER(value_type));
+					 value_type == GALAGO_VALUE_TYPE_BOOLEAN ||
+					 IS_TYPE_INTEGER(value_type));
 
 	if (person->priv->properties_table == NULL)
 	{
@@ -916,47 +914,70 @@
 _galago_dbus_person_set_property(GalagoPerson *person, const char *name,
 								 GalagoValue *value)
 {
-	GalagoValue *new_value;
+	DBusMessage *message;
+	DBusMessageIter iter, value_iter;
 	GalagoType type;
+	gboolean success = TRUE;
 
 	if (!galago_is_connected() || !galago_is_feed())
 		return;
 
 	type = galago_value_get_type(value);
 
+	message = galago_dbus_message_new_method_call(GALAGO_OBJECT(person),
+												  "SetProperty", FALSE,
+												  &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
 	switch (type)
 	{
 		case GALAGO_VALUE_TYPE_STRING:
 		{
 			const char *str = galago_value_get_string(value);
-			new_value = galago_value_new(GALAGO_VALUE_TYPE_STRING, &str, NULL);
+			dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+											 DBUS_TYPE_STRING_AS_STRING,
+											 &value_iter);
+			dbus_message_iter_append_basic(&value_iter,
+										   DBUS_TYPE_STRING, &str);
+			dbus_message_iter_close_container(&iter, &value_iter);
 			break;
 		}
 
 		case GALAGO_VALUE_TYPE_BOOLEAN:
 		{
 			gboolean b = galago_value_get_boolean(value);
-			new_value = galago_value_new(GALAGO_VALUE_TYPE_BOOLEAN, &b, NULL);
+			dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+											 DBUS_TYPE_BOOLEAN_AS_STRING,
+											 &value_iter);
+			dbus_message_iter_append_basic(&value_iter,
+										   DBUS_TYPE_BOOLEAN, &b);
+			dbus_message_iter_close_container(&iter, &value_iter);
 			break;
 		}
 
 		case GALAGO_VALUE_TYPE_UINT:
 		{
 			unsigned int i = galago_value_get_uint(value);
-			new_value = galago_value_new(GALAGO_VALUE_TYPE_UINT, &i, NULL);
+			dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+											 DBUS_TYPE_UINT32_AS_STRING,
+											 &value_iter);
+			dbus_message_iter_append_basic(&value_iter,
+										   DBUS_TYPE_UINT32, &i);
+			dbus_message_iter_close_container(&iter, &value_iter);
 			break;
 		}
 
 		default:
 			galago_log_error("Unknown property type %d for property %s\n",
 							 type, name);
+			success = FALSE;
 			return;
 	}
 
-	galago_dbus_send_message(GALAGO_OBJECT(person), "SetProperty",
-							 galago_value_new(GALAGO_VALUE_TYPE_STRING,
-											  &name, NULL),
-							 new_value, NULL);
+	if (success)
+		dbus_connection_send(galago_get_dbus_conn(), message, NULL);
+
+	dbus_message_unref(message);
 }
 
 static GalagoValue *

Modified: trunk/libgalago/libgalago/galago.h
===================================================================
--- trunk/libgalago/libgalago/galago.h	2005-11-16 04:45:29 UTC (rev 2318)
+++ trunk/libgalago/libgalago/galago.h	2005-11-19 23:00:10 UTC (rev 2319)
@@ -33,5 +33,6 @@
 #include <libgalago/galago-presence.h>
 #include <libgalago/galago-service.h>
 #include <libgalago/galago-status.h>
+#include <libgalago/galago-value.h>
 
 #endif /* _GALAGO_H_ */

Modified: trunk/libgalago/tests/Makefile.am
===================================================================
--- trunk/libgalago/tests/Makefile.am	2005-11-16 04:45:29 UTC (rev 2318)
+++ trunk/libgalago/tests/Makefile.am	2005-11-19 23:00:10 UTC (rev 2319)
@@ -7,6 +7,7 @@
 noinst_PROGRAMS = \
 	get-avatar \
 	get-presence \
+	get-property \
 	monitor \
 	presence-feed \
 	presence-feed-2 \
@@ -23,6 +24,9 @@
 get_presence_SOURCES = get-presence.c
 get_presence_LDADD   = $(common_ldflags)
 
+get_property_SOURCES = get-property.c
+get_property_LDADD   = $(common_ldflags)
+
 monitor_SOURCES = monitor.c
 monitor_LDADD   = $(common_ldflags)
 

Added: trunk/libgalago/tests/get-property.c
===================================================================
--- trunk/libgalago/tests/get-property.c	2005-11-16 04:45:29 UTC (rev 2318)
+++ trunk/libgalago/tests/get-property.c	2005-11-19 23:00:10 UTC (rev 2319)
@@ -0,0 +1,79 @@
+/**
+ * @file get-property.c Queries the property of a person.
+ *
+ * @Copyright (C) 2004-2005 Christian Hammond
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA  02111-1307  USA
+ */
+#include <libgalago/galago.h>
+#include <stdio.h>
+
+int
+main(int argc, char **argv)
+{
+	char *person_id, *prop_name;
+	GalagoPerson *person;
+	const GalagoValue *property;
+
+	if (argc != 3)
+	{
+		fprintf(stderr, "Usage: get-property person-id property\n");
+		exit(1);
+	}
+
+	person_id = argv[1];
+	prop_name = argv[2];
+
+	galago_init("get_property", FALSE);
+
+	person = galago_get_person(person_id, GALAGO_REMOTE, TRUE);
+
+	if (person == NULL)
+	{
+		fprintf(stderr, "Unknown person %s\n", person_id);
+		exit(1);
+	}
+
+	property = galago_person_get_property(person, prop_name);
+
+	if (property == NULL)
+	{
+		fprintf(stderr, "Property '%s' is not set\n", prop_name);
+		exit(1);
+	}
+
+	switch (galago_value_get_type(property))
+	{
+		case GALAGO_VALUE_TYPE_STRING:
+			printf("%s\n", galago_value_get_string(property));
+			break;
+
+		case GALAGO_VALUE_TYPE_BOOLEAN:
+			printf("%s\n",
+				   galago_value_get_boolean(property) ? "true" : "false");
+			break;
+
+		case GALAGO_VALUE_TYPE_UINT:
+			printf("%d\n", galago_value_get_uint(property));
+			break;
+
+		default:
+			fprintf(stderr, "Unknown property type returned\n");
+			break;
+	}
+
+	return 0;
+}



More information about the galago-commits mailing list