/* insert-events.c generated by valac 0.39.91, 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 __lambda4_ (Block1Data* _data1_,
                 GObject* log,
                 GAsyncResult* res);
static void ___lambda4__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
__lambda4_ (Block1Data* _data1_,
            GObject* log,
            GAsyncResult* res)
{
	GArray* event_ids = NULL;
	ZeitgeistLog* zg = NULL;
	ZeitgeistLog* _tmp0_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (res != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (log, ZEITGEIST_TYPE_LOG, ZeitgeistLog));
	zg = _tmp0_;
	{
		GArray* _tmp1_ = NULL;
		ZeitgeistLog* _tmp2_;
		GArray* _tmp3_;
		GArray* _tmp4_;
		_tmp2_ = zg;
		_tmp3_ = zeitgeist_log_insert_events_finish (_tmp2_, res, &_inner_error_);
		_tmp1_ = _tmp3_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp4_ = _tmp1_;
		_tmp1_ = NULL;
		_g_array_unref0 (event_ids);
		event_ids = _tmp4_;
		_g_array_unref0 (_tmp1_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp5_;
		const gchar* _tmp6_;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_tmp5_ = _error_;
		_tmp6_ = _tmp5_->message;
		g_critical ("insert-events.vala:31: Failed to insert events: %s", _tmp6_);
		_g_error_free0 (_error_);
		_g_object_unref0 (zg);
		_g_array_unref0 (event_ids);
		return;
	}
	__finally0:
	if (G_UNLIKELY (_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
___lambda4__gasync_ready_callback (GObject* source_object,
                                   GAsyncResult* res,
                                   gpointer self)
{
	__lambda4_ (self, source_object, res);
	block1_data_unref (self);
}


gint
_vala_main (void)
{
	gint result = 0;
	Block1Data* _data1_;
	GMainContext* _tmp0_;
	GMainLoop* _tmp1_;
	GPtrArray* events = NULL;
	GPtrArray* _tmp2_;
	ZeitgeistEvent* ev = NULL;
	ZeitgeistEvent* _tmp3_;
	ZeitgeistSubject* su = NULL;
	ZeitgeistSubject* _tmp4_;
	ZeitgeistEvent* _tmp5_;
	ZeitgeistLog* _tmp6_;
	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_full ((guint) 0, _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, ___lambda4__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)
{
	return _vala_main ();
}



