/* insert-events.c generated by valac 0.20.1, the Vala compiler
 * generated from insert-events.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include "zeitgeist-datamodel.h"
#include "zeitgeist.h"
#include <gio/gio.h>

typedef struct _Block1Data Block1Data;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))

struct _Block1Data {
	int _ref_count_;
	GMainLoop* mainloop;
};



gint _vala_main (void);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void _g_object_unref0_ (gpointer var);
static void __lambda2_ (Block1Data* _data1_, GObject* log, GAsyncResult* res);
static void ___lambda2__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self);


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_main_loop_unref0 (_data1_->mainloop);
		g_slice_free (Block1Data, _data1_);
	}
}


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


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


static void __lambda2_ (Block1Data* _data1_, GObject* log, GAsyncResult* res) {
	GArray* event_ids = NULL;
	GObject* _tmp0_;
	ZeitgeistLog* _tmp1_;
	ZeitgeistLog* zg;
	GError * _inner_error_ = NULL;
	g_return_if_fail (res != NULL);
	_tmp0_ = log;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, ZEITGEIST_TYPE_LOG, ZeitgeistLog));
	zg = _tmp1_;
	{
		ZeitgeistLog* _tmp2_;
		GAsyncResult* _tmp3_;
		GArray* _tmp4_ = NULL;
		GArray* _tmp5_;
		_tmp2_ = zg;
		_tmp3_ = res;
		_tmp4_ = zeitgeist_log_insert_events_finish (_tmp2_, _tmp3_, &_inner_error_);
		_tmp5_ = _tmp4_;
		if (_inner_error_ != NULL) {
			goto __catch0_g_error;
		}
		_g_array_unref0 (event_ids);
		event_ids = _tmp5_;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_tmp6_ = _error_;
		_tmp7_ = _tmp6_->message;
		g_critical ("insert-events.vala:31: Failed to insert events: %s", _tmp7_);
		_g_error_free0 (_error_);
		_g_object_unref0 (zg);
		_g_array_unref0 (event_ids);
		return;
	}
	__finally0:
	if (_inner_error_ != NULL) {
		_g_object_unref0 (zg);
		_g_array_unref0 (event_ids);
		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;
	}
	g_main_loop_quit (_data1_->mainloop);
	_g_object_unref0 (zg);
	_g_array_unref0 (event_ids);
}


static void ___lambda2__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self) {
	__lambda2_ (self, source_object, res);
	block1_data_unref (self);
}


gint _vala_main (void) {
	gint result = 0;
	Block1Data* _data1_;
	GMainContext* _tmp0_ = NULL;
	GMainLoop* _tmp1_;
	GPtrArray* _tmp2_;
	GPtrArray* events;
	ZeitgeistEvent* _tmp3_;
	ZeitgeistEvent* ev;
	ZeitgeistSubject* _tmp4_;
	ZeitgeistSubject* su;
	ZeitgeistEvent* _tmp5_;
	ZeitgeistLog* _tmp6_ = NULL;
	ZeitgeistLog* _tmp7_;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_tmp0_ = g_main_context_default ();
	_tmp1_ = g_main_loop_new (_tmp0_, FALSE);
	_data1_->mainloop = _tmp1_;
	_tmp2_ = g_ptr_array_new_with_free_func (_g_object_unref0_);
	events = _tmp2_;
	_tmp3_ = zeitgeist_event_new ();
	ev = _tmp3_;
	_tmp4_ = zeitgeist_subject_new ();
	su = _tmp4_;
	zeitgeist_event_add_subject (ev, su);
	_tmp5_ = _g_object_ref0 (ev);
	g_ptr_array_add (events, _tmp5_);
	zeitgeist_event_set_interpretation (ev, "foo://Interp");
	zeitgeist_event_set_manifestation (ev, "foo://Manif");
	zeitgeist_event_set_actor (ev, "app://firefox.desktop");
	zeitgeist_subject_set_uri (su, "file:///tmp/bar.txt");
	zeitgeist_subject_set_interpretation (su, "foo://TextDoc");
	zeitgeist_subject_set_manifestation (su, "foo://File");
	zeitgeist_subject_set_mimetype (su, "text/plain");
	zeitgeist_subject_set_origin (su, "file:///tmp");
	zeitgeist_subject_set_text (su, "bar.txt");
	zeitgeist_subject_set_storage (su, "bfb486f6-f5f8-4296-8871-0cc749cf8ef7");
	_tmp6_ = zeitgeist_log_get_default ();
	_tmp7_ = _tmp6_;
	zeitgeist_log_insert_events (_tmp7_, events, NULL, ___lambda2__gasync_ready_callback, block1_data_ref (_data1_));
	_g_object_unref0 (_tmp7_);
	g_main_loop_run (_data1_->mainloop);
	result = 0;
	_g_object_unref0 (su);
	_g_object_unref0 (ev);
	_g_ptr_array_unref0 (events);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return result;
}


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



