cpw.nader.asynclogging-3: 98aaf314: Cleaned up and updated the docs in log.h

morshed.nader at gmail.com morshed.nader at gmail.com
Wed Jan 19 01:50:42 EST 2011


----------------------------------------------------------------------
Revision: 98aaf314a845a1d550deeeb8c1a91f3f6fdf8075
Parent:   d4290ea54506b3b5ad2332520d0162f25e1986be
Author:   morshed.nader at gmail.com
Date:     01/18/11 13:42:05
Branch:   im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/98aaf314a845a1d550deeeb8c1a91f3f6fdf8075

Changelog: 

Cleaned up and updated the docs in log.h
Made purple_log_logger_get_options only check for write_fn

Changes against parent d4290ea54506b3b5ad2332520d0162f25e1986be

  patched  libpurple/commonlog.c
  patched  libpurple/log.c
  patched  libpurple/log.h

-------------- next part --------------
============================================================
--- libpurple/log.c	b0b025f999a3ed31d95229c835fbcd0a1a65757b
+++ libpurple/log.c	209ddae54b08b76a01b9bf97aedcb32cb64b24e3
@@ -1761,11 +1761,11 @@ purple_log_logger_get_options(void)
 
 		class = g_type_class_ref(log_type);
 
-		if (class->write_fn == NULL && class->write_async == NULL)
+		if (class->write_fn == NULL)
 			continue;
 
-		list = g_list_append(list, (void *) class->logger_name);
-		list = g_list_append(list, (void *) class->logger_id);
+		list = g_list_append(list, (gpointer) class->logger_name);
+		list = g_list_append(list, (gpointer) class->logger_id);
 	}
 
 	return list;
@@ -1802,45 +1802,6 @@ purple_log_get_logs(PurpleLog *log, Purp
 	return class->list_fn(log, chat_type, name, account, cancellable, error);
 }
 
-GList *
-purple_logs_get_logs(PurpleLogChatType chat_type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error)
-{
-	GArray *array;
-	GList *logs = NULL;
-	guint i;
-
-	g_return_val_if_fail(name != NULL, NULL);
-	g_return_val_if_fail(account != NULL, NULL); // PURPLE_IS_ACCOUNT(account)
-
-	array = purple_log_logger_get_all();
-
-	for (i = 0; i < array->len; i++) {
-		PurpleLog *log;
-		GError *err = NULL;
-		GList *list;
-		GType log_type = g_array_index(array, GType, i);
-
-		log = g_object_new(log_type, NULL);
-		list = purple_log_get_logs(log, chat_type, name, account, cancellable, &err);
-
-		if (list == NULL && err != NULL) {
-			g_propagate_error(error, err);
-			g_list_foreach(logs, (GFunc) g_object_unref, NULL);
-			g_list_free(logs);
-
-			g_clear_error(&err);
-			g_object_unref(log);
-
-			return NULL;
-		}
-
-		logs = g_list_concat(list, logs);
-		g_object_unref(log);
-	}
-
-	return g_list_sort(logs, purple_log_compare);
-}
-
 static void
 get_logs_thread(GSimpleAsyncResult *simple, GObject *object, GCancellable *cancellable)
 {
@@ -1892,6 +1853,67 @@ purple_log_get_logs_async(PurpleLog *log
 	PURPLE_LOG_GET_CLASS(log)->list_async(log, chat_type, name, account, io_priority, cancellable, cb, userdata);
 }
 
+static GList *
+purple_log_real_get_logs_finish(PurpleLog *log, GAsyncResult *res, GError **error)
+{
+	return g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(res));
+}
+
+GList *
+purple_log_get_logs_finish(PurpleLog *log, GAsyncResult *res, GError **error)
+{
+	g_return_val_if_fail(PURPLE_IS_LOG(log), NULL);
+	g_return_val_if_fail(G_IS_ASYNC_RESULT(res), NULL);
+
+	if (G_IS_SIMPLE_ASYNC_RESULT(res)) {
+		GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(res);
+
+		if (g_simple_async_result_propagate_error(simple, error))
+			return NULL;
+	}
+
+	return PURPLE_LOG_GET_CLASS(log)->list_finish(log, res, error);
+}
+
+GList *
+purple_logs_get_logs(PurpleLogChatType chat_type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error)
+{
+	GArray *array;
+	GList *logs = NULL;
+	guint i;
+
+	g_return_val_if_fail(name != NULL, NULL);
+	g_return_val_if_fail(account != NULL, NULL); // PURPLE_IS_ACCOUNT(account)
+
+	array = purple_log_logger_get_all();
+
+	for (i = 0; i < array->len; i++) {
+		PurpleLog *log;
+		GError *err = NULL;
+		GList *list;
+		GType log_type = g_array_index(array, GType, i);
+
+		log = g_object_new(log_type, NULL);
+		list = purple_log_get_logs(log, chat_type, name, account, cancellable, &err);
+
+		if (list == NULL && err != NULL) {
+			g_propagate_error(error, err);
+			g_list_foreach(logs, (GFunc) g_object_unref, NULL);
+			g_list_free(logs);
+
+			g_clear_error(&err);
+			g_object_unref(log);
+
+			return NULL;
+		}
+
+		logs = g_list_concat(list, logs);
+		g_object_unref(log);
+	}
+
+	return g_list_sort(logs, purple_log_compare);
+}
+
 void
 purple_logs_get_logs_async(PurpleLogChatType chat_type, const gchar *name, PurpleAccount *account, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback cb, gpointer userdata)
 {
@@ -1920,29 +1942,7 @@ purple_logs_get_logs_async(PurpleLogChat
 	}
 }
 
-static GList *
-purple_log_real_get_logs_finish(PurpleLog *log, GAsyncResult *res, GError **error)
-{
-	return g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(res));
-}
-
 GList *
-purple_log_get_logs_finish(PurpleLog *log, GAsyncResult *res, GError **error)
-{
-	g_return_val_if_fail(PURPLE_IS_LOG(log), NULL);
-	g_return_val_if_fail(G_IS_ASYNC_RESULT(res), NULL);
-
-	if (G_IS_SIMPLE_ASYNC_RESULT(res)) {
-		GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(res);
-
-		if (g_simple_async_result_propagate_error(simple, error))
-			return NULL;
-	}
-
-	return PURPLE_LOG_GET_CLASS(log)->list_finish(log, res, error);
-}
-
-GList *
 purple_logs_get_logs_finish(GAsyncResult *res, GError **error)
 {
 	GSimpleAsyncResult *simple;
============================================================
--- libpurple/log.h	320d87df0fb2a91df0c5cebbf722aeac6d13c3a5
+++ libpurple/log.h	3931c44fa1c5609b9c81fabfb6bc9cb0c92807ba
@@ -95,8 +95,11 @@ struct _PurpleLog {
 
 
 /**
- * This struct gets filled out and is included in the PurpleLog. It contains everything
- * needed to write and read from logs.
+ * This struct gets filled out and is included in the PurpleLog. It contains
+ * everything needed to write and read from logs.
+ *
+ * All asynchronous and finish methods are normally implemented by PurpleLog
+ * and rely on the synchronous versions being implemented by the subclasses
  */
 struct _PurpleLogClass {
 	GObjectClass parent_class;
@@ -107,54 +110,121 @@ struct _PurpleLogClass {
 	/** An identifier to refer to this logger */
 	const gchar *logger_id;
 
-	/** This is used to write to the log file */
-	gssize (* write_fn) (PurpleLog *log, PurpleMessageFlags type, const gchar *from, time_t time, const gchar *message, GCancellable *cancellable, GError **error);
+	/** Writes a message to a log */
+	gssize (* write_fn) (PurpleLog *log, PurpleMessageFlags type,
+		const gchar *from, time_t time, const gchar *message,
+		GCancellable *cancellable, GError **error);
 
-	void (* write_async) (PurpleLog *log, PurpleMessageFlags type, const gchar *from, time_t time, const gchar *message, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
+	/** Asynchronously writes a message to a log */
+	void (* write_async) (PurpleLog *log, PurpleMessageFlags type,
+		const gchar *from, time_t time, const gchar *message,
+		gint io_priority, GCancellable *cancellable,
+		GAsyncReadyCallback callback, gpointer user_data);
 
+	/** Finishes an asynchronous write operation */
 	gssize (* write_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
 
-	/** This function returns a sorted #GList of available #PurpleLog<!-- -->s */
-	GList * (* list_fn) (PurpleLog *log, PurpleLogChatType type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error);
+	/** Reads all messages from a log */
+	gchar * (* read_fn) (PurpleLog *log, PurpleLogReadFlags *flags,
+		GCancellable *cancellable, GError **error);
 
-	//log is a dummy, only used to keep track of the class
-	void (* list_async) (PurpleLog *log, PurpleLogChatType type, const gchar *name, PurpleAccount *account, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
+	/** Asynchronously reads all messages from a log */
+	void (* read_async) (PurpleLog *log, gint io_priority,
+		GCancellable *cancellable, GAsyncReadyCallback callback,
+		gpointer user_data);
 
-	//log is a dummy, only used to keep track of the class
-	GList * (* list_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
+	/** Finishes an asynchronous read operation */
+	gchar * (* read_finish) (PurpleLog *log, GAsyncResult *res,
+		PurpleLogReadFlags *flags, GError **error);
 
-	/** Given one of the logs returned by the logger's list function,
-	 *  this returns the contents of the log in GtkIMHtml markup */
-	gchar * (* read_fn) (PurpleLog *log, PurpleLogReadFlags *flags, GCancellable *cancellable, GError **error);
+	/** Gets the size of a log */
+	gssize (* size_fn) (PurpleLog *log, GCancellable *cancellable, GError **error);
 
-	void (* read_async) (PurpleLog *log, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
+	/** Asynchronously gets the size of a log */
+	void (* size_async) (PurpleLog *log, gint io_priority,
+		GCancellable *cancellable, GAsyncReadyCallback callback,
+		gpointer user_data);
 
-	gchar * (* read_finish) (PurpleLog *log, GAsyncResult *res, PurpleLogReadFlags *flags, GError **error);
+	/** Finishes an asynchronous size operation */
+	gssize (* size_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
 
-	/** Given one of the logs returned by the logger's list function,
-	 *  this returns the size of the log in bytes */
-	gssize (* size_fn) (PurpleLog *log, GCancellable *cancellable, GError **error);
+	/**
+	 * Lists all available logs
+	 *
+	 * The log argument is a dummy object, only used to keep track of the class
+	 */
+	GList * (* list_fn) (PurpleLog *log, PurpleLogChatType type,
+		const gchar *name, PurpleAccount *account,
+		GCancellable *cancellable, GError **error);
 
-	void (* size_async) (PurpleLog *log, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
+	/**
+	 * Asynchronously lists all available logs
+	 *
+	 * The log argument is a dummy object, only used to keep track of the class
+	 */
+	void (* list_async) (PurpleLog *log, PurpleLogChatType type,
+		const gchar *name, PurpleAccount *account, gint io_priority,
+		GCancellable *cancellable, GAsyncReadyCallback callback,
+		gpointer user_data);
 
-	gssize (* size_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
+	/**
+	 * Finishes an asynchronous list logs operation
+	 *
+	 * The log argument is a dummy object, only used to keep track of the class
+	 */
+	GList * (* list_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
 
-	/** Returns the total size of all the logs. If this is undefined a default
-	 *  implementation is used */
-	gssize (* total_size_fn) (PurpleLog *log, PurpleLogChatType type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error);
+	/**
+	 * Lists all available system logs
+	 *
+	 * The log argument is a dummy object, only used to keep track of the class
+	 */
+	GList * (* list_syslog_fn) (PurpleLog *log, PurpleAccount *account,
+		GCancellable *cancellable, GError **error);
 
-	//log is a dummy, only used to keep track of the class
-	void (* total_size_async) (PurpleLog *log, PurpleLogChatType type, const gchar *name, PurpleAccount *account, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
+	/**
+	 * Asynchronously lists all available system logs
+	 *
+	 * The log argument is a dummy object, only used to keep track of the class
+	 */
+	void (* list_syslog_async) (PurpleLog *log, PurpleAccount *account,
+		gint io_priority, GCancellable *cancellable,
+		GAsyncReadyCallback callback, gpointer user_data);
 
-	//log is a dummy, only used to keep track of the class
-	gssize (* total_size_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
+	/**
+	 * Finishes an asynchronous list system logs operation
+	 *
+	 * The log argument is a dummy object, only used to keep track of the class
+	 */
+	GList * (* list_syslog_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
 
-	/** This function returns a sorted #GList of available system #PurpleLog<!-- -->s */
-	GList * (* list_syslog_fn) (PurpleLog *log, PurpleAccount *account, GCancellable *cancellable, GError **error);
+	/**
+	 * Gets the total size for all available logs
+	 *
+	 * If this is undefined a default implementation is used
+	 *
+	 * The log argument is a dummy object, only used to keep track of the class
+	 */
+	gssize (* total_size_fn) (PurpleLog *log, PurpleLogChatType type,
+		const gchar *name, PurpleAccount *account,
+		GCancellable *cancellable, GError **error);
 
-	void (* list_syslog_async) (PurpleLog *log, PurpleAccount *account, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
+	/**
+	 * Asynchronously gets the total size for all available logs
+	 *
+	 * The log argument is a dummy object, only used to keep track of the class
+	 */
+	void (* total_size_async) (PurpleLog *log, PurpleLogChatType type,
+		const gchar *name, PurpleAccount *account, gint io_priority,
+		GCancellable *cancellable, GAsyncReadyCallback callback,
+		gpointer user_data);
 
-	GList * (* list_syslog_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
+	/**
+	 * Finishes an asynchronous total size operation
+	 *
+	 * The log argument is a dummy object, only used to keep track of the class
+	 */
+	gssize (* total_size_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
 
 	/** Adds #PurpleLogSet<!-- -->s to a #GHashTable. By passing the data in the #PurpleLogSet<!-- -->s
 	 *  to list, the caller can get every available PurpleLog from the logger.
@@ -164,25 +234,42 @@ struct _PurpleLogClass {
 	 *
 	 *  Loggers which implement this function must create a #PurpleLogSet,
 	 *  then call @a cb with @a sets and the newly created #PurpleLogSet. */
-	GHashTable * (* get_log_sets_fn) (PurpleLog *log, GCancellable *cancellable, GError **error);
+	GHashTable * (* get_log_sets_fn) (PurpleLog *log, GCancellable *cancellable,
+		GError **error);
 
-	void (* get_log_sets_async) (PurpleLog *log, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
+	/** Asynchronously gets all available log sets */
+	void (* get_log_sets_async) (PurpleLog *log, gint io_priority,
+		GCancellable *cancellable, GAsyncReadyCallback callback,
+		gpointer user_data);
 
-	GHashTable * (* get_log_sets_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
+	/** Finishes an asynchronous get log sets operation */
+	GHashTable * (* get_log_sets_finish) (PurpleLog *log, GAsyncResult *res,
+		GError **error);
 
-	/** Attempts to remove the specified log, indicating success or failure */
-	gboolean (* remove_fn) (PurpleLog *log, GCancellable *cancellable, GError **error);
+	/** Removes a log */
+	gboolean (* remove_fn) (PurpleLog *log, GCancellable *cancellable,
+		GError **error);
 
-	void (* remove_async) (PurpleLog *log, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
+	/** Asynchronously removes a log */
+	void (* remove_async) (PurpleLog *log, gint io_priority,
+		GCancellable *cancellable, GAsyncReadyCallback callback,
+		gpointer user_data);
 
+	/** Finishes an asynchronously remove operation */
 	gboolean (* remove_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
 
 	/** Tests whether a log is removable */
-	gboolean (* is_removable_fn) (PurpleLog *log, GCancellable *cancellable, GError **error);
+	gboolean (* is_removable_fn) (PurpleLog *log, GCancellable *cancellable,
+		GError **error);
 
-	void (* is_removable_async) (PurpleLog *log, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
+	/** Asynchronously tests whether a log is removable */
+	void (* is_removable_async) (PurpleLog *log, gint io_priority,
+		GCancellable *cancellable, GAsyncReadyCallback callback,
+		gpointer user_data);
 
-	gboolean (* is_removable_finish) (PurpleLog *log, GAsyncResult *res, GError **error);
+	/** Finishes an asynchronous test of whether a log is removable */
+	gboolean (* is_removable_finish) (PurpleLog *log, GAsyncResult *res,
+		GError **error);
 
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);
@@ -190,6 +277,7 @@ struct _PurpleLogClass {
 	void (*_purple_reserved4)(void);
 };
 
+//GObjectify this?
 /**
  * Describes available logs.
  *
@@ -197,21 +285,30 @@ struct _PurpleLogSet {
  * can get all available #PurpleLog<!-- -->s.
  */
 struct _PurpleLogSet {
-	PurpleLogChatType type;        /**< The type of logs available */
-	gchar *name;               /**< The name of the logs available */
-	PurpleAccount *account;    /**< The account the available logs took place on.
-								*   This will be @c %NULL if the account no longer exists.
-								*
-								*   (Depending on a logger's implementation of list, it may
-								*   not be possible to load such logs.)
-								*/
-	gboolean buddy;            /**< Is this (account, name) a buddy on the buddy list? */
-	gchar *normalized_name;    /**< The normalized version of @a name. It must be set, and
-								*   may be set to the same pointer value as @a name. */
+	/** The type of logs available */
+	PurpleLogChatType type;
 
-	/* IMPORTANT: Some code in log.c allocates these without zeroing them.
-	 * IMPORTANT: Update that code if you add members here. */
+	/** The name of the logs available */
+	gchar *name;
 
+	/**
+	 * The account the available logs took place on.
+	 * This will be @c %NULL if the account no longer exists.
+	 *
+	 * (Depending on a logger's implementation of list, it may
+	 * not be possible to load such logs.)
+	 */
+	PurpleAccount *account;
+
+	/** Is this (account, name) a buddy on the buddy list? */
+	gboolean buddy;
+
+	/**
+	 * The normalized version of @a name. It must be set, and
+	 * may be set to the same pointer value as @a name.
+	 */
+	gchar *normalized_name;
+
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);
 	void (*_purple_reserved3)(void);
@@ -243,8 +340,6 @@ PurpleLog *purple_log_new(GType log_type
 PurpleLog *purple_log_new(GType log_type, PurpleLogChatType chat_type, const gchar *name, PurpleAccount *account, PurpleConversation *conv, time_t time, const struct tm *tm);
 
 //
-void purple_log_set_logger_data(PurpleLog *log, gpointer logger_data);
-//
 PurpleLogChatType purple_log_get_chat_type(const PurpleLog *log);
 //
 G_CONST_RETURN gchar *purple_log_get_name(const PurpleLog *log);
@@ -744,7 +839,7 @@ GArray *purple_log_logger_get_all(void);
 GArray *purple_log_logger_get_all(void);
 
 /**
- * Gets a #GList containing the IDs and names of the registered loggers.
+ * Gets a #GList containing the IDs and names of the registered loggers that are writeable.
  *
  * @return            The list of IDs and names
  */
============================================================
--- libpurple/commonlog.c	a2aac71630152dfdf5e12271795e544c4b2d5721
+++ libpurple/commonlog.c	2c2837e8f675a36c6bceb5c85bc51c466eea48c9
@@ -455,7 +455,6 @@ purple_log_common_lister(PurpleLogChatTy
 
 	if (dir == NULL) {
 		g_free(path);
-
 		return NULL;
 	}
 


More information about the Commits mailing list