cpw.nader.asynclogging-3: e31dd8da: Changed the API slightly to take PurpleL...
morshed.nader at gmail.com
morshed.nader at gmail.com
Thu Jan 5 15:27:25 EST 2012
----------------------------------------------------------------------
Revision: e31dd8da50bae95052313ade60ff6e020a291080
Parent: 62eab5af1004e838f99360445f1f8ae074cf7b85
Author: morshed.nader at gmail.com
Date: 01/04/12 19:38:07
Branch: im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/e31dd8da50bae95052313ade60ff6e020a291080
Changelog:
Changed the API slightly to take PurpleLogClass'es instead of GTypes
Changes against parent 62eab5af1004e838f99360445f1f8ae074cf7b85
patched libpurple/commonlog.c
patched libpurple/commonlog.h
patched libpurple/htmllog.c
patched libpurple/log.c
patched libpurple/log.h
patched libpurple/oldlog.c
patched libpurple/txtlog.c
-------------- next part --------------
============================================================
--- libpurple/log.c 1571b9f7d76e188aeb558770ec49645073607bbc
+++ libpurple/log.c 4df70e25a6fcba0f063566e0e354420a6996ccc3
@@ -148,10 +148,11 @@ static void log_hash_cb(GObject *, GAsyn
static void log_total_size_cb(GObject *, GAsyncResult *, gpointer);
static void log_hash_cb(GObject *, GAsyncResult *, gpointer);
+static GArray *purple_log_logger_get_all(void);
static GList *purple_log_list_copy(GList *);
static GArray *loggers = NULL;
-static GType current_logger = G_TYPE_INVALID;
+static PurpleLogClass *current_logger = NULL;
static GHashTable *logsize_users = NULL;
static GHashTable *logsize_users_decayed = NULL;
@@ -561,21 +562,20 @@ PurpleLog *
}
PurpleLog *
-purple_log_new(GType log_type, PurpleLogChatType chat_type, const gchar *name,
- PurpleAccount *account, PurpleConversation *conv, time_t time,
- const struct tm *tm)
+purple_log_new(PurpleLogClass *klass, PurpleLogChatType chat_type,
+ const gchar *name, PurpleAccount *account, PurpleConversation *conv,
+ time_t time, const struct tm *tm)
{
PurpleLog *log;
- g_return_val_if_fail(log_type == G_TYPE_INVALID || g_type_is_a(log_type, PURPLE_TYPE_LOG),
- NULL);
+ g_return_val_if_fail(klass == NULL || PURPLE_IS_LOG_CLASS(klass), NULL);
g_return_val_if_fail(name != NULL, NULL);
g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
- if (log_type == G_TYPE_INVALID)
- log_type = current_logger;
+ if (klass == NULL)
+ klass = current_logger;
- log = g_object_new(log_type,
+ log = g_object_new(G_OBJECT_CLASS_TYPE(klass),
"chat-type", chat_type,
"name", g_strdup(purple_normalize(account, name)),
"account", account,
@@ -1689,75 +1689,64 @@ logger_pref_cb(const gchar *name, Purple
array = purple_log_logger_get_all();
for (i = 0; i < array->len; i++) {
- PurpleLogClass *class;
- GType log_type = g_array_index(array, GType, i);
+ PurpleLogClass *klass = g_array_index(array, PurpleLogClass *, i);
- class = g_type_class_peek(log_type);
-
- if (purple_strequal(class->logger_id, value)) {
- purple_log_logger_set(log_type);
+ if (purple_strequal(klass->logger_id, value)) {
+ purple_log_logger_set(klass);
return;
}
}
- purple_log_logger_set(PURPLE_TYPE_TXT_LOG);
+ purple_log_logger_set(g_type_class_peek(PURPLE_TYPE_TXT_LOG));
}
void
-purple_log_logger_add(GType log_type)
+purple_log_logger_add(PurpleLogClass *klass)
{
- PurpleLogClass *class;
guint i;
- g_return_if_fail(log_type == G_TYPE_INVALID || g_type_is_a(log_type, PURPLE_TYPE_LOG));
+ g_return_if_fail(PURPLE_IS_LOG_CLASS(klass));
- for (i = 0; i < loggers->len; i++) {
- if (log_type == g_array_index(loggers, GType, i)) {
+ for (i = 0; i < loggers->len; i++)
+ if (klass == g_array_index(loggers, PurpleLogClass *, i))
return;
- }
- }
- loggers = g_array_append_val(loggers, log_type);
+ loggers = g_array_append_val(loggers, klass);
- class = g_type_class_ref(log_type);
-
if (purple_strequal(purple_prefs_get_string("/purple/logging/format"),
- class->logger_id))
+ klass->logger_id))
purple_prefs_trigger_callback("/purple/logging/format");
}
void
-purple_log_logger_remove(GType log_type)
+purple_log_logger_remove(PurpleLogClass *klass)
{
guint i;
- g_return_if_fail(log_type == G_TYPE_INVALID || g_type_is_a(log_type, PURPLE_TYPE_LOG));
+ g_return_if_fail(PURPLE_IS_LOG_CLASS(klass));
- for (i = 0; i < loggers->len; i++) {
- if (log_type == g_array_index(loggers, GType, i)) {
+ for (i = 0; i < loggers->len; i++)
+ if (klass == g_array_index(loggers, PurpleLogClass *, i)) {
loggers = g_array_remove_index_fast(loggers, i);
- g_type_class_unref(g_type_class_peek(log_type));
-
break;
}
- }
}
void
-purple_log_logger_set(GType log_type)
+purple_log_logger_set(PurpleLogClass *class)
{
- g_return_if_fail(log_type == G_TYPE_INVALID || g_type_is_a(log_type, PURPLE_TYPE_LOG));
+ g_return_if_fail(PURPLE_IS_LOG_CLASS(class));
- current_logger = log_type;
+ current_logger = class;
}
-GType
+PurpleLogClass *
purple_log_logger_get_default(void)
{
return current_logger;
}
-GArray *
+static GArray *
purple_log_logger_get_all(void)
{
return loggers;
@@ -1773,16 +1762,13 @@ purple_log_logger_get_options(void)
array = purple_log_logger_get_all();
for (i = 0; i < array->len; i++) {
- PurpleLogClass *class;
- GType log_type = g_array_index(array, GType, i);
+ PurpleLogClass *klass = g_array_index(array, PurpleLogClass *, i);
- class = g_type_class_ref(log_type);
-
- if (class->write_fn == NULL)
+ if (klass->write_fn == NULL)
continue;
- list = g_list_append(list, (gpointer) class->logger_name);
- list = g_list_append(list, (gpointer) class->logger_id);
+ list = g_list_append(list, (gpointer) klass->logger_name);
+ list = g_list_append(list, (gpointer) klass->logger_id);
}
return list;
============================================================
--- libpurple/log.h e2fb2a56fae482c7365b6dc52f7d3b4fd838c1f0
+++ libpurple/log.h 410d09e43c4dae8687ae910a641e294bec752f77
@@ -318,7 +318,7 @@ GType purple_log_get_type(void);
/**
* Creates a new log
*
- * @param log_type The type for the log class, must extend PURPLE_LOG_TYPE
+ * @param klass The log's class
* @param chat_type The type of log this is
* @param name The name of this conversation (buddy name, chat name, etc.)
* @param account The account the conversation is occurring on
@@ -329,7 +329,7 @@ GType purple_log_get_type(void);
*
* @return The new log
*/
-PurpleLog *purple_log_new(GType log_type, PurpleLogChatType chat_type,
+PurpleLog *purple_log_new(PurpleLogClass *klass, PurpleLogChatType chat_type,
const gchar *name, PurpleAccount *account, PurpleConversation *conv,
time_t time, const struct tm *tm);
@@ -1081,41 +1081,32 @@ void purple_log_set_free(PurpleLogSet *s
/**
* Adds a new logger
*
- * @param log_type The new logger to add
+ * @param klass The new logger to add
*/
-void purple_log_logger_add(GType log_type);
+void purple_log_logger_add(PurpleLogClass *klass);
/**
* Removes a logger
*
- * @param log_type The logger to remove
+ * @param klass The logger to remove
*/
-void purple_log_logger_remove(GType log_type);
+void purple_log_logger_remove(PurpleLogClass *klass);
/**
* Sets the current logger
*
- * @param log_type The logger to set
+ * @param klass The logger to set
*/
-void purple_log_logger_set(GType log_type);
+void purple_log_logger_set(PurpleLogClass *klass);
/**
- * Gets the current default logger's type
+ * Gets the current default logger
*
- * @return The current default logger type
+ * @return The current default logger's class
*/
-GType purple_log_logger_get_default(void);
+PurpleLogClass *purple_log_logger_get_default(void);
/**
- * Gets a list of all the available loggers
- *
- * @return All available loggers
- *
- * @since 3.0.0
- */
-GArray *purple_log_logger_get_all(void);
-
-/**
* Gets a GList containing the IDs and names of the registered loggers
* that are writeable.
*
============================================================
--- libpurple/htmllog.c 5cf4776cc696e07f01d72ae7739e471e9b517653
+++ libpurple/htmllog.c b86dc7520add74933781f1b8bdbe7e3e26dcd0be
@@ -88,8 +88,8 @@ G_DEFINE_TYPE (PurpleHtmlLog, purple_htm
purple_html_write_callback_data *);
G_DEFINE_TYPE (PurpleHtmlLog, purple_html_log, PURPLE_TYPE_COMMON_LOG)
+PurpleLogClass *html_klass = NULL;
-
/* XXX: Move the extension in CommonLog somehow to reduce duplicate code here/txt
* and make things more configurable for future loggers? */
static gboolean
@@ -641,7 +641,7 @@ purple_html_log_list(PurpleLog *log, Pur
PurpleAccount *account, GCancellable *cancellable, GError **error)
{
return purple_common_log_list(type, sn, account, ".html",
- PURPLE_TYPE_HTML_LOG, cancellable, error);
+ html_klass, cancellable, error);
}
static void
@@ -650,7 +650,7 @@ purple_html_log_list_async(PurpleLog *lo
GCancellable *cancellable, GAsyncReadyCallback cb, gpointer userdata)
{
purple_common_log_list_async(type, sn, account, ".html",
- PURPLE_TYPE_HTML_LOG, io_priority, cancellable, cb, userdata);
+ html_klass, io_priority, cancellable, cb, userdata);
}
static GList *
@@ -658,7 +658,7 @@ purple_html_log_list_syslog(PurpleLog *l
GCancellable *cancellable, GError **error)
{
return purple_common_log_list(PURPLE_LOG_SYSTEM, ".system", account,
- ".html", PURPLE_TYPE_HTML_LOG, cancellable, error);
+ ".html", html_klass, cancellable, error);
}
static void
@@ -667,7 +667,7 @@ purple_html_log_list_syslog_async(Purple
gpointer userdata)
{
purple_common_log_list_async(PURPLE_LOG_SYSTEM, ".system", account,
- ".html", PURPLE_TYPE_HTML_LOG, io_priority, cancellable, cb, userdata);
+ ".html", html_klass, io_priority, cancellable, cb, userdata);
}
static gchar *
@@ -844,11 +844,13 @@ purple_html_log_system_init(void)
{
purple_prefs_add_string("/purple/logging/format", "html");
- purple_log_logger_add(PURPLE_TYPE_HTML_LOG);
+ html_klass = g_type_class_ref(PURPLE_TYPE_HTML_LOG);
+ purple_log_logger_add(html_klass);
}
void
purple_html_log_system_uninit(void)
{
- purple_log_logger_remove(PURPLE_TYPE_HTML_LOG);
+ purple_log_logger_remove(html_klass);
+ g_type_class_unref(html_klass);
}
============================================================
--- libpurple/oldlog.c 81c37bbece596d99bfd27b97d6db287ece3fb624
+++ libpurple/oldlog.c cad89a752c00c9310446b5849284dd3bd48d9d2e
@@ -29,6 +29,7 @@ G_DEFINE_TYPE (PurpleOldLog, purple_old_
#include "debug.h"
G_DEFINE_TYPE (PurpleOldLog, purple_old_log, PURPLE_TYPE_COMMON_LOG)
+PurpleLogClass *old_klass = NULL;
static GList *purple_old_log_list(PurpleLog *, PurpleLogChatType, const gchar *,
PurpleAccount *, GCancellable *, GError **);
@@ -164,7 +165,7 @@ purple_old_log_list(PurpleLog *log, Purp
{
PurpleLog *log;
- log = purple_log_new(PURPLE_TYPE_OLD_LOG, PURPLE_LOG_IM,
+ log = purple_log_new(old_klass, PURPLE_LOG_IM,
sn, account, NULL, idx_time, NULL);
purple_common_log_set_path(PURPLE_COMMON_LOG(log),
@@ -270,7 +271,7 @@ purple_old_log_list(PurpleLog *log, Purp
newlen--;
if (newlen != 0) {
- PurpleLog *log = purple_log_new(PURPLE_TYPE_OLD_LOG,
+ PurpleLog *log = purple_log_new(old_klass,
PURPLE_LOG_IM, sn, account, NULL, lasttime, NULL);
purple_common_log_set_path(PURPLE_COMMON_LOG(log),
@@ -331,7 +332,7 @@ purple_old_log_list(PurpleLog *log, Purp
if (log_found) {
if ((newlen = offset - lastoff) != 0) {
- PurpleLog *log = purple_log_new(PURPLE_TYPE_OLD_LOG, PURPLE_LOG_IM,
+ PurpleLog *log = purple_log_new(old_klass, PURPLE_LOG_IM,
sn, account, NULL, lasttime, NULL);
purple_common_log_set_path(PURPLE_COMMON_LOG(log),
@@ -595,11 +596,13 @@ purple_old_log_system_init(void)
{
purple_prefs_add_string("/purple/logging/format", "old");
- purple_log_logger_add(PURPLE_TYPE_OLD_LOG);
+ old_klass = g_type_class_ref(PURPLE_TYPE_OLD_LOG);
+ purple_log_logger_add(old_klass);
}
void
purple_old_log_system_uninit(void)
{
- purple_log_logger_remove(PURPLE_TYPE_OLD_LOG);
+ purple_log_logger_remove(old_klass);
+ g_type_class_unref(old_klass);
}
============================================================
--- libpurple/txtlog.c 00e7d09eb6d7103ecb27638b3554f1faf1651ed8
+++ libpurple/txtlog.c 2b1f737bc7ccbb1f6823633c345072c2b9882ce7
@@ -67,6 +67,7 @@ G_DEFINE_TYPE (PurpleTxtLog, purple_txt_
/* Function prototypes */
G_DEFINE_TYPE (PurpleTxtLog, purple_txt_log, PURPLE_TYPE_COMMON_LOG)
+PurpleLogClass *txt_klass = NULL;
static void purple_txt_log_read_async_2(GObject *, GAsyncResult *, gpointer);
@@ -220,7 +221,7 @@ purple_txt_log_list(PurpleLog *log, Purp
PurpleAccount *account, GCancellable *cancellable, GError **error)
{
return purple_common_log_list(type, sn, account, ".txt",
- PURPLE_TYPE_TXT_LOG, cancellable, error);
+ txt_klass, cancellable, error);
}
static void
@@ -229,7 +230,7 @@ purple_txt_log_list_async(PurpleLog *log
GCancellable *cancellable, GAsyncReadyCallback cb, gpointer userdata)
{
purple_common_log_list_async(type, sn, account, ".txt",
- PURPLE_TYPE_TXT_LOG, io_priority, cancellable, cb, userdata);
+ txt_klass, io_priority, cancellable, cb, userdata);
}
static GList *
@@ -237,7 +238,7 @@ purple_txt_log_list_syslog(PurpleLog *lo
GCancellable *cancellable, GError **error)
{
return purple_common_log_list(PURPLE_LOG_SYSTEM, ".system", account,
- ".txt", PURPLE_TYPE_TXT_LOG, cancellable, error);
+ ".txt", txt_klass, cancellable, error);
}
static void
@@ -246,7 +247,7 @@ purple_txt_log_list_syslog_async(PurpleL
gpointer userdata)
{
purple_common_log_list_async(PURPLE_LOG_SYSTEM, ".system", account,
- ".txt", PURPLE_TYPE_TXT_LOG, io_priority, cancellable, cb, userdata);
+ ".txt", txt_klass, io_priority, cancellable, cb, userdata);
}
static gchar *
@@ -369,12 +370,14 @@ purple_txt_log_system_init(void)
{
purple_prefs_add_string("/purple/logging/format", "txt");
- purple_log_logger_add(PURPLE_TYPE_TXT_LOG);
+ txt_klass = g_type_class_ref(PURPLE_TYPE_TXT_LOG);
+ purple_log_logger_add(txt_klass);
}
void
purple_txt_log_system_uninit(void)
{
- purple_log_logger_remove(PURPLE_TYPE_TXT_LOG);
+ purple_log_logger_remove(txt_klass);
+ g_type_class_unref(txt_klass);
}
============================================================
--- libpurple/commonlog.c f39333822c96056c1a81868ad78d9a539ffe79bc
+++ libpurple/commonlog.c f18ec5466f9c01327e0c62892f98edb20aef8033
@@ -123,7 +123,7 @@ typedef struct {
gchar *name;
PurpleAccount *account;
gchar *ext;
- GType log_type;
+ PurpleLogClass *klass;
gint io_priority;
GCancellable *cancel;
GAsyncReadyCallback cb;
@@ -757,7 +757,7 @@ purple_common_log_read_async_2(GIOChanne
else
data->allocated *= 2;
- tmp = g_try_realloc(data->contents, data->allocated);
+ tmp = g_try_realloc(data->contents, sizeof(gchar) * data->allocated);
if (tmp == NULL) {
SIMPLE_ASYNC_RESULT_FROM_NEW_ERROR(data->log, data->cb,
@@ -828,7 +828,7 @@ create_log(const gchar *dir, const gchar
/* XXX: Poorly named */
static PurpleLog *
create_log(const gchar *dir, const gchar *filename, PurpleLogChatType chat_type,
- const gchar *name, PurpleAccount *account, GType log_type)
+ const gchar *name, PurpleAccount *account, PurpleLogClass *klass)
{
PurpleLog *log;
gchar *tmp;
@@ -852,19 +852,19 @@ create_log(const gchar *dir, const gchar
(end = strchr(rest, '.')) == NULL ||
strchr(rest, ' ') != NULL)
{
- log = purple_log_new(log_type, chat_type, name, account, NULL,
+ log = purple_log_new(klass, chat_type, name, account, NULL,
stamp, NULL);
} else {
gchar *tmp = g_strndup(rest, end - rest);
tm.tm_zone = tmp;
- log = purple_log_new(log_type, chat_type, name, account, NULL,
+ log = purple_log_new(klass, chat_type, name, account, NULL,
stamp, &tm);
g_free(tmp);
}
#else
time_t stamp = purple_str_to_time(filename, FALSE, &tm, NULL, NULL);
- log = purple_log_new(log_type, chat_type, name, account, NULL,
+ log = purple_log_new(klass, chat_type, name, account, NULL,
stamp, (stamp != 0) ? &tm : NULL);
#endif
@@ -877,7 +877,7 @@ purple_common_log_list(PurpleLogChatType
GList *
purple_common_log_list(PurpleLogChatType chat_type, const gchar *name,
- PurpleAccount *account, const gchar *ext, GType log_type,
+ PurpleAccount *account, const gchar *ext, PurpleLogClass *klass,
GCancellable *cancellable, GError **error)
{
GDir *dir;
@@ -889,9 +889,7 @@ purple_common_log_list(PurpleLogChatType
g_return_val_if_fail(name != NULL, NULL);
g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
g_return_val_if_fail(ext != NULL, NULL);
- g_return_val_if_fail(log_type == G_TYPE_INVALID ||
- g_type_is_a(log_type, PURPLE_TYPE_LOG),
- NULL);
+ g_return_val_if_fail(PURPLE_IS_LOG_CLASS(klass), NULL);
path = purple_log_get_log_dir(chat_type, name, account);
@@ -931,8 +929,8 @@ purple_common_log_list(PurpleLogChatType
if (purple_str_has_suffix(filename, ext) &&
strlen(filename) >= (17 + strlen(ext))) /* XXX: ? */
{
- PurpleLog *log = create_log(path, filename, chat_type, name, account,
- log_type);
+ PurpleLog *log = create_log(path, filename, chat_type, name,
+ account, klass);
list = g_list_prepend(list, log);
}
}
@@ -945,8 +943,9 @@ purple_common_log_list_async(PurpleLogCh
void
purple_common_log_list_async(PurpleLogChatType chat_type, const gchar *name,
- PurpleAccount *account, const gchar *ext, GType log_type, gint io_priority,
- GCancellable *cancellable, GAsyncReadyCallback cb, gpointer userdata)
+ PurpleAccount *account, const gchar *ext, PurpleLogClass *klass,
+ gint io_priority, GCancellable *cancellable, GAsyncReadyCallback cb,
+ gpointer userdata)
{
GFile *dir;
gchar *path;
@@ -957,7 +956,7 @@ purple_common_log_list_async(PurpleLogCh
data->name = g_strdup(name);
data->account = account; /* XXX: g_object_ref(account) */
data->ext = g_strdup(ext);
- data->log_type = log_type;
+ data->klass = klass;
data->io_priority = io_priority;
data->cancel = g_object_ref(cancellable);
data->cb = cb;
@@ -1042,7 +1041,7 @@ purple_common_log_list_async_3(GObject *
continue;
log = create_log(dir, filename, data->chat_type, data->name,
- data->account, data->log_type);
+ data->account, data->klass);
data->logs = g_list_prepend(data->logs, log);
}
============================================================
--- libpurple/commonlog.h 85004b453fd72a95b01a140e99fd26f73b3d5c91
+++ libpurple/commonlog.h b729a01ce46c18d98275851a4fc18951240f5308
@@ -234,15 +234,15 @@ gchar *purple_common_log_read_finish(Pur
* @param name The name of the log
* @param account The account of the log
* @param ext The file extension this log format uses
- * @param log_type The log type to create the new logs with, or
- * G_TYPE_INVALID to use the default type
+ * @param klass The log class to create the new logs with, or
+ * NULL to use the default type
* @param cancellable (allow-none): GCancellable object
* @param error (out) (allow-none): a GError location to store the error
*
* @return The sorted list of logs matching the parameters
*/
GList *purple_common_log_list(PurpleLogChatType chat_type, const gchar *name,
- PurpleAccount *account, const gchar *ext, GType log_type,
+ PurpleAccount *account, const gchar *ext, PurpleLogClass *klass,
GCancellable *cancellable, GError **error);
/**
@@ -253,8 +253,8 @@ GList *purple_common_log_list(PurpleLogC
* @param name The name of the log
* @param account The account of the log
* @param ext The file extension this log format uses
- * @param log_type The log type to create the new logs with, or
- * G_TYPE_INVALID to use the default type
+ * @param klass The log class to create the new logs with, or
+ * NULL to use the default type
* @param io_priority The io priority of the request
* @param cancellable (allow-none): GCancellable object
* @param cb (allow-none): A GAsyncReadyCallback to call when the
@@ -264,8 +264,9 @@ void purple_common_log_list_async(Purple
* @since 3.0.0
*/
void purple_common_log_list_async(PurpleLogChatType type, const gchar *name,
- PurpleAccount *account, const gchar *ext, GType log_type, gint io_priority,
- GCancellable *cancellable, GAsyncReadyCallback cb, gpointer userdata);
+ PurpleAccount *account, const gchar *ext, PurpleLogClass *klass,
+ gint io_priority, GCancellable *cancellable, GAsyncReadyCallback cb,
+ gpointer userdata);
/**
* Finishes asynchronously listing the logs of a requested type.
More information about the Commits
mailing list