summaryrefslogtreecommitdiff
path: root/src/pop-transaction.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pop-transaction.c')
-rw-r--r--src/pop-transaction.c452
1 files changed, 246 insertions, 206 deletions
diff --git a/src/pop-transaction.c b/src/pop-transaction.c
index f787ae6..2e33e55 100644
--- a/src/pop-transaction.c
+++ b/src/pop-transaction.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include "config.h"
#include "pop-transaction.h"
@@ -27,7 +27,7 @@
#include <glib-object.h>
#include <glib/gi18n.h>
-typedef enum
+typedef enum
{
POP_TRANSACTION_STATE_UNCOMMITED = 0,
POP_TRANSACTION_STATE_COMMITED,
@@ -66,25 +66,26 @@ typedef struct
{
PopActionProcessFunc process_func;
PopActionRollbackFunc rollback_func;
- gpointer user_data;
- GDestroyNotify free_func;
+ gpointer user_data;
+ GDestroyNotify free_func;
} PopAction;
-typedef gboolean (* PopTransactionIdleFunc) (PopTransaction *transaction);
+typedef gboolean (*PopTransactionIdleFunc) (PopTransaction *transaction);
-static void pop_transaction_finalize (GObject * object);
+static void pop_transaction_finalize (GObject *object);
static void pop_transaction_class_install_signals (PopTransactionClass *
- transaction_class);
+ transaction_class);
static void pop_transaction_class_install_properties (PopTransactionClass *
- transaction_class);
-
-static void pop_transaction_set_property (GObject * object,
- guint prop_id,
- const GValue * value,
- GParamSpec * pspec);
-static void pop_transaction_get_property (GObject * object,
- guint prop_id,
- GValue * value, GParamSpec * pspec);
+ transaction_class);
+
+static void pop_transaction_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void pop_transaction_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
static void pop_transaction_fail (PopTransaction *transaction);
static void pop_transaction_process_on_idle (PopTransaction *transaction);
static void pop_transaction_rollback_on_idle (PopTransaction *transaction);
@@ -116,7 +117,7 @@ static guint pop_transaction_signals[NUMBER_OF_SIGNALS];
G_DEFINE_TYPE (PopTransaction, pop_transaction, G_TYPE_OBJECT);
static void
-pop_transaction_class_init (PopTransactionClass * transaction_class)
+pop_transaction_class_init (PopTransactionClass *transaction_class)
{
GObjectClass *object_class;
@@ -128,12 +129,12 @@ pop_transaction_class_init (PopTransactionClass * transaction_class)
pop_transaction_class_install_signals (transaction_class);
g_type_class_add_private (transaction_class,
- sizeof (PopTransactionPrivate));
+ sizeof (PopTransactionPrivate));
}
static void
pop_transaction_class_install_signals (PopTransactionClass *
- transaction_class)
+ transaction_class)
{
GObjectClass *object_class;
@@ -141,49 +142,51 @@ pop_transaction_class_install_signals (PopTransactionClass *
pop_transaction_signals[PROCESS] =
g_signal_new ("process", G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (PopTransactionClass, process),
- NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PopTransactionClass, process),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
transaction_class->process = NULL;
pop_transaction_signals[WAIT] =
g_signal_new ("wait", G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (PopTransactionClass, wait),
- NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PopTransactionClass, wait),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
transaction_class->wait = NULL;
pop_transaction_signals[RESUME] =
g_signal_new ("resume", G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (PopTransactionClass, resume),
- NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PopTransactionClass, resume),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
transaction_class->resume = NULL;
pop_transaction_signals[CANCEL] =
g_signal_new ("cancel", G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (PopTransactionClass, cancel),
- NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PopTransactionClass, cancel),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
transaction_class->cancel = NULL;
pop_transaction_signals[FINISH] =
g_signal_new ("finish", G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (PopTransactionClass, finish),
- NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PopTransactionClass, finish),
+ NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1,
+ G_TYPE_INT);
transaction_class->finish = NULL;
pop_transaction_signals[ROLLBACK] =
g_signal_new ("rollback", G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (PopTransactionClass, rollback),
- NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PopTransactionClass, rollback),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
transaction_class->rollback = NULL;
}
static void
-pop_transaction_class_install_properties (PopTransactionClass *transaction_class)
+pop_transaction_class_install_properties (
+ PopTransactionClass *transaction_class)
{
GObjectClass *object_class;
GParamSpec *param_spec;
@@ -194,21 +197,21 @@ pop_transaction_class_install_properties (PopTransactionClass *transaction_class
/* FIXME: do the whole enum gtype song and dance
*/
- param_spec = g_param_spec_int ("status", _("Status"),
- _("Current status of the transaction"),
- POP_TRANSACTION_STATUS_NOT_FINISHED,
+ param_spec = g_param_spec_int ("status", _ ("Status"),
+ _ ("Current status of the transaction"),
+ POP_TRANSACTION_STATUS_NOT_FINISHED,
POP_TRANSACTION_STATUS_SUCCEEDED,
POP_TRANSACTION_STATUS_NOT_FINISHED,
G_PARAM_READABLE);
g_object_class_install_property (object_class, PROP_STATUS, param_spec);
- param_spec = g_param_spec_pointer ("result", _("Result"),
- _("Output of transaction"),
+ param_spec = g_param_spec_pointer ("result", _ ("Result"),
+ _ ("Output of transaction"),
G_PARAM_READABLE);
g_object_class_install_property (object_class, PROP_RESULT, param_spec);
- param_spec = g_param_spec_pointer ("error", _("Error"),
- _("Reason for transaction error"),
+ param_spec = g_param_spec_pointer ("error", _ ("Error"),
+ _ ("Reason for transaction error"),
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_ERROR, param_spec);
}
@@ -219,8 +222,8 @@ pop_transaction_init (PopTransaction *transaction)
g_assert (POP_IS_TRANSACTION (transaction));
transaction->priv = G_TYPE_INSTANCE_GET_PRIVATE (transaction,
- POP_TYPE_TRANSACTION,
- PopTransactionPrivate);
+ POP_TYPE_TRANSACTION,
+ PopTransactionPrivate);
transaction->priv->actions = g_queue_new ();
transaction->priv->status = POP_TRANSACTION_STATUS_NOT_FINISHED;
@@ -243,13 +246,15 @@ pop_transaction_finalize (GObject *object)
pop_transaction_set_result (transaction, NULL, NULL);
if (parent_class->finalize != NULL)
- parent_class->finalize (object);
+ {
+ parent_class->finalize (object);
+ }
}
static void
pop_transaction_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
+ guint prop_id,
+ const GValue *value,
GParamSpec *pspec)
{
PopTransaction *transaction;
@@ -260,20 +265,20 @@ pop_transaction_set_property (GObject *object,
switch (prop_id)
{
- case PROP_ERROR:
- pop_transaction_set_error (transaction,
- (GError *) g_value_get_pointer (value));
- break;
+ case PROP_ERROR:
+ pop_transaction_set_error (transaction,
+ (GError *) g_value_get_pointer (value));
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
pop_transaction_get_property (GObject *object,
- guint prop_id,
- GValue *value,
+ guint prop_id,
+ GValue *value,
GParamSpec *pspec)
{
PopTransaction *transaction;
@@ -284,18 +289,20 @@ pop_transaction_get_property (GObject *object,
switch (prop_id)
{
- case PROP_STATUS:
- g_value_set_int (value, pop_transaction_get_status (transaction));
- break;
- case PROP_ERROR:
- g_value_set_pointer (value, pop_transaction_get_error (transaction));
- break;
- case PROP_RESULT:
- g_value_set_pointer (value, pop_transaction_get_result (transaction));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ case PROP_STATUS:
+ g_value_set_int (value, pop_transaction_get_status (transaction));
+ break;
+
+ case PROP_ERROR:
+ g_value_set_pointer (value, pop_transaction_get_error (transaction));
+ break;
+
+ case PROP_RESULT:
+ g_value_set_pointer (value, pop_transaction_get_result (transaction));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
@@ -345,7 +352,7 @@ pop_action_new (PopActionProcessFunc action_process_func,
action->rollback_func = action_rollback_func;
action->user_data = user_data;
action->free_func = free_func;
-
+
return action;
}
@@ -355,14 +362,16 @@ pop_action_free (PopAction *action)
g_assert (action != NULL);
if (action->free_func != NULL)
- action->free_func (action->user_data);
+ {
+ action->free_func (action->user_data);
+ }
- g_slice_free (PopAction, action);
+ g_slice_free (PopAction, action);
}
-void
-pop_transaction_add_action_full (PopTransaction *transaction,
- PopActionProcessFunc action_process_func,
+void
+pop_transaction_add_action_full (PopTransaction *transaction,
+ PopActionProcessFunc action_process_func,
PopActionRollbackFunc action_rollback_func,
gpointer user_data,
GDestroyNotify free_func)
@@ -371,15 +380,18 @@ pop_transaction_add_action_full (PopTransaction *transaction,
g_return_if_fail (POP_IS_TRANSACTION (transaction));
- action = pop_action_new (action_process_func, action_rollback_func, user_data, free_func);
+ action = pop_action_new (action_process_func, action_rollback_func, user_data,
+ free_func);
if (transaction->priv->current_action_node == NULL)
- g_queue_push_tail (transaction->priv->actions, action);
+ {
+ g_queue_push_tail (transaction->priv->actions, action);
+ }
else
{
gboolean can_rewind;
- g_queue_insert_before (transaction->priv->actions,
+ g_queue_insert_before (transaction->priv->actions,
transaction->priv->current_action_node,
action);
can_rewind = pop_transaction_rewind (transaction);
@@ -388,18 +400,18 @@ pop_transaction_add_action_full (PopTransaction *transaction,
}
}
-void
+void
pop_transaction_add_action (PopTransaction *transaction,
PopActionProcessFunc action_process_func,
PopActionRollbackFunc action_rollback_func,
gpointer user_data)
{
- pop_transaction_add_action_full (transaction, action_process_func,
+ pop_transaction_add_action_full (transaction, action_process_func,
action_rollback_func,
user_data, NULL);
}
-static PopActionProcessStatus
+static PopActionProcessStatus
pop_transaction_process_subtransaction (PopTransaction *transaction,
PopTransaction *subtransaction)
{
@@ -411,8 +423,8 @@ pop_transaction_process_subtransaction (PopTransaction *transaction,
if (!pop_transaction_is_committed (transaction))
{
pop_transaction_wait (transaction);
- g_signal_connect_swapped (G_OBJECT (subtransaction),
- "finish", G_CALLBACK (pop_transaction_resume),
+ g_signal_connect_swapped (G_OBJECT (subtransaction),
+ "finish", G_CALLBACK (pop_transaction_resume),
transaction);
pop_transaction_commit (transaction);
@@ -423,26 +435,28 @@ pop_transaction_process_subtransaction (PopTransaction *transaction,
status = pop_transaction_get_status (subtransaction);
g_assert (status != POP_TRANSACTION_STATUS_NOT_FINISHED);
- g_assert (status == POP_TRANSACTION_STATUS_CANCELED ||
- status == POP_TRANSACTION_STATUS_FAILED ||
- status == POP_TRANSACTION_STATUS_SUCCEEDED);
+ g_assert (status == POP_TRANSACTION_STATUS_CANCELED
+ || status == POP_TRANSACTION_STATUS_FAILED
+ || status == POP_TRANSACTION_STATUS_SUCCEEDED);
- if ((status == POP_TRANSACTION_STATUS_CANCELED) ||
- (status == POP_TRANSACTION_STATUS_FAILED))
- return POP_ACTION_PROCESS_STATUS_FAILED;
+ if ((status == POP_TRANSACTION_STATUS_CANCELED)
+ || (status == POP_TRANSACTION_STATUS_FAILED))
+ {
+ return POP_ACTION_PROCESS_STATUS_FAILED;
+ }
return POP_ACTION_PROCESS_STATUS_SUCCEEDED;
}
-static PopActionRollbackStatus
+static PopActionRollbackStatus
pop_transaction_rollback_subtransaction (PopTransaction *transaction,
PopTransaction *subtransaction)
{
PopTransactionStatus status;
-
+
status = pop_transaction_get_status (subtransaction);
- /* FIXME: things are a little confusing here. when you
+ /* FIXME: things are a little confusing here. when you
* rollback a transaction it puts the status in NOT_FINISHED
* and emits a "finish" signal. That's pretty counter-intuitive.
*
@@ -450,8 +464,8 @@ pop_transaction_rollback_subtransaction (PopTransaction *transaction,
* for when the rollback completes
*/
- g_assert ((status == POP_TRANSACTION_STATUS_SUCCEEDED) ||
- (status == POP_TRANSACTION_STATUS_NOT_FINISHED));
+ g_assert ((status == POP_TRANSACTION_STATUS_SUCCEEDED)
+ || (status == POP_TRANSACTION_STATUS_NOT_FINISHED));
/* not rolled back yet
*/
@@ -459,19 +473,19 @@ pop_transaction_rollback_subtransaction (PopTransaction *transaction,
{
pop_transaction_wait (transaction);
pop_transaction_rollback (subtransaction);
- g_signal_connect_swapped (G_OBJECT (subtransaction),
- "finish", G_CALLBACK (pop_transaction_resume),
+ g_signal_connect_swapped (G_OBJECT (subtransaction),
+ "finish", G_CALLBACK (pop_transaction_resume),
transaction);
return POP_ACTION_ROLLBACK_STATUS_NOT_FINISHED;
}
- /* the second time we've been called. After the pop_transaction_resume()
+ /* the second time we've been called. After the pop_transaction_resume()
*/
return POP_ACTION_ROLLBACK_STATUS_FINISHED;
}
-void
+void
pop_transaction_add_subtransaction (PopTransaction *transaction,
PopTransaction *subtransaction)
{
@@ -479,13 +493,13 @@ pop_transaction_add_subtransaction (PopTransaction *transaction,
g_return_if_fail (POP_IS_TRANSACTION (subtransaction));
g_return_if_fail (!pop_transaction_is_committed (subtransaction));
- pop_transaction_add_action_full (transaction,
- (PopActionProcessFunc)
+ pop_transaction_add_action_full (transaction,
+ (PopActionProcessFunc)
pop_transaction_process_subtransaction,
- (PopActionRollbackFunc)
+ (PopActionRollbackFunc)
pop_transaction_rollback_subtransaction,
g_object_ref (subtransaction),
- (GDestroyNotify) g_object_unref);
+ (GDestroyNotify) g_object_unref);
}
void
@@ -498,14 +512,14 @@ pop_transaction_resume (PopTransaction *transaction)
{
case POP_TRANSACTION_STATE_PROCESSING:
pop_transaction_process_on_idle (transaction);
- break;
+ break;
case POP_TRANSACTION_STATE_ROLLING_BACK:
pop_transaction_rollback_on_idle (transaction);
- break;
-
+ break;
+
default:
- break;
+ break;
}
g_source_remove (transaction->priv->wait_id);
@@ -528,7 +542,7 @@ pop_transaction_is_in_action (PopTransaction *transaction)
return FALSE;
}
-void
+void
pop_transaction_wait (PopTransaction *transaction)
{
g_return_if_fail (POP_IS_TRANSACTION (transaction));
@@ -541,17 +555,17 @@ pop_transaction_wait (PopTransaction *transaction)
g_assert (transaction->priv->rollback_idle_id == 0);
g_source_remove (transaction->priv->process_idle_id);
transaction->priv->process_idle_id = 0;
- break;
+ break;
case POP_TRANSACTION_STATE_ROLLING_BACK:
g_assert (transaction->priv->rollback_idle_id != 0);
g_assert (transaction->priv->process_idle_id == 0);
g_source_remove (transaction->priv->rollback_idle_id);
transaction->priv->rollback_idle_id = 0;
- break;
-
+ break;
+
default:
- break;
+ break;
}
g_signal_emit (transaction, pop_transaction_signals[WAIT], 0);
@@ -564,7 +578,7 @@ pop_transaction_on_fd_ready_resume (GIOChannel *channel,
{
PopTransaction *transaction;
- g_assert (POP_IS_TRANSACTION (data));
+ g_assert (POP_IS_TRANSACTION (data));
transaction = POP_TRANSACTION (data);
@@ -589,7 +603,8 @@ pop_transaction_wait_for_fd (PopTransaction *transaction,
channel = g_io_channel_unix_new (fd);
g_io_channel_set_buffered (channel, FALSE);
source = g_io_create_watch (channel, condition);
- g_source_set_callback (source, (GSourceFunc) pop_transaction_on_fd_ready_resume,
+ g_source_set_callback (source,
+ (GSourceFunc) pop_transaction_on_fd_ready_resume,
transaction, NULL);
transaction->priv->wait_id = g_source_attach (source,
transaction->priv->context);
@@ -602,7 +617,7 @@ pop_transaction_on_timeout_resume (gpointer data)
{
PopTransaction *transaction;
- g_assert (POP_IS_TRANSACTION (data));
+ g_assert (POP_IS_TRANSACTION (data));
transaction = POP_TRANSACTION (data);
@@ -623,7 +638,8 @@ pop_transaction_wait_a_while (PopTransaction *transaction,
pop_transaction_wait (transaction);
source = g_timeout_source_new (milliseconds);
- g_source_set_callback (source, (GSourceFunc) pop_transaction_on_timeout_resume,
+ g_source_set_callback (source,
+ (GSourceFunc) pop_transaction_on_timeout_resume,
transaction, NULL);
transaction->priv->wait_id = g_source_attach (source,
transaction->priv->context);
@@ -641,10 +657,10 @@ pop_transaction_call_on_idle (PopTransaction *transaction,
source = g_idle_source_new ();
g_object_ref (transaction);
- g_source_set_callback (source, (GSourceFunc) callback, transaction,
+ g_source_set_callback (source, (GSourceFunc) callback, transaction,
(GDestroyNotify) g_object_unref);
- idle_id = g_source_attach (source, transaction->priv->context);
+ idle_id = g_source_attach (source, transaction->priv->context);
g_source_unref (source);
return idle_id;
@@ -669,10 +685,12 @@ pop_transaction_rewind (PopTransaction *transaction)
g_assert (POP_IS_TRANSACTION (transaction));
if (pop_transaction_is_at_first_action (transaction))
- return FALSE;
+ {
+ return FALSE;
+ }
transaction->priv->current_action_node =
- transaction->priv->current_action_node->prev;
+ transaction->priv->current_action_node->prev;
return TRUE;
}
@@ -684,7 +702,7 @@ pop_transaction_seek_forward (PopTransaction *transaction)
g_assert (transaction->priv->current_action_node != NULL);
transaction->priv->current_action_node =
- transaction->priv->current_action_node->next;
+ transaction->priv->current_action_node->next;
return transaction->priv->current_action_node != NULL;
}
@@ -696,12 +714,12 @@ pop_transaction_finish (PopTransaction *transaction)
transaction->priv->state = POP_TRANSACTION_STATE_FINISHED;
- g_signal_emit (transaction, pop_transaction_signals[FINISH], 0,
+ g_signal_emit (transaction, pop_transaction_signals[FINISH], 0,
transaction->priv->status);
}
static gboolean
-pop_transaction_process_current_action_and_seek_forward (PopTransaction *transaction)
+pop_transaction_run_action_and_seek_forward (PopTransaction *transaction)
{
PopAction *action;
PopActionProcessStatus status;
@@ -722,16 +740,20 @@ pop_transaction_process_current_action_and_seek_forward (PopTransaction *transac
transaction->priv->is_in_action = TRUE;
if (action->process_func != NULL)
- status = action->process_func (transaction, action->user_data);
+ {
+ status = action->process_func (transaction, action->user_data);
+ }
else
- status = POP_ACTION_PROCESS_STATUS_SUCCEEDED;
+ {
+ status = POP_ACTION_PROCESS_STATUS_SUCCEEDED;
+ }
transaction->priv->is_in_action = FALSE;
switch (status)
{
case POP_ACTION_PROCESS_STATUS_NOT_FINISHED:
- should_continue = TRUE;
- break;
+ should_continue = TRUE;
+ break;
case POP_ACTION_PROCESS_STATUS_SUCCEEDED:
if (!pop_transaction_seek_forward (transaction))
@@ -739,11 +761,13 @@ pop_transaction_process_current_action_and_seek_forward (PopTransaction *transac
pop_transaction_set_status (transaction,
POP_TRANSACTION_STATUS_SUCCEEDED);
pop_transaction_finish (transaction);
- should_continue = FALSE;
+ should_continue = FALSE;
}
else
- should_continue = TRUE;
- break;
+ {
+ should_continue = TRUE;
+ }
+ break;
default:
g_warning ("status %d is not valid processing status\n", (int) status);
@@ -752,9 +776,9 @@ pop_transaction_process_current_action_and_seek_forward (PopTransaction *transac
*/
case POP_ACTION_PROCESS_STATUS_FAILED:
- should_continue = FALSE;
+ should_continue = FALSE;
pop_transaction_fail (transaction);
- break;
+ break;
}
if (!should_continue)
@@ -771,16 +795,16 @@ pop_transaction_process_on_idle (PopTransaction *transaction)
{
g_assert (POP_IS_TRANSACTION (transaction));
- transaction->priv->current_action_node =
- g_queue_peek_head_link (transaction->priv->actions);
+ transaction->priv->current_action_node =
+ g_queue_peek_head_link (transaction->priv->actions);
transaction->priv->process_idle_id =
pop_transaction_call_on_idle (transaction,
- pop_transaction_process_current_action_and_seek_forward);
+ pop_transaction_run_action_and_seek_forward);
}
static gboolean
-pop_transaction_rollback_current_action_and_rewind (PopTransaction *transaction)
+pop_transaction_rollback_action_and_rewind (PopTransaction *transaction)
{
PopAction *action;
PopActionRollbackStatus status;
@@ -790,7 +814,9 @@ pop_transaction_rollback_current_action_and_rewind (PopTransaction *transaction)
g_assert (transaction->priv->current_action_node != NULL);
if (transaction->priv->state == POP_TRANSACTION_STATE_PROCESSING)
- transaction->priv->state = POP_TRANSACTION_STATE_ROLLING_BACK;
+ {
+ transaction->priv->state = POP_TRANSACTION_STATE_ROLLING_BACK;
+ }
g_assert (transaction->priv->state == POP_TRANSACTION_STATE_ROLLING_BACK);
@@ -798,16 +824,20 @@ pop_transaction_rollback_current_action_and_rewind (PopTransaction *transaction)
transaction->priv->is_in_action = TRUE;
if (action->rollback_func != NULL)
- status = action->rollback_func (transaction, action->user_data);
+ {
+ status = action->rollback_func (transaction, action->user_data);
+ }
else
- status = POP_ACTION_ROLLBACK_STATUS_FINISHED;
+ {
+ status = POP_ACTION_ROLLBACK_STATUS_FINISHED;
+ }
transaction->priv->is_in_action = FALSE;
switch (status)
{
case POP_ACTION_ROLLBACK_STATUS_NOT_FINISHED:
should_continue = TRUE;
- break;
+ break;
default:
g_warning ("status %d is not valid rollback status\n", (int) status);
@@ -817,10 +847,10 @@ pop_transaction_rollback_current_action_and_rewind (PopTransaction *transaction)
case POP_ACTION_ROLLBACK_STATUS_FINISHED:
should_continue = pop_transaction_rewind (transaction);
- break;
+ break;
- should_continue = FALSE;
- break;
+ should_continue = FALSE;
+ break;
}
if (!should_continue)
@@ -839,11 +869,12 @@ pop_transaction_rollback_on_idle (PopTransaction *transaction)
{
g_assert (POP_IS_TRANSACTION (transaction));
- transaction->priv->current_action_node = transaction->priv->current_action_node->prev;
+ transaction->priv->current_action_node = transaction->priv->
+ current_action_node->prev;
transaction->priv->rollback_idle_id =
pop_transaction_call_on_idle (transaction,
- pop_transaction_rollback_current_action_and_rewind);
+ pop_transaction_rollback_action_and_rewind);
}
static void
@@ -878,7 +909,7 @@ pop_transaction_is_attached (PopTransaction *transaction)
return transaction->priv->context != NULL;
}
-void
+void
pop_transaction_attach (PopTransaction *transaction,
GMainContext *context)
{
@@ -922,7 +953,7 @@ pop_transaction_is_finished (PopTransaction *transaction)
return transaction->priv->state == POP_TRANSACTION_STATE_FINISHED;
}
-void
+void
pop_transaction_cancel (PopTransaction *transaction)
{
g_return_if_fail (POP_IS_TRANSACTION (transaction));
@@ -941,7 +972,7 @@ pop_transaction_rollback (PopTransaction *transaction)
{
g_return_if_fail (POP_IS_TRANSACTION (transaction));
g_return_if_fail (pop_transaction_is_finished (transaction));
- g_return_if_fail (pop_transaction_get_status (transaction) ==
+ g_return_if_fail (pop_transaction_get_status (transaction) ==
POP_TRANSACTION_STATUS_SUCCEEDED);
pop_transaction_set_status (transaction,
@@ -959,15 +990,16 @@ pop_transaction_set_result (PopTransaction *transaction,
{
g_return_if_fail (POP_IS_TRANSACTION (transaction));
-
- if (transaction->priv->free_result_func != NULL)
- transaction->priv->free_result_func (transaction->priv->result);
+ if (transaction->priv->free_result_func != NULL)
+ {
+ transaction->priv->free_result_func (transaction->priv->result);
+ }
transaction->priv->result = result;
transaction->priv->free_result_func = free_func;
}
-gpointer
+gpointer
pop_transaction_get_result (PopTransaction *transaction)
{
g_return_val_if_fail (POP_IS_TRANSACTION (transaction), NULL);
@@ -975,7 +1007,7 @@ pop_transaction_get_result (PopTransaction *transaction)
return transaction->priv->result;
}
-void
+void
pop_transaction_set_error (PopTransaction *transaction,
const GError *error)
{
@@ -984,7 +1016,9 @@ pop_transaction_set_error (PopTransaction *transaction,
if (transaction->priv->error != error)
{
if (transaction->priv->error != NULL)
- g_error_free (transaction->priv->error);
+ {
+ g_error_free (transaction->priv->error);
+ }
transaction->priv->error = g_error_copy (error);
g_object_notify (G_OBJECT (transaction), "error");
@@ -1006,14 +1040,14 @@ pop_transaction_get_error (PopTransaction *transaction)
#include <glib.h>
-typedef struct
+typedef struct
{
int fd;
guint8 *buffer;
gssize number_of_bytes_to_process;
} InputOutputArguments;
-typedef ssize_t (* InputOutputFunc) (int fd, void *buf, size_t count);
+typedef ssize_t (*InputOutputFunc) (int fd, void *buf, size_t count);
static PopActionProcessStatus
proces_io_action (PopTransaction *transaction,
@@ -1031,18 +1065,18 @@ proces_io_action (PopTransaction *transaction,
g_return_val_if_fail (arguments->buffer != NULL,
POP_ACTION_PROCESS_STATUS_FAILED);
- is_ready = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (transaction),
- "is-ready"));
+ is_ready = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (transaction),
+ "is-ready"));
if (is_ready)
{
- /* pause transaction until fd is ready for reading (or writing
+ /* pause transaction until fd is ready for reading (or writing
* depending on the io_func)
*/
pop_transaction_wait_for_fd (transaction, arguments->fd, condition,
- NULL);
- g_object_set_data (G_OBJECT (transaction), "bytes-left-to-process",
- GINT_TO_POINTER (arguments->number_of_bytes_to_process));
-
+ NULL);
+ g_object_set_data (G_OBJECT (transaction), "bytes-left-to-process",
+ GINT_TO_POINTER (arguments->number_of_bytes_to_process));
+
/* when the transaction gets unpaused we want to continue on
*/
g_object_set_data (G_OBJECT (transaction), "is-ready",
@@ -1050,24 +1084,26 @@ proces_io_action (PopTransaction *transaction,
return POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
}
- bytes_done = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (transaction),
- "bytes-already-processed"));
- bytes_left = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (transaction),
- "bytes-left-to-process"));
+ bytes_done = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (transaction),
+ "bytes-already-processed"));
+ bytes_left = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (transaction),
+ "bytes-left-to-process"));
- bytes_done_this_time = io_func (arguments->fd,
+ bytes_done_this_time = io_func (arguments->fd,
arguments->buffer + bytes_done,
bytes_left);
if (bytes_done_this_time < 0)
{
- GError *error;
+ GError *error;
if ((errno == EINTR) || (errno == EAGAIN))
- return POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
+ {
+ return POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
+ }
error = g_error_new_literal (G_FILE_ERROR,
g_file_error_from_errno (errno),
- g_strerror (errno));
+ g_strerror (errno));
pop_transaction_set_error (transaction, error);
g_error_free (error);
@@ -1078,10 +1114,10 @@ proces_io_action (PopTransaction *transaction,
bytes_done += bytes_done_this_time;
bytes_left -= bytes_done_this_time;
-
- g_object_set_data (G_OBJECT (transaction), "bytes-already-processed",
+
+ g_object_set_data (G_OBJECT (transaction), "bytes-already-processed",
GINT_TO_POINTER (bytes_done));
- g_object_set_data (G_OBJECT (transaction), "bytes-left-to-process",
+ g_object_set_data (G_OBJECT (transaction), "bytes-left-to-process",
GINT_TO_POINTER (bytes_left));
if (bytes_left == 0)
@@ -1091,9 +1127,9 @@ proces_io_action (PopTransaction *transaction,
}
return POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
-}
+}
-static PopActionProcessStatus
+static PopActionProcessStatus
process_read_action (PopTransaction *transaction,
InputOutputArguments *arguments)
{
@@ -1101,7 +1137,7 @@ process_read_action (PopTransaction *transaction,
arguments, G_IO_IN);
}
-static PopActionProcessStatus
+static PopActionProcessStatus
process_write_action (PopTransaction *transaction,
InputOutputArguments *arguments)
{
@@ -1122,7 +1158,7 @@ on_transaction_finish (PopTransaction *transaction,
g_main_loop_quit (loop);
}
-static PopActionProcessStatus
+static PopActionProcessStatus
preemptive_action (PopTransaction *transaction,
gpointer user_data)
{
@@ -1131,49 +1167,50 @@ preemptive_action (PopTransaction *transaction,
return POP_ACTION_PROCESS_STATUS_SUCCEEDED;
}
-static PopActionProcessStatus
+static PopActionProcessStatus
test_action (PopTransaction *transaction,
gpointer user_data)
{
PopActionProcessStatus status;
int generation;
+
generation = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (transaction),
"generation"));
g_print ("Generation %d\n", generation);
switch (generation)
{
case 0:
- g_print ("First instance of test action\n");
- g_print ("Press enter to continue\n");
- pop_transaction_wait_for_fd (transaction, fileno (stdin), G_IO_IN, NULL);
- status = POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
- break;
+ g_print ("First instance of test action\n");
+ g_print ("Press enter to continue\n");
+ pop_transaction_wait_for_fd (transaction, fileno (stdin), G_IO_IN, NULL);
+ status = POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
+ break;
case 1:
- getc (stdin);
- g_print ("enter detected, will continue in 5 seconds...\n");
- pop_transaction_wait_a_while (transaction, 5 * 1000);
- status = POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
- break;
+ getc (stdin);
+ g_print ("enter detected, will continue in 5 seconds...\n");
+ pop_transaction_wait_a_while (transaction, 5 * 1000);
+ status = POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
+ break;
case 2:
- g_print ("5 seconds elapsed, finishing first action...\n");
- status = POP_ACTION_PROCESS_STATUS_SUCCEEDED;
- break;
+ g_print ("5 seconds elapsed, finishing first action...\n");
+ status = POP_ACTION_PROCESS_STATUS_SUCCEEDED;
+ break;
case 3:
- g_print ("Second instance of test action\n");
- g_print ("waiting on blocking action before continuing.\n");
- pop_transaction_add_action (transaction, preemptive_action, NULL, NULL);
- status = POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
- break;
+ g_print ("Second instance of test action\n");
+ g_print ("waiting on blocking action before continuing.\n");
+ pop_transaction_add_action (transaction, preemptive_action, NULL, NULL);
+ status = POP_ACTION_PROCESS_STATUS_NOT_FINISHED;
+ break;
case 4:
- g_print ("blocking action complete.\n");
- g_print ("failing anyway because I'm a failure.\n");
- status = POP_ACTION_PROCESS_STATUS_FAILED;
- break;
+ g_print ("blocking action complete.\n");
+ g_print ("failing anyway because I'm a failure.\n");
+ status = POP_ACTION_PROCESS_STATUS_FAILED;
+ break;
}
generation++;
@@ -1182,7 +1219,7 @@ test_action (PopTransaction *transaction,
return status;
}
-static PopActionRollbackStatus
+static PopActionRollbackStatus
test_action_cleanup (PopTransaction *transaction,
gpointer user_data)
{
@@ -1191,14 +1228,15 @@ test_action_cleanup (PopTransaction *transaction,
}
int
-main (int argc, char **argv)
+main (int argc,
+ char **argv)
{
GMainLoop *loop;
PopTransaction *transaction;
int exit_code;
g_log_set_always_fatal (G_LOG_LEVEL_ERROR
- | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
+ | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
g_type_init ();
@@ -1208,12 +1246,13 @@ main (int argc, char **argv)
transaction = pop_transaction_new ();
g_message ("'transaction' object created successfully");
- g_signal_connect (G_OBJECT (transaction), "finish",
+ g_signal_connect (G_OBJECT (transaction), "finish",
G_CALLBACK (on_transaction_finish),
loop);
g_message ("adding simple test action...");
- pop_transaction_add_action (transaction, test_action, test_action_cleanup, NULL);
+ pop_transaction_add_action (transaction, test_action, test_action_cleanup,
+ NULL);
g_message ("done adding simple test action...");
g_message ("adding duplicate test action...");
@@ -1240,4 +1279,5 @@ main (int argc, char **argv)
return exit_code;
}
+
#endif /* POP_TRANSACTION_ENABLE_TEST */