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


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

typedef struct _Block1Data Block1Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#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)))

struct _Block1Data {
	int _ref_count_;
	GArray* ids;
	GMainLoop* loop;
	ZeitgeistLog* zg;
};



gint _vala_main (void);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda2_ (Block1Data* _data1_, GObject* obj, 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_object_unref0 (_data1_->zg);
		_g_main_loop_unref0 (_data1_->loop);
		_g_array_unref0 (_data1_->ids);
		g_slice_free (Block1Data, _data1_);
	}
}


static void __lambda2_ (Block1Data* _data1_, GObject* obj, GAsyncResult* res) {
	GAsyncResult* _tmp0_;
	ZeitgeistResultSet* _tmp1_ = NULL;
	ZeitgeistResultSet* events;
	GError * _inner_error_ = NULL;
	g_return_if_fail (res != NULL);
	_tmp0_ = res;
	_tmp1_ = zeitgeist_log_get_events_finish (_data1_->zg, _tmp0_, &_inner_error_);
	events = _tmp1_;
	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;
	}
	{
		gint i;
		i = 0;
		{
			gboolean _tmp2_;
			_tmp2_ = TRUE;
			while (TRUE) {
				gboolean _tmp3_;
				gint _tmp5_;
				guint _tmp6_ = 0U;
				ZeitgeistEvent* _tmp7_ = NULL;
				ZeitgeistEvent* event;
				ZeitgeistEvent* _tmp8_;
				_tmp3_ = _tmp2_;
				if (!_tmp3_) {
					gint _tmp4_;
					_tmp4_ = i;
					i = _tmp4_ + 1;
				}
				_tmp2_ = FALSE;
				_tmp5_ = i;
				_tmp6_ = zeitgeist_result_set_size (events);
				if (!(((guint) _tmp5_) < _tmp6_)) {
					break;
				}
				_tmp7_ = zeitgeist_result_set_next_value (events);
				event = _tmp7_;
				_tmp8_ = event;
				if (_tmp8_ != NULL) {
					FILE* _tmp9_;
					ZeitgeistEvent* _tmp10_;
					GPtrArray* _tmp11_;
					GPtrArray* _tmp12_;
					gconstpointer _tmp13_ = NULL;
					const gchar* _tmp14_;
					const gchar* _tmp15_;
					_tmp9_ = stdout;
					_tmp10_ = event;
					_tmp11_ = zeitgeist_event_get_subjects (_tmp10_);
					_tmp12_ = _tmp11_;
					_tmp13_ = g_ptr_array_index (_tmp12_, (guint) 0);
					_tmp14_ = zeitgeist_subject_get_uri ((ZeitgeistSubject*) _tmp13_);
					_tmp15_ = _tmp14_;
					fprintf (_tmp9_, "First subject: %s\n", _tmp15_);
				} else {
					FILE* _tmp16_;
					gint _tmp17_;
					guint32 _tmp18_ = 0U;
					_tmp16_ = stdout;
					_tmp17_ = i;
					_tmp18_ = g_array_index (_data1_->ids, guint32, (guint) _tmp17_);
					fprintf (_tmp16_, "Event %d doesn't exist.\n", (gint) _tmp18_);
				}
				_g_object_unref0 (event);
			}
		}
	}
	g_main_loop_quit (_data1_->loop);
	_g_object_unref0 (events);
}


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_;
	GArray* _tmp0_;
	guint32 id1;
	guint32 id2;
	GMainLoop* _tmp1_;
	ZeitgeistLog* _tmp2_;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_tmp0_ = g_array_new (TRUE, TRUE, sizeof (guint32));
	_data1_->ids = _tmp0_;
	id1 = (guint32) 2100000;
	id2 = (guint32) 222;
	g_array_append_val (_data1_->ids, id1);
	g_array_append_val (_data1_->ids, id2);
	_tmp1_ = g_main_loop_new (NULL, FALSE);
	_data1_->loop = _tmp1_;
	_tmp2_ = zeitgeist_log_new ();
	_data1_->zg = _tmp2_;
	zeitgeist_log_get_events (_data1_->zg, _data1_->ids, NULL, ___lambda2__gasync_ready_callback, block1_data_ref (_data1_));
	g_main_loop_run (_data1_->loop);
	result = 0;
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return result;
}


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



