cpw.nader.asynclogging-3: d55884d4: Removed the length and offset properties...
morshed.nader at gmail.com
morshed.nader at gmail.com
Sat Jan 7 22:01:56 EST 2012
----------------------------------------------------------------------
Revision: d55884d4478d38142536c16c4d2668db13162112
Parent: 17498befb6aeeeb4253902c47056c06775b14b06
Author: morshed.nader at gmail.com
Date: 01/06/12 12:32:08
Branch: im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/d55884d4478d38142536c16c4d2668db13162112
Changelog:
Removed the length and offset properties from commonlog and moved them to private properties for oldlogs
Made set_socket for common logs a private function/a read-only property
Updated the documentation in log.h and commonlog.h for how the asyncronous listers behave
Changes against parent 17498befb6aeeeb4253902c47056c06775b14b06
patched libpurple/commonlog.c
patched libpurple/commonlog.h
patched libpurple/log.h
patched libpurple/oldlog.c
-------------- next part --------------
============================================================
--- libpurple/log.h 2e5e14c1a81e72c3d90381b6830cd71815edc6b9
+++ libpurple/log.h 6d97fe48d8538e5e81b2022dfbd265cdd61e8d2b
@@ -494,7 +494,6 @@ gssize purple_log_get_size_finish(Purple
/**
* Gets a list of all available logs for all available added loggers.
- * See purple_log_get_logs() for more details.
*
* @param chat_type The type of the log
* @param name The name of the log
@@ -512,8 +511,11 @@ GList *purple_logs_list_logs(PurpleLogCh
/**
* Asynchronously gets a list of all available logs for all available added
* loggers.
- * See purple_log_get_logs_async() for more details.
*
+ * Will continously call cb with more logs until all have been listed, allowing
+ * for continous display of the data. When done, the cb receive NULL from
+ * purple_logs_list_logs_finish() and the error pointer will remain untouched.
+ *
* @param type The type of the log
* @param name The name of the log
* @param account The account
@@ -533,8 +535,10 @@ void purple_logs_list_logs_async(PurpleL
/**
* Finishes asynchronously getting a list of all available logs
- * See purple_log_get_logs_finish() for more details.
*
+ * Note: Make sure to examine that error is not NULL as this function will also
+ * return NULL when all logs have been listed.
+ *
* @param res A GAsyncResult
* @param error (out) (allow-none): a GError location to store the error
*
@@ -546,7 +550,6 @@ GList *purple_logs_list_logs_finish(GAsy
/**
* Gets a list of all available system logs for all added loggers.
- * See purple_log_get_system_logs() for more details.
*
* @param account The account
* @param cancellable (allow-none): GCancellable object
@@ -562,8 +565,11 @@ GList *purple_logs_list_system_logs(Purp
/**
* Asynchronously gets a list of all available system logs for all added
* loggers.
- * See purple_log_get_system_logs_async() for more details.
*
+ * Will continously call cb with more logs until all have been listed, allowing
+ * for continous display of the data. When done, the cb receive NULL from
+ * purple_logs_list_logs_finish() and the error pointer will remain untouched.
+ *
* @param account The account
* @param io_priority The io priority of the request
* @param cancellable (allow-none): GCancellable object
@@ -580,8 +586,10 @@ void purple_logs_list_system_logs_async(
/**
* Finishes asynchronously getting all available system logs for all added
* loggers.
- * See purple_log_get_system_logs_finish() for more details.
*
+ * Note: Make sure to examine that error is not NULL as this function will also
+ * return NULL when all logs have been listed.
+ *
* @param res A GAsyncResult
* @param error (out) (allow-none): a GError location to store the error
*
@@ -593,7 +601,6 @@ GList *purple_logs_list_system_logs_fini
/**
* Gets the total size of all stored conversations.
- * See purple_log_get_total_size().
*
* @param type The type of the log
* @param name The name of the log
@@ -610,7 +617,6 @@ gssize purple_logs_get_total_size(Purple
/**
* Asynchronously gets the total size of all stored conversations.
- * See purple_log_get_total_size_async().
*
* @param type The type of the log
* @param name The name of the log
@@ -629,7 +635,6 @@ void purple_logs_get_total_size_async(Pu
/**
* Finishes asynchronously getting the total size of all stored conversations.
- * See purple_log_get_total_size_finish().
*
* @param res A GAsyncResult
* @param error (out) (allow-none): a GError location to store the error
@@ -642,7 +647,6 @@ gssize purple_logs_get_total_size_finish
/**
* Gets a hash table for the combined log sets of all accounts.
- * See purple_log_get_log_sets() for more details.
*
* @param cancellable (allow-none): GCancellable object
* @param error (out) (allow-none): a GError location to store the error
@@ -656,7 +660,6 @@ GHashTable *purple_logs_get_log_sets(GCa
/**
* Asynchronously gets a GHashTable for the combined log sets of all accounts.
- * See purple_log_get_log_sets_async() for more details.
*
* @param io_priority The io priority of the request
* @param cancellable (allow-none): GCancellable object
@@ -671,7 +674,6 @@ void purple_logs_get_log_sets_async(gint
/**
* Finishes asynchronously getting the log sets for all accounts.
- * See purple_log_get_log_sets_finish() for more details.
*
* @param res A GAsyncResult
* @param error (out) (allow-none): a GError location to store the error
============================================================
--- libpurple/oldlog.c d269cc7cc81e499e0b5e0a326c1e3823e94fb363
+++ libpurple/oldlog.c 552d2b6cd4a3e44519526bbd86a9bdb107f75b0e
@@ -29,6 +29,15 @@ G_DEFINE_TYPE (PurpleOldLog, purple_old_
#include "debug.h"
G_DEFINE_TYPE (PurpleOldLog, purple_old_log, PURPLE_TYPE_COMMON_LOG)
+#define PURPLE_OLD_LOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+ PURPLE_TYPE_OLD_LOG, PurpleOldLogPrivate))
+typedef struct _PurpleOldLogPrivate PurpleOldLogPrivate;
+
+struct _PurpleOldLogPrivate {
+ gssize offset;
+ gssize length;
+};
+
PurpleLogClass *old_klass = NULL;
/**
@@ -134,16 +143,17 @@ purple_old_log_list(PurpleLogChatType ch
&idx_time) == 3)
{
PurpleLog *log;
+ PurpleOldLogPrivate *priv;
log = purple_log_new(old_klass, PURPLE_LOG_IM,
sn, account, NULL, idx_time, NULL);
+ priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
+
purple_common_log_set_path(PURPLE_COMMON_LOG(log),
g_file_get_path(file));
- purple_common_log_set_offset(PURPLE_COMMON_LOG(log),
- lastoff);
- purple_common_log_set_length(PURPLE_COMMON_LOG(log),
- newlen);
+ priv->offset = lastoff;
+ priv->length = newlen;
list = g_list_prepend(list, log);
}
@@ -241,15 +251,18 @@ purple_old_log_list(PurpleLogChatType ch
newlen--;
if (newlen != 0) {
- PurpleLog *log = purple_log_new(old_klass,
- PURPLE_LOG_IM, sn, account, NULL, lasttime, NULL);
+ PurpleLog *log;
+ PurpleOldLogPrivate *priv;
+
+ log = purple_log_new(old_klass, PURPLE_LOG_IM, sn, account,
+ NULL, lasttime, NULL);
+ priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
+
purple_common_log_set_path(PURPLE_COMMON_LOG(log),
g_file_get_path(file));
- purple_common_log_set_offset(PURPLE_COMMON_LOG(log),
- lastoff);
- purple_common_log_set_length(PURPLE_COMMON_LOG(log),
- newlen);
+ priv->offset = lastoff;
+ priv->length = newlen;
list = g_list_prepend(list, log);
@@ -302,13 +315,18 @@ purple_old_log_list(PurpleLogChatType ch
if (log_found) {
if ((newlen = offset - lastoff) != 0) {
- PurpleLog *log = purple_log_new(old_klass, PURPLE_LOG_IM,
- sn, account, NULL, lasttime, NULL);
+ PurpleLog *log;
+ PurpleOldLogPrivate *priv;
+
+ log = purple_log_new(old_klass, PURPLE_LOG_IM, sn, account,
+ NULL, lasttime, NULL);
+ priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
+
purple_common_log_set_path(PURPLE_COMMON_LOG(log),
g_file_get_path(file));
- purple_common_log_set_offset(PURPLE_COMMON_LOG(log), lastoff);
- purple_common_log_set_length(PURPLE_COMMON_LOG(log), newlen);
+ priv->offset = lastoff;
+ priv->length = newlen;
list = g_list_prepend(list, log);
@@ -391,12 +409,13 @@ purple_old_log_read(PurpleLog *log, Purp
purple_old_log_read(PurpleLog *log, PurpleLogReadFlags *flags,
GCancellable *cancellable, GError **error)
{
+ PurpleOldLogPrivate *priv;
GFile *file;
GFileInputStream *file_stream;
GInputStream *stream;
const gchar *path;
gchar *read;
- gssize length, offset, result;
+ gssize result;
path = purple_common_log_get_path(PURPLE_COMMON_LOG(log));
file = g_file_new_for_path(path);
@@ -406,9 +425,9 @@ purple_old_log_read(PurpleLog *log, Purp
if (file_stream == NULL)
return NULL;
- offset = purple_common_log_get_offset(PURPLE_COMMON_LOG(log));
stream = G_INPUT_STREAM(file_stream);
- result = g_input_stream_skip(stream, offset, cancellable, error);
+ priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
+ result = g_input_stream_skip(stream, priv->offset, cancellable, error);
if (result < 0) {
g_object_unref(stream);
@@ -416,9 +435,8 @@ purple_old_log_read(PurpleLog *log, Purp
return NULL;
}
- length = purple_common_log_get_length(PURPLE_COMMON_LOG(log));
- read = g_malloc(length + 1);
- result = g_input_stream_read(stream, read, length, cancellable, error);
+ read = g_malloc(priv->length + 1);
+ result = g_input_stream_read(stream, read, priv->length, cancellable, error);
if (result < 0) {
g_free(read);
@@ -429,7 +447,7 @@ purple_old_log_read(PurpleLog *log, Purp
g_object_unref(stream);
- read[length] = '\0';
+ read[priv->length] = '\0';
if (flags != NULL) {
if (strstr(read, "<BR>"))
============================================================
--- libpurple/commonlog.c 72483c0d5a5f2cfd79ac4bf1b01fd149dad126ba
+++ libpurple/commonlog.c cf289a0c56478a5211e103b0f0a3b06161fed03b
@@ -82,8 +82,6 @@ enum {
PROP_0,
PROP_COMMON_LOG_PATH,
PROP_COMMON_LOG_SOCKET,
- PROP_COMMON_LOG_OFFSET,
- PROP_COMMON_LOG_LENGTH,
LAST_PROP
};
@@ -96,8 +94,6 @@ struct _PurpleCommonLogPrivate {
struct _PurpleCommonLogPrivate {
gchar *path;
gint socket;
- gssize offset;
- gssize length;
};
typedef struct {
@@ -247,26 +243,8 @@ purple_common_log_class_init(PurpleCommo
-1,
G_MAXINT,
-1,
- G_PARAM_READWRITE);
+ G_PARAM_READABLE);
- properties[PROP_COMMON_LOG_OFFSET] =
- g_param_spec_long("offset",
- "Offset",
- "The log's offset within its file",
- -1,
- G_MAXSSIZE,
- -1,
- G_PARAM_READWRITE);
-
- properties[PROP_COMMON_LOG_LENGTH] =
- g_param_spec_long("length",
- "Length",
- "The log's total size (Not necessary its file size)",
- -1,
- G_MAXSSIZE,
- -1,
- G_PARAM_READWRITE);
-
g_object_class_install_property(gobject_class,
PROP_COMMON_LOG_PATH,
properties[PROP_COMMON_LOG_PATH]);
@@ -275,14 +253,6 @@ purple_common_log_class_init(PurpleCommo
PROP_COMMON_LOG_SOCKET,
properties[PROP_COMMON_LOG_SOCKET]);
- g_object_class_install_property(gobject_class,
- PROP_COMMON_LOG_OFFSET,
- properties[PROP_COMMON_LOG_OFFSET]);
-
- g_object_class_install_property(gobject_class,
- PROP_COMMON_LOG_LENGTH,
- properties[PROP_COMMON_LOG_LENGTH]);
-
g_type_class_add_private(gobject_class, sizeof(PurpleCommonLogPrivate));
}
@@ -293,8 +263,6 @@ purple_common_log_init(PurpleCommonLog *
priv->path = NULL;
priv->socket = -1;
- priv->offset = -1;
- priv->length = -1;
}
static void
@@ -307,15 +275,6 @@ purple_common_log_set_property(GObject *
case PROP_COMMON_LOG_PATH:
purple_common_log_set_path(common_log, g_value_get_string(value));
break;
- case PROP_COMMON_LOG_SOCKET:
- purple_common_log_set_socket(common_log, g_value_get_int(value));
- break;
- case PROP_COMMON_LOG_OFFSET:
- purple_common_log_set_offset(common_log, g_value_get_long(value));
- break;
- case PROP_COMMON_LOG_LENGTH:
- purple_common_log_set_length(common_log, g_value_get_long(value));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -335,12 +294,6 @@ purple_common_log_get_property(GObject *
case PROP_COMMON_LOG_SOCKET:
g_value_set_int(value, purple_common_log_get_socket(common_log));
break;
- case PROP_COMMON_LOG_OFFSET:
- g_value_set_long(value, purple_common_log_get_offset(common_log));
- break;
- case PROP_COMMON_LOG_LENGTH:
- g_value_set_long(value, purple_common_log_get_length(common_log));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -364,7 +317,7 @@ purple_common_log_set_path(PurpleCommonL
G_OBJECT_NOTIFY(common_log, PROP_COMMON_LOG_PATH, "path");
}
-void
+static void
purple_common_log_set_socket(PurpleCommonLog *common_log, gint socket)
{
PurpleCommonLogPrivate *priv;
@@ -382,28 +335,6 @@ purple_common_log_set_socket(PurpleCommo
G_OBJECT_NOTIFY(common_log, PROP_COMMON_LOG_SOCKET, "socket");
}
-void
-purple_common_log_set_offset(PurpleCommonLog *common_log, gssize offset)
-{
- g_return_if_fail(PURPLE_IS_COMMON_LOG(common_log));
- g_return_if_fail(offset >= -1);
-
- PURPLE_COMMON_LOG_GET_PRIVATE(log)->offset = offset;
-
- G_OBJECT_NOTIFY(common_log, PROP_COMMON_LOG_OFFSET, "offset");
-}
-
-void
-purple_common_log_set_length(PurpleCommonLog *common_log, gssize length)
-{
- g_return_if_fail(PURPLE_IS_COMMON_LOG(common_log));
- g_return_if_fail(length >= -1);
-
- PURPLE_COMMON_LOG_GET_PRIVATE(log)->length = length;
-
- G_OBJECT_NOTIFY(common_log, PROP_COMMON_LOG_LENGTH, "length");
-}
-
const gchar *
purple_common_log_get_path(PurpleCommonLog *common_log)
{
@@ -420,22 +351,6 @@ purple_common_log_get_socket(PurpleCommo
return PURPLE_COMMON_LOG_GET_PRIVATE(common_log)->socket;
}
-gssize
-purple_common_log_get_offset(PurpleCommonLog *common_log)
-{
- g_return_val_if_fail(PURPLE_IS_COMMON_LOG(common_log), -1);
-
- return PURPLE_COMMON_LOG_GET_PRIVATE(common_log)->offset;
-}
-
-gssize
-purple_common_log_get_length(PurpleCommonLog *common_log)
-{
- g_return_val_if_fail(PURPLE_IS_COMMON_LOG(common_log), -1);
-
- return PURPLE_COMMON_LOG_GET_PRIVATE(common_log)->length;
-}
-
static gboolean
purple_common_log_remove(PurpleLog *log, GCancellable *cancellable,
GError **error)
@@ -840,7 +755,7 @@ static PurpleLog *
/* XXX: Poorly named */
static PurpleLog *
-create_log(const gchar *path, PurpleLogChatType chat_type, const gchar *name,
+log_from_data(const gchar *path, PurpleLogChatType chat_type, const gchar *name,
PurpleAccount *account, PurpleLogClass *klass)
{
PurpleLog *log;
@@ -956,7 +871,7 @@ purple_common_log_list(PurpleLogChatType
continue;
}
- log = create_log(child_path, chat_type, name, account, klass);
+ log = log_from_data(child_path, chat_type, name, account, klass);
g_free(child_path);
list = g_list_prepend(list, log);
@@ -1070,11 +985,13 @@ purple_common_log_list_async_3(GObject *
continue;
}
- log = create_log(child_path, data->chat_type, data->name,
+ log = log_from_data(child_path, data->chat_type, data->name,
data->account, data->klass);
g_free(child_path);
- logs = g_list_prepend(logs, log);
+
+ if (log != NULL)
+ logs = g_list_prepend(logs, log);
}
g_list_foreach(file_infos, (GFunc) g_object_unref, NULL);
@@ -1381,15 +1298,9 @@ purple_common_log_size(PurpleLog *log, G
PurpleCommonLog *common_log = PURPLE_COMMON_LOG(log);
GFile *file;
GFileInfo *info;
- gssize length;
const gchar *path;
guint64 file_size;
- length = purple_common_log_get_length(common_log);
-
- if (length >= 0)
- return length;
-
path = purple_common_log_get_path(common_log);
if (path == NULL) {
============================================================
--- libpurple/commonlog.h b729a01ce46c18d98275851a4fc18951240f5308
+++ libpurple/commonlog.h 1dda2a0e61b5c886a8afbc1d2d368c3afa278db1
@@ -85,37 +85,6 @@ void purple_common_log_set_path(PurpleCo
void purple_common_log_set_path(PurpleCommonLog *common_log, const gchar *path);
/**
- * Sets a log's IO socket
- *
- * @param common_log The log
- * @param socket The log's IO socket
- *
- * @since 3.0.0
- */
-void purple_common_log_set_socket(PurpleCommonLog *common_log, gint socket);
-
-/**
- * Sets a log's offset, useful for storing multiple logs in one file.
- *
- * @param common_log The log
- * @param offset The log's offset
- *
- * @since 3.0.0
- */
-void purple_common_log_set_offset(PurpleCommonLog *common_log, gssize offset);
-
-/**
- * Sets a log's size (Not necessary its file size), useful for storing multiple
- * logs in one file.
- *
- * @param common_log The log
- * @param length The log's size
- *
- * @since 3.0.0
- */
-void purple_common_log_set_length(PurpleCommonLog *common_log, gssize length);
-
-/**
* Gets the log's path on disk
*
* @param common_log The log
@@ -138,28 +107,6 @@ gint purple_common_log_get_socket(Purple
gint purple_common_log_get_socket(PurpleCommonLog *common_log);
/**
- * Gets the log's offset within its file, if available
- *
- * @param common_log The log
- *
- * @return The log's offset
- *
- * @since 3.0.0
- */
-gssize purple_common_log_get_offset(PurpleCommonLog *common_log);
-
-/**
- * Gets the log's size (Not necessary its file size)
- *
- * @param common_log The log
- *
- * @return The log's size
- *
- * @since 3.0.0
- */
-gssize purple_common_log_get_length(PurpleCommonLog *common_log);
-
-/**
* Creates a new log file in the standard log location
* with the given file extension, named for the current time,
* for writing. If a log file is already open, the existing
@@ -224,8 +171,8 @@ gchar *purple_common_log_read_finish(Pur
/**
* Returns a sorted list of logs of the requested type
*
- * This function should only be used with logs that are written
- * with purple_common_log_writer(). It's intended to be used as
+ * This function should only be used with logs that are created
+ * with purple_common_log_create(). It's intended to be used as
* a "common" implementation of a logger's @c list function.
* It should only be passed to purple_log_logger_new() and never
* called directly.
@@ -249,6 +196,10 @@ GList *purple_common_log_list(PurpleLogC
* Asynchronously gets a sorted list of log of the requested type.
* See purple_common_log_list() for more details.
*
+ * Will continously call cb with more logs until all have been listed, allowing
+ * for continous display of the data. When done, the cb receive NULL from
+ * purple_common_log_list_finish() and the error pointer will remain untouched.
+ *
* @param type The type of the logs being listed
* @param name The name of the log
* @param account The account of the log
@@ -272,8 +223,8 @@ void purple_common_log_list_async(Purple
* Finishes asynchronously listing the logs of a requested type.
* Remember to free the list returned if you do not store it.
*
- * Note: Make sure to examine that error is not NULL as it is completely possible
- * for the list to be empty and the function to return NULL without an error
+ * Note: Make sure to examine that error is not NULL as this function will also
+ * return NULL when all logs have been listed.
*
* @param res A GAsyncResult
* @param error (out) (allow-none): a GError location to store the error
@@ -288,8 +239,8 @@ GList *purple_common_log_list_finish(GAs
* Returns the total size of all the logs for a given user, with
* a given extension.
*
- * This function should only be used with logs that are written
- * with purple_common_log_writer(). It's intended to be used as
+ * This function should only be used with logs that are created
+ * with purple_common_log_create(). It's intended to be used as
* a "common" implementation of a logger's @c total_size function.
* It should only be passed to purple_log_logger_new() and never
* called directly.
More information about the Commits
mailing list