~kamstrup/dee/sorted

« back to all changes in this revision

Viewing changes to dee/dee-transaction.h

  • Committer: Tarmac
  • Author(s): Mikkel Kamstrup Erlandsen
  • Date: 2011-12-15 12:38:40 UTC
  • mfrom: (309.1.42 transactions)
  • Revision ID: tarmac-20111215123840-c8orvxf3iq88widl
Implement transaction logic for DeeModels in DeeTransaction

This branch implements a new class, DeeTransaction, that implements
transaction isolation on top of any old DeeModel implementation. It
has only one interesting API call so far,namely commit() which does
as labeled.

How/if exactly we want to expose a transactional API on DeeModel itself
is still up in the air; but this work should provide a solid foundation
for that. (and all of the trickier code needed, anything else will be
mostly just gloss).

Since this is a rather complicated afair I recomment that we take a somewhat
functional approach to the review. Validate the testing harness - and possibly
submit a few new test cases to cover the stuff I didn't think of.. Fixes: https://bugs.launchpad.net/bugs/894023. Appoved by Michal Hruby.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Canonical, Ltd.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License
 
6
 * version 3.0 as published by the Free Software Foundation.
 
7
 *
 
8
 * This library is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License version 3.0 for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public
 
14
 * License along with this library. If not, see
 
15
 * <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 
18
 */
 
19
 
 
20
#if !defined (_DEE_H_INSIDE) && !defined (DEE_COMPILATION)
 
21
#error "Only <dee.h> can be included directly."
 
22
#endif
 
23
 
 
24
#ifndef _HAVE_DEE_TRANSACTION_H
 
25
#define _HAVE_DEE_TRANSACTION_H
 
26
 
 
27
#include <glib.h>
 
28
#include <glib-object.h>
 
29
 
 
30
#include <dee-model.h>
 
31
#include <dee-serializable-model.h>
 
32
 
 
33
G_BEGIN_DECLS
 
34
 
 
35
#define DEE_TYPE_TRANSACTION (dee_transaction_get_type ())
 
36
 
 
37
#define DEE_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
 
38
        DEE_TYPE_TRANSACTION, DeeTransaction))
 
39
 
 
40
#define DEE_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \
 
41
        DEE_TYPE_TRANSACTION, DeeTransactionClass))
 
42
 
 
43
#define DEE_IS_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
 
44
        DEE_TYPE_TRANSACTION))
 
45
 
 
46
#define DEE_IS_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \
 
47
        DEE_TYPE_TRANSACTION))
 
48
 
 
49
#define DEE_TRANSACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
 
50
        DBUS_TYPE_SEQUENCE_MODEL, DeeTransactionClass))
 
51
 
 
52
typedef struct _DeeTransaction DeeTransaction;
 
53
typedef struct _DeeTransactionClass DeeTransactionClass;
 
54
typedef struct _DeeTransactionPrivate DeeTransactionPrivate;
 
55
 
 
56
/**
 
57
 * DeeTransaction:
 
58
 *
 
59
 * All fields in the DeeTransaction structure are private and should never be
 
60
 * accessed directly
 
61
 */
 
62
struct _DeeTransaction
 
63
{
 
64
  /*< private >*/
 
65
  DeeSerializableModel     parent;
 
66
 
 
67
  DeeTransactionPrivate *priv;
 
68
};
 
69
 
 
70
struct _DeeTransactionClass
 
71
{
 
72
  /*< private >*/
 
73
  DeeSerializableModelClass parent_class;
 
74
                                             
 
75
  /*< private >*/
 
76
  void     (*_dee_transaction_1) (void);
 
77
  void     (*_dee_transaction_2) (void);
 
78
  void     (*_dee_transaction_3) (void);
 
79
  void     (*_dee_transaction_4) (void);
 
80
};
 
81
 
 
82
/**
 
83
 * DEE_TRANSACTION_ERROR:
 
84
 *
 
85
 * Error domain for the #DeeTransaction. Error codes will be from the
 
86
 * #DeeTransactionError enumeration
 
87
 */
 
88
#define DEE_TRANSACTION_ERROR dee_transaction_error_quark()
 
89
 
 
90
/**
 
91
 * DeeTransactionError:
 
92
 *
 
93
 * Error codes for the #DeeTransaction class. These codes will be set when the
 
94
 * error domain is #DEE_TRANSACTION_ERROR.
 
95
 *
 
96
 * @DEE_TRANSACTION_ERROR_CONCURRENT_MODIFICATION: The target model has been
 
97
 *   modified while the transaction was open.
 
98
 *
 
99
 * @DEE_TRANSACTION_ERROR_COMMITTED: Raised when someone tries to commit a
 
100
 *   transaction that has already been committed
 
101
 */
 
102
typedef enum {
 
103
  DEE_TRANSACTION_ERROR_CONCURRENT_MODIFICATION = 1,
 
104
  DEE_TRANSACTION_ERROR_COMMITTED = 2,
 
105
} DeeTransactionError;
 
106
 
 
107
/**
 
108
 * dee_transaction_get_type:
 
109
 *
 
110
 * The GType of #DeeTransaction
 
111
 *
 
112
 * Return value: the #GType of #DeeTransaction
 
113
 **/
 
114
GType           dee_transaction_get_type               (void);
 
115
 
 
116
DeeModel*       dee_transaction_new                    (DeeModel        *target);
 
117
 
 
118
DeeModel*       dee_transaction_get_target             (DeeTransaction  *self);
 
119
 
 
120
gboolean        dee_transaction_is_committed           (DeeTransaction  *self);
 
121
 
 
122
gboolean        dee_transaction_commit                 (DeeTransaction  *self,
 
123
                                                        GError         **error);
 
124
 
 
125
GQuark          dee_transaction_error_quark            (void);
 
126
 
 
127
G_END_DECLS
 
128
 
 
129
#endif /* _HAVE_DEE_TRANSACTION_H */