cpw.nader.asynclogging-3: ee94bde9: Changed the listing code so that logs ar...
morshed.nader at gmail.com
morshed.nader at gmail.com
Sat Jan 7 22:02:01 EST 2012
----------------------------------------------------------------------
Revision: ee94bde9b570987da9de046f56639d859293ad36
Parent: 159177a40d26495d9a8c6b750dddaf66af86463e
Author: morshed.nader at gmail.com
Date: 01/06/12 18:56:32
Branch: im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/ee94bde9b570987da9de046f56639d859293ad36
Changelog:
Changed the listing code so that logs are continuously fed back into the callback function until none are left, allowing the UI to be updated more continuously
Disabled the old logger functions for now as that module still performs blocking IO
Changes against parent 159177a40d26495d9a8c6b750dddaf66af86463e
patched finch/gntlog.c
patched libpurple/commonlog.c
patched libpurple/log.c
patched pidgin/gtklog.c
-------------- next part --------------
============================================================
--- libpurple/log.c 2d1cb9be42188a375f1d86a047bb0b98c24be196
+++ libpurple/log.c 5815186ea1542d70efb38648f8821f1da4df5abf
@@ -38,6 +38,8 @@
#include "imgstore.h"
#include "time.h"
+
+/* Helpful macros */
#define PURPLE_IS_ACCOUNT(account) TRUE
#define PURPLE_IS_CONVERSATION(account) TRUE
#define PURPLE_ACCOUNT(account) ((PurpleAccount *) account)
@@ -53,6 +55,35 @@
#endif
+#define SIMPLE_ASYNC_RESULT_NEW_GOOD(obj, cb, data, source, set_op_cmb, val, ...) \
+ { \
+ GSimpleAsyncResult *simple; \
+ simple = g_simple_async_result_new(G_OBJECT(obj), cb, data, source); \
+ set_op_cmb(simple, val, ##__VA_ARGS__); \
+ g_simple_async_result_complete_in_idle(simple); \
+ g_object_unref(simple); \
+ }
+
+#define SIMPLE_ASYNC_RESULT_FROM_ERROR(obj, cb, data, err) \
+ { \
+ GSimpleAsyncResult *simple; \
+ simple = g_simple_async_result_new_from_error(G_OBJECT(obj), cb, \
+ data, err); \
+ g_clear_error(&err); \
+ g_simple_async_result_complete_in_idle(simple); \
+ g_object_unref(simple); \
+ }
+
+#define SIMPLE_ASYNC_RESULT_FROM_NEW_ERROR(obj, cb, data, domain, code, format, ...) \
+ { \
+ GSimpleAsyncResult *simple; \
+ simple = g_simple_async_result_new_error(G_OBJECT(obj), cb, data, \
+ domain, code, format, ##__VA_ARGS__); \
+ g_simple_async_result_complete_in_idle(simple); \
+ g_object_unref(simple); \
+ }
+
+
G_DEFINE_TYPE (PurpleLog, purple_log, G_TYPE_OBJECT)
static void purple_log_get_property(GObject *, guint, GValue *, GParamSpec *);
static void purple_log_set_property(GObject *, guint, const GValue *,
@@ -113,7 +144,6 @@ typedef struct {
typedef struct {
GAsyncReadyCallback cb;
- GList *logs;
gpointer userdata;
guint counter;
} _list_logs_callback_data;
@@ -824,7 +854,6 @@ purple_logs_list_logs_async(PurpleLogCha
callback_data->cb = cb;
callback_data->userdata = userdata;
callback_data->counter = array->len;
- callback_data->logs = NULL;
any = FALSE;
@@ -841,10 +870,8 @@ purple_logs_list_logs_async(PurpleLogCha
cancellable, log_list_cb, callback_data);
}
- if (!any) {
- callback_data->counter = 1;
+ if (!any)
log_list_cb(NULL, NULL, callback_data);
- }
}
GList *
@@ -914,7 +941,6 @@ purple_logs_list_system_logs_async(Purpl
callback_data->userdata = userdata;
callback_data->cb = cb;
callback_data->counter = array->len;
- callback_data->logs = NULL;
any = FALSE;
@@ -931,10 +957,8 @@ purple_logs_list_system_logs_async(Purpl
log_system_list_cb, callback_data);
}
- if (!any) {
- callback_data->counter = 1;
+ if (!any)
log_system_list_cb(NULL, NULL, callback_data);
- }
}
static GList *
@@ -1119,10 +1143,8 @@ purple_logs_get_total_size_async(PurpleL
cancellable, log_total_size_cb, callback_data);
}
- if (!any) {
- callback_data->counter = 1;
+ if (!any)
log_total_size_cb(NULL, NULL, callback_data);
- }
}
gssize
@@ -1665,7 +1687,7 @@ purple_log_system_init(void)
purple_html_log_system_init();
purple_txt_log_system_init();
- purple_old_log_system_init();
+// purple_old_log_system_init();
purple_signal_register(handle, "log-timestamp",
#if SIZEOF_TIME_T == 4
@@ -1988,80 +2010,89 @@ log_list_cb(GObject *object, GAsyncResul
static void
log_list_cb(GObject *object, GAsyncResult *res, gpointer userdata)
{
- _list_logs_callback_data *callback_data = userdata;
+ _list_logs_callback_data *data = userdata;
GError *error = NULL;
GList *list;
if (res != NULL) {
list = purple_logs_list_logs_finish(res, &error);
- callback_data->counter--;
- } else
- list = NULL;
- if (list == NULL) {
- if (error != NULL && error->code != G_IO_ERROR_NOT_SUPPORTED)
- purple_debug_error("log", "Error listing logs: %s\n",
- error->message);
- } else
- callback_data->logs = g_list_concat(callback_data->logs, list);
+ if (list == NULL) {
+ /* It's hard to pass all the errors up, so just log them :( */
+ if (error != NULL)
+ purple_debug_error("log", "Error listing logs: %s\n",
+ error->message);
- g_clear_error(&error);
+ data->counter--;
+ } else {
+ SIMPLE_ASYNC_RESULT_NEW_GOOD(NULL, data->cb, data->userdata,
+ purple_logs_list_logs_async,
+ g_simple_async_result_set_op_res_gpointer,
+ list,
+ (GDestroyNotify) purple_log_list_free);
+ }
- if (callback_data->counter < 1) {
- GSimpleAsyncResult *simple = g_simple_async_result_new(NULL,
- callback_data->cb, callback_data->userdata,
- purple_logs_list_logs_async);
+ g_clear_error(&error);
+ }
- g_simple_async_result_set_op_res_gpointer(simple, callback_data->logs,
- (GDestroyNotify) purple_log_list_free);
- g_simple_async_result_complete_in_idle(simple);
+ /* If res is NULL, data->counter should already be set to 0 */
- g_object_unref(simple);
- g_free(callback_data);
+ if (data->counter < 1) {
+ SIMPLE_ASYNC_RESULT_NEW_GOOD(NULL, data->cb, data->userdata,
+ purple_logs_list_logs_async,
+ g_simple_async_result_set_op_res_gpointer,
+ NULL,
+ NULL);
+
+ g_free(data);
}
}
static void
log_system_list_cb(GObject *object, GAsyncResult *res, gpointer userdata)
{
- _list_logs_callback_data *callback_data = userdata;
- PurpleLog *log = PURPLE_LOG(object);
+ _list_logs_callback_data *data = userdata;
GError *error = NULL;
GList *list;
if (res != NULL) {
list = purple_logs_list_system_logs_finish(res, &error);
- callback_data->counter--;
- } else
- list = NULL;
- if (list == NULL) {
- if (error != NULL && error->code != G_IO_ERROR_NOT_SUPPORTED)
- purple_debug_error("log", "Error listing %s system logs: %s\n",
- PURPLE_LOG_GET_CLASS(log)->logger_name, error->message);
- } else
- callback_data->logs = g_list_concat(callback_data->logs, list);
+ if (list == NULL) {
+ /* It's hard to pass all the errors up, so just log them :( */
+ if (error != NULL)
+ purple_debug_error("log", "Error listing logs: %s\n",
+ error->message);
- g_clear_error(&error);
+ data->counter--;
+ } else {
+ SIMPLE_ASYNC_RESULT_NEW_GOOD(NULL, data->cb, data->userdata,
+ purple_logs_list_system_logs_async,
+ g_simple_async_result_set_op_res_gpointer,
+ list,
+ (GDestroyNotify) purple_log_list_free);
+ }
- if (callback_data->counter < 1) {
- GSimpleAsyncResult *simple = g_simple_async_result_new(NULL,
- callback_data->cb, callback_data->userdata,
- purple_logs_list_system_logs_async);
+ g_clear_error(&error);
+ }
- g_simple_async_result_set_op_res_gpointer(simple, callback_data->logs,
- (GDestroyNotify) purple_log_list_free);
- g_simple_async_result_complete_in_idle(simple);
+ /* If res is NULL, data->counter should already be set to 0 */
- g_object_unref(simple);
- g_free(callback_data);
+ if (data->counter < 1) {
+ SIMPLE_ASYNC_RESULT_NEW_GOOD(NULL, data->cb, data->userdata,
+ purple_logs_list_system_logs_async,
+ g_simple_async_result_set_op_res_gpointer,
+ NULL,
+ NULL);
+
+ g_free(data);
}
}
static void
log_total_size_cb(GObject *object, GAsyncResult *res, gpointer userdata)
{
- _purple_log_total_size_callback_data *callback_data = userdata;
+ _purple_log_total_size_callback_data *data = userdata;
GError *error = NULL;
gssize size;
@@ -2074,34 +2105,26 @@ log_total_size_cb(GObject *object, GAsyn
if (size < 0 && error != NULL)
purple_debug_error("log", "Error getting total size for logs: %s\n",
error->message);
- else if (size > 0)
- callback_data->total += size;
+ else
+ data->total += size;
g_clear_error(&error);
- callback_data->counter--;
+ data->counter--;
- if (callback_data->counter < 1) {
- if (callback_data->cb) {
- GSimpleAsyncResult *simple;
+ if (data->counter < 1) {
+ SIMPLE_ASYNC_RESULT_NEW_GOOD(NULL, data->cb, data->userdata,
+ purple_logs_list_system_logs_async,
+ g_simple_async_result_set_op_res_gssize,
+ data->total);
- simple = g_simple_async_result_new(NULL, callback_data->cb,
- callback_data->userdata, purple_logs_get_total_size_async);
-
- g_simple_async_result_set_op_res_gssize(simple,
- callback_data->total);
- g_simple_async_result_complete_in_idle(simple);
-
- g_object_unref(simple);
- }
-
- g_free(callback_data);
+ g_free(data);
}
}
static void
log_hash_cb(GObject *object, GAsyncResult *res, gpointer userdata)
{
- _purple_log_sets_callback_data *callback_data = userdata;
+ _purple_log_sets_callback_data *data = userdata;
GError *error = NULL;
GHashTable *one_set;
@@ -2112,28 +2135,23 @@ log_hash_cb(GObject *object, GAsyncResul
error->message);
} else {
g_hash_table_foreach_steal(one_set, steal_log_sets,
- callback_data->sets);
+ data->sets);
g_hash_table_destroy(one_set);
}
- callback_data->counter--;
+ data->counter--;
- if (callback_data->counter < 1) {
- if (callback_data->cb) {
- GSimpleAsyncResult *simple;
-
- simple = g_simple_async_result_new(object, callback_data->cb,
- callback_data->userdata, log_get_log_sets_common_async);
-
- g_simple_async_result_set_op_res_gpointer(simple,
- callback_data->sets, (GDestroyNotify) g_hash_table_unref);
- g_simple_async_result_complete_in_idle(simple);
-
- g_object_unref(simple);
+ if (data->counter < 1) {
+ if (data->cb) {
+ SIMPLE_ASYNC_RESULT_NEW_GOOD(NULL, data->cb, data->userdata,
+ log_get_log_sets_common_async,
+ g_simple_async_result_set_op_res_gpointer,
+ data->sets,
+ (GDestroyNotify) g_hash_table_unref);
} else
- g_hash_table_unref(callback_data->sets);
+ g_hash_table_unref(data->sets);
- g_free(callback_data);
+ g_free(data);
}
}
============================================================
--- pidgin/gtklog.c a0e8e4417a03aaa908140d9469337125f57b5c8f
+++ pidgin/gtklog.c d3f4b86555ba09ca175187626abf6b48921799f5
@@ -1165,9 +1165,9 @@ pidgin_log_list_cb(GObject *object, GAsy
GList *list;
list = purple_logs_list_logs_finish(res, &error);
- pidgin_log_data->count--;
+ if (list == NULL) {
+ pidgin_log_data->count--;
- if (list == NULL) {
if (error != NULL && error->code != G_IO_ERROR_CANCELLED)
purple_debug_error("gtklog", "Error getting logs: %s\n",
error->message);
@@ -1191,9 +1191,10 @@ pidgin_log_system_list_cb(GObject *objec
GList *list;
list = purple_logs_list_system_logs_finish(res, &error);
- pidgin_log_data->count--;
if (list == NULL) {
+ pidgin_log_data->count--;
+
if (error != NULL && error->code != G_IO_ERROR_CANCELLED)
purple_debug_error("gtklog", "Error getting system logs: %s\n",
error->message);
============================================================
--- finch/gntlog.c bdabee070f2a152c3aa52913e5f2a5fd69d088e4
+++ finch/gntlog.c 667560b25653cbeee9ef8cdb85a1e620e87fd9df
@@ -639,9 +639,10 @@ finch_log_list_cb(GObject *object, GAsyn
GList *list;
list = purple_logs_list_logs_finish(res, &error);
- finch_log_data->count--;
if (list == NULL) {
+ finch_log_data->count--;
+
if (error != NULL && error->code != G_IO_ERROR_CANCELLED)
purple_debug_error("gntlog", "Error getting logs: %s\n",
error->message);
@@ -665,9 +666,10 @@ finch_log_system_list_cb(GObject *object
GList *list;
list = purple_logs_list_system_logs_finish(res, &error);
- finch_log_data->count--;
if (list == NULL) {
+ finch_log_data->count--;
+
if (error != NULL && error->code != G_IO_ERROR_CANCELLED)
purple_debug_error("gntlog", "Error getting system logs: %s\n",
error->message);
============================================================
--- libpurple/commonlog.c d6d9392d94afb521124cacb67520f8f0432631fb
+++ libpurple/commonlog.c f11617d875efcb112fbce3153cd7ad98ab55df21
@@ -128,7 +128,6 @@ typedef struct {
GCancellable *cancel;
GAsyncReadyCallback cb;
gpointer userdata;
- GList *logs;
GFile *dir;
} list_callback_data;
@@ -993,7 +992,6 @@ purple_common_log_list_async(PurpleLogCh
data->cancel = g_object_ref(cancellable);
data->cb = cb;
data->userdata = userdata;
- data->logs = NULL;
path = purple_log_get_log_dir(chat_type, name, account);
data->dir = g_file_new_for_path(path);
@@ -1032,7 +1030,7 @@ purple_common_log_list_async_3(GObject *
{
GError *err = NULL;
GFileEnumerator *enumerator = G_FILE_ENUMERATOR(object);
- GList *file_infos, *file;
+ GList *file_infos, *file, *logs;
gchar *dir_path;
list_callback_data *data = userdata;
@@ -1043,7 +1041,6 @@ purple_common_log_list_async_3(GObject *
SIMPLE_ASYNC_RESULT_FROM_ERROR(enumerator, data->cb, data->userdata,
err);
list_callback_data_free(data);
- purple_log_list_free(data->logs);
return;
}
@@ -1056,6 +1053,7 @@ purple_common_log_list_async_3(GObject *
}
dir_path = g_file_get_path(data->dir);
+ logs = NULL;
for (file = file_infos; file != NULL; file = file->next) {
GFileInfo *info = file->data;
@@ -1076,13 +1074,19 @@ purple_common_log_list_async_3(GObject *
data->account, data->klass);
g_free(child_path);
- data->logs = g_list_prepend(data->logs, log);
+ logs = g_list_prepend(logs, log);
}
g_list_foreach(file_infos, (GFunc) g_object_unref, NULL);
g_list_free(file_infos);
g_free(dir_path);
+ SIMPLE_ASYNC_RESULT_NEW_GOOD(NULL, data->cb, data->userdata,
+ purple_common_log_list_async,
+ g_simple_async_result_set_op_res_gpointer,
+ logs,
+ (GDestroyNotify) purple_log_list_free);
+
g_file_enumerator_next_files_async(enumerator, 20, data->io_priority,
data->cancel, purple_common_log_list_async_3, data);
}
@@ -1099,17 +1103,14 @@ purple_common_log_list_async_4(GObject *
result = g_file_enumerator_close_finish(enumerator, res, &err);
if (!result) {
- SIMPLE_ASYNC_RESULT_FROM_ERROR(enumerator, data->cb, data->userdata,
- err);
-
- purple_log_list_free(data->logs);
+ SIMPLE_ASYNC_RESULT_FROM_ERROR(NULL, data->cb, data->userdata, err);
} else
/* Everything went fine, notify the user of the logs */
- SIMPLE_ASYNC_RESULT_NEW_GOOD(enumerator, data->cb, data->userdata,
+ SIMPLE_ASYNC_RESULT_NEW_GOOD(NULL, data->cb, data->userdata,
purple_common_log_list_async,
g_simple_async_result_set_op_res_gpointer,
- data->logs,
- (GDestroyNotify) purple_log_list_free);
+ NULL,
+ NULL);
list_callback_data_free(data);
}
More information about the Commits
mailing list