Author: otaylor Date: Fri Feb 8 22:28:52 2008 New Revision: 7250 URL: http://svn.gnome.org/viewvc/desktop-data-model?rev=7250&view=rev
Log: Change things so that updates can have fetch strings and return objects (involves D-BUS protocol change) Modified: trunk/ddm/ddm-data-model-dbus.c trunk/ddm/ddm-data-model.c trunk/ddm/ddm-data-model.h trunk/ddm/ddm-data-query-internal.h trunk/ddm/ddm-data-query.c trunk/ddm/ddm-data-query.h trunk/engine-dbus/hippo-dbus-model-client.c trunk/engine-dbus/hippo-dbus-model-client.h trunk/engine-dbus/hippo-dbus-model.c trunk/engine/hippo-connection.c Modified: trunk/ddm/ddm-data-model-dbus.c ============================================================================== --- trunk/ddm/ddm-data-model-dbus.c (original) +++ trunk/ddm/ddm-data-model-dbus.c Fri Feb 8 22:28:52 2008 @@ -932,12 +932,14 @@ } static void -ddm_dbus_send_query (DDMDataModel *ddm_model, - DDMDataQuery *query, - void *backend_data) +send_query_or_update (DDMDataModel *ddm_model, + DDMDataQuery *query, + void *backend_data, + gboolean is_update) { DBusModel *dbus_model; QueryData *qd; + const char *fetch_string; dbus_model = get_dbus_model(ddm_model); @@ -955,10 +957,13 @@ return; } - g_debug("sending Query to org.freedesktop.od.Engine %s#%s fetch %s", + fetch_string = ddm_data_query_get_fetch_string(query); + + g_debug("sending %s to org.freedesktop.od.Engine %s#%s fetch '%s'", + is_update ? "update" : "query", ddm_data_query_get_qname(query)->uri, ddm_data_query_get_qname(query)->name, - ddm_data_query_get_fetch_string(query)); + fetch_string != NULL ? fetch_string : ""); qd = g_new(QueryData, 1); @@ -967,7 +972,7 @@ qd->query = query; hippo_dbus_proxy_call_method_async_appender(dbus_model->engine_proxy, - "Query", + is_update ? "Update" : "Query", handle_query_reply, qd, free_query_data, @@ -975,103 +980,21 @@ qd); } - static void -handle_update_reply(DBusMessage *reply, - void *data) +ddm_dbus_send_query (DDMDataModel *ddm_model, + DDMDataQuery *query, + void *backend_data) { - QueryData *qd = data; - - if (qd->dbus_model->ddm_model == NULL) /* happens if the reply comes in after we nuke the model */ - return; - - if (dbus_message_get_type(reply) != DBUS_MESSAGE_TYPE_METHOD_RETURN) { - /* the dbus API does not give us the error code right now */ - const char *message = NULL; - dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &message, DBUS_TYPE_INVALID); - ddm_data_query_error(qd->query, - DDM_DATA_ERROR_INTERNAL_SERVER_ERROR, /* arbitrary */ - message ? message : "unknown error"); - return; - } - - /* a successful "ack" reply */ - ddm_data_query_response(qd->query, NULL); + send_query_or_update(ddm_model, query, backend_data, FALSE); } -static dbus_bool_t -append_update_args(DBusMessage *message, - void *data) -{ - QueryData *qd = data; - DBusMessageIter toplevel_iter, params_dict_iter; - char *s; - - dbus_message_iter_init_append(message, &toplevel_iter); - - /* method uri */ - s = ddm_qname_to_uri(ddm_data_query_get_qname(qd->query)); - if (!dbus_message_iter_append_basic(&toplevel_iter, - DBUS_TYPE_STRING, &s)) { - g_free(s); - return FALSE; - } - g_free(s); - - /* dictionary of params, string:string */ - - if (!dbus_message_iter_open_container(&toplevel_iter, DBUS_TYPE_ARRAY, - "{ss}", ¶ms_dict_iter)) - return FALSE; - - if (!append_params(¶ms_dict_iter, ddm_data_query_get_params(qd->query))) - return FALSE; - - if (!dbus_message_iter_close_container(&toplevel_iter, ¶ms_dict_iter)) - return FALSE; - - return TRUE; -} static void ddm_dbus_send_update (DDMDataModel *ddm_model, DDMDataQuery *query, void *backend_data) { - DBusModel *dbus_model; - QueryData *qd; - - dbus_model = get_dbus_model(ddm_model); - - if (dbus_model->engine_proxy == NULL) { - ddm_data_query_error_async (query, - DDM_DATA_ERROR_NO_CONNECTION, - "No connection to data model engine"); - return; - } - - if (!dbus_model->engine_ready) { - ddm_data_query_error_async (query, - DDM_DATA_ERROR_NO_CONNECTION, - "Data model engine is not ready"); - return; - } - - g_debug("sending Update to org.freedesktop.od.Engine"); - - qd = g_new(QueryData, 1); - - model_ref(dbus_model); - qd->dbus_model = dbus_model; - qd->query = query; - - hippo_dbus_proxy_call_method_async_appender(dbus_model->engine_proxy, - "Update", - handle_update_reply, - qd, - free_query_data, - append_update_args, - qd); + send_query_or_update(ddm_model, query, backend_data, TRUE); } static const DDMDataModelBackend dbus_backend = { Modified: trunk/ddm/ddm-data-model.c ============================================================================== --- trunk/ddm/ddm-data-model.c (original) +++ trunk/ddm/ddm-data-model.c Fri Feb 8 22:28:52 2008 @@ -445,6 +445,7 @@ DDMDataQuery * ddm_data_model_update_params(DDMDataModel *model, const char *method, + const char *fetch, GHashTable *params) { DDMDataQuery *query; @@ -457,7 +458,7 @@ if (method_qname == NULL) /* Invalid method URI */ return NULL; - query = _ddm_data_query_new_update(model, method_qname, params, model->next_query_serial++); + query = _ddm_data_query_new_update(model, method_qname, fetch, params, model->next_query_serial++); debug_dump_query(query); @@ -469,17 +470,18 @@ DDMDataQuery * ddm_data_model_update(DDMDataModel *model, const char *method, + const char *fetch, ...) { DDMDataQuery *query; GHashTable *params; va_list vap; - va_start(vap, method); + va_start(vap, fetch); params = params_from_valist(vap); va_end(vap); - query = ddm_data_model_update_params(model, method, params); + query = ddm_data_model_update_params(model, method, fetch, params); g_hash_table_destroy(params); Modified: trunk/ddm/ddm-data-model.h ============================================================================== --- trunk/ddm/ddm-data-model.h (original) +++ trunk/ddm/ddm-data-model.h Fri Feb 8 22:28:52 2008 @@ -71,9 +71,11 @@ DDMDataQuery *ddm_data_model_update (DDMDataModel *model, const char *method, + const char *fetch, ...) G_GNUC_NULL_TERMINATED; DDMDataQuery *ddm_data_model_update_params (DDMDataModel *model, const char *method, + const char *fetch, GHashTable *params); DDMDataResource *ddm_data_model_lookup_resource (DDMDataModel *model, Modified: trunk/ddm/ddm-data-query-internal.h ============================================================================== --- trunk/ddm/ddm-data-query-internal.h (original) +++ trunk/ddm/ddm-data-query-internal.h Fri Feb 8 22:28:52 2008 @@ -15,6 +15,7 @@ DDMDataQuery *_ddm_data_query_new_update(DDMDataModel *model, DDMQName *qname, + const char *fetch_string, GHashTable *params, gint64 serial); Modified: trunk/ddm/ddm-data-query.c ============================================================================== --- trunk/ddm/ddm-data-query.c (original) +++ trunk/ddm/ddm-data-query.c Fri Feb 8 22:28:52 2008 @@ -7,9 +7,9 @@ typedef enum { HANDLER_NONE, + HANDLER_VOID, HANDLER_SINGLE, - HANDLER_MULTI, - HANDLER_UPDATE + HANDLER_MULTI } HandlerType; struct _DDMDataQuery { @@ -27,9 +27,9 @@ HandlerType handler_type; union { + DDMVoidHandler void_; DDMSingleHandler single; DDMMultiHandler multi; - DDMUpdateHandler update; } handler; gpointer handler_data; DDMErrorHandler error_handler; @@ -98,6 +98,18 @@ } void +ddm_data_query_set_void_handler (DDMDataQuery *query, + DDMVoidHandler handler, + gpointer user_data) +{ + g_return_if_fail(query != NULL); + + query->handler_type = HANDLER_VOID; + query->handler.void_ = handler; + query->handler_data = user_data; +} + +void ddm_data_query_set_single_handler (DDMDataQuery *query, DDMSingleHandler handler, gpointer user_data) @@ -122,18 +134,6 @@ } void -ddm_data_query_set_update_handler (DDMDataQuery *query, - DDMUpdateHandler handler, - gpointer user_data) -{ - g_return_if_fail(query != NULL); - - query->handler_type = HANDLER_UPDATE; - query->handler.update = handler; - query->handler_data = user_data; -} - -void ddm_data_query_set_error_handler (DDMDataQuery *query, DDMErrorHandler handler, gpointer user_data) @@ -197,16 +197,28 @@ DDMDataQuery * _ddm_data_query_new_update (DDMDataModel *model, DDMQName *qname, + const char *fetch_string, GHashTable *params, gint64 serial) { DDMDataQuery *query = g_new0(DDMDataQuery, 1); + DDMDataFetch *fetch; + + if (fetch_string != NULL) { + fetch = ddm_data_fetch_from_string(fetch_string); + if (fetch == NULL) { + g_warning("Invalid fetch string '%s'", fetch_string); + return NULL; + } + } else { + fetch = NULL; + } query->model = model; query->qname = qname; query->is_update = TRUE; - query->fetch_string = NULL; - query->is_update = TRUE; + query->fetch_string = g_strdup(fetch_string); + query->fetch = fetch; query->params = g_hash_table_new_full(g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); g_hash_table_foreach(params, add_param_foreach, query); @@ -341,6 +353,15 @@ switch (query->handler_type) { case HANDLER_NONE: return; + case HANDLER_VOID: + if (query->results != NULL) { + ddm_data_query_error(query, + DDM_DATA_ERROR_BAD_REPLY, + "Got results for a query expecting no results"); + return; + } + query->handler.void_(query->handler_data); + break; case HANDLER_SINGLE: if (query->results == NULL) { ddm_data_query_error(query, @@ -359,15 +380,6 @@ case HANDLER_MULTI: query->handler.multi(query->results, query->handler_data); break; - case HANDLER_UPDATE: - if (query->results != NULL) { - ddm_data_query_error(query, - DDM_DATA_ERROR_BAD_REPLY, - "Got results for a query expecting no results"); - return; - } - query->handler.update(query->handler_data); - break; } ddm_data_query_free(query); Modified: trunk/ddm/ddm-data-query.h ============================================================================== --- trunk/ddm/ddm-data-query.h (original) +++ trunk/ddm/ddm-data-query.h Fri Feb 8 22:28:52 2008 @@ -16,26 +16,26 @@ G_BEGIN_DECLS +typedef void (*DDMVoidHandler) (gpointer user_data); typedef void (*DDMSingleHandler) (DDMDataResource *result, gpointer user_data); typedef void (*DDMMultiHandler) (GSList *results, gpointer user_data); -typedef void (*DDMUpdateHandler) (gpointer user_data); typedef void (*DDMErrorHandler) (DDMDataError error, const char *message, gpointer user_data); /******* For applications *******/ +void ddm_data_query_set_void_handler (DDMDataQuery *query, + DDMVoidHandler handler, + gpointer user_data); void ddm_data_query_set_single_handler (DDMDataQuery *query, DDMSingleHandler handler, gpointer user_data); void ddm_data_query_set_multi_handler (DDMDataQuery *query, DDMMultiHandler handler, gpointer user_data); -void ddm_data_query_set_update_handler (DDMDataQuery *query, - DDMUpdateHandler handler, - gpointer user_data); void ddm_data_query_set_error_handler (DDMDataQuery *query, DDMErrorHandler handler, gpointer user_data); Modified: trunk/engine-dbus/hippo-dbus-model-client.c ============================================================================== --- trunk/engine-dbus/hippo-dbus-model-client.c (original) +++ trunk/engine-dbus/hippo-dbus-model-client.c Fri Feb 8 22:28:52 2008 @@ -700,7 +700,8 @@ DBusMessage *message, const char *method_uri, DDMDataFetch *fetch, - GHashTable *params) + GHashTable *params, + gboolean is_update) { DataClientQueryClosure *closure; DDMDataQuery *query; @@ -711,55 +712,24 @@ closure = data_client_query_closure_new(client, client->connection, message, fetch); - fetch_string = ddm_data_fetch_to_string(fetch); - query = ddm_data_model_query_params(client->model, method_uri, fetch_string, params); - g_free(fetch_string); + if (fetch != NULL) + fetch_string = ddm_data_fetch_to_string(fetch); + else + fetch_string = NULL; - if (query == NULL) { - data_client_query_closure_destroy(closure); - return FALSE; - } - - ddm_data_query_set_multi_handler(query, on_query_success, closure); - ddm_data_query_set_error_handler(query, on_query_error, closure); - - return TRUE; -} - -/*****************************************************************/ - -static void -on_update_success (gpointer data) -{ - DataClientQueryClosure *closure = data; - DBusMessage *reply; - - reply = dbus_message_new_method_return(closure->message); - dbus_connection_send(closure->connection, reply, NULL); - dbus_message_unref(reply); + if (is_update) + query = ddm_data_model_update_params(client->model, method_uri, fetch_string, params); + else + query = ddm_data_model_query_params(client->model, method_uri, fetch_string, params); - data_client_query_closure_destroy(closure); -} - -gboolean -hippo_dbus_model_client_do_update (DDMDataModel *model, - DBusConnection *connection, - DBusMessage *message, - const char *method_uri, - GHashTable *params) -{ - DataClientQueryClosure *closure; - DDMDataQuery *query; + g_free(fetch_string); - closure = data_client_query_closure_new(NULL, connection, message, NULL); - - query = ddm_data_model_update_params(model, method_uri, params); if (query == NULL) { data_client_query_closure_destroy(closure); return FALSE; } - ddm_data_query_set_update_handler(query, on_update_success, closure); + ddm_data_query_set_multi_handler(query, on_query_success, closure); ddm_data_query_set_error_handler(query, on_query_error, closure); return TRUE; Modified: trunk/engine-dbus/hippo-dbus-model-client.h ============================================================================== --- trunk/engine-dbus/hippo-dbus-model-client.h (original) +++ trunk/engine-dbus/hippo-dbus-model-client.h Fri Feb 8 22:28:52 2008 @@ -36,17 +36,8 @@ DBusMessage *message, const char *method_uri, DDMDataFetch *fetch, - GHashTable *params); - -/* Since the update() method doesn't take a notification path, we don't - * know or need to know the client it corresponds to. But we put it in - * here because of it's close connection to do_query() - */ -gboolean hippo_dbus_model_client_do_update (DDMDataModel *model, - DBusConnection *connection, - DBusMessage *message, - const char *method_uri, - GHashTable *params); + GHashTable *params, + gboolean is_update); G_END_DECLS Modified: trunk/engine-dbus/hippo-dbus-model.c ============================================================================== --- trunk/engine-dbus/hippo-dbus-model.c (original) +++ trunk/engine-dbus/hippo-dbus-model.c Fri Feb 8 22:28:52 2008 @@ -153,9 +153,10 @@ } static DBusMessage* -handle_query (void *object, - DBusMessage *message, - DBusError *error) +handle_query_or_update (void *object, + DBusMessage *message, + DBusError *error, + gboolean is_update) { DDMDataModel *model; const char *notification_path; @@ -195,6 +196,17 @@ dbus_message_iter_get_basic(&iter, &fetch_string); dbus_message_iter_next (&iter); + if (fetch_string != NULL && *fetch_string != '\0') { + fetch = ddm_data_fetch_from_string(fetch_string); + if (fetch == NULL) { + return dbus_message_new_error(message, + DBUS_ERROR_INVALID_ARGS, + _("Couldn't parse fetch string")); + } + } else { + fetch = NULL; + } + params = read_params_dictionary(&iter); if (params == NULL) return dbus_message_new_error(message, @@ -206,79 +218,40 @@ DBUS_ERROR_INVALID_ARGS, _("Too many arguments")); - fetch = ddm_data_fetch_from_string(fetch_string); - if (fetch == NULL) { - return dbus_message_new_error(message, - DBUS_ERROR_INVALID_ARGS, - _("Couldn't parse fetch string")); - } - client_map = data_client_map_get(model); client = data_client_map_get_client(client_map, dbus_message_get_sender(message), notification_path); - if (!hippo_dbus_model_client_do_query(client, message, method_uri, fetch, params)) { + if (!hippo_dbus_model_client_do_query(client, message, method_uri, fetch, params, is_update)) { /* We've already validated most arguments, so don't worry too much about getting a * good error message if something goes wrong at this point */ return dbus_message_new_error(message, DBUS_ERROR_FAILED, - _("Couldn't send query")); + is_update ? _("Couldn't send update)") : _("Couldn't send query)")); } g_hash_table_destroy(params); - ddm_data_fetch_unref(fetch); + if (fetch != NULL) + ddm_data_fetch_unref(fetch); return NULL; } static DBusMessage* +handle_query (void *object, + DBusMessage *message, + DBusError *error) +{ + return handle_query_or_update(object, message, error, FALSE); +} + +static DBusMessage* handle_update (void *object, DBusMessage *message, DBusError *error) { - DDMDataModel *model; - const char *method_uri; - GHashTable *params = NULL; - DBusMessageIter iter; - - model = hippo_engine_app_get_data_model(hippo_get_engine_app()); - - dbus_message_iter_init (message, &iter); - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) { - return dbus_message_new_error(message, - DBUS_ERROR_INVALID_ARGS, - _("First argument should be a string (method_uri)")); - } - dbus_message_iter_get_basic(&iter, &method_uri); - dbus_message_iter_next (&iter); - - params = read_params_dictionary(&iter); - if (params == NULL) - return dbus_message_new_error(message, - DBUS_ERROR_INVALID_ARGS, - _("Second argument should be a dictionary string=>string (params)")); - - if (dbus_message_iter_has_next(&iter)) - return dbus_message_new_error(message, - DBUS_ERROR_INVALID_ARGS, - _("Too many arguments")); - - if (!hippo_dbus_model_client_do_update(model, - hippo_dbus_get_connection(hippo_engine_app_get_dbus(hippo_get_engine_app())), - message, method_uri, params)) { - /* We've already validated most arguments, so don't worry too much about getting a - * good error message if something goes wrong at this point - */ - return dbus_message_new_error(message, - DBUS_ERROR_FAILED, - _("Couldn't send update")); - } - - g_hash_table_destroy(params); - - return NULL; + return handle_query_or_update(object, message, error, TRUE); } static DBusMessage* @@ -393,7 +366,7 @@ * Parameter value */ - { HIPPO_DBUS_MEMBER_METHOD, "Update", "sa{ss}", "", handle_update }, + { HIPPO_DBUS_MEMBER_METHOD, "Update", "ossa{ss}", "a(ssba(ssyyyv))", handle_update }, /* Forget: Remove notifications resulting from an earlier Query request * Modified: trunk/engine/hippo-connection.c ============================================================================== --- trunk/engine/hippo-connection.c (original) +++ trunk/engine/hippo-connection.c Fri Feb 8 22:28:52 2008 @@ -3505,11 +3505,9 @@ dm_context_pop_node(&context); } - if (!ddm_data_query_is_update(query)) { - disk_cache = _hippo_data_model_get_disk_cache(context.model); - if (disk_cache) - _hippo_disk_cache_save_query_to_disk(disk_cache, query, results, notifications); - } + disk_cache = _hippo_data_model_get_disk_cache(context.model); + if (disk_cache) + _hippo_disk_cache_save_query_to_disk(disk_cache, query, results, notifications); ddm_notification_set_free(notifications); @@ -3578,7 +3576,7 @@ lm_message_node_set_attribute(child, "xmlns", query_qname->uri); lm_message_node_set_attribute(child, "xmlns:m", "http://mugshot.org/p/system"); - if (fetch != NULL) + if (fetch != NULL && *fetch != '\0') lm_message_node_set_attribute(child, "m:fetch", fetch); g_hash_table_foreach(params, add_param_foreach, child); _______________________________________________ SVN-commits-list mailing list (read only) http://mail.gnome.org/mailman/listinfo/svn-commits-list Want to limit the commits to a few modules? Go to above URL, log in to edit your options and select the modules ('topics') you want. Module maintainer? It is possible to set the reply-to to your development mailing list. Email [EMAIL PROTECTED] if interested.