summaryrefslogtreecommitdiff
path: root/gdata/gdata-batch-operation.h
blob: 1626a282e293151d6ac2b2e1f35c18a1cc142d5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
 * GData Client
 * Copyright (C) Philip Withnall 2010 <philip@tecnocode.co.uk>
 *
 * GData Client is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GData Client is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GDATA_BATCH_OPERATION_H
#define GDATA_BATCH_OPERATION_H

#include <glib.h>
#include <glib-object.h>

#include <gdata/gdata-service.h>
#include <gdata/gdata-entry.h>
#include <gdata/gdata-authorization-domain.h>

G_BEGIN_DECLS

/**
 * GDATA_LINK_BATCH:
 *
 * The relation type URI for the batch operation URI for a given #GDataFeed.
 *
 * For more information, see the <ulink type="http" url="http://code.google.com/apis/gdata/docs/batch.html#Submit_HTTP">GData specification</ulink>.
 *
 * Since: 0.7.0
 */
#define GDATA_LINK_BATCH "http://schemas.google.com/g/2005#batch"

/**
 * GDataBatchOperationType:
 * @GDATA_BATCH_OPERATION_QUERY: a query operation
 * @GDATA_BATCH_OPERATION_INSERTION: an insertion operation
 * @GDATA_BATCH_OPERATION_UPDATE: an update operation
 * @GDATA_BATCH_OPERATION_DELETION: a deletion operation
 *
 * Indicates which type of batch operation caused the current #GDataBatchOperationCallback to be called.
 *
 * Since: 0.7.0
 */
typedef enum {
	GDATA_BATCH_OPERATION_QUERY = 0,
	GDATA_BATCH_OPERATION_INSERTION,
	GDATA_BATCH_OPERATION_UPDATE,
	GDATA_BATCH_OPERATION_DELETION
} GDataBatchOperationType;

/**
 * GDataBatchOperationCallback:
 * @operation_id: the operation ID returned from gdata_batch_operation_add_*()
 * @operation_type: the type of operation which was requested
 * @entry: the result of the operation, or %NULL
 * @error: a #GError describing any error which occurred, or %NULL
 * @user_data: user data passed to the callback
 *
 * Callback function called once for each operation in a batch operation run. The operation is identified by @operation_id and @operation_type (where
 * @operation_id is the ID returned by the relevant call to gdata_batch_operation_add_query(), gdata_batch_operation_add_insertion(),
 * gdata_batch_operation_add_update() or gdata_batch_operation_add_deletion(), and @operation_type shows which one of the above was called).
 *
 * If the operation was successful, the resulting #GDataEntry will be passed in as @entry, and @error will be %NULL. Otherwise, @entry will be %NULL
 * and a descriptive error will be in @error. If @operation_type is %GDATA_BATCH_OPERATION_DELETION, @entry will always be %NULL, and @error will be
 * %NULL or non-%NULL as appropriate.
 *
 * If the callback code needs to retain a copy of @entry, it must be referenced (with g_object_ref()). Similarly, @error is owned by the calling code,
 * and must not be freed.
 *
 * The callback is called in the main thread, and there is no guarantee on the order in which the callbacks for the operations in a run are executed,
 * or whether they will be called in a timely manner. It is, however, guaranteed that they will all be called before the #GAsyncReadyCallback which
 * signals the completion of the run (if initiated with gdata_batch_operation_run_async()) is called; or gdata_batch_operation_run() returns (if
 * initiated synchronously).
 *
 * Since: 0.7.0
 */
typedef void (*GDataBatchOperationCallback) (guint operation_id, GDataBatchOperationType operation_type, GDataEntry *entry,
                                             GError *error, gpointer user_data);

#define GDATA_TYPE_BATCH_OPERATION		(gdata_batch_operation_get_type ())
#define GDATA_BATCH_OPERATION(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GDATA_TYPE_BATCH_OPERATION, GDataBatchOperation))
#define GDATA_BATCH_OPERATION_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_BATCH_OPERATION, GDataBatchOperationClass))
#define GDATA_IS_BATCH_OPERATION(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GDATA_TYPE_BATCH_OPERATION))
#define GDATA_IS_BATCH_OPERATION_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GDATA_TYPE_BATCH_OPERATION))
#define GDATA_BATCH_OPERATION_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GDATA_TYPE_BATCH_OPERATION, GDataBatchOperationClass))

typedef struct _GDataBatchOperationPrivate	GDataBatchOperationPrivate;

/**
 * GDataBatchOperation:
 *
 * All the fields in the #GDataBatchOperation structure are private and should never be accessed directly.
 *
 * Since: 0.7.0
 */
typedef struct {
	GObject parent;
	GDataBatchOperationPrivate *priv;
} GDataBatchOperation;

/**
 * GDataBatchOperationClass:
 *
 * All the fields in the #GDataBatchOperationClass structure are private and should never be accessed directly.
 *
 * Since: 0.7.0
 */
typedef struct {
	/*< private >*/
	GObjectClass parent;

	/*< private >*/
	/* Padding for future expansion */
	void (*_g_reserved0) (void);
	void (*_g_reserved1) (void);
	void (*_g_reserved2) (void);
	void (*_g_reserved3) (void);
	void (*_g_reserved4) (void);
	void (*_g_reserved5) (void);
} GDataBatchOperationClass;

GType gdata_batch_operation_get_type (void) G_GNUC_CONST;

GDataService *gdata_batch_operation_get_service (GDataBatchOperation *self) G_GNUC_PURE;
GDataAuthorizationDomain *gdata_batch_operation_get_authorization_domain (GDataBatchOperation *self) G_GNUC_PURE;
const gchar *gdata_batch_operation_get_feed_uri (GDataBatchOperation *self) G_GNUC_PURE;

guint gdata_batch_operation_add_query (GDataBatchOperation *self, const gchar *id, GType entry_type,
                                       GDataBatchOperationCallback callback, gpointer user_data);
guint gdata_batch_operation_add_insertion (GDataBatchOperation *self, GDataEntry *entry, GDataBatchOperationCallback callback, gpointer user_data);
guint gdata_batch_operation_add_update (GDataBatchOperation *self, GDataEntry *entry, GDataBatchOperationCallback callback, gpointer user_data);
guint gdata_batch_operation_add_deletion (GDataBatchOperation *self, GDataEntry *entry, GDataBatchOperationCallback callback, gpointer user_data);

gboolean gdata_batch_operation_run (GDataBatchOperation *self, GCancellable *cancellable, GError **error);
void gdata_batch_operation_run_async (GDataBatchOperation *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
gboolean gdata_batch_operation_run_finish (GDataBatchOperation *self, GAsyncResult *async_result, GError **error);

G_END_DECLS

#endif /* !GDATA_BATCH_OPERATION_H */