Commit 7bd93d24 authored by Martyn James Russell's avatar Martyn James Russell

Some code clean ups.

	* src/libtracker-db/tracker-db-dbus.c: Some code clean ups.

	* src/libtracker-common/tracker-thumbnailer.c: When we get an
	error from the thumbnailer, include the context so we know where
	the error came from.

	* src/libtracker-db/tracker-db-manager.c:
	(function_group_concat_step): Fixed my g_return_if_fail()
	change for the g_assert() which ottela added initially, logic was
	wrong way round.

svn path=/trunk/; revision=3029
parent f94c78d4
2009-03-06 Martyn Russell <martyn@imendio.com>
* src/libtracker-common/tracker-dbus.[ch]: Added
tracker_dbus_str_to_strv() since it is pretty common.
* src/libtracker-db/tracker-db-dbus.c: Some code clean ups.
* src/libtracker-common/tracker-thumbnailer.c: When we get an
error from the thumbnailer, include the context so we know where
the error came from.
* src/libtracker-db/tracker-db-manager.c:
(function_group_concat_step): Fixed my g_return_if_fail()
change for the g_assert() which ottela added initially, logic was
wrong way round.
2009-03-06 Carlos Garnacho <carlos@imendio.com>
* src/tracker-indexer/tracker-main.c:
......
......@@ -127,6 +127,19 @@ tracker_dbus_slist_to_strv (GSList *list)
return strv;
}
gchar **
tracker_dbus_str_to_strv (const gchar *str)
{
gchar **strv;
strv = g_new (gchar*, 2);
strv[0] = g_strdup (str);
strv[1] = NULL;
return strv;
}
gchar **
tracker_dbus_queue_str_to_strv (GQueue *queue,
gint max)
......
......@@ -91,6 +91,7 @@ TrackerDBusData *tracker_dbus_data_new (const gpointer arg1,
GValue * tracker_dbus_gvalue_slice_new (GType type);
void tracker_dbus_gvalue_slice_free (GValue *value);
gchar ** tracker_dbus_slist_to_strv (GSList *list);
gchar ** tracker_dbus_str_to_strv (const gchar *str);
gchar ** tracker_dbus_queue_str_to_strv (GQueue *queue,
gint max);
gchar ** tracker_dbus_queue_gfile_to_strv (GQueue *queue,
......
......@@ -140,13 +140,14 @@ thumbnailer_enabled_cb (GObject *pspec,
private->service_is_enabled = tracker_config_get_enable_thumbnails (private->config);
g_debug ("Thumbnailer service %s",
private->service_is_enabled ? "enabled" : "disabled");
private->service_is_enabled ? "enabled" : "disabled");
}
static void
thumbnailer_reply_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
thumbnailer_reply_handle (DBusGProxy *proxy,
DBusGProxyCall *call,
guint request_id,
const gchar *operation)
{
GError *error = NULL;
guint handle;
......@@ -163,13 +164,48 @@ thumbnailer_reply_cb (DBusGProxy *proxy,
G_TYPE_INVALID);
if (error) {
g_warning ("%s", error->message);
g_warning ("Thumbnailer %s failed for request ID:%d, %s",
operation,
request_id,
error->message);
g_error_free (error);
return;
}
g_debug ("Received response from thumbnailer, request ID:%d",
GPOINTER_TO_UINT (user_data));
g_debug ("Thumbnailer response received for request ID:%d",
request_id);
}
static void
thumbnailer_reply_queue_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
thumbnailer_reply_handle (proxy, call, GPOINTER_TO_UINT (user_data), "queue");
}
static void
thumbnailer_reply_move_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
thumbnailer_reply_handle (proxy, call, GPOINTER_TO_UINT (user_data), "move");
}
static void
thumbnailer_reply_delete_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
thumbnailer_reply_handle (proxy, call, GPOINTER_TO_UINT (user_data), "delete");
}
static void
thumbnailer_reply_cleanup_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
thumbnailer_reply_handle (proxy, call, GPOINTER_TO_UINT (user_data), "cleanup");
}
static gboolean
......@@ -187,12 +223,12 @@ thumbnailer_request_timeout_cb (gpointer data)
private->mime_types[private->count] = NULL;
g_debug ("Sending request to thumbnailer to queue %d files, request ID:%d...",
private->count,
private->request_id);
private->count,
private->request_id);
dbus_g_proxy_begin_call (private->requester_proxy,
"Queue",
thumbnailer_reply_cb,
thumbnailer_reply_queue_cb,
GUINT_TO_POINTER (private->request_id),
NULL,
G_TYPE_STRV, private->uris,
......@@ -289,12 +325,12 @@ tracker_thumbnailer_init (TrackerConfig *config, guint timeout_seconds)
if (error) {
g_debug ("Thumbnailer service did not return supported mime types, %s",
error->message);
error->message);
g_error_free (error);
} else if (mime_types) {
g_debug ("Thumbnailer supports %d mime types",
g_strv_length (mime_types));
g_strv_length (mime_types));
private->supported_mime_types = mime_types;
private->service_is_available = TRUE;
......@@ -340,24 +376,25 @@ tracker_thumbnailer_move (const gchar *from_uri,
private->request_id++;
g_debug ("Requesting thumbnailer moves URI from:'%s' to:'%s', request_id:%d...",
from_uri,
to_uri,
private->request_id);
from_uri,
to_uri,
private->request_id);
if (!strstr (to_uri, ":/"))
if (!strstr (to_uri, ":/")) {
to[0] = g_filename_to_uri (to_uri, NULL, NULL);
else
} else {
to[0] = g_strdup (to_uri);
}
if (!strstr (from_uri, ":/"))
if (!strstr (from_uri, ":/")) {
from[0] = g_filename_to_uri (from_uri, NULL, NULL);
else
} else {
from[0] = g_strdup (from_uri);
}
dbus_g_proxy_begin_call (private->requester_proxy,
"Move",
thumbnailer_reply_cb,
thumbnailer_reply_move_cb,
GUINT_TO_POINTER (private->request_id),
NULL,
G_TYPE_STRV, from,
......@@ -366,7 +403,6 @@ tracker_thumbnailer_move (const gchar *from_uri,
g_free (from[0]);
g_free (to[0]);
}
void
......@@ -400,18 +436,19 @@ tracker_thumbnailer_remove (const gchar *uri,
private->request_id++;
if (!strstr (uri, ":/"))
if (!strstr (uri, ":/")) {
uris[0] = g_filename_to_uri (uri, NULL, NULL);
else
} else {
uris[0] = g_strdup (uri);
}
g_debug ("Requesting thumbnailer removes URI:'%s', request_id:%d...",
uri,
private->request_id);
uri,
private->request_id);
dbus_g_proxy_begin_call (private->requester_proxy,
"Delete",
thumbnailer_reply_cb,
thumbnailer_reply_delete_cb,
GUINT_TO_POINTER (private->request_id),
NULL,
G_TYPE_STRV, uris,
......@@ -439,12 +476,12 @@ tracker_thumbnailer_cleanup (const gchar *uri_prefix)
private->request_id++;
g_debug ("Requesting thumbnailer cleanup URI:'%s', request_id:%d...",
uri_prefix,
private->request_id);
uri_prefix,
private->request_id);
dbus_g_proxy_begin_call (private->requester_proxy,
"Cleanup",
thumbnailer_reply_cb,
thumbnailer_reply_cleanup_cb,
GUINT_TO_POINTER (private->request_id),
NULL,
G_TYPE_STRING, uri_prefix,
......@@ -479,8 +516,8 @@ tracker_thumbnailer_get_file_thumbnail (const gchar *uri,
private->request_id++;
g_debug ("Requesting thumbnailer to get thumbnail for URI:'%s', request_id:%d...",
uri,
private->request_id);
uri,
private->request_id);
/* We want to deal with the current list first if it is
* already at the limit.
......@@ -496,10 +533,11 @@ tracker_thumbnailer_get_file_thumbnail (const gchar *uri,
}
/* Add new URI (detect if we got passed a path) */
if (!strstr (uri, ":/"))
if (!strstr (uri, ":/")) {
private->uris[private->count] = g_filename_to_uri (uri, NULL, NULL);
else
} else {
private->uris[private->count] = g_strdup (uri);
}
if (mime_type) {
private->mime_types[private->count] = g_strdup (mime_type);
......
......@@ -35,28 +35,36 @@ typedef struct {
} OneElem;
static inline void
row_add (GPtrArray *row, gchar *value)
row_add (GPtrArray *row,
gchar *value)
{
OneElem *elem = g_slice_new (OneElem);
OneElem *elem;
GSList *list = NULL;
elem = g_slice_new (OneElem);
list = NULL;
list = g_slist_prepend (list, value);
elem->value = list;
g_ptr_array_add (row, elem);
}
static inline void
row_insert (GPtrArray *row, gchar *value, guint lindex)
row_insert (GPtrArray *row,
gchar *value,
guint lindex)
{
OneElem *elem = g_ptr_array_index (row, lindex);
GSList *list = elem->value;
OneElem *elem;
GSList *list;
GSList *iter;
elem = g_ptr_array_index (row, lindex);
list = elem->value;
/* We check for duplicate values here so that
* we can have several multivalued fields in
* the same query.
*/
for (iter = list; iter; iter=iter->next) {
if (strcmp (iter->data, value) == 0) {
return;
......@@ -74,7 +82,7 @@ row_destroy (GPtrArray *row)
for (i = 0; i < row->len; i++) {
OneElem *elem;
GSList *list;
GSList *list;
elem = g_ptr_array_index (row, i);
list = elem->value;
......@@ -89,13 +97,17 @@ row_destroy (GPtrArray *row)
}
static inline gpointer
rows_lookup (GPtrArray *rows, gint key)
rows_lookup (GPtrArray *rows,
gint key)
{
guint i;
gpointer value = NULL;
for (i = 0; i < rows->len; i++) {
OneRow *row = g_ptr_array_index (rows, i);
OneRow *row;
row = g_ptr_array_index (rows, i);
if (row->key == key) {
value = row->value;
break;
......@@ -121,9 +133,13 @@ rows_destroy (GPtrArray *rows)
}
static inline void
rows_add (GPtrArray *rows, gint key, gpointer value)
rows_add (GPtrArray *rows,
gint key,
gpointer value)
{
OneRow *row = g_slice_new (OneRow);
OneRow *row;
row = g_slice_new (OneRow);
row->key = key;
row->value = value;
......@@ -132,15 +148,16 @@ rows_add (GPtrArray *rows, gint key, gpointer value)
}
static inline void
rows_migrate (GPtrArray *rows, GPtrArray *result)
rows_migrate (GPtrArray *rows,
GPtrArray *result)
{
guint i,j;
guint i, j;
/* Go thought the lists and join with | separator */
for (i = 0; i < rows->len; i++) {
OneRow *row;
GPtrArray *array;
gchar **strv;
OneRow *row;
GPtrArray *array;
gchar **strv;
row = g_ptr_array_index (rows, i);
array = row->value;
......@@ -148,10 +165,10 @@ rows_migrate (GPtrArray *rows, GPtrArray *result)
strv = g_new0 (gchar*, array->len + 1);
for (j = 0; j < array->len; j++) {
OneElem *elem;
GSList *list;
GSList *iter;
GString *string;
OneElem *elem;
GSList *list;
GSList *iter;
GString *string;
elem = g_ptr_array_index (array, j);
list = elem->value;
......@@ -172,7 +189,6 @@ rows_migrate (GPtrArray *rows, GPtrArray *result)
}
}
static gchar **
dbus_query_result_to_strv (TrackerDBResultSet *result_set,
gint column,
......@@ -246,15 +262,15 @@ tracker_dbus_query_result_numeric_to_strv (TrackerDBResultSet *result_set,
gchar **
tracker_dbus_query_result_columns_to_strv (TrackerDBResultSet *result_set,
gint offset_column,
gint until_column,
gboolean rewind)
gint offset_column,
gint until_column,
gboolean rewind)
{
gchar **strv = NULL;
gint i = 0;
gint columns;
gint row_counter = 0;
gboolean valid = TRUE;
gchar **strv = NULL;
gint i = 0;
gint columns;
gint row_counter = 0;
gboolean valid = TRUE;
if (result_set) {
columns = tracker_db_result_set_get_n_columns (result_set);
......@@ -268,11 +284,13 @@ tracker_dbus_query_result_columns_to_strv (TrackerDBResultSet *result_set,
strv = g_new (gchar*, 1);
strv[0] = NULL;
return strv;
} else if (offset_column == -1)
} else if (offset_column == -1) {
offset_column = 0;
}
if (until_column == -1)
if (until_column == -1) {
until_column = columns;
}
strv = g_new (gchar*, until_column + 1);
......@@ -280,7 +298,7 @@ tracker_dbus_query_result_columns_to_strv (TrackerDBResultSet *result_set,
for (i = offset_column ; i < until_column; i++) {
GValue value = {0, };
GValue transform = {0, };
GValue transform = {0, };
g_value_init (&transform, G_TYPE_STRING);
......@@ -408,12 +426,12 @@ tracker_dbus_query_result_to_ptr_array (TrackerDBResultSet *result_set)
}
while (valid) {
GSList *list = NULL;
gchar **p;
GSList *list = NULL;
gchar **p;
/* Append fields to the array */
for (i = 0; i < columns; i++) {
GValue transform = { 0, };
GValue transform = { 0, };
GValue value = { 0, };
gchar *str;
......@@ -458,10 +476,10 @@ tracker_dbus_query_result_to_ptr_array (TrackerDBResultSet *result_set)
GPtrArray *
tracker_dbus_query_result_multi_to_ptr_array (TrackerDBResultSet *result_set)
{
GPtrArray *result;
GPtrArray *rows;
gboolean valid = FALSE;
gint columns;
GPtrArray *result;
GPtrArray *rows;
gboolean valid = FALSE;
gint columns;
rows = g_ptr_array_new ();
......@@ -476,12 +494,11 @@ tracker_dbus_query_result_multi_to_ptr_array (TrackerDBResultSet *result_set)
}
while (valid) {
gint key;
GPtrArray *row;
gint column;
gboolean add = FALSE;
GValue value_in = {0, };
GPtrArray *row;
GValue value_in = {0, };
gint key;
gint column;
gboolean add = FALSE;
/* Get the key and the matching row if exists */
_tracker_db_result_set_get_value (result_set, 0, &value_in);
......@@ -494,9 +511,9 @@ tracker_dbus_query_result_multi_to_ptr_array (TrackerDBResultSet *result_set)
/* Append fields or values to the array */
for (column = 1; column < columns; column++) {
GValue transform = { 0, };
GValue value = { 0, };
gchar *str;
GValue transform = { 0, };
GValue value = { 0, };
gchar *str;
g_value_init (&transform, G_TYPE_STRING);
......
......@@ -28,20 +28,19 @@ G_BEGIN_DECLS
#include "tracker-db-interface.h"
gchar ** tracker_dbus_query_result_to_strv (TrackerDBResultSet *result_set,
gint column,
gint *count);
gchar ** tracker_dbus_query_result_numeric_to_strv (TrackerDBResultSet *result_set,
gint column,
gint *count);
gchar ** tracker_dbus_query_result_columns_to_strv (TrackerDBResultSet *result_set,
gint offset_column,
gint until_column,
gboolean rewind);
GHashTable *tracker_dbus_query_result_to_hash_table (TrackerDBResultSet *result_set);
GPtrArray * tracker_dbus_query_result_to_ptr_array (TrackerDBResultSet *result_set);
GPtrArray * tracker_dbus_query_result_multi_to_ptr_array (TrackerDBResultSet *result_set);
gchar ** tracker_dbus_query_result_to_strv (TrackerDBResultSet *result_set,
gint column,
gint *count);
gchar ** tracker_dbus_query_result_numeric_to_strv (TrackerDBResultSet *result_set,
gint column,
gint *count);
gchar ** tracker_dbus_query_result_columns_to_strv (TrackerDBResultSet *result_set,
gint offset_column,
gint until_column,
gboolean rewind);
GHashTable *tracker_dbus_query_result_to_hash_table (TrackerDBResultSet *result_set);
GPtrArray * tracker_dbus_query_result_to_ptr_array (TrackerDBResultSet *result_set);
GPtrArray * tracker_dbus_query_result_multi_to_ptr_array (TrackerDBResultSet *result_set);
G_END_DECLS
......
......@@ -1316,7 +1316,7 @@ function_group_concat_step (TrackerDBInterface *interface,
{
AggregateData *p;
g_return_if_fail (argc != 1);
g_return_if_fail (argc == 1);
p = aggregate_context;
......@@ -1348,7 +1348,6 @@ function_group_concat_final (TrackerDBInterface *interface,
return result;
}
static GValue
function_get_service_name (TrackerDBInterface *interface,
gint argc,
......@@ -1730,7 +1729,6 @@ db_set_params (TrackerDBInterface *iface,
}
}
static void
db_get_static_data (TrackerDBInterface *iface)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment