/* idle-monitor-provider.c generated by valac 0.56.19, the Vala compiler
 * generated from idle-monitor-provider.vala, do not modify */

/*
 * Copyright (c) 2024-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "ft_plugin_gnome.h"
#include <gio/gio.h>
#include <glib.h>
#include "ft_core.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>

#define GNOME_IDLE_MONITOR_PROVIDER_TIMEOUT_TOLERANCE (100 * FT_INTERVAL_MILLISECOND)
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

typedef struct _GnomeIdleMonitorProviderWatch GnomeIdleMonitorProviderWatch;
enum  {
	GNOME_IDLE_MONITOR_PROVIDER_0_PROPERTY,
	GNOME_IDLE_MONITOR_PROVIDER_PRIORITY_PROPERTY,
	GNOME_IDLE_MONITOR_PROVIDER_CAN_IGNORE_INHIBITORS_PROPERTY,
	GNOME_IDLE_MONITOR_PROVIDER_NUM_PROPERTIES
};
static GParamSpec* gnome_idle_monitor_provider_properties[GNOME_IDLE_MONITOR_PROVIDER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _GnomeIdleMonitorProviderInitializeData GnomeIdleMonitorProviderInitializeData;
typedef struct _GnomeIdleMonitorProviderUninitializeData GnomeIdleMonitorProviderUninitializeData;
typedef struct _GnomeIdleMonitorProviderEnableData GnomeIdleMonitorProviderEnableData;
typedef struct _Block1Data Block1Data;
typedef struct _GnomeIdleMonitorProviderDisableData GnomeIdleMonitorProviderDisableData;
#define _gnome_idle_monitor_provider_watch_free0(var) ((var == NULL) ? NULL : (var = (gnome_idle_monitor_provider_watch_free (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GnomeIdleMonitorProviderPrivate {
	GnomeIdleMonitor* proxy;
	GCancellable* cancellable;
	guint dbus_watcher_id;
	GHashTable* watches;
	guint32 active_watch_id;
	guint active_watch_use_count;
	gint idle_time_freeze_count;
	gint64 idle_time;
};

struct _GnomeIdleMonitorProviderWatch {
	guint32 id;
	gint64 absolute_timeout;
	gint64 relative_timeout;
	gint64 reference_time;
	gboolean has_active_watch;
	gboolean invalid;
};

struct _GnomeIdleMonitorProviderInitializeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GnomeIdleMonitorProvider* self;
	GCancellable* cancellable;
};

struct _GnomeIdleMonitorProviderUninitializeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GnomeIdleMonitorProvider* self;
};

struct _GnomeIdleMonitorProviderEnableData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GnomeIdleMonitorProvider* self;
	GCancellable* cancellable;
	GnomeIdleMonitor* _tmp0_;
	GCancellable* _tmp1_;
	GnomeIdleMonitor* _tmp2_;
	GCancellable* _tmp3_;
	GnomeIdleMonitor* _tmp4_;
	GnomeIdleMonitor* _tmp5_;
	GnomeIdleMonitor* _tmp6_;
	GError* _inner_error0_;
};

struct _Block1Data {
	int _ref_count_;
	GnomeIdleMonitorProvider* self;
	guint32* ids;
	gint ids_length1;
	gint _ids_size_;
	gpointer _async_data_;
};

struct _GnomeIdleMonitorProviderDisableData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GnomeIdleMonitorProvider* self;
	Block1Data* _data1_;
	GCancellable* _tmp0_;
	GCancellable* _tmp1_;
	GnomeIdleMonitor* _tmp2_;
	GnomeIdleMonitor* _tmp3_;
	guint _tmp4_;
	guint32* _tmp5_;
	GHashTable* _tmp6_;
	gint index;
	gboolean _tmp7_;
	gint _tmp8_;
	guint32* _tmp9_;
	gint _tmp9__length1;
	guint32* _tmp10_;
	gint _tmp10__length1;
	guint32 _tmp11_;
	GError* _inner_error0_;
};

static gint GnomeIdleMonitorProvider_private_offset;
static gpointer gnome_idle_monitor_provider_parent_class = NULL;
static FtIdleMonitorProviderIface * gnome_idle_monitor_provider_ft_idle_monitor_provider_parent_iface = NULL;
static GType gnome_idle_monitor_provider_type_id = 0;

static void gnome_idle_monitor_provider_watch_free (GnomeIdleMonitorProviderWatch * self);
static inline gint64 gnome_idle_monitor_provider_from_milliseconds (GnomeIdleMonitorProvider* self,
                                                      guint64 milliseconds);
static inline guint64 gnome_idle_monitor_provider_to_milliseconds (GnomeIdleMonitorProvider* self,
                                                     gint64 interval);
static void gnome_idle_monitor_provider_freeze_idle_time (GnomeIdleMonitorProvider* self);
static void gnome_idle_monitor_provider_thaw_idle_time (GnomeIdleMonitorProvider* self);
static void gnome_idle_monitor_provider_remove_active_watch_internal (GnomeIdleMonitorProvider* self,
                                                               GError** error);
static gint64 gnome_idle_monitor_provider_get_idle_time (GnomeIdleMonitorProvider* self,
                                                  GError** error);
static void gnome_idle_monitor_provider_on_name_appeared (GnomeIdleMonitorProvider* self,
                                                   GDBusConnection* connection,
                                                   const gchar* name,
                                                   const gchar* name_owner);
static void gnome_idle_monitor_provider_on_name_vanished (GnomeIdleMonitorProvider* self,
                                                   GDBusConnection* connection,
                                                   const gchar* name);
static void gnome_idle_monitor_provider_on_became_active (GnomeIdleMonitorProvider* self);
static void gnome_idle_monitor_provider_on_became_idle (GnomeIdleMonitorProvider* self,
                                                 GnomeIdleMonitorProviderWatch* watch);
static void gnome_idle_monitor_provider_on_watch_fired (GnomeIdleMonitorProvider* self,
                                                 GnomeIdleMonitor* idle_monitor,
                                                 guint32 id);
static void gnome_idle_monitor_provider_real_initialize_data_free (gpointer _data);
static void gnome_idle_monitor_provider_real_initialize (FtProvider* base,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
static gboolean gnome_idle_monitor_provider_real_initialize_co (GnomeIdleMonitorProviderInitializeData* _data_);
static void _gnome_idle_monitor_provider_on_name_appeared_gbus_name_appeared_callback (GDBusConnection* connection,
                                                                                const gchar* name,
                                                                                const gchar* name_owner,
                                                                                gpointer self);
static void _gnome_idle_monitor_provider_on_name_vanished_gbus_name_vanished_callback (GDBusConnection* connection,
                                                                                const gchar* name,
                                                                                gpointer self);
static void gnome_idle_monitor_provider_real_uninitialize_data_free (gpointer _data);
static void gnome_idle_monitor_provider_real_uninitialize (FtProvider* base,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
static gboolean gnome_idle_monitor_provider_real_uninitialize_co (GnomeIdleMonitorProviderUninitializeData* _data_);
static void gnome_idle_monitor_provider_real_enable_data_free (gpointer _data);
static void gnome_idle_monitor_provider_real_enable (FtProvider* base,
                                              GCancellable* cancellable,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_);
static gboolean gnome_idle_monitor_provider_real_enable_co (GnomeIdleMonitorProviderEnableData* _data_);
static void gnome_idle_monitor_provider_enable_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static void _gnome_idle_monitor_provider_on_watch_fired_gnome_idle_monitor_watch_fired (GnomeIdleMonitor* _sender,
                                                                                 guint32 id,
                                                                                 gpointer self);
static void gnome_idle_monitor_provider_real_disable_data_free (gpointer _data);
static void gnome_idle_monitor_provider_real_disable (FtProvider* base,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_);
static gboolean gnome_idle_monitor_provider_real_disable_co (GnomeIdleMonitorProviderDisableData* _data_);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda5_ (Block1Data* _data1_,
                 gint64* id,
                 GnomeIdleMonitorProviderWatch* watch);
static void _vala_array_add1 (guint32* * array,
                       gint* length,
                       gint* size,
                       guint32 value);
static void ___lambda5__gh_func (gconstpointer key,
                          gconstpointer value,
                          gpointer self);
static guint32 gnome_idle_monitor_provider_real_add_idle_watch (FtIdleMonitorProvider* base,
                                                         gint64 timeout,
                                                         gboolean ignore_inhibitors,
                                                         gint64 monotonic_time,
                                                         GError** error);
static GnomeIdleMonitorProviderWatch* gnome_idle_monitor_provider_watch_new (void);
static gint64* _int64_dup (gint64* self);
static void gnome_idle_monitor_provider_real_remove_idle_watch (FtIdleMonitorProvider* base,
                                                         guint32 id,
                                                         GError** error);
static guint32 gnome_idle_monitor_provider_real_reset_idle_watch (FtIdleMonitorProvider* base,
                                                           guint32 id,
                                                           gint64 monotonic_time,
                                                           GError** error);
static void gnome_idle_monitor_provider_real_add_active_watch (FtIdleMonitorProvider* base,
                                                        GError** error);
static void gnome_idle_monitor_provider_real_remove_active_watch (FtIdleMonitorProvider* base,
                                                           GError** error);
static void gnome_idle_monitor_provider_real_dispose (GObject* base);
static void gnome_idle_monitor_provider_watch_instance_init (GnomeIdleMonitorProviderWatch * self);
static GObject * gnome_idle_monitor_provider_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties);
static void _g_free0_ (gpointer var);
static void _gnome_idle_monitor_provider_watch_free0_ (gpointer var);
static void gnome_idle_monitor_provider_finalize (GObject * obj);
static void _vala_gnome_idle_monitor_provider_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec);

static inline gpointer
gnome_idle_monitor_provider_get_instance_private (GnomeIdleMonitorProvider* self)
{
	return G_STRUCT_MEMBER_P (self, GnomeIdleMonitorProvider_private_offset);
}

static inline gint64
gnome_idle_monitor_provider_from_milliseconds (GnomeIdleMonitorProvider* self,
                                               guint64 milliseconds)
{
	gint64 _tmp0_ = 0LL;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	if (milliseconds < ((guint64) (G_MAXINT64 / FT_INTERVAL_MILLISECOND))) {
		_tmp0_ = ((gint64) milliseconds) * FT_INTERVAL_MILLISECOND;
	} else {
		_tmp0_ = G_MAXINT64;
	}
	result = _tmp0_;
	return result;
}

static inline guint64
gnome_idle_monitor_provider_to_milliseconds (GnomeIdleMonitorProvider* self,
                                             gint64 interval)
{
	guint64 result;
	g_return_val_if_fail (self != NULL, 0ULL);
	result = ((guint64) MAX (interval, (gint64) 0)) / FT_INTERVAL_MILLISECOND;
	return result;
}

static void
gnome_idle_monitor_provider_freeze_idle_time (GnomeIdleMonitorProvider* self)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->idle_time_freeze_count;
	self->priv->idle_time_freeze_count = _tmp0_ + 1;
}

static void
gnome_idle_monitor_provider_thaw_idle_time (GnomeIdleMonitorProvider* self)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->idle_time_freeze_count;
	self->priv->idle_time_freeze_count = _tmp0_ - 1;
}

static void
gnome_idle_monitor_provider_remove_active_watch_internal (GnomeIdleMonitorProvider* self,
                                                          GError** error)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	if (self->priv->active_watch_id != ((guint32) 0)) {
		guint32 watch_id = 0U;
		GnomeIdleMonitor* _tmp0_;
		watch_id = self->priv->active_watch_id;
		self->priv->active_watch_id = (guint32) 0;
		self->priv->active_watch_use_count = (guint) 0;
		_tmp0_ = self->priv->proxy;
		gnome_idle_monitor_remove_watch (_tmp0_, watch_id, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
	}
}

static gint64
gnome_idle_monitor_provider_get_idle_time (GnomeIdleMonitorProvider* self,
                                           GError** error)
{
	gboolean _tmp0_ = FALSE;
	GnomeIdleMonitor* _tmp1_;
	guint64 _tmp2_ = 0ULL;
	GnomeIdleMonitor* _tmp3_;
	gint64 idle_time = 0LL;
	GError* _inner_error0_ = NULL;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	if (self->priv->idle_time_freeze_count > 0) {
		_tmp0_ = self->priv->idle_time >= ((gint64) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		result = self->priv->idle_time;
		return result;
	}
	_tmp1_ = self->priv->proxy;
	if (_tmp1_ == NULL) {
		result = (gint64) 0;
		return result;
	}
	_tmp3_ = self->priv->proxy;
	_tmp2_ = gnome_idle_monitor_get_idletime (_tmp3_, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint64 _tmp4_ = -1LL;
		g_propagate_error (error, _inner_error0_);
		return _tmp4_;
	}
	idle_time = gnome_idle_monitor_provider_from_milliseconds (self, _tmp2_);
	if (self->priv->idle_time_freeze_count > 0) {
		self->priv->idle_time = idle_time;
	}
	result = idle_time;
	return result;
}

static void
gnome_idle_monitor_provider_on_name_appeared (GnomeIdleMonitorProvider* self,
                                              GDBusConnection* connection,
                                              const gchar* name,
                                              const gchar* name_owner)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (connection != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (name_owner != NULL);
	ft_provider_set_available ((FtProvider*) self, TRUE);
}

static void
gnome_idle_monitor_provider_on_name_vanished (GnomeIdleMonitorProvider* self,
                                              GDBusConnection* connection,
                                              const gchar* name)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	ft_provider_set_available ((FtProvider*) self, FALSE);
}

static void
gnome_idle_monitor_provider_on_became_active (GnomeIdleMonitorProvider* self)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	{
		gnome_idle_monitor_provider_remove_active_watch_internal (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = _error_;
		_tmp1_ = _tmp0_->message;
		g_warning ("idle-monitor-provider.vala:128: Error while removing active-watch: %s", _tmp1_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	g_signal_emit_by_name ((FtIdleMonitorProvider*) self, "became-active");
}

static void
gnome_idle_monitor_provider_on_became_idle (GnomeIdleMonitorProvider* self,
                                            GnomeIdleMonitorProviderWatch* watch)
{
	gint64 monotonic_time = 0LL;
	gint64 min_elapsed = 0LL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (watch != NULL);
	monotonic_time = g_get_monotonic_time ();
	min_elapsed = MAX (watch->relative_timeout - GNOME_IDLE_MONITOR_PROVIDER_TIMEOUT_TOLERANCE, watch->relative_timeout / 2);
	if ((monotonic_time - watch->reference_time) >= min_elapsed) {
		g_signal_emit_by_name ((FtIdleMonitorProvider*) self, "became-idle", watch->id);
	}
}

static void
gnome_idle_monitor_provider_on_watch_fired (GnomeIdleMonitorProvider* self,
                                            GnomeIdleMonitor* idle_monitor,
                                            guint32 id)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (idle_monitor != NULL);
	if (id == ((guint32) 0)) {
		return;
	}
	gnome_idle_monitor_provider_freeze_idle_time (self);
	if (id == self->priv->active_watch_id) {
		self->priv->idle_time = (gint64) 0;
		gnome_idle_monitor_provider_on_became_active (self);
	} else {
		GnomeIdleMonitorProviderWatch* watch = NULL;
		GHashTable* _tmp0_;
		gint64 _tmp1_;
		gconstpointer _tmp2_;
		gboolean _tmp3_ = FALSE;
		GnomeIdleMonitorProviderWatch* _tmp4_;
		_tmp0_ = self->priv->watches;
		_tmp1_ = (gint64) id;
		_tmp2_ = g_hash_table_lookup (_tmp0_, &_tmp1_);
		watch = (GnomeIdleMonitorProviderWatch*) _tmp2_;
		_tmp4_ = watch;
		if (_tmp4_ != NULL) {
			GnomeIdleMonitorProviderWatch* _tmp5_;
			_tmp5_ = watch;
			_tmp3_ = !_tmp5_->invalid;
		} else {
			_tmp3_ = FALSE;
		}
		if (_tmp3_) {
			GnomeIdleMonitorProviderWatch* _tmp6_;
			GnomeIdleMonitorProviderWatch* _tmp7_;
			_tmp6_ = watch;
			self->priv->idle_time = _tmp6_->absolute_timeout;
			_tmp7_ = watch;
			gnome_idle_monitor_provider_on_became_idle (self, _tmp7_);
		}
	}
	gnome_idle_monitor_provider_thaw_idle_time (self);
}

static void
gnome_idle_monitor_provider_real_initialize_data_free (gpointer _data)
{
	GnomeIdleMonitorProviderInitializeData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GnomeIdleMonitorProviderInitializeData, _data_);
}

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

static void
gnome_idle_monitor_provider_real_initialize (FtProvider* base,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	GnomeIdleMonitorProvider * self;
	GnomeIdleMonitorProviderInitializeData* _data_;
	GnomeIdleMonitorProvider* _tmp0_;
	GCancellable* _tmp1_;
	self = (GnomeIdleMonitorProvider*) base;
	_data_ = g_slice_new0 (GnomeIdleMonitorProviderInitializeData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, gnome_idle_monitor_provider_real_initialize_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	gnome_idle_monitor_provider_real_initialize_co (_data_);
}

static void
gnome_idle_monitor_provider_initialize_finish (FtProvider* base,
                                               GAsyncResult* _res_,
                                               GError** error)
{
	GnomeIdleMonitorProviderInitializeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
_gnome_idle_monitor_provider_on_name_appeared_gbus_name_appeared_callback (GDBusConnection* connection,
                                                                           const gchar* name,
                                                                           const gchar* name_owner,
                                                                           gpointer self)
{
	gnome_idle_monitor_provider_on_name_appeared ((GnomeIdleMonitorProvider*) self, connection, name, name_owner);
}

static void
_gnome_idle_monitor_provider_on_name_vanished_gbus_name_vanished_callback (GDBusConnection* connection,
                                                                           const gchar* name,
                                                                           gpointer self)
{
	gnome_idle_monitor_provider_on_name_vanished ((GnomeIdleMonitorProvider*) self, connection, name);
}

static gboolean
gnome_idle_monitor_provider_real_initialize_co (GnomeIdleMonitorProviderInitializeData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->self->priv->dbus_watcher_id == ((guint) 0)) {
		_data_->self->priv->dbus_watcher_id = g_bus_watch_name_with_closures (G_BUS_TYPE_SESSION, "org.gnome.Mutter.IdleMonitor", G_BUS_NAME_WATCHER_FLAGS_NONE, (GClosure*) ((_gnome_idle_monitor_provider_on_name_appeared_gbus_name_appeared_callback == NULL) ? NULL : g_cclosure_new ((GCallback) _gnome_idle_monitor_provider_on_name_appeared_gbus_name_appeared_callback, g_object_ref (_data_->self), (GClosureNotify) g_object_unref)), (GClosure*) ((_gnome_idle_monitor_provider_on_name_vanished_gbus_name_vanished_callback == NULL) ? NULL : g_cclosure_new ((GCallback) _gnome_idle_monitor_provider_on_name_vanished_gbus_name_vanished_callback, g_object_ref (_data_->self), (GClosureNotify) g_object_unref)));
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
gnome_idle_monitor_provider_real_uninitialize_data_free (gpointer _data)
{
	GnomeIdleMonitorProviderUninitializeData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GnomeIdleMonitorProviderUninitializeData, _data_);
}

static void
gnome_idle_monitor_provider_real_uninitialize (FtProvider* base,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	GnomeIdleMonitorProvider * self;
	GnomeIdleMonitorProviderUninitializeData* _data_;
	GnomeIdleMonitorProvider* _tmp0_;
	self = (GnomeIdleMonitorProvider*) base;
	_data_ = g_slice_new0 (GnomeIdleMonitorProviderUninitializeData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, gnome_idle_monitor_provider_real_uninitialize_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	gnome_idle_monitor_provider_real_uninitialize_co (_data_);
}

static void
gnome_idle_monitor_provider_uninitialize_finish (FtProvider* base,
                                                 GAsyncResult* _res_,
                                                 GError** error)
{
	GnomeIdleMonitorProviderUninitializeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
gnome_idle_monitor_provider_real_uninitialize_co (GnomeIdleMonitorProviderUninitializeData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->self->priv->dbus_watcher_id != ((guint) 0)) {
		g_bus_unwatch_name (_data_->self->priv->dbus_watcher_id);
		_data_->self->priv->dbus_watcher_id = (guint) 0;
	}
	_g_object_unref0 (_data_->self->priv->cancellable);
	_data_->self->priv->cancellable = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
gnome_idle_monitor_provider_real_enable_data_free (gpointer _data)
{
	GnomeIdleMonitorProviderEnableData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GnomeIdleMonitorProviderEnableData, _data_);
}

static void
gnome_idle_monitor_provider_real_enable (FtProvider* base,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_)
{
	GnomeIdleMonitorProvider * self;
	GnomeIdleMonitorProviderEnableData* _data_;
	GnomeIdleMonitorProvider* _tmp0_;
	GCancellable* _tmp1_;
	self = (GnomeIdleMonitorProvider*) base;
	_data_ = g_slice_new0 (GnomeIdleMonitorProviderEnableData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, gnome_idle_monitor_provider_real_enable_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	gnome_idle_monitor_provider_real_enable_co (_data_);
}

static void
gnome_idle_monitor_provider_enable_finish (FtProvider* base,
                                           GAsyncResult* _res_,
                                           GError** error)
{
	GnomeIdleMonitorProviderEnableData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
gnome_idle_monitor_provider_enable_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	GnomeIdleMonitorProviderEnableData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	gnome_idle_monitor_provider_real_enable_co (_data_);
}

static void
_gnome_idle_monitor_provider_on_watch_fired_gnome_idle_monitor_watch_fired (GnomeIdleMonitor* _sender,
                                                                            guint32 id,
                                                                            gpointer self)
{
	gnome_idle_monitor_provider_on_watch_fired ((GnomeIdleMonitorProvider*) self, _sender, id);
}

static gboolean
gnome_idle_monitor_provider_real_enable_co (GnomeIdleMonitorProviderEnableData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->proxy;
	if (_data_->_tmp0_ != NULL) {
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = g_cancellable_new ();
	_g_object_unref0 (_data_->self->priv->cancellable);
	_data_->self->priv->cancellable = _data_->_tmp1_;
	_data_->_tmp3_ = _data_->self->priv->cancellable;
	_data_->_state_ = 1;
	g_async_initable_new_async (GNOME_TYPE_IDLE_MONITOR_PROXY, 0, _data_->_tmp3_, gnome_idle_monitor_provider_enable_ready, _data_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", "org.gnome.Mutter.IdleMonitor", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/gnome/Mutter/IdleMonitor/Core", "g-interface-name", "org.gnome.Mutter.IdleMonitor", NULL);
	return FALSE;
	_state_1:
	_data_->_tmp4_ = (GnomeIdleMonitor*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp2_ = (GnomeIdleMonitor*) _data_->_tmp4_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp5_ = _data_->_tmp2_;
	_data_->_tmp2_ = NULL;
	_g_object_unref0 (_data_->self->priv->proxy);
	_data_->self->priv->proxy = _data_->_tmp5_;
	_data_->_tmp6_ = _data_->self->priv->proxy;
	g_signal_connect_object (_data_->_tmp6_, "watch-fired", (GCallback) _gnome_idle_monitor_provider_on_watch_fired_gnome_idle_monitor_watch_fired, _data_->self, 0);
	_g_object_unref0 (_data_->_tmp2_);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
gnome_idle_monitor_provider_real_disable_data_free (gpointer _data)
{
	GnomeIdleMonitorProviderDisableData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GnomeIdleMonitorProviderDisableData, _data_);
}

static void
gnome_idle_monitor_provider_real_disable (FtProvider* base,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	GnomeIdleMonitorProvider * self;
	GnomeIdleMonitorProviderDisableData* _data_;
	GnomeIdleMonitorProvider* _tmp0_;
	self = (GnomeIdleMonitorProvider*) base;
	_data_ = g_slice_new0 (GnomeIdleMonitorProviderDisableData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, gnome_idle_monitor_provider_real_disable_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	gnome_idle_monitor_provider_real_disable_co (_data_);
}

static void
gnome_idle_monitor_provider_disable_finish (FtProvider* base,
                                            GAsyncResult* _res_,
                                            GError** error)
{
	GnomeIdleMonitorProviderDisableData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

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_)) {
		GnomeIdleMonitorProvider* self;
		self = _data1_->self;
		_data1_->ids = (g_free (_data1_->ids), NULL);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static void
_vala_array_add1 (guint32* * array,
                  gint* length,
                  gint* size,
                  guint32 value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (guint32, *array, *size);
	}
	(*array)[(*length)++] = value;
}

static void
__lambda5_ (Block1Data* _data1_,
            gint64* id,
            GnomeIdleMonitorProviderWatch* watch)
{
	GnomeIdleMonitorProvider* self;
	self = _data1_->self;
	g_return_if_fail (watch != NULL);
	_vala_array_add1 (&_data1_->ids, &_data1_->ids_length1, &_data1_->_ids_size_, watch->id);
}

static void
___lambda5__gh_func (gconstpointer key,
                     gconstpointer value,
                     gpointer self)
{
	__lambda5_ (self, (gint64*) key, (GnomeIdleMonitorProviderWatch*) value);
}

static gboolean
gnome_idle_monitor_provider_real_disable_co (GnomeIdleMonitorProviderDisableData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data1_ = g_slice_new0 (Block1Data);
	_data_->_data1_->_ref_count_ = 1;
	_data_->_data1_->self = g_object_ref (_data_->self);
	_data_->_data1_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->self->priv->cancellable;
	if (_data_->_tmp0_ != NULL) {
		_data_->_tmp1_ = _data_->self->priv->cancellable;
		g_cancellable_cancel (_data_->_tmp1_);
	}
	_data_->_tmp2_ = _data_->self->priv->proxy;
	if (_data_->_tmp2_ == NULL) {
		block1_data_unref (_data_->_data1_);
		_data_->_data1_ = NULL;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->self->priv->proxy;
	g_signal_parse_name ("watch-fired", GNOME_TYPE_IDLE_MONITOR, &_data_->_tmp4_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_data_->_tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _data_->_tmp4_, 0, NULL, (GCallback) _gnome_idle_monitor_provider_on_watch_fired_gnome_idle_monitor_watch_fired, _data_->self);
	_data_->_tmp5_ = g_new0 (guint32, 0);
	_data_->_data1_->ids = _data_->_tmp5_;
	_data_->_data1_->ids_length1 = 0;
	_data_->_data1_->_ids_size_ = _data_->_data1_->ids_length1;
	_data_->_tmp6_ = _data_->self->priv->watches;
	g_hash_table_foreach (_data_->_tmp6_, ___lambda5__gh_func, _data_->_data1_);
	{
		_data_->index = 0;
		{
			_data_->_tmp7_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp7_) {
					_data_->_tmp8_ = _data_->index;
					_data_->index = _data_->_tmp8_ + 1;
				}
				_data_->_tmp7_ = FALSE;
				_data_->_tmp9_ = _data_->_data1_->ids;
				_data_->_tmp9__length1 = _data_->_data1_->ids_length1;
				if (!(_data_->index < _data_->_tmp9__length1)) {
					break;
				}
				_data_->_tmp10_ = _data_->_data1_->ids;
				_data_->_tmp10__length1 = _data_->_data1_->ids_length1;
				_data_->_tmp11_ = _data_->_tmp10_[_data_->index];
				ft_idle_monitor_provider_remove_idle_watch ((FtIdleMonitorProvider*) _data_->self, _data_->_tmp11_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
					block1_data_unref (_data_->_data1_);
					_data_->_data1_ = NULL;
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
			}
		}
	}
	gnome_idle_monitor_provider_remove_active_watch_internal (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block1_data_unref (_data_->_data1_);
		_data_->_data1_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->self->priv->proxy);
	_data_->self->priv->proxy = NULL;
	block1_data_unref (_data_->_data1_);
	_data_->_data1_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gint64*
_int64_dup (gint64* self)
{
	gint64* dup;
	dup = g_new0 (gint64, 1);
	memcpy (dup, self, sizeof (gint64));
	return dup;
}

static gpointer
__int64_dup0 (gpointer self)
{
	return self ? _int64_dup (self) : NULL;
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static guint32
gnome_idle_monitor_provider_real_add_idle_watch (FtIdleMonitorProvider* base,
                                                 gint64 timeout,
                                                 gboolean ignore_inhibitors,
                                                 gint64 monotonic_time,
                                                 GError** error)
{
	GnomeIdleMonitorProvider * self;
	GnomeIdleMonitor* _tmp0_;
	gint64 relative_timeout = 0LL;
	gint64 absolute_timeout = 0LL;
	gint64 idle_time = 0LL;
	guint32 watch_id = 0U;
	GnomeIdleMonitor* _tmp3_;
	GnomeIdleMonitorProviderWatch* watch = NULL;
	GnomeIdleMonitorProviderWatch* _tmp5_;
	GnomeIdleMonitorProviderWatch* _tmp6_;
	GnomeIdleMonitorProviderWatch* _tmp7_;
	GnomeIdleMonitorProviderWatch* _tmp8_;
	GnomeIdleMonitorProviderWatch* _tmp9_;
	GnomeIdleMonitorProviderWatch* _watch = NULL;
	GnomeIdleMonitorProviderWatch* _tmp10_;
	GHashTable* _tmp11_;
	gint64 _tmp12_;
	gint64* _tmp13_;
	GnomeIdleMonitorProviderWatch* _tmp14_;
	gboolean _tmp15_ = FALSE;
	GnomeIdleMonitorProviderWatch* _tmp16_;
	GError* _inner_error0_ = NULL;
	guint32 result;
	self = (GnomeIdleMonitorProvider*) base;
	_tmp0_ = self->priv->proxy;
	_vala_return_val_if_fail (_tmp0_ != NULL, "this.proxy != null", 0U);
	relative_timeout = timeout;
	absolute_timeout = timeout;
	if (ft_timestamp_is_undefined (monotonic_time)) {
		monotonic_time = g_get_monotonic_time () - relative_timeout;
	} else {
		gint64 _tmp1_ = 0LL;
		_tmp1_ = gnome_idle_monitor_provider_get_idle_time (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			guint32 _tmp2_ = 0U;
			g_propagate_error (error, _inner_error0_);
			return _tmp2_;
		}
		idle_time = _tmp1_;
		absolute_timeout = ft_idle_monitor_provider_calculate_absolute_timeout (relative_timeout, idle_time, monotonic_time);
		if (llabs (absolute_timeout - relative_timeout) < GNOME_IDLE_MONITOR_PROVIDER_TIMEOUT_TOLERANCE) {
			absolute_timeout = relative_timeout;
		}
	}
	_tmp3_ = self->priv->proxy;
	watch_id = gnome_idle_monitor_add_idle_watch (_tmp3_, gnome_idle_monitor_provider_to_milliseconds (self, absolute_timeout), &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		guint32 _tmp4_ = 0U;
		g_propagate_error (error, _inner_error0_);
		return _tmp4_;
	}
	_tmp5_ = gnome_idle_monitor_provider_watch_new ();
	watch = _tmp5_;
	_tmp6_ = watch;
	_tmp6_->id = watch_id;
	_tmp7_ = watch;
	_tmp7_->relative_timeout = relative_timeout;
	_tmp8_ = watch;
	_tmp8_->absolute_timeout = absolute_timeout;
	_tmp9_ = watch;
	_tmp9_->reference_time = monotonic_time;
	_tmp10_ = watch;
	_watch = _tmp10_;
	_tmp11_ = self->priv->watches;
	_tmp12_ = (gint64) watch_id;
	_tmp13_ = __int64_dup0 (&_tmp12_);
	_tmp14_ = watch;
	watch = NULL;
	g_hash_table_insert (_tmp11_, _tmp13_, _tmp14_);
	_tmp16_ = _watch;
	if (!_tmp16_->has_active_watch) {
		GnomeIdleMonitorProviderWatch* _tmp17_;
		GnomeIdleMonitorProviderWatch* _tmp18_;
		_tmp17_ = _watch;
		_tmp18_ = _watch;
		_tmp15_ = _tmp17_->absolute_timeout != _tmp18_->relative_timeout;
	} else {
		_tmp15_ = FALSE;
	}
	if (_tmp15_) {
		{
			GnomeIdleMonitorProviderWatch* _tmp19_;
			ft_idle_monitor_provider_add_active_watch ((FtIdleMonitorProvider*) self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp19_ = _watch;
			_tmp19_->has_active_watch = TRUE;
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* _error_ = NULL;
			GError* _tmp20_;
			const gchar* _tmp21_;
			GError* _tmp22_;
			GError* _tmp23_;
			_error_ = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp20_ = _error_;
			_tmp21_ = _tmp20_->message;
			g_debug ("idle-monitor-provider.vala:280: Unable to add active watch: %s", _tmp21_);
			ft_idle_monitor_provider_remove_idle_watch ((FtIdleMonitorProvider*) self, watch_id, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_error_free0 (_error_);
				goto __finally0;
			}
			_tmp22_ = _error_;
			_tmp23_ = _g_error_copy0 (_tmp22_);
			_inner_error0_ = _tmp23_;
			_g_error_free0 (_error_);
			goto __finally0;
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			guint32 _tmp24_ = 0U;
			g_propagate_error (error, _inner_error0_);
			_gnome_idle_monitor_provider_watch_free0 (watch);
			return _tmp24_;
		}
	}
	result = watch_id;
	_gnome_idle_monitor_provider_watch_free0 (watch);
	return result;
}

static void
gnome_idle_monitor_provider_real_remove_idle_watch (FtIdleMonitorProvider* base,
                                                    guint32 id,
                                                    GError** error)
{
	GnomeIdleMonitorProvider * self;
	GnomeIdleMonitor* _tmp0_;
	GnomeIdleMonitorProviderWatch* watch = NULL;
	GHashTable* _tmp1_;
	gint64 _tmp2_;
	gconstpointer _tmp3_;
	GnomeIdleMonitorProviderWatch* _tmp4_;
	GnomeIdleMonitorProviderWatch* _tmp5_;
	GError* _inner_error0_ = NULL;
	self = (GnomeIdleMonitorProvider*) base;
	_tmp0_ = self->priv->proxy;
	_vala_return_if_fail (_tmp0_ != NULL, "this.proxy != null");
	_tmp1_ = self->priv->watches;
	_tmp2_ = (gint64) id;
	_tmp3_ = g_hash_table_lookup (_tmp1_, &_tmp2_);
	watch = (GnomeIdleMonitorProviderWatch*) _tmp3_;
	_tmp4_ = watch;
	if (_tmp4_ == NULL) {
		return;
	}
	_tmp5_ = watch;
	_tmp5_->invalid = TRUE;
	{
		GnomeIdleMonitor* _tmp6_;
		GnomeIdleMonitorProviderWatch* _tmp7_;
		GnomeIdleMonitorProviderWatch* _tmp8_;
		_tmp6_ = self->priv->proxy;
		_tmp7_ = watch;
		gnome_idle_monitor_remove_watch (_tmp6_, _tmp7_->id, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp8_ = watch;
		if (!_tmp8_->has_active_watch) {
			GHashTable* _tmp9_;
			gint64 _tmp10_;
			_tmp9_ = self->priv->watches;
			_tmp10_ = (gint64) id;
			g_hash_table_remove (_tmp9_, &_tmp10_);
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp11_;
		const gchar* _tmp12_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp11_ = _error_;
		_tmp12_ = _tmp11_->message;
		g_warning ("idle-monitor-provider.vala:322: Error while removing idle watch: %s", _tmp12_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static guint32
gnome_idle_monitor_provider_real_reset_idle_watch (FtIdleMonitorProvider* base,
                                                   guint32 id,
                                                   gint64 monotonic_time,
                                                   GError** error)
{
	GnomeIdleMonitorProvider * self;
	GnomeIdleMonitor* _tmp0_;
	GnomeIdleMonitorProviderWatch* watch = NULL;
	GHashTable* _tmp1_;
	gint64 _tmp2_;
	gconstpointer _tmp3_;
	gboolean _tmp4_ = FALSE;
	GnomeIdleMonitorProviderWatch* _tmp5_;
	guint32 new_id = 0U;
	GnomeIdleMonitorProviderWatch* _tmp8_;
	GError* _inner_error0_ = NULL;
	guint32 result;
	self = (GnomeIdleMonitorProvider*) base;
	_tmp0_ = self->priv->proxy;
	_vala_return_val_if_fail (_tmp0_ != NULL, "this.proxy != null", 0U);
	_tmp1_ = self->priv->watches;
	_tmp2_ = (gint64) id;
	_tmp3_ = g_hash_table_lookup (_tmp1_, &_tmp2_);
	watch = (GnomeIdleMonitorProviderWatch*) _tmp3_;
	_tmp5_ = watch;
	if (_tmp5_ == NULL) {
		_tmp4_ = TRUE;
	} else {
		GnomeIdleMonitorProviderWatch* _tmp6_;
		GnomeIdleMonitorProviderWatch* _tmp7_;
		_tmp6_ = watch;
		_tmp7_ = watch;
		_tmp4_ = _tmp6_->absolute_timeout == _tmp7_->relative_timeout;
	}
	if (_tmp4_) {
		result = id;
		return result;
	}
	_tmp8_ = watch;
	new_id = ft_idle_monitor_provider_add_idle_watch ((FtIdleMonitorProvider*) self, _tmp8_->relative_timeout, FALSE, monotonic_time, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		guint32 _tmp9_ = 0U;
		g_propagate_error (error, _inner_error0_);
		return _tmp9_;
	}
	{
		GnomeIdleMonitor* _tmp10_;
		GnomeIdleMonitorProviderWatch* _tmp11_;
		_tmp10_ = self->priv->proxy;
		_tmp11_ = watch;
		gnome_idle_monitor_remove_watch (_tmp10_, _tmp11_->id, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp12_;
		GError* _tmp13_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		ft_idle_monitor_provider_remove_idle_watch ((FtIdleMonitorProvider*) self, new_id, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_error_free0 (_error_);
			goto __finally0;
		}
		_tmp12_ = _error_;
		_tmp13_ = _g_error_copy0 (_tmp12_);
		_inner_error0_ = _tmp13_;
		_g_error_free0 (_error_);
		goto __finally0;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		guint32 _tmp14_ = 0U;
		g_propagate_error (error, _inner_error0_);
		return _tmp14_;
	}
	result = new_id;
	return result;
}

static void
gnome_idle_monitor_provider_real_add_active_watch (FtIdleMonitorProvider* base,
                                                   GError** error)
{
	GnomeIdleMonitorProvider * self;
	GnomeIdleMonitor* _tmp0_;
	guint _tmp3_;
	GError* _inner_error0_ = NULL;
	self = (GnomeIdleMonitorProvider*) base;
	_tmp0_ = self->priv->proxy;
	_vala_return_if_fail (_tmp0_ != NULL, "this.proxy != null");
	if (self->priv->active_watch_id == ((guint32) 0)) {
		guint32 _tmp1_ = 0U;
		GnomeIdleMonitor* _tmp2_;
		_tmp2_ = self->priv->proxy;
		_tmp1_ = gnome_idle_monitor_add_user_active_watch (_tmp2_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
		self->priv->active_watch_id = _tmp1_;
	}
	_tmp3_ = self->priv->active_watch_use_count;
	self->priv->active_watch_use_count = _tmp3_ + 1;
}

static void
gnome_idle_monitor_provider_real_remove_active_watch (FtIdleMonitorProvider* base,
                                                      GError** error)
{
	GnomeIdleMonitorProvider * self;
	GError* _inner_error0_ = NULL;
	self = (GnomeIdleMonitorProvider*) base;
	_vala_return_if_fail (self->priv->active_watch_use_count > ((guint) 0), "this.active_watch_use_count > 0");
	if (self->priv->active_watch_use_count > ((guint) 1)) {
		guint _tmp0_;
		_tmp0_ = self->priv->active_watch_use_count;
		self->priv->active_watch_use_count = _tmp0_ - 1;
	} else {
		if (self->priv->active_watch_use_count == ((guint) 1)) {
			gnome_idle_monitor_provider_remove_active_watch_internal (self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				return;
			}
		}
	}
}

static void
gnome_idle_monitor_provider_real_dispose (GObject* base)
{
	GnomeIdleMonitorProvider * self;
	self = (GnomeIdleMonitorProvider*) base;
	_g_hash_table_unref0 (self->priv->watches);
	self->priv->watches = NULL;
	G_OBJECT_CLASS (gnome_idle_monitor_provider_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_PROVIDER, FtProvider));
}

GnomeIdleMonitorProvider*
gnome_idle_monitor_provider_construct (GType object_type)
{
	GnomeIdleMonitorProvider * self = NULL;
	self = (GnomeIdleMonitorProvider*) ft_provider_construct (object_type);
	return self;
}

GnomeIdleMonitorProvider*
gnome_idle_monitor_provider_new (void)
{
	return gnome_idle_monitor_provider_construct (GNOME_TYPE_IDLE_MONITOR_PROVIDER);
}

FtPriority
gnome_idle_monitor_provider_get_priority (GnomeIdleMonitorProvider* self)
{
	FtPriority result;
	g_return_val_if_fail (self != NULL, 0);
	result = FT_PRIORITY_DEFAULT;
	return result;
}

static gboolean
gnome_idle_monitor_provider_real_get_can_ignore_inhibitors (FtIdleMonitorProvider* base)
{
	gboolean result;
	GnomeIdleMonitorProvider* self;
	self = (GnomeIdleMonitorProvider*) base;
	result = FALSE;
	return result;
}

static GnomeIdleMonitorProviderWatch*
gnome_idle_monitor_provider_watch_new (void)
{
	GnomeIdleMonitorProviderWatch* self;
	self = g_slice_new0 (GnomeIdleMonitorProviderWatch);
	gnome_idle_monitor_provider_watch_instance_init (self);
	return self;
}

static void
gnome_idle_monitor_provider_watch_instance_init (GnomeIdleMonitorProviderWatch * self)
{
	self->id = (guint32) 0;
	self->absolute_timeout = (gint64) 0;
	self->relative_timeout = (gint64) 0;
	self->reference_time = FT_TIMESTAMP_UNDEFINED;
	self->has_active_watch = FALSE;
	self->invalid = FALSE;
}

static void
gnome_idle_monitor_provider_watch_free (GnomeIdleMonitorProviderWatch * self)
{
	g_slice_free (GnomeIdleMonitorProviderWatch, self);
}

static void
_g_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_free (var), NULL));
}

static void
_gnome_idle_monitor_provider_watch_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (gnome_idle_monitor_provider_watch_free (var), NULL));
}

static GObject *
gnome_idle_monitor_provider_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GnomeIdleMonitorProvider * self;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	parent_class = G_OBJECT_CLASS (gnome_idle_monitor_provider_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_TYPE_IDLE_MONITOR_PROVIDER, GnomeIdleMonitorProvider);
	_tmp0_ = g_int64_hash;
	_tmp1_ = g_int64_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _gnome_idle_monitor_provider_watch_free0_);
	_g_hash_table_unref0 (self->priv->watches);
	self->priv->watches = _tmp2_;
	return obj;
}

static void
gnome_idle_monitor_provider_class_init (GnomeIdleMonitorProviderClass * klass,
                                        gpointer klass_data)
{
	gnome_idle_monitor_provider_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GnomeIdleMonitorProvider_private_offset);
	((FtProviderClass *) klass)->initialize = (void (*) (FtProvider*, GCancellable*, GAsyncReadyCallback, gpointer)) gnome_idle_monitor_provider_real_initialize;
	((FtProviderClass *) klass)->initialize_finish = (void (*) (FtProvider*, GAsyncResult*, GError**)) gnome_idle_monitor_provider_initialize_finish;
	((FtProviderClass *) klass)->uninitialize = (void (*) (FtProvider*, GAsyncReadyCallback, gpointer)) gnome_idle_monitor_provider_real_uninitialize;
	((FtProviderClass *) klass)->uninitialize_finish = (void (*) (FtProvider*, GAsyncResult*, GError**)) gnome_idle_monitor_provider_uninitialize_finish;
	((FtProviderClass *) klass)->enable = (void (*) (FtProvider*, GCancellable*, GAsyncReadyCallback, gpointer)) gnome_idle_monitor_provider_real_enable;
	((FtProviderClass *) klass)->enable_finish = (void (*) (FtProvider*, GAsyncResult*, GError**)) gnome_idle_monitor_provider_enable_finish;
	((FtProviderClass *) klass)->disable = (void (*) (FtProvider*, GAsyncReadyCallback, gpointer)) gnome_idle_monitor_provider_real_disable;
	((FtProviderClass *) klass)->disable_finish = (void (*) (FtProvider*, GAsyncResult*, GError**)) gnome_idle_monitor_provider_disable_finish;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) gnome_idle_monitor_provider_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_gnome_idle_monitor_provider_get_property;
	G_OBJECT_CLASS (klass)->constructor = gnome_idle_monitor_provider_constructor;
	G_OBJECT_CLASS (klass)->finalize = gnome_idle_monitor_provider_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GNOME_IDLE_MONITOR_PROVIDER_PRIORITY_PROPERTY, gnome_idle_monitor_provider_properties[GNOME_IDLE_MONITOR_PROVIDER_PRIORITY_PROPERTY] = g_param_spec_enum ("priority", "priority", "priority", FT_TYPE_PRIORITY, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GNOME_IDLE_MONITOR_PROVIDER_CAN_IGNORE_INHIBITORS_PROPERTY, gnome_idle_monitor_provider_properties[GNOME_IDLE_MONITOR_PROVIDER_CAN_IGNORE_INHIBITORS_PROPERTY] = g_param_spec_boolean ("can-ignore-inhibitors", "can-ignore-inhibitors", "can-ignore-inhibitors", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
gnome_idle_monitor_provider_ft_idle_monitor_provider_interface_init (FtIdleMonitorProviderIface * iface,
                                                                     gpointer iface_data)
{
	gnome_idle_monitor_provider_ft_idle_monitor_provider_parent_iface = g_type_interface_peek_parent (iface);
	iface->add_idle_watch = (guint32 (*) (FtIdleMonitorProvider*, gint64, gboolean, gint64, GError**)) gnome_idle_monitor_provider_real_add_idle_watch;
	iface->remove_idle_watch = (void (*) (FtIdleMonitorProvider*, guint32, GError**)) gnome_idle_monitor_provider_real_remove_idle_watch;
	iface->reset_idle_watch = (guint32 (*) (FtIdleMonitorProvider*, guint32, gint64, GError**)) gnome_idle_monitor_provider_real_reset_idle_watch;
	iface->add_active_watch = (void (*) (FtIdleMonitorProvider*, GError**)) gnome_idle_monitor_provider_real_add_active_watch;
	iface->remove_active_watch = (void (*) (FtIdleMonitorProvider*, GError**)) gnome_idle_monitor_provider_real_remove_active_watch;
	iface->get_can_ignore_inhibitors = gnome_idle_monitor_provider_real_get_can_ignore_inhibitors;
}

static void
gnome_idle_monitor_provider_instance_init (GnomeIdleMonitorProvider * self,
                                           gpointer klass)
{
	self->priv = gnome_idle_monitor_provider_get_instance_private (self);
	self->priv->proxy = NULL;
	self->priv->cancellable = NULL;
	self->priv->dbus_watcher_id = (guint) 0;
	self->priv->watches = NULL;
	self->priv->active_watch_id = (guint32) 0;
	self->priv->active_watch_use_count = (guint) 0;
	self->priv->idle_time_freeze_count = 0;
	self->priv->idle_time = (gint64) -1;
}

static void
gnome_idle_monitor_provider_finalize (GObject * obj)
{
	GnomeIdleMonitorProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_TYPE_IDLE_MONITOR_PROVIDER, GnomeIdleMonitorProvider);
	_g_object_unref0 (self->priv->proxy);
	_g_object_unref0 (self->priv->cancellable);
	_g_hash_table_unref0 (self->priv->watches);
	G_OBJECT_CLASS (gnome_idle_monitor_provider_parent_class)->finalize (obj);
}

GType
gnome_idle_monitor_provider_get_type (void)
{
	return gnome_idle_monitor_provider_type_id;
}

GType
gnome_idle_monitor_provider_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (GnomeIdleMonitorProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gnome_idle_monitor_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GnomeIdleMonitorProvider), 0, (GInstanceInitFunc) gnome_idle_monitor_provider_instance_init, NULL };
	static const GInterfaceInfo ft_idle_monitor_provider_info = { (GInterfaceInitFunc) gnome_idle_monitor_provider_ft_idle_monitor_provider_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	gnome_idle_monitor_provider_type_id = g_type_module_register_type (module, FT_TYPE_PROVIDER, "GnomeIdleMonitorProvider", &g_define_type_info, 0);
	g_type_module_add_interface (module, gnome_idle_monitor_provider_type_id, FT_TYPE_IDLE_MONITOR_PROVIDER, &ft_idle_monitor_provider_info);
	GnomeIdleMonitorProvider_private_offset = sizeof (GnomeIdleMonitorProviderPrivate);
	return gnome_idle_monitor_provider_type_id;
}

static void
_vala_gnome_idle_monitor_provider_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec)
{
	GnomeIdleMonitorProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GNOME_TYPE_IDLE_MONITOR_PROVIDER, GnomeIdleMonitorProvider);
	switch (property_id) {
		case GNOME_IDLE_MONITOR_PROVIDER_PRIORITY_PROPERTY:
		g_value_set_enum (value, gnome_idle_monitor_provider_get_priority (self));
		break;
		case GNOME_IDLE_MONITOR_PROVIDER_CAN_IGNORE_INHIBITORS_PROPERTY:
		g_value_set_boolean (value, ft_idle_monitor_provider_get_can_ignore_inhibitors ((FtIdleMonitorProvider*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

