[Galago-commits] r2375 - in trunk/galago-daemon: . src
galago-commits at freedesktop.org
galago-commits at freedesktop.org
Wed Dec 14 00:28:11 PST 2005
Author: chipx86
Date: 2005-12-14 00:28:08 -0800 (Wed, 14 Dec 2005)
New Revision: 2375
Modified:
trunk/galago-daemon/ChangeLog
trunk/galago-daemon/src/person.c
trunk/galago-daemon/src/utils.c
trunk/galago-daemon/src/utils.h
Log:
Updated to move to the Object Attributes model.
Modified: trunk/galago-daemon/ChangeLog
===================================================================
--- trunk/galago-daemon/ChangeLog 2005-12-14 08:27:23 UTC (rev 2374)
+++ trunk/galago-daemon/ChangeLog 2005-12-14 08:28:08 UTC (rev 2375)
@@ -1,3 +1,10 @@
+Wed Dec 14 00:27:46 PST 2005 Christian Hammond <chipx86 at chipx86.com>
+
+ * src/person.c:
+ * src/utils.c:
+ * src/utils.h:
+ - Updated to move to the Object Attributes model.
+
Sun Dec 04 03:08:38 PST 2005 Christian Hammond <chipx86 at chipx86.com>
D src/image.c:
Modified: trunk/galago-daemon/src/person.c
===================================================================
--- trunk/galago-daemon/src/person.c 2005-12-14 08:27:23 UTC (rev 2374)
+++ trunk/galago-daemon/src/person.c 2005-12-14 08:28:08 UTC (rev 2375)
@@ -60,220 +60,38 @@
}
static DBusHandlerResult
-person_set_property(DBusConnection *dbus_conn, DBusMessage *message,
- GalagodCoCo *coco, GalagoPerson *person)
+person_set_attribute(DBusConnection *dbus_conn, DBusMessage *message,
+ GalagodCoCo *coco, GalagoPerson *person)
{
- GalagodMetaPerson *meta_person;
- GalagoPerson *main_person;
- const char *name;
- DBusMessage *signal;
- DBusMessageIter iter, value_iter;
- DBusMessageIter signal_iter, signal_value_iter;
- int arg_type;
- gboolean success = TRUE;
+ GalagoPerson *main_person =
+ galagod_meta_person_get_person(GALAGOD_META_PERSON(person));
- meta_person = GALAGOD_META_PERSON(person);
- main_person = galagod_meta_person_get_person(meta_person);
-
- dbus_message_iter_init(message, &iter);
-
- signal = dbus_message_new_signal(
- galago_object_get_dbus_path(GALAGO_OBJECT(main_person)),
- GALAGO_DBUS_PERSON_INTERFACE,
- "PropertySet");
- dbus_message_iter_init_append(signal, &signal_iter);
-
- dbus_message_iter_get_basic(&iter, &name);
- dbus_message_iter_next(&iter);
-
- dbus_message_iter_append_basic(&signal_iter, DBUS_TYPE_STRING, &name);
-
- dbus_message_iter_recurse(&iter, &value_iter);
- arg_type = dbus_message_iter_get_arg_type(&value_iter);
-
- switch (arg_type)
- {
- case DBUS_TYPE_STRING:
- {
- const char *value;
- dbus_message_iter_get_basic(&value_iter, &value);
- galago_person_set_property_string(main_person, name, value);
- dbus_message_iter_open_container(&signal_iter, DBUS_TYPE_VARIANT,
- DBUS_TYPE_STRING_AS_STRING,
- &signal_value_iter);
- dbus_message_iter_append_basic(&signal_value_iter,
- DBUS_TYPE_STRING, &value);
- dbus_message_iter_close_container(&signal_iter,
- &signal_value_iter);
- break;
- }
-
- case DBUS_TYPE_BOOLEAN:
- {
- gboolean value;
- dbus_message_iter_get_basic(&value_iter, &value);
- galago_person_set_property_bool(main_person, name, value);
- dbus_message_iter_open_container(&signal_iter, DBUS_TYPE_VARIANT,
- DBUS_TYPE_BOOLEAN_AS_STRING,
- &signal_value_iter);
- dbus_message_iter_append_basic(&signal_value_iter,
- DBUS_TYPE_BOOLEAN, &value);
- dbus_message_iter_close_container(&signal_iter,
- &signal_value_iter);
- break;
- }
-
- case DBUS_TYPE_UINT32:
- {
- dbus_uint32_t value;
- dbus_message_iter_get_basic(&value_iter, &value);
- galago_person_set_property_uint32(main_person, name, value);
- dbus_message_iter_open_container(&signal_iter, DBUS_TYPE_VARIANT,
- DBUS_TYPE_UINT32_AS_STRING,
- &signal_value_iter);
- dbus_message_iter_append_basic(&signal_value_iter,
- DBUS_TYPE_UINT32, &value);
- dbus_message_iter_close_container(&signal_iter,
- &signal_value_iter);
- break;
- }
-
- default:
- g_warning("Invalid property type %d passed to "
- "SetProperty", arg_type);
- success = FALSE;
- break;
- }
-
- if (success)
- dbus_connection_send(dbus_conn, signal, NULL);
-
- dbus_message_unref(signal);
-
- galagod_dbus_send_empty_reply(dbus_conn, message);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return common_object_set_attribute(dbus_conn, message,
+ GALAGO_DBUS_PERSON_INTERFACE,
+ GALAGO_OBJECT(main_person));
}
static DBusHandlerResult
-person_remove_property(DBusConnection *dbus_conn, DBusMessage *message,
- GalagodCoCo *coco, GalagoPerson *person)
+person_remove_attribute(DBusConnection *dbus_conn, DBusMessage *message,
+ GalagodCoCo *coco, GalagoPerson *person)
{
- GalagodMetaPerson *meta_person;
- GalagoPerson *main_person;
- const char *name;
- DBusMessage *signal;
- DBusMessageIter iter, signal_iter;
+ GalagoPerson *main_person =
+ galagod_meta_person_get_person(GALAGOD_META_PERSON(person));
- dbus_message_iter_init(message, &iter);
- dbus_message_iter_get_basic(&iter, &name);
-
- meta_person = GALAGOD_META_PERSON(person);
- main_person = galagod_meta_person_get_person(meta_person);
-
- galago_person_remove_property(main_person, name);
-
- galagod_dbus_send_empty_reply(dbus_conn, message);
-
- /* Emit the signal */
- signal = dbus_message_new_signal(
- galago_object_get_dbus_path(GALAGO_OBJECT(main_person)),
- GALAGO_DBUS_PERSON_INTERFACE,
- "PropertyUnset");
- dbus_message_iter_init_append(signal, &signal_iter);
- dbus_message_iter_append_basic(&signal_iter, DBUS_TYPE_STRING, &name);
- dbus_connection_send(dbus_conn, signal, NULL);
- dbus_message_unref(signal);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return common_object_remove_attribute(dbus_conn, message,
+ GALAGO_DBUS_PERSON_INTERFACE,
+ GALAGO_OBJECT(main_person));
}
static DBusHandlerResult
-person_get_property(DBusConnection *dbus_conn, DBusMessage *message,
- GalagodCoCo *coco, GalagoPerson *person)
+person_get_attribute(DBusConnection *dbus_conn, DBusMessage *message,
+ GalagodCoCo *coco, GalagoPerson *person)
{
- GalagodMetaPerson *meta_person;
- GalagoPerson *main_person;
- const GalagoValue *value;
- char *name;
- DBusMessageIter iter;
- DBusMessage *reply = NULL;
+ GalagoPerson *main_person =
+ galagod_meta_person_get_person(GALAGOD_META_PERSON(person));
- dbus_message_iter_init(message, &iter);
- dbus_message_iter_get_basic(&iter, &name);
-
- meta_person = GALAGOD_META_PERSON(person);
- main_person = galagod_meta_person_get_person(meta_person);
-
- value = galago_person_get_property(main_person, name);
-
- if (value == NULL)
- {
- reply = dbus_message_new_error_printf(message,
- GALAGO_DBUS_ERROR_INVALID_PROPERTY,
- "The property \"%s\" is invalid.", name);
- }
- else
- {
- DBusMessageIter value_iter;
- GalagoType type = galago_value_get_type(value);
-
- reply = dbus_message_new_method_return(message);
- dbus_message_iter_init_append(reply, &iter);
-
- switch (type)
- {
- case GALAGO_VALUE_TYPE_STRING:
- {
- const char *str = galago_value_get_string(value);
- 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);
- 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:
- {
- dbus_uint32_t i = galago_value_get_uint(value);
- 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:
- /* This should never happen. */
- g_warning("Unknown property type %d for property %s",
- type, name);
- break;
- }
- }
-
- if (reply != NULL)
- {
- dbus_connection_send(dbus_conn, reply, NULL);
- dbus_message_unref(reply);
- }
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return common_object_get_attribute(dbus_conn, message,
+ GALAGO_OBJECT(main_person));
}
static DBusHandlerResult
@@ -453,9 +271,9 @@
static const GalagodCommand commands[] =
{
- GALAGOD_COMMAND("SetProperty", person_set_property),
- GALAGOD_COMMAND("RemoveProperty", person_remove_property),
- GALAGOD_COMMAND("GetProperty", person_get_property),
+ GALAGOD_COMMAND("SetAttribute", person_set_attribute),
+ GALAGOD_COMMAND("RemoveAttribute", person_remove_attribute),
+ GALAGOD_COMMAND("GetAttribute", person_get_attribute),
GALAGOD_COMMAND("GetAccount", person_get_account),
GALAGOD_COMMAND("GetAccounts", person_get_accounts),
GALAGOD_COMMAND("GetAccountsCount", person_get_accounts_count),
Modified: trunk/galago-daemon/src/utils.c
===================================================================
--- trunk/galago-daemon/src/utils.c 2005-12-14 08:27:23 UTC (rev 2374)
+++ trunk/galago-daemon/src/utils.c 2005-12-14 08:28:08 UTC (rev 2375)
@@ -69,3 +69,194 @@
return err_msg;
}
+
+DBusHandlerResult
+common_object_set_attribute(DBusConnection *dbus_conn,
+ DBusMessage *message,
+ const char *iface,
+ GalagoObject *object)
+{
+ DBusMessage *signal;
+ DBusMessageIter iter, value_iter;
+ DBusMessageIter signal_iter, signal_value_iter;
+ gboolean success = TRUE;
+ const char *name;
+ int arg_type;
+
+ dbus_message_iter_init(message, &iter);
+
+ signal = dbus_message_new_signal(galago_object_get_dbus_path(object),
+ iface, "AttributeSet");
+ dbus_message_iter_init_append(signal, &signal_iter);
+
+ dbus_message_iter_get_basic(&iter, &name);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_append_basic(&signal_iter, DBUS_TYPE_STRING, &name);
+
+ dbus_message_iter_recurse(&iter, &value_iter);
+ arg_type = dbus_message_iter_get_arg_type(&value_iter);
+
+ switch (arg_type)
+ {
+ case DBUS_TYPE_STRING:
+ {
+ const char *value;
+ dbus_message_iter_get_basic(&value_iter, &value);
+ galago_object_set_attr_string(object, name, value);
+ dbus_message_iter_open_container(&signal_iter, DBUS_TYPE_VARIANT,
+ DBUS_TYPE_STRING_AS_STRING,
+ &signal_value_iter);
+ dbus_message_iter_append_basic(&signal_value_iter,
+ DBUS_TYPE_STRING, &value);
+ dbus_message_iter_close_container(&signal_iter,
+ &signal_value_iter);
+ break;
+ }
+
+ case DBUS_TYPE_BOOLEAN:
+ {
+ gboolean value;
+ dbus_message_iter_get_basic(&value_iter, &value);
+ galago_object_set_attr_bool(object, name, value);
+ dbus_message_iter_open_container(&signal_iter, DBUS_TYPE_VARIANT,
+ DBUS_TYPE_BOOLEAN_AS_STRING,
+ &signal_value_iter);
+ dbus_message_iter_append_basic(&signal_value_iter,
+ DBUS_TYPE_BOOLEAN, &value);
+ dbus_message_iter_close_container(&signal_iter,
+ &signal_value_iter);
+ break;
+ }
+
+ case DBUS_TYPE_UINT32:
+ {
+ dbus_uint32_t value;
+ dbus_message_iter_get_basic(&value_iter, &value);
+ galago_object_set_attr_int(object, name, value);
+ dbus_message_iter_open_container(&signal_iter, DBUS_TYPE_VARIANT,
+ DBUS_TYPE_UINT32_AS_STRING,
+ &signal_value_iter);
+ dbus_message_iter_append_basic(&signal_value_iter,
+ DBUS_TYPE_UINT32, &value);
+ dbus_message_iter_close_container(&signal_iter,
+ &signal_value_iter);
+ break;
+ }
+
+ default:
+ g_warning("Invalid property type %d passed to "
+ "SetProperty", arg_type);
+ success = FALSE;
+ break;
+ }
+
+ if (success)
+ dbus_connection_send(dbus_conn, signal, NULL);
+
+ dbus_message_unref(signal);
+
+ galagod_dbus_send_empty_reply(dbus_conn, message);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+DBusHandlerResult
+common_object_remove_attribute(DBusConnection *dbus_conn,
+ DBusMessage *message,
+ const char *iface,
+ GalagoObject *object)
+{
+ DBusMessage *signal;
+ DBusMessageIter iter;
+ const char *name;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_get_basic(&iter, &name);
+ galago_object_remove_attr(object, name);
+
+ galagod_dbus_send_empty_reply(dbus_conn, message);
+
+ /* Emit the signal */
+ signal = dbus_message_new_signal(galago_object_get_dbus_path(object),
+ iface, "AttributeUnset");
+ dbus_message_iter_init_append(signal, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+ dbus_connection_send(dbus_conn, signal, NULL);
+ dbus_message_unref(signal);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+DBusHandlerResult
+common_object_get_attribute(DBusConnection *dbus_conn,
+ DBusMessage *message,
+ GalagoObject *object)
+{
+ const GValue *value;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ char *name;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_get_basic(&iter, &name);
+ value = galago_object_get_attr(object, name);
+
+ if (value == NULL)
+ {
+ reply = dbus_message_new_error_printf(message,
+ GALAGO_DBUS_ERROR_INVALID_ATTRIBUTE,
+ "The property \"%s\" is invalid.", name);
+ }
+ else
+ {
+ DBusMessageIter value_iter;
+
+ reply = dbus_message_new_method_return(message);
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (G_VALUE_HOLDS(value, G_TYPE_STRING))
+ {
+ const char *str = g_value_get_string(value);
+ 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);
+ }
+ else if (G_VALUE_HOLDS(value, G_TYPE_BOOLEAN))
+ {
+ gboolean b = g_value_get_boolean(value);
+ 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);
+ }
+ else if (G_VALUE_HOLDS(value, G_TYPE_INT))
+ {
+ dbus_uint32_t i = g_value_get_int(value);
+ 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);
+ }
+ else
+ {
+ /* This should never happen. */
+ g_warning("Unknown property type %s for property %s",
+ G_VALUE_TYPE_NAME(value), name);
+ }
+ }
+
+ if (reply != NULL)
+ {
+ dbus_connection_send(dbus_conn, reply, NULL);
+ dbus_message_unref(reply);
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
Modified: trunk/galago-daemon/src/utils.h
===================================================================
--- trunk/galago-daemon/src/utils.h 2005-12-14 08:27:23 UTC (rev 2374)
+++ trunk/galago-daemon/src/utils.h 2005-12-14 08:28:08 UTC (rev 2375)
@@ -31,4 +31,16 @@
DBusMessage *galagod_object_not_found_error_new(DBusMessage *message,
const char *str, ...);
+DBusHandlerResult common_object_set_attribute(DBusConnection *dbus_conn,
+ DBusMessage *message,
+ const char *iface,
+ GalagoObject *object);
+DBusHandlerResult common_object_remove_attribute(DBusConnection *dbus_conn,
+ DBusMessage *message,
+ const char *iface,
+ GalagoObject *object);
+DBusHandlerResult common_object_get_attribute(DBusConnection *dbus_conn,
+ DBusMessage *message,
+ GalagoObject *object);
+
#endif /* _GALAGOD_UTILS_H_ */
More information about the galago-commits
mailing list