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


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

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

struct _Block1Data {
	int _ref_count_;
	ZeitgeistMonitor* monitor;
	ZeitgeistLog* log;
};



void on_events_inserted (ZeitgeistTimeRange* tr,
                         ZeitgeistResultSet* events);
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 _on_events_inserted_zeitgeist_monitor_events_inserted (ZeitgeistMonitor* _sender,
                                                            ZeitgeistTimeRange* time_range,
                                                            ZeitgeistResultSet* events,
                                                            gpointer self);
static gboolean __lambda4_ (Block1Data* _data1_);
static gboolean ___lambda4__gsource_func (gpointer self);


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


void
on_events_inserted (ZeitgeistTimeRange* tr,
                    ZeitgeistResultSet* events)
{
	g_return_if_fail (tr != NULL);
	g_return_if_fail (events != NULL);
	g_message ("monitor-events.vala:3: %u events inserted", zeitgeist_result_set_size (events));
	{
		ZeitgeistResultSet* _event_it = NULL;
		ZeitgeistResultSet* _tmp0_;
		ZeitgeistEvent* event = NULL;
		_tmp0_ = zeitgeist_result_set_iterator (events);
		_event_it = _tmp0_;
		while (TRUE) {
			ZeitgeistResultSet* _tmp1_;
			ZeitgeistEvent* _tmp2_;
			ZeitgeistEvent* _tmp3_;
			_tmp1_ = _event_it;
			_tmp2_ = zeitgeist_result_set_next_value (_tmp1_);
			_g_object_unref0 (event);
			event = _tmp2_;
			_tmp3_ = event;
			if (!(_tmp3_ != NULL)) {
				break;
			}
			{
				gint i = 0;
				i = 0;
				{
					gboolean _tmp4_ = FALSE;
					_tmp4_ = TRUE;
					while (TRUE) {
						gint _tmp6_;
						ZeitgeistEvent* _tmp7_;
						ZeitgeistSubject* subject = NULL;
						ZeitgeistEvent* _tmp8_;
						GPtrArray* _tmp9_;
						GPtrArray* _tmp10_;
						gint _tmp11_;
						gconstpointer _tmp12_;
						ZeitgeistSubject* _tmp13_;
						ZeitgeistSubject* _tmp14_;
						const gchar* _tmp15_;
						const gchar* _tmp16_;
						if (!_tmp4_) {
							gint _tmp5_;
							_tmp5_ = i;
							i = _tmp5_ + 1;
						}
						_tmp4_ = FALSE;
						_tmp6_ = i;
						_tmp7_ = event;
						if (!(_tmp6_ < zeitgeist_event_num_subjects (_tmp7_))) {
							break;
						}
						_tmp8_ = event;
						_tmp9_ = zeitgeist_event_get_subjects (_tmp8_);
						_tmp10_ = _tmp9_;
						_tmp11_ = i;
						_tmp12_ = g_ptr_array_index (_tmp10_, (guint) _tmp11_);
						_tmp13_ = _g_object_ref0 ((ZeitgeistSubject*) _tmp12_);
						subject = _tmp13_;
						_tmp14_ = subject;
						_tmp15_ = zeitgeist_subject_get_uri (_tmp14_);
						_tmp16_ = _tmp15_;
						g_message ("monitor-events.vala:10:  * %s", _tmp16_);
						_g_object_unref0 (subject);
					}
				}
			}
		}
		_g_object_unref0 (event);
		_g_object_unref0 (_event_it);
	}
}


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_->log);
		_g_object_unref0 (_data1_->monitor);
		g_slice_free (Block1Data, _data1_);
	}
}


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


static gpointer
_g_ptr_array_ref0 (gpointer self)
{
	return self ? g_ptr_array_ref (self) : NULL;
}


static void
_on_events_inserted_zeitgeist_monitor_events_inserted (ZeitgeistMonitor* _sender,
                                                       ZeitgeistTimeRange* time_range,
                                                       ZeitgeistResultSet* events,
                                                       gpointer self)
{
	on_events_inserted (time_range, events);
}


static gboolean
__lambda4_ (Block1Data* _data1_)
{
	gboolean result = FALSE;
	ZeitgeistMonitor* _tmp0_;
	GError * _inner_error_ = NULL;
	_tmp0_ = _g_object_ref0 (_data1_->monitor);
	zeitgeist_log_remove_monitor (_data1_->log, _tmp0_, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		gboolean _tmp1_ = FALSE;
		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 _tmp1_;
	}
	result = FALSE;
	return result;
}


static gboolean
___lambda4__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda4_ (self);
	return result;
}


gint
_vala_main (void)
{
	gint result = 0;
	Block1Data* _data1_;
	GMainLoop* loop = NULL;
	GMainLoop* _tmp0_;
	ZeitgeistTimeRange* time_range = NULL;
	ZeitgeistTimeRange* _tmp1_;
	GPtrArray* template = NULL;
	GPtrArray* _tmp2_;
	GPtrArray* _tmp3_;
	ZeitgeistMonitor* _tmp4_;
	ZeitgeistLog* _tmp5_;
	GError * _inner_error_ = NULL;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_tmp0_ = g_main_loop_new (NULL, FALSE);
	loop = _tmp0_;
	_tmp1_ = zeitgeist_time_range_new_anytime ();
	time_range = _tmp1_;
	_tmp2_ = g_ptr_array_new_full ((guint) 0, _g_object_unref0_);
	template = _tmp2_;
	_tmp3_ = _g_ptr_array_ref0 (template);
	_tmp4_ = zeitgeist_monitor_new (time_range, _tmp3_);
	_data1_->monitor = _tmp4_;
	_tmp5_ = zeitgeist_log_new ();
	_data1_->log = _tmp5_;
	g_signal_connect (_data1_->monitor, "events-inserted", (GCallback) _on_events_inserted_zeitgeist_monitor_events_inserted, NULL);
	zeitgeist_log_install_monitor (_data1_->log, _data1_->monitor, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		gint _tmp6_ = 0;
		_g_ptr_array_unref0 (template);
		_g_object_unref0 (time_range);
		_g_main_loop_unref0 (loop);
		block1_data_unref (_data1_);
		_data1_ = 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 _tmp6_;
	}
	g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 2000, ___lambda4__gsource_func, block1_data_ref (_data1_), block1_data_unref);
	g_main_loop_run (loop);
	result = 0;
	_g_ptr_array_unref0 (template);
	_g_object_unref0 (time_range);
	_g_main_loop_unref0 (loop);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return result;
}


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



