File: async.c

package info (click to toggle)
sqlheavy 0.1.1-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,400 kB
  • sloc: ansic: 30,371; sh: 11,012; makefile: 367; sql: 20
file content (496 lines) | stat: -rw-r--r-- 15,585 bytes parent folder | download
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/* async.c generated by valac 0.16.0, the Vala compiler
 * generated from async.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <SQLHeavy.h>
#include <stdlib.h>
#include <string.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _TestData TestData;
#define __vala_GValue_free0(var) ((var == NULL) ? NULL : (var = (_vala_GValue_free (var), NULL)))
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))

struct _Block1Data {
	int _ref_count_;
	GCancellable* cancellable;
	gpointer _async_data_;
};

struct _TestData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	SQLHeavyDatabase* db;
	Block1Data* _data1_;
	guint _tmp0_;
	guint id;
	SQLHeavyDatabase* _tmp1_;
	SQLHeavyQuery* _tmp2_;
	SQLHeavyQuery* stmt;
	GCancellable* _tmp3_;
	SQLHeavyQuery* _tmp4_;
	GCancellable* _tmp5_;
	SQLHeavyQueryResult* _tmp6_;
	SQLHeavyQueryResult* _tmp7_;
	GError* e;
	GError* _tmp8_;
	GError* _tmp9_;
	const gchar* _tmp10_;
	GError* _tmp11_;
	gint _tmp12_;
	guint _tmp13_;
	GMainLoop* _tmp14_;
	GError * _inner_error_;
};


extern GMainLoop* loop;
GMainLoop* loop = NULL;

static void test_data_free (gpointer _data);
void test (SQLHeavyDatabase* db, GAsyncReadyCallback _callback_, gpointer _user_data_);
void test_finish (GAsyncResult* _res_);
static gboolean test_co (TestData* _data_);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static gboolean __lambda2_ (Block1Data* _data1_);
static gboolean ___lambda2__gsource_func (gpointer self);
static void test_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
gint _vala_main (gchar** args, int args_length1);
static void _vala_GValue_free (GValue* self);


static void test_data_free (gpointer _data) {
	TestData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->db);
	g_slice_free (TestData, _data_);
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


void test (SQLHeavyDatabase* db, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	TestData* _data_;
	SQLHeavyDatabase* _tmp0_;
	SQLHeavyDatabase* _tmp1_;
	_data_ = g_slice_new0 (TestData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, test);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, test_data_free);
	_tmp0_ = db;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data_->db = _tmp1_;
	test_co (_data_);
}


void test_finish (GAsyncResult* _res_) {
	TestData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


/**
 * Some basic testing for the asnychronous functions.
 */
static Block1Data* block1_data_ref (Block1Data* _data1_) {
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}


static void block1_data_unref (void * _userdata_) {
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		_g_object_unref0 (_data1_->cancellable);
		g_slice_free (Block1Data, _data1_);
	}
}


static gboolean __lambda2_ (Block1Data* _data1_) {
	gboolean result = FALSE;
	GCancellable* _tmp0_;
	_tmp0_ = _data1_->cancellable;
	if (_tmp0_ != NULL) {
		GCancellable* _tmp1_;
		g_debug ("async.vala:10: Canceling...");
		_tmp1_ = _data1_->cancellable;
		g_cancellable_cancel (_tmp1_);
		result = FALSE;
		return result;
	}
	g_debug ("async.vala:14: Tick");
	result = TRUE;
	return result;
}


static gboolean ___lambda2__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda2_ (self);
	return result;
}


static void test_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	TestData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	test_co (_data_);
}


static gboolean test_co (TestData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data1_ = g_slice_new0 (Block1Data);
	_data_->_data1_->_ref_count_ = 1;
	_data_->_data1_->_async_data_ = _data_;
	_data_->_data1_->cancellable = NULL;
	_data_->_tmp0_ = 0U;
	_data_->_tmp0_ = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 1, ___lambda2__gsource_func, block1_data_ref (_data_->_data1_), block1_data_unref);
	_data_->id = _data_->_tmp0_;
	g_debug ("async.vala:18: Running query...");
	{
		_data_->_tmp1_ = _data_->db;
		_data_->_tmp2_ = NULL;
		_data_->_tmp2_ = sql_heavy_queryable_prepare ((SQLHeavyQueryable*) _data_->_tmp1_, "UPDATE `foo` SET `bar` = ((`bar` + 1729) / 7) % 3;", &_data_->_inner_error_);
		_data_->stmt = _data_->_tmp2_;
		if (_data_->_inner_error_ != NULL) {
			if (_data_->_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			block1_data_unref (_data_->_data1_);
			_data_->_data1_ = NULL;
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
		_data_->_tmp3_ = g_cancellable_new ();
		_g_object_unref0 (_data_->_data1_->cancellable);
		_data_->_data1_->cancellable = _data_->_tmp3_;
		_data_->_tmp4_ = _data_->stmt;
		_data_->_tmp5_ = _data_->_data1_->cancellable;
		_data_->_state_ = 1;
		sql_heavy_query_execute_async (_data_->_tmp4_, _data_->_tmp5_, test_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp6_ = NULL;
		_data_->_tmp6_ = sql_heavy_query_execute_finish (_data_->_tmp4_, _data_->_res_, &_data_->_inner_error_);
		_data_->_tmp7_ = _data_->_tmp6_;
		_g_object_unref0 (_data_->_tmp7_);
		if (_data_->_inner_error_ != NULL) {
			_g_object_unref0 (_data_->stmt);
			if (_data_->_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			_g_object_unref0 (_data_->stmt);
			block1_data_unref (_data_->_data1_);
			_data_->_data1_ = NULL;
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
		_g_object_unref0 (_data_->stmt);
	}
	goto __finally0;
	__catch0_sql_heavy_error:
	{
		_data_->e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp8_ = _data_->e;
		if (g_error_matches (_data_->_tmp8_, SQL_HEAVY_ERROR, SQL_HEAVY_ERROR_INTERRUPTED)) {
			g_debug ("async.vala:26: Query canceled.");
		} else {
			_data_->_tmp9_ = _data_->e;
			_data_->_tmp10_ = _data_->_tmp9_->message;
			_data_->_tmp11_ = _data_->e;
			_data_->_tmp12_ = _data_->_tmp11_->code;
			g_error ("async.vala:28: Execution threw an error: %s (%d)", _data_->_tmp10_, _data_->_tmp12_);
		}
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (_data_->_inner_error_ != NULL) {
		block1_data_unref (_data_->_data1_);
		_data_->_data1_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	g_debug ("async.vala:30: Finished running query.");
	_data_->_tmp13_ = _data_->id;
	g_source_remove (_data_->_tmp13_);
	_data_->_tmp14_ = loop;
	g_main_loop_quit (_data_->_tmp14_);
	block1_data_unref (_data_->_data1_);
	_data_->_data1_ = NULL;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void _vala_GValue_free (GValue* self) {
	g_value_unset (self);
	g_free (self);
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GMainLoop* _tmp29_;
	GMainLoop* _tmp30_;
	GError * _inner_error_ = NULL;
	{
		SQLHeavyDatabase* _tmp0_;
		SQLHeavyDatabase* db;
		SQLHeavyDatabase* _tmp1_;
		SQLHeavyQuery* _tmp2_ = NULL;
		SQLHeavyQuery* stmt;
		SQLHeavyQuery* _tmp3_;
		SQLHeavyQueryResult* _tmp4_ = NULL;
		SQLHeavyQueryResult* _tmp5_;
		SQLHeavyDatabase* _tmp6_;
		SQLHeavyTransaction* _tmp7_ = NULL;
		SQLHeavyTransaction* trans;
		SQLHeavyTransaction* _tmp8_;
		SQLHeavyQuery* _tmp9_ = NULL;
		SQLHeavyQuery* _tmp10_;
		SQLHeavyTransaction* _tmp23_;
		SQLHeavyDatabase* _tmp24_;
		_tmp0_ = sql_heavy_database_new (NULL, (SQL_HEAVY_FILE_MODE_READ | SQL_HEAVY_FILE_MODE_WRITE) | SQL_HEAVY_FILE_MODE_CREATE, &_inner_error_);
		db = _tmp0_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch1_sql_heavy_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp1_ = db;
		_tmp2_ = sql_heavy_queryable_prepare ((SQLHeavyQueryable*) _tmp1_, "CREATE TABLE `foo` ( `bar` INT );", &_inner_error_);
		stmt = _tmp2_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch1_sql_heavy_error;
			}
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp3_ = stmt;
		_tmp4_ = sql_heavy_query_execute (_tmp3_, NULL, &_inner_error_, NULL);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp5_);
		if (_inner_error_ != NULL) {
			_g_object_unref0 (stmt);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch1_sql_heavy_error;
			}
			_g_object_unref0 (stmt);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		g_debug ("async.vala:45: Populating database...");
		_tmp6_ = db;
		_tmp7_ = sql_heavy_queryable_begin_transaction ((SQLHeavyQueryable*) _tmp6_, &_inner_error_);
		trans = _tmp7_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (stmt);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch1_sql_heavy_error;
			}
			_g_object_unref0 (stmt);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp8_ = trans;
		_tmp9_ = sql_heavy_queryable_prepare ((SQLHeavyQueryable*) _tmp8_, "INSERT INTO `foo` (`bar`) VALUES (:value);", &_inner_error_);
		_tmp10_ = _tmp9_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (trans);
			_g_object_unref0 (stmt);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch1_sql_heavy_error;
			}
			_g_object_unref0 (trans);
			_g_object_unref0 (stmt);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_g_object_unref0 (stmt);
		stmt = _tmp10_;
		{
			gint i;
			i = 0;
			{
				gboolean _tmp11_;
				_tmp11_ = TRUE;
				while (TRUE) {
					gboolean _tmp12_;
					gint _tmp14_;
					gint _tmp15_;
					SQLHeavyQuery* _tmp17_;
					gint _tmp18_;
					GValue* _tmp19_ = NULL;
					SQLHeavyQuery* _tmp20_;
					SQLHeavyQueryResult* _tmp21_ = NULL;
					SQLHeavyQueryResult* _tmp22_;
					_tmp12_ = _tmp11_;
					if (!_tmp12_) {
						gint _tmp13_;
						_tmp13_ = i;
						i = _tmp13_ + 1;
					}
					_tmp11_ = FALSE;
					_tmp14_ = i;
					if (!(_tmp14_ < (65536 * 8))) {
						break;
					}
					_tmp15_ = i;
					if ((_tmp15_ & 0xffff) == 0xffff) {
						gint _tmp16_;
						_tmp16_ = i;
						g_debug ("async.vala:51: %d...", _tmp16_);
					}
					_tmp17_ = stmt;
					_tmp18_ = i;
					_tmp19_ = g_new0 (GValue, 1);
					g_value_init (_tmp19_, G_TYPE_INT);
					g_value_set_int (_tmp19_, _tmp18_);
					sql_heavy_query_set (_tmp17_, ":value", _tmp19_, &_inner_error_);
					__vala_GValue_free0 (_tmp19_);
					if (_inner_error_ != NULL) {
						_g_object_unref0 (trans);
						_g_object_unref0 (stmt);
						_g_object_unref0 (db);
						if (_inner_error_->domain == SQL_HEAVY_ERROR) {
							goto __catch1_sql_heavy_error;
						}
						_g_object_unref0 (trans);
						_g_object_unref0 (stmt);
						_g_object_unref0 (db);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return 0;
					}
					_tmp20_ = stmt;
					_tmp21_ = sql_heavy_query_execute (_tmp20_, NULL, &_inner_error_, NULL);
					_tmp22_ = _tmp21_;
					_g_object_unref0 (_tmp22_);
					if (_inner_error_ != NULL) {
						_g_object_unref0 (trans);
						_g_object_unref0 (stmt);
						_g_object_unref0 (db);
						if (_inner_error_->domain == SQL_HEAVY_ERROR) {
							goto __catch1_sql_heavy_error;
						}
						_g_object_unref0 (trans);
						_g_object_unref0 (stmt);
						_g_object_unref0 (db);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return 0;
					}
				}
			}
		}
		_tmp23_ = trans;
		sql_heavy_transaction_commit (_tmp23_, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_object_unref0 (trans);
			_g_object_unref0 (stmt);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch1_sql_heavy_error;
			}
			_g_object_unref0 (trans);
			_g_object_unref0 (stmt);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp24_ = db;
		test (_tmp24_, NULL, NULL);
		_g_object_unref0 (trans);
		_g_object_unref0 (stmt);
		_g_object_unref0 (db);
	}
	goto __finally1;
	__catch1_sql_heavy_error:
	{
		GError* e = NULL;
		GError* _tmp25_;
		const gchar* _tmp26_;
		GError* _tmp27_;
		gint _tmp28_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp25_ = e;
		_tmp26_ = _tmp25_->message;
		_tmp27_ = e;
		_tmp28_ = _tmp27_->code;
		g_debug ("async.vala:61: Error: %s (%d)", _tmp26_, _tmp28_);
		_g_error_free0 (e);
	}
	__finally1:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	_tmp29_ = g_main_loop_new (NULL, FALSE);
	_g_main_loop_unref0 (loop);
	loop = _tmp29_;
	_tmp30_ = loop;
	g_main_loop_run (_tmp30_);
	result = 0;
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main (argv, argc);
}