[evolution-data-server] CamelIMAPXJob: Split out "sync_changes" data.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] CamelIMAPXJob: Split out "sync_changes" data.
- Date: Tue, 31 Jan 2012 22:09:55 +0000 (UTC)
commit 11b59f9865b7af061dbb6c455390ddd6eeb88920
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Jan 31 14:54:07 2012 -0500
CamelIMAPXJob: Split out "sync_changes" data.
Define a standalone SyncChangesData struct and "free" function.
Use camel_imapx_job_set_data() to attach an allocated struct to a
CamelIMAPXJob such that it will be freed along with the job.
Use camel_imapx_job_get_data() to obtain a pointer to the allocated
struct as needed, always with a NULL check for safety.
camel/providers/imapx/camel-imapx-job.h | 8 ---
camel/providers/imapx/camel-imapx-server.c | 89 +++++++++++++++++++++-------
2 files changed, 67 insertions(+), 30 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-job.h b/camel/providers/imapx/camel-imapx-job.h
index 539340e..a7ea019 100644
--- a/camel/providers/imapx/camel-imapx-job.h
+++ b/camel/providers/imapx/camel-imapx-job.h
@@ -57,14 +57,6 @@ struct _CamelIMAPXJob {
union {
struct {
- GPtrArray *changed_uids;
- guint32 on_set;
- guint32 off_set;
- GArray *on_user; /* imapx_flag_change */
- GArray *off_user;
- gint unread_change;
- } sync_changes;
- struct {
gchar *path;
CamelMessageInfo *info;
} append_message;
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index a016de3..50f572c 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -74,6 +74,7 @@ extern gint camel_application_is_exiting;
/* Job-specific structs */
typedef struct _GetMessageData GetMessageData;
typedef struct _RefreshInfoData RefreshInfoData;
+typedef struct _SyncChangesData SyncChangesData;
struct _GetMessageData {
/* in: uid requested */
@@ -100,6 +101,16 @@ struct _RefreshInfoData {
CamelFolderChangeInfo *changes;
};
+struct _SyncChangesData {
+ CamelFolder *folder;
+ GPtrArray *changed_uids;
+ guint32 on_set;
+ guint32 off_set;
+ GArray *on_user; /* imapx_flag_change */
+ GArray *off_user;
+ gint unread_change;
+};
+
enum {
SELECT_CHANGED,
SHUTDOWN,
@@ -182,6 +193,7 @@ static void imapx_job_fetch_new_messages_start (CamelIMAPXJob *job, CamelIMAPXSe
static gint imapx_refresh_info_uid_cmp (gconstpointer ap, gconstpointer bp, gboolean ascending);
static gint imapx_uids_array_cmp (gconstpointer ap, gconstpointer bp);
static gboolean imapx_server_sync_changes (CamelIMAPXServer *is, CamelFolder *folder, gint pri, GCancellable *cancellable, GError **error);
+static void imapx_sync_free_user (GArray *user_set);
static void imapx_command_copy_messages_step_start
(CamelIMAPXServer *is,
@@ -254,6 +266,20 @@ refresh_info_data_free (RefreshInfoData *data)
g_slice_free (RefreshInfoData, data);
}
+static void
+sync_changes_data_free (SyncChangesData *data)
+{
+ if (data->folder != NULL) {
+ camel_folder_free_uids (data->folder, data->changed_uids);
+ g_object_unref (data->folder);
+ }
+
+ imapx_sync_free_user (data->on_user);
+ imapx_sync_free_user (data->off_user);
+
+ g_slice_free (SyncChangesData, data);
+}
+
/*
this creates a uid (or sequence number) set directly into a command,
if total is set, then we break it up into total uids. (i.e. command time)
@@ -4492,9 +4518,13 @@ imapx_command_sync_changes_done (CamelIMAPXServer *is,
{
CamelIMAPXJob *job = ic->job;
CamelStore *parent_store;
+ SyncChangesData *data;
const gchar *full_name;
gboolean success = TRUE;
+ data = camel_imapx_job_get_data (job);
+ g_return_val_if_fail (data != NULL, FALSE);
+
job->commands--;
full_name = camel_folder_get_full_name (job->folder);
@@ -4520,9 +4550,9 @@ imapx_command_sync_changes_done (CamelIMAPXServer *is,
} else {
gint i;
- for (i = 0; i < job->u.sync_changes.changed_uids->len; i++) {
+ for (i = 0; i < data->changed_uids->len; i++) {
CamelIMAPXMessageInfo *xinfo = (CamelIMAPXMessageInfo *) camel_folder_summary_get (job->folder->summary,
- job->u.sync_changes.changed_uids->pdata[i]);
+ data->changed_uids->pdata[i]);
if (!xinfo)
continue;
@@ -4537,7 +4567,7 @@ imapx_command_sync_changes_done (CamelIMAPXServer *is,
}
/* Apply the changes to server-side unread count; it won't tell
* us of these changes, of course. */
- ((CamelIMAPXFolder *) job->folder)->unread_on_server += job->u.sync_changes.unread_change;
+ ((CamelIMAPXFolder *) job->folder)->unread_on_server += data->unread_change;
}
if (job->commands == 0) {
@@ -4573,14 +4603,20 @@ static void
imapx_job_sync_changes_start (CamelIMAPXJob *job,
CamelIMAPXServer *is)
{
+ SyncChangesData *data;
guint32 i, j;
struct _uidset_state ss;
- GPtrArray *uids = job->u.sync_changes.changed_uids;
+ GPtrArray *uids;
gint on;
+ data = camel_imapx_job_get_data (job);
+ g_return_if_fail (data != NULL);
+
+ uids = data->changed_uids;
+
for (on = 0; on < 2; on++) {
- guint32 orset = on ? job->u.sync_changes.on_set : job->u.sync_changes.off_set;
- GArray *user_set = on ? job->u.sync_changes.on_user : job->u.sync_changes.off_user;
+ guint32 orset = on ? data->on_set : data->off_set;
+ GArray *user_set = on ? data->on_user : data->off_user;
for (j = 0; j < G_N_ELEMENTS (flags_table); j++) {
guint32 flag = flags_table[j].flag;
@@ -4627,9 +4663,9 @@ imapx_job_sync_changes_start (CamelIMAPXJob *job,
/* Remember how the server's unread count will change if this
* command succeeds */
if (on)
- job->u.sync_changes.unread_change--;
+ data->unread_change--;
else
- job->u.sync_changes.unread_change++;
+ data->unread_change++;
}
camel_message_info_free (info);
}
@@ -5403,6 +5439,7 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
GArray *on_user = NULL, *off_user = NULL;
CamelIMAPXMessageInfo *info;
CamelIMAPXJob *job;
+ SyncChangesData *data;
gboolean registered;
gboolean success = TRUE;
@@ -5505,8 +5542,11 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
}
if ((on_orset | off_orset) == 0 && on_user == NULL && off_user == NULL) {
- success = TRUE;
- goto done;
+ imapx_sync_free_user (on_user);
+ imapx_sync_free_user (off_user);
+ camel_folder_free_uids (folder, uids);
+
+ return TRUE;
}
/* TODO above code should go into changes_start */
@@ -5518,20 +5558,31 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
job->pri = pri;
QUEUE_UNLOCK (is);
- goto done;
+
+ imapx_sync_free_user (on_user);
+ imapx_sync_free_user (off_user);
+ camel_folder_free_uids (folder, uids);
+
+ return TRUE;
}
+ data = g_slice_new0 (SyncChangesData);
+ data->folder = g_object_ref (folder);
+ data->changed_uids = uids; /* takes ownership */
+ data->on_set = on_orset;
+ data->off_set = off_orset;
+ data->on_user = on_user; /* takes ownership */
+ data->off_user = off_user; /* takes ownership */
+
job = camel_imapx_job_new (cancellable);
job->type = IMAPX_JOB_SYNC_CHANGES;
job->start = imapx_job_sync_changes_start;
job->matches = imapx_job_sync_changes_matches;
job->pri = pri;
job->folder = folder;
- job->u.sync_changes.changed_uids = uids;
- job->u.sync_changes.on_set = on_orset;
- job->u.sync_changes.off_set = off_orset;
- job->u.sync_changes.on_user = on_user;
- job->u.sync_changes.off_user = off_user;
+
+ camel_imapx_job_set_data (
+ job, data, (GDestroyNotify) sync_changes_data_free);
registered = imapx_register_job (is, job, error);
@@ -5541,12 +5592,6 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
camel_imapx_job_unref (job);
-done:
- imapx_sync_free_user (on_user);
- imapx_sync_free_user (off_user);
-
- camel_folder_free_uids (folder, uids);
-
return success;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]