/* download-manager.c generated by valac 0.56.19, the Vala compiler
 * generated from download-manager.vala, do not modify */

#include "protonplus_core.h"
#include <glib.h>
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>

#define PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_SETTINGS_KEY "download-speed-limit-bps"
#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

enum  {
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_0_PROPERTY,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_ACTIVE_DOWNLOADS_PROPERTY,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_BPS_PROPERTY,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_THROTTLE_GENERATION_PROPERTY,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_NUM_PROPERTIES
};
static GParamSpec* proton_plus_utils_download_manager_properties[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block60Data Block60Data;
#define _g_source_unref0(var) ((var == NULL) ? NULL : (var = (g_source_unref (var), NULL)))
typedef struct _ProtonPlusUtilsDownloadManagerWaitForThrottleDeadlineData ProtonPlusUtilsDownloadManagerWaitForThrottleDeadlineData;
typedef struct _ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData;
enum  {
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_DOWNLOAD_ADDED_SIGNAL,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_DOWNLOAD_REMOVED_SIGNAL,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_DOWNLOAD_FINISHED_SIGNAL,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_PROGRESS_UPDATED_SIGNAL,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_TOOL_UPDATED_SIGNAL,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_TOOL_REMOVED_SIGNAL,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_CHANGED_SIGNAL,
	PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_NUM_SIGNALS
};
static guint proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_NUM_SIGNALS] = {0};

struct _ProtonPlusUtilsDownloadManagerPrivate {
	gulong speed_limit_settings_changed_handler;
	gint64 global_throttle_next_allowed_time_us;
	guint64 _throttle_generation;
	gint64 _speed_limit_bps;
	GeeLinkedList* _active_downloads;
};

struct _Block60Data {
	int _ref_count_;
	ProtonPlusUtilsDownloadManager* self;
	gpointer _async_data_;
};

struct _ProtonPlusUtilsDownloadManagerWaitForThrottleDeadlineData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ProtonPlusUtilsDownloadManager* self;
	gint64 deadline_us;
	guint64 expected_generation;
	GCancellable* cancellable;
	Block60Data* _data60_;
	gboolean _tmp0_;
	gint64 now_us;
	guint remaining_ms;
	GSource* source;
	GSource* _tmp1_;
	GSource* _tmp2_;
	GSource* _tmp3_;
	GMainContext* _tmp4_;
};

struct _ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ProtonPlusUtilsDownloadManager* self;
	gint64 bytes_written;
	gint64 transfer_started_us;
	guint64 expected_generation;
	GCancellable* cancellable;
	gint64 speed_limit;
	gint64 _tmp0_;
	gint64 _tmp1_;
	gint64 now_us;
	gint64 schedule_base_us;
	gboolean _tmp2_;
	gint64 chunk_budget_us;
	gint64 delay_us;
};

static gint ProtonPlusUtilsDownloadManager_private_offset;
static gpointer proton_plus_utils_download_manager_parent_class = NULL;
static ProtonPlusUtilsDownloadManager* proton_plus_utils_download_manager__instance;
static ProtonPlusUtilsDownloadManager* proton_plus_utils_download_manager__instance = NULL;

static ProtonPlusUtilsDownloadManager* proton_plus_utils_download_manager_new (void);
static ProtonPlusUtilsDownloadManager* proton_plus_utils_download_manager_construct (GType object_type);
static void proton_plus_utils_download_manager_set_active_downloads (ProtonPlusUtilsDownloadManager* self,
                                                              GeeLinkedList* value);
static void ___lambda21_ (ProtonPlusUtilsDownloadManager* self);
static void ____lambda21__g_settings_changed (GSettings* _sender,
                                       const gchar* key,
                                       gpointer self);
static void proton_plus_utils_download_manager_invalidate_throttle_schedule (ProtonPlusUtilsDownloadManager* self);
static void proton_plus_utils_download_manager_wait_for_throttle_deadline_data_free (gpointer _data);
static void proton_plus_utils_download_manager_wait_for_throttle_deadline (ProtonPlusUtilsDownloadManager* self,
                                                                    gint64 deadline_us,
                                                                    guint64 expected_generation,
                                                                    GCancellable* cancellable,
                                                                    GAsyncReadyCallback _callback_,
                                                                    gpointer _user_data_);
static void proton_plus_utils_download_manager_wait_for_throttle_deadline_finish (ProtonPlusUtilsDownloadManager* self,
                                                                           GAsyncResult* _res_);
static gboolean proton_plus_utils_download_manager_wait_for_throttle_deadline_co (ProtonPlusUtilsDownloadManagerWaitForThrottleDeadlineData* _data_);
static Block60Data* block60_data_ref (Block60Data* _data60_);
static void block60_data_unref (void * _userdata_);
static gboolean ___lambda22_ (Block60Data* _data60_);
static gboolean ____lambda22__gsource_func (gpointer self);
static void proton_plus_utils_download_manager_throttle_global_download_bytes_data_free (gpointer _data);
static gboolean proton_plus_utils_download_manager_throttle_global_download_bytes_co (ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData* _data_);
static void proton_plus_utils_download_manager_throttle_global_download_bytes_ready (GObject* source_object,
                                                                              GAsyncResult* _res_,
                                                                              gpointer _user_data_);
static void g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN (GClosure * closure,
                                                   GValue * return_value,
                                                   guint n_param_values,
                                                   const GValue * param_values,
                                                   gpointer invocation_hint,
                                                   gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__INT64 (GClosure * closure,
                                          GValue * return_value,
                                          guint n_param_values,
                                          const GValue * param_values,
                                          gpointer invocation_hint,
                                          gpointer marshal_data);
static void proton_plus_utils_download_manager_finalize (GObject * obj);
static GType proton_plus_utils_download_manager_get_type_once (void);
static void _vala_proton_plus_utils_download_manager_get_property (GObject * object,
                                                            guint property_id,
                                                            GValue * value,
                                                            GParamSpec * pspec);
static void _vala_proton_plus_utils_download_manager_set_property (GObject * object,
                                                            guint property_id,
                                                            const GValue * value,
                                                            GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
proton_plus_utils_download_manager_get_instance_private (ProtonPlusUtilsDownloadManager* self)
{
	return G_STRUCT_MEMBER_P (self, ProtonPlusUtilsDownloadManager_private_offset);
}

gboolean
proton_plus_utils_download_manager_is_downloading (ProtonPlusUtilsDownloadManager* self,
                                                   ProtonPlusServicesInstallJob* job)
{
	ProtonPlusServicesInstallJob* _tmp0_;
	ProtonPlusServicesInstallJob* _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (job != NULL, FALSE);
	_tmp0_ = proton_plus_utils_download_manager_get_active_download (self, job);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ != NULL;
	_g_object_unref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

ProtonPlusServicesInstallJob*
proton_plus_utils_download_manager_get_active_download (ProtonPlusUtilsDownloadManager* self,
                                                        ProtonPlusServicesInstallJob* job)
{
	ProtonPlusServicesInstallJob* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (job != NULL, NULL);
	{
		GeeLinkedList* _active_download_list = NULL;
		GeeLinkedList* _tmp0_;
		gint _active_download_size = 0;
		GeeLinkedList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _active_download_index = 0;
		_tmp0_ = self->priv->_active_downloads;
		_active_download_list = _tmp0_;
		_tmp1_ = _active_download_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_active_download_size = _tmp3_;
		_active_download_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			ProtonPlusServicesInstallJob* active_download = NULL;
			GeeLinkedList* _tmp6_;
			gpointer _tmp7_;
			ProtonPlusServicesInstallJob* _tmp8_;
			gchar* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			gchar* _tmp12_;
			gchar* _tmp13_;
			gchar* _tmp14_;
			gboolean _tmp15_;
			_active_download_index = _active_download_index + 1;
			_tmp4_ = _active_download_index;
			_tmp5_ = _active_download_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _active_download_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _active_download_index);
			active_download = (ProtonPlusServicesInstallJob*) _tmp7_;
			_tmp8_ = active_download;
			_tmp9_ = proton_plus_services_install_job_get_operation_id (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp11_ = _tmp10_;
			_tmp12_ = proton_plus_services_install_job_get_operation_id (job);
			_tmp13_ = _tmp12_;
			_tmp14_ = _tmp13_;
			_tmp15_ = g_strcmp0 (_tmp11_, _tmp14_) == 0;
			_g_free0 (_tmp14_);
			_g_free0 (_tmp11_);
			if (_tmp15_) {
				result = active_download;
				return result;
			}
			_g_object_unref0 (active_download);
		}
	}
	result = NULL;
	return result;
}

gboolean
proton_plus_utils_download_manager_has_active_installation_at (ProtonPlusUtilsDownloadManager* self,
                                                               const gchar* install_location)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (install_location != NULL, FALSE);
	{
		GeeLinkedList* _active_download_list = NULL;
		GeeLinkedList* _tmp0_;
		gint _active_download_size = 0;
		GeeLinkedList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _active_download_index = 0;
		_tmp0_ = self->priv->_active_downloads;
		_active_download_list = _tmp0_;
		_tmp1_ = _active_download_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_active_download_size = _tmp3_;
		_active_download_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			ProtonPlusServicesInstallJob* active_download = NULL;
			GeeLinkedList* _tmp6_;
			gpointer _tmp7_;
			ProtonPlusServicesInstallJob* _tmp8_;
			const gchar* _tmp9_;
			const gchar* _tmp10_;
			_active_download_index = _active_download_index + 1;
			_tmp4_ = _active_download_index;
			_tmp5_ = _active_download_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _active_download_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _active_download_index);
			active_download = (ProtonPlusServicesInstallJob*) _tmp7_;
			_tmp8_ = active_download;
			_tmp9_ = proton_plus_services_install_job_get_install_location (_tmp8_);
			_tmp10_ = _tmp9_;
			if (g_strcmp0 (_tmp10_, install_location) == 0) {
				result = TRUE;
				_g_object_unref0 (active_download);
				return result;
			}
			_g_object_unref0 (active_download);
		}
	}
	result = FALSE;
	return result;
}

static ProtonPlusUtilsDownloadManager*
proton_plus_utils_download_manager_construct (GType object_type)
{
	ProtonPlusUtilsDownloadManager * self = NULL;
	GeeLinkedList* _tmp0_;
	GeeLinkedList* _tmp1_;
	self = (ProtonPlusUtilsDownloadManager*) g_object_new (object_type, NULL);
	_tmp0_ = gee_linked_list_new (PROTON_PLUS_SERVICES_TYPE_INSTALL_JOB, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_tmp1_ = _tmp0_;
	proton_plus_utils_download_manager_set_active_downloads (self, _tmp1_);
	_g_object_unref0 (_tmp1_);
	proton_plus_utils_download_manager_sync_speed_limit_from_settings (self);
	return self;
}

static ProtonPlusUtilsDownloadManager*
proton_plus_utils_download_manager_new (void)
{
	return proton_plus_utils_download_manager_construct (PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER);
}

static void
___lambda21_ (ProtonPlusUtilsDownloadManager* self)
{
	gint64 next_limit = 0LL;
	GSettings* _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp2_;
	_tmp0_ = proton_plus_globals_SETTINGS;
	next_limit = g_settings_get_int64 (_tmp0_, PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_SETTINGS_KEY);
	if (next_limit < ((gint64) 0)) {
		next_limit = (gint64) 0;
	}
	_tmp1_ = proton_plus_utils_download_manager_get_speed_limit_bps (self);
	_tmp2_ = _tmp1_;
	if (_tmp2_ != next_limit) {
		proton_plus_utils_download_manager_set_speed_limit_bps (self, next_limit);
	}
}

static void
____lambda21__g_settings_changed (GSettings* _sender,
                                  const gchar* key,
                                  gpointer self)
{
	___lambda21_ ((ProtonPlusUtilsDownloadManager*) self);
}

void
proton_plus_utils_download_manager_sync_speed_limit_from_settings (ProtonPlusUtilsDownloadManager* self)
{
	GSettings* _tmp0_;
	gint64 configured_limit = 0LL;
	GSettings* _tmp4_;
	gint64 _tmp6_;
	gint64 _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_globals_SETTINGS;
	if (_tmp0_ == NULL) {
		return;
	}
	if (self->priv->speed_limit_settings_changed_handler == ((gulong) 0)) {
		GSettings* _tmp1_;
		gchar* _tmp2_;
		gulong _tmp3_;
		_tmp1_ = proton_plus_globals_SETTINGS;
		_tmp2_ = g_strconcat ("changed::", PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_SETTINGS_KEY, NULL);
		_tmp3_ = g_signal_connect_object (_tmp1_, _tmp2_, (GCallback) ____lambda21__g_settings_changed, self, 0);
		self->priv->speed_limit_settings_changed_handler = _tmp3_;
		_g_free0 (_tmp2_);
	}
	_tmp4_ = proton_plus_globals_SETTINGS;
	configured_limit = g_settings_get_int64 (_tmp4_, PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_SETTINGS_KEY);
	if (configured_limit < ((gint64) 0)) {
		GSettings* _tmp5_;
		configured_limit = (gint64) 0;
		_tmp5_ = proton_plus_globals_SETTINGS;
		g_settings_set_int64 (_tmp5_, PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_SETTINGS_KEY, configured_limit);
	}
	_tmp6_ = proton_plus_utils_download_manager_get_speed_limit_bps (self);
	_tmp7_ = _tmp6_;
	if (_tmp7_ != configured_limit) {
		proton_plus_utils_download_manager_set_speed_limit_bps (self, configured_limit);
	}
}

static void
proton_plus_utils_download_manager_invalidate_throttle_schedule (ProtonPlusUtilsDownloadManager* self)
{
	guint64 _tmp0_;
	g_return_if_fail (self != NULL);
	self->priv->global_throttle_next_allowed_time_us = (gint64) 0;
	_tmp0_ = self->priv->_throttle_generation;
	self->priv->_throttle_generation = _tmp0_ + 1;
}

void
proton_plus_utils_download_manager_add_download (ProtonPlusUtilsDownloadManager* self,
                                                 ProtonPlusServicesInstallJob* job)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (job != NULL);
	if (!proton_plus_utils_download_manager_is_downloading (self, job)) {
		GeeLinkedList* _tmp0_;
		_tmp0_ = self->priv->_active_downloads;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, job);
		g_signal_emit (self, proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_DOWNLOAD_ADDED_SIGNAL], 0, job);
	}
}

void
proton_plus_utils_download_manager_remove_download (ProtonPlusUtilsDownloadManager* self,
                                                    ProtonPlusServicesInstallJob* job)
{
	GeeLinkedList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (job != NULL);
	_tmp0_ = self->priv->_active_downloads;
	if (gee_abstract_collection_contains ((GeeAbstractCollection*) _tmp0_, job)) {
		GeeLinkedList* _tmp1_;
		_tmp1_ = self->priv->_active_downloads;
		gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp1_, job);
		g_signal_emit (self, proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_DOWNLOAD_REMOVED_SIGNAL], 0, job);
	}
}

void
proton_plus_utils_download_manager_add_to_history (ProtonPlusUtilsDownloadManager* self,
                                                   ProtonPlusServicesInstallJob* job,
                                                   gboolean success)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (job != NULL);
	g_signal_emit (self, proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_DOWNLOAD_FINISHED_SIGNAL], 0, job, success);
}

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

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

static void
proton_plus_utils_download_manager_wait_for_throttle_deadline (ProtonPlusUtilsDownloadManager* self,
                                                               gint64 deadline_us,
                                                               guint64 expected_generation,
                                                               GCancellable* cancellable,
                                                               GAsyncReadyCallback _callback_,
                                                               gpointer _user_data_)
{
	ProtonPlusUtilsDownloadManagerWaitForThrottleDeadlineData* _data_;
	ProtonPlusUtilsDownloadManager* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ProtonPlusUtilsDownloadManagerWaitForThrottleDeadlineData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_utils_download_manager_wait_for_throttle_deadline_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->deadline_us = deadline_us;
	_data_->expected_generation = expected_generation;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	proton_plus_utils_download_manager_wait_for_throttle_deadline_co (_data_);
}

static void
proton_plus_utils_download_manager_wait_for_throttle_deadline_finish (ProtonPlusUtilsDownloadManager* self,
                                                                      GAsyncResult* _res_)
{
	ProtonPlusUtilsDownloadManagerWaitForThrottleDeadlineData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static Block60Data*
block60_data_ref (Block60Data* _data60_)
{
	g_atomic_int_inc (&_data60_->_ref_count_);
	return _data60_;
}

static void
block60_data_unref (void * _userdata_)
{
	Block60Data* _data60_;
	_data60_ = (Block60Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data60_->_ref_count_)) {
		ProtonPlusUtilsDownloadManager* self;
		self = _data60_->self;
		_g_object_unref0 (self);
		g_slice_free (Block60Data, _data60_);
	}
}

static gboolean
___lambda22_ (Block60Data* _data60_)
{
	ProtonPlusUtilsDownloadManager* self;
	gboolean result;
	self = _data60_->self;
	proton_plus_utils_download_manager_wait_for_throttle_deadline_co (_data60_->_async_data_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
____lambda22__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda22_ (self);
	return result;
}

static gboolean
proton_plus_utils_download_manager_wait_for_throttle_deadline_co (ProtonPlusUtilsDownloadManagerWaitForThrottleDeadlineData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data60_ = g_slice_new0 (Block60Data);
	_data_->_data60_->_ref_count_ = 1;
	_data_->_data60_->self = g_object_ref (_data_->self);
	_data_->_data60_->_async_data_ = _data_;
	while (TRUE) {
		if (_data_->cancellable != NULL) {
			_data_->_tmp0_ = g_cancellable_is_cancelled (_data_->cancellable);
		} else {
			_data_->_tmp0_ = FALSE;
		}
		if (_data_->_tmp0_) {
			block60_data_unref (_data_->_data60_);
			_data_->_data60_ = 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;
		}
		if (_data_->self->priv->_throttle_generation != _data_->expected_generation) {
			block60_data_unref (_data_->_data60_);
			_data_->_data60_ = 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_->now_us = g_get_monotonic_time ();
		if (_data_->now_us >= _data_->deadline_us) {
			block60_data_unref (_data_->_data60_);
			_data_->_data60_ = 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_->remaining_ms = (guint) (((_data_->deadline_us - _data_->now_us) + 999) / 1000);
		if (_data_->remaining_ms > ((guint) 25)) {
			_data_->remaining_ms = (guint) 25;
		}
		_data_->_tmp1_ = g_timeout_source_new (_data_->remaining_ms);
		_data_->source = _data_->_tmp1_;
		_data_->_tmp2_ = _data_->source;
		g_source_set_callback (_data_->_tmp2_, ____lambda22__gsource_func, block60_data_ref (_data_->_data60_), block60_data_unref);
		_data_->_tmp3_ = _data_->source;
		_data_->_tmp4_ = g_main_context_default ();
		g_source_attach (_data_->_tmp3_, _data_->_tmp4_);
		_data_->_state_ = 1;
		return FALSE;
		_state_1:
		;
		_g_source_unref0 (_data_->source);
	}
	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
proton_plus_utils_download_manager_throttle_global_download_bytes_data_free (gpointer _data)
{
	ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData, _data_);
}

void
proton_plus_utils_download_manager_throttle_global_download_bytes (ProtonPlusUtilsDownloadManager* self,
                                                                   gint64 bytes_written,
                                                                   gint64 transfer_started_us,
                                                                   guint64 expected_generation,
                                                                   GCancellable* cancellable,
                                                                   GAsyncReadyCallback _callback_,
                                                                   gpointer _user_data_)
{
	ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData* _data_;
	ProtonPlusUtilsDownloadManager* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_utils_download_manager_throttle_global_download_bytes_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->bytes_written = bytes_written;
	_data_->transfer_started_us = transfer_started_us;
	_data_->expected_generation = expected_generation;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	proton_plus_utils_download_manager_throttle_global_download_bytes_co (_data_);
}

void
proton_plus_utils_download_manager_throttle_global_download_bytes_finish (ProtonPlusUtilsDownloadManager* self,
                                                                          GAsyncResult* _res_)
{
	ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static void
proton_plus_utils_download_manager_throttle_global_download_bytes_ready (GObject* source_object,
                                                                         GAsyncResult* _res_,
                                                                         gpointer _user_data_)
{
	ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_utils_download_manager_throttle_global_download_bytes_co (_data_);
}

static gboolean
proton_plus_utils_download_manager_throttle_global_download_bytes_co (ProtonPlusUtilsDownloadManagerThrottleGlobalDownloadBytesData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->bytes_written <= ((gint64) 0)) {
		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;
	}
	if (_data_->self->priv->_throttle_generation != _data_->expected_generation) {
		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_->_tmp0_ = proton_plus_utils_download_manager_get_speed_limit_bps (_data_->self);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->speed_limit = _data_->_tmp1_;
	if (_data_->speed_limit <= ((gint64) 0)) {
		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_->now_us = g_get_monotonic_time ();
	_data_->schedule_base_us = _data_->self->priv->global_throttle_next_allowed_time_us;
	if (_data_->transfer_started_us > _data_->schedule_base_us) {
		_data_->_tmp2_ = _data_->transfer_started_us < _data_->now_us;
	} else {
		_data_->_tmp2_ = FALSE;
	}
	if (_data_->_tmp2_) {
		_data_->schedule_base_us = _data_->transfer_started_us;
	}
	if (_data_->schedule_base_us == ((gint64) 0)) {
		_data_->schedule_base_us = _data_->now_us;
	}
	_data_->chunk_budget_us = (_data_->bytes_written * 1000000) / _data_->speed_limit;
	_data_->self->priv->global_throttle_next_allowed_time_us = _data_->schedule_base_us + _data_->chunk_budget_us;
	if (_data_->self->priv->global_throttle_next_allowed_time_us < _data_->now_us) {
		_data_->self->priv->global_throttle_next_allowed_time_us = _data_->now_us;
	}
	_data_->delay_us = _data_->self->priv->global_throttle_next_allowed_time_us - _data_->now_us;
	if (_data_->delay_us > ((gint64) 0)) {
		_data_->_state_ = 1;
		proton_plus_utils_download_manager_wait_for_throttle_deadline (_data_->self, _data_->self->priv->global_throttle_next_allowed_time_us, _data_->expected_generation, _data_->cancellable, proton_plus_utils_download_manager_throttle_global_download_bytes_ready, _data_);
		return FALSE;
		_state_1:
		proton_plus_utils_download_manager_wait_for_throttle_deadline_finish (_data_->self, _data_->_res_);
	}
	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;
}

ProtonPlusUtilsDownloadManager*
proton_plus_utils_download_manager_get_instance (void)
{
	ProtonPlusUtilsDownloadManager* result;
	ProtonPlusUtilsDownloadManager* _tmp0_;
	ProtonPlusUtilsDownloadManager* _tmp2_;
	_tmp0_ = proton_plus_utils_download_manager__instance;
	if (_tmp0_ == NULL) {
		ProtonPlusUtilsDownloadManager* _tmp1_;
		_tmp1_ = proton_plus_utils_download_manager_new ();
		_g_object_unref0 (proton_plus_utils_download_manager__instance);
		proton_plus_utils_download_manager__instance = _tmp1_;
	}
	_tmp2_ = proton_plus_utils_download_manager__instance;
	result = _tmp2_;
	return result;
}

GeeLinkedList*
proton_plus_utils_download_manager_get_active_downloads (ProtonPlusUtilsDownloadManager* self)
{
	GeeLinkedList* result;
	GeeLinkedList* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_active_downloads;
	result = _tmp0_;
	return result;
}

static void
proton_plus_utils_download_manager_set_active_downloads (ProtonPlusUtilsDownloadManager* self,
                                                         GeeLinkedList* value)
{
	GeeLinkedList* old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_utils_download_manager_get_active_downloads (self);
	if (old_value != value) {
		GeeLinkedList* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_active_downloads);
		self->priv->_active_downloads = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_utils_download_manager_properties[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_ACTIVE_DOWNLOADS_PROPERTY]);
	}
}

gint64
proton_plus_utils_download_manager_get_speed_limit_bps (ProtonPlusUtilsDownloadManager* self)
{
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	result = self->priv->_speed_limit_bps;
	return result;
}

void
proton_plus_utils_download_manager_set_speed_limit_bps (ProtonPlusUtilsDownloadManager* self,
                                                        gint64 value)
{
	gint64 _tmp0_ = 0LL;
	gint64 normalized_limit = 0LL;
	GSettings* _tmp1_;
	g_return_if_fail (self != NULL);
	if (value > ((gint64) 0)) {
		_tmp0_ = value;
	} else {
		_tmp0_ = (gint64) 0;
	}
	normalized_limit = _tmp0_;
	if (self->priv->_speed_limit_bps == normalized_limit) {
		return;
	}
	self->priv->_speed_limit_bps = normalized_limit;
	proton_plus_utils_download_manager_invalidate_throttle_schedule (self);
	_tmp1_ = proton_plus_globals_SETTINGS;
	if (_tmp1_ != NULL) {
		gint64 persisted = 0LL;
		GSettings* _tmp2_;
		_tmp2_ = proton_plus_globals_SETTINGS;
		persisted = g_settings_get_int64 (_tmp2_, PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_SETTINGS_KEY);
		if (persisted != self->priv->_speed_limit_bps) {
			GSettings* _tmp3_;
			_tmp3_ = proton_plus_globals_SETTINGS;
			g_settings_set_int64 (_tmp3_, PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_SETTINGS_KEY, self->priv->_speed_limit_bps);
		}
	}
	g_signal_emit (self, proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_CHANGED_SIGNAL], 0, self->priv->_speed_limit_bps);
	g_object_notify_by_pspec ((GObject *) self, proton_plus_utils_download_manager_properties[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_BPS_PROPERTY]);
}

guint64
proton_plus_utils_download_manager_get_throttle_generation (ProtonPlusUtilsDownloadManager* self)
{
	guint64 result;
	g_return_val_if_fail (self != NULL, 0ULL);
	result = self->priv->_throttle_generation;
	return result;
}

static void
g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN (GClosure * closure,
                                              GValue * return_value,
                                              guint n_param_values,
                                              const GValue * param_values,
                                              gpointer invocation_hint,
                                              gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_BOOLEAN) (gpointer data1, gpointer arg_1, gboolean arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_BOOLEAN callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_BOOLEAN) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_boolean (param_values + 2), data2);
}

static void
g_cclosure_user_marshal_VOID__INT64 (GClosure * closure,
                                     GValue * return_value,
                                     guint n_param_values,
                                     const GValue * param_values,
                                     gpointer invocation_hint,
                                     gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT64) (gpointer data1, gint64 arg_1, gpointer data2);
	register GMarshalFunc_VOID__INT64 callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 2);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT64) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int64 (param_values + 1), data2);
}

static void
proton_plus_utils_download_manager_class_init (ProtonPlusUtilsDownloadManagerClass * klass,
                                               gpointer klass_data)
{
	proton_plus_utils_download_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ProtonPlusUtilsDownloadManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_proton_plus_utils_download_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_proton_plus_utils_download_manager_set_property;
	G_OBJECT_CLASS (klass)->finalize = proton_plus_utils_download_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_ACTIVE_DOWNLOADS_PROPERTY, proton_plus_utils_download_manager_properties[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_ACTIVE_DOWNLOADS_PROPERTY] = g_param_spec_object ("active-downloads", "active-downloads", "active-downloads", GEE_TYPE_LINKED_LIST, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_BPS_PROPERTY, proton_plus_utils_download_manager_properties[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_BPS_PROPERTY] = g_param_spec_int64 ("speed-limit-bps", "speed-limit-bps", "speed-limit-bps", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_THROTTLE_GENERATION_PROPERTY, proton_plus_utils_download_manager_properties[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_THROTTLE_GENERATION_PROPERTY] = g_param_spec_uint64 ("throttle-generation", "throttle-generation", "throttle-generation", 0, G_MAXUINT64, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_DOWNLOAD_ADDED_SIGNAL] = g_signal_new ("download-added", PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, PROTON_PLUS_SERVICES_TYPE_INSTALL_JOB);
	proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_DOWNLOAD_REMOVED_SIGNAL] = g_signal_new ("download-removed", PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, PROTON_PLUS_SERVICES_TYPE_INSTALL_JOB);
	proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_DOWNLOAD_FINISHED_SIGNAL] = g_signal_new ("download-finished", PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, PROTON_PLUS_SERVICES_TYPE_INSTALL_JOB, G_TYPE_BOOLEAN);
	proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_PROGRESS_UPDATED_SIGNAL] = g_signal_new ("progress-updated", PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, PROTON_PLUS_SERVICES_TYPE_INSTALL_JOB);
	proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_TOOL_UPDATED_SIGNAL] = g_signal_new ("tool-updated", PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, PROTON_PLUS_SERVICES_TYPE_INSTALL_JOB, G_TYPE_BOOLEAN);
	proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_TOOL_REMOVED_SIGNAL] = g_signal_new ("tool-removed", PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, PROTON_PLUS_SERVICES_TYPE_INSTALL_JOB);
	proton_plus_utils_download_manager_signals[PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_CHANGED_SIGNAL] = g_signal_new ("speed-limit-changed", PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64);
}

static void
proton_plus_utils_download_manager_instance_init (ProtonPlusUtilsDownloadManager * self,
                                                  gpointer klass)
{
	self->priv = proton_plus_utils_download_manager_get_instance_private (self);
	self->priv->speed_limit_settings_changed_handler = (gulong) 0;
	self->priv->global_throttle_next_allowed_time_us = (gint64) 0;
	self->priv->_throttle_generation = (guint64) 0;
	self->priv->_speed_limit_bps = (gint64) 0;
}

static void
proton_plus_utils_download_manager_finalize (GObject * obj)
{
	ProtonPlusUtilsDownloadManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, ProtonPlusUtilsDownloadManager);
	_g_object_unref0 (self->priv->_active_downloads);
	G_OBJECT_CLASS (proton_plus_utils_download_manager_parent_class)->finalize (obj);
}

static GType
proton_plus_utils_download_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusUtilsDownloadManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_utils_download_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusUtilsDownloadManager), 0, (GInstanceInitFunc) proton_plus_utils_download_manager_instance_init, NULL };
	GType proton_plus_utils_download_manager_type_id;
	proton_plus_utils_download_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusUtilsDownloadManager", &g_define_type_info, 0);
	ProtonPlusUtilsDownloadManager_private_offset = g_type_add_instance_private (proton_plus_utils_download_manager_type_id, sizeof (ProtonPlusUtilsDownloadManagerPrivate));
	return proton_plus_utils_download_manager_type_id;
}

GType
proton_plus_utils_download_manager_get_type (void)
{
	static volatile gsize proton_plus_utils_download_manager_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_download_manager_type_id__once)) {
		GType proton_plus_utils_download_manager_type_id;
		proton_plus_utils_download_manager_type_id = proton_plus_utils_download_manager_get_type_once ();
		g_once_init_leave (&proton_plus_utils_download_manager_type_id__once, proton_plus_utils_download_manager_type_id);
	}
	return proton_plus_utils_download_manager_type_id__once;
}

static void
_vala_proton_plus_utils_download_manager_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec)
{
	ProtonPlusUtilsDownloadManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, ProtonPlusUtilsDownloadManager);
	switch (property_id) {
		case PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_ACTIVE_DOWNLOADS_PROPERTY:
		g_value_set_object (value, proton_plus_utils_download_manager_get_active_downloads (self));
		break;
		case PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_BPS_PROPERTY:
		g_value_set_int64 (value, proton_plus_utils_download_manager_get_speed_limit_bps (self));
		break;
		case PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_THROTTLE_GENERATION_PROPERTY:
		g_value_set_uint64 (value, proton_plus_utils_download_manager_get_throttle_generation (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_proton_plus_utils_download_manager_set_property (GObject * object,
                                                       guint property_id,
                                                       const GValue * value,
                                                       GParamSpec * pspec)
{
	ProtonPlusUtilsDownloadManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_UTILS_TYPE_DOWNLOAD_MANAGER, ProtonPlusUtilsDownloadManager);
	switch (property_id) {
		case PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_ACTIVE_DOWNLOADS_PROPERTY:
		proton_plus_utils_download_manager_set_active_downloads (self, g_value_get_object (value));
		break;
		case PROTON_PLUS_UTILS_DOWNLOAD_MANAGER_SPEED_LIMIT_BPS_PROPERTY:
		proton_plus_utils_download_manager_set_speed_limit_bps (self, g_value_get_int64 (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

