/* tracker-backup.c generated by valac 0.56.3, the Vala compiler
 * generated from tracker-backup.vala, do not modify */

/*
 * Copyright (C) 2006, Jamie McCracken <jamiemcc@gnome.org>
 * Copyright (C) 2008-2011, Nokia <ivan.frade@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "tracker-store/tracker-events.h"
#include "libtracker-common/tracker-common.h"
#include "libtracker-data/tracker-data-backup.h"
#include "libtracker-data/tracker-data-manager.h"
#include "libtracker-data/tracker-data-query.h"
#include "libtracker-data/tracker-data-update.h"

#define TRACKER_BACKUP_PATH "/org/freedesktop/Tracker1/Backup"
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TRACKER_TYPE_BACKUP (tracker_backup_get_type ())
#define TRACKER_BACKUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TRACKER_TYPE_BACKUP, TrackerBackup))
#define TRACKER_BACKUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_BACKUP, TrackerBackupClass))
#define TRACKER_IS_BACKUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TRACKER_TYPE_BACKUP))
#define TRACKER_IS_BACKUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_BACKUP))
#define TRACKER_BACKUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_BACKUP, TrackerBackupClass))

typedef struct _TrackerBackup TrackerBackup;
typedef struct _TrackerBackupClass TrackerBackupClass;
typedef struct _TrackerBackupPrivate TrackerBackupPrivate;
enum  {
	TRACKER_BACKUP_0_PROPERTY,
	TRACKER_BACKUP_NUM_PROPERTIES
};
static GParamSpec* tracker_backup_properties[TRACKER_BACKUP_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;

#define TRACKER_TYPE_RESOURCES (tracker_resources_get_type ())
#define TRACKER_RESOURCES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TRACKER_TYPE_RESOURCES, TrackerResources))
#define TRACKER_RESOURCES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_RESOURCES, TrackerResourcesClass))
#define TRACKER_IS_RESOURCES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TRACKER_TYPE_RESOURCES))
#define TRACKER_IS_RESOURCES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_RESOURCES))
#define TRACKER_RESOURCES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_RESOURCES, TrackerResourcesClass))

typedef struct _TrackerResources TrackerResources;
typedef struct _TrackerResourcesClass TrackerResourcesClass;
typedef struct _Block2Data Block2Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _TrackerBackupSaveData TrackerBackupSaveData;

#define TRACKER_TYPE_STATUS (tracker_status_get_type ())
#define TRACKER_STATUS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TRACKER_TYPE_STATUS, TrackerStatus))
#define TRACKER_STATUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_STATUS, TrackerStatusClass))
#define TRACKER_IS_STATUS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TRACKER_TYPE_STATUS))
#define TRACKER_IS_STATUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_STATUS))
#define TRACKER_STATUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_STATUS, TrackerStatusClass))

typedef struct _TrackerStatus TrackerStatus;
typedef struct _TrackerStatusClass TrackerStatusClass;
typedef struct _TrackerBackupRestoreData TrackerBackupRestoreData;
typedef struct _TrackerBackupSaveReadyData TrackerBackupSaveReadyData;
typedef struct _TrackerBackupRestoreReadyData TrackerBackupRestoreReadyData;

struct _TrackerBackup {
	GObject parent_instance;
	TrackerBackupPrivate * priv;
};

struct _TrackerBackupClass {
	GObjectClass parent_class;
};

struct _Block1Data {
	int _ref_count_;
	TrackerBackup* self;
	gpointer _async_data_;
};

struct _Block2Data {
	int _ref_count_;
	Block1Data * _data1_;
	GError* backup_error;
};

struct _TrackerBackupSaveData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	TrackerBackup* self;
	char* sender;
	gchar* destination_uri;
	Block1Data* _data1_;
	TrackerResources* resources;
	GObject* _tmp0_;
	TrackerResources* _tmp1_;
	TrackerDBusRequest* request;
	TrackerDBusRequest* _tmp2_;
	Block2Data* _data2_;
	GFile* destination;
	GFile* _tmp3_;
	gboolean _tmp4_;
	GFile* _tmp5_;
	GFile* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GError* _tmp13_;
	GError* _tmp14_;
	TrackerDataManager* data_manager;
	TrackerDataManager* _tmp15_;
	TrackerDataManager* _tmp16_;
	TrackerDataManager* _tmp17_;
	GFile* _tmp18_;
	GFile* _tmp19_;
	GError* _tmp20_;
	GError* _tmp21_;
	GError* _tmp22_;
	TrackerDBusRequest* _tmp23_;
	GError* e;
	TrackerDBusRequest* _tmp24_;
	GError* _tmp25_;
	GError* _tmp26_;
	GError* _tmp27_;
	GError* _inner_error1_;
	TrackerResources* _tmp28_;
	GError* _inner_error0_;
};

struct _TrackerBackupRestoreData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	TrackerBackup* self;
	char* sender;
	gchar* journal_uri;
	TrackerResources* resources;
	GObject* _tmp0_;
	TrackerResources* _tmp1_;
	TrackerDBusRequest* request;
	TrackerDBusRequest* _tmp2_;
	GFile* journal;
	GFile* _tmp3_;
	gboolean _tmp4_;
	GFile* _tmp5_;
	GFile* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GError* _tmp13_;
	GError* _tmp14_;
	TrackerStatus* notifier;
	GObject* _tmp15_;
	TrackerBusyCallback busy_callback;
	TrackerStatus* _tmp16_;
	gpointer _tmp17_;
	GDestroyNotify _tmp18_;
	TrackerBusyCallback _tmp19_;
	gpointer busy_callback_target;
	GDestroyNotify busy_callback_target_destroy_notify;
	TrackerDataManager* data_manager;
	TrackerDataManager* _tmp20_;
	TrackerDataManager* _tmp21_;
	TrackerDataManager* _tmp22_;
	GFile* _tmp23_;
	TrackerBusyCallback _tmp24_;
	gpointer _tmp24__target;
	TrackerDBusRequest* _tmp25_;
	GError* e;
	TrackerDBusRequest* _tmp26_;
	GError* _tmp27_;
	GError* _tmp28_;
	GError* _tmp29_;
	GError* _inner_error1_;
	TrackerResources* _tmp30_;
	GError* _inner_error0_;
};

struct _TrackerBackupSaveReadyData {
	GDBusMethodInvocation* _invocation_;
	gchar* destination_uri;
};

struct _TrackerBackupRestoreReadyData {
	GDBusMethodInvocation* _invocation_;
	gchar* journal_uri;
};

static gpointer tracker_backup_parent_class = NULL;

VALA_EXTERN GType tracker_backup_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TrackerBackup, g_object_unref)
VALA_EXTERN guint tracker_backup_register_object (void* object,
                                      GDBusConnection* connection,
                                      const gchar* path,
                                      GError** error);
static void tracker_backup_save_data_free (gpointer _data);
VALA_EXTERN void tracker_backup_save (TrackerBackup* self,
                          const char* sender,
                          const gchar* destination_uri,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_);
VALA_EXTERN void tracker_backup_save_finish (TrackerBackup* self,
                                 GAsyncResult* _res_,
                                 GError** error);
static gboolean tracker_backup_save_co (TrackerBackupSaveData* _data_);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
VALA_EXTERN GType tracker_resources_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TrackerResources, g_object_unref)
VALA_EXTERN guint tracker_resources_register_object (void* object,
                                         GDBusConnection* connection,
                                         const gchar* path,
                                         GError** error);
VALA_EXTERN GObject* tracker_dbus_get_object (GType type);
VALA_EXTERN void tracker_store_disable_signals (void);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
VALA_EXTERN void tracker_store_pause (GAsyncReadyCallback _callback_,
                          gpointer _user_data_);
VALA_EXTERN void tracker_store_pause_finish (GAsyncResult* _res_);
static void tracker_backup_save_ready (GObject* source_object,
                                GAsyncResult* _res_,
                                gpointer _user_data_);
VALA_EXTERN TrackerDataManager* tracker_main_get_data_manager (void);
static void ___lambda15_ (Block2Data* _data2_,
                   GError* _error_);
static void ____lambda15__tracker_data_backup_finished (GError* _error_,
                                                 gpointer self);
VALA_EXTERN void tracker_store_enable_signals (void);
VALA_EXTERN void tracker_store_resume (void);
static void tracker_backup_restore_data_free (gpointer _data);
VALA_EXTERN void tracker_backup_restore (TrackerBackup* self,
                             const char* sender,
                             const gchar* journal_uri,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_);
VALA_EXTERN void tracker_backup_restore_finish (TrackerBackup* self,
                                    GAsyncResult* _res_,
                                    GError** error);
static gboolean tracker_backup_restore_co (TrackerBackupRestoreData* _data_);
static void tracker_backup_restore_ready (GObject* source_object,
                                   GAsyncResult* _res_,
                                   gpointer _user_data_);
VALA_EXTERN GType tracker_status_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TrackerStatus, g_object_unref)
VALA_EXTERN guint tracker_status_register_object (void* object,
                                      GDBusConnection* connection,
                                      const gchar* path,
                                      GError** error);
VALA_EXTERN TrackerBusyCallback tracker_status_get_callback (TrackerStatus* self,
                                                 gpointer* result_target,
                                                 GDestroyNotify* result_target_destroy_notify);
VALA_EXTERN TrackerBackup* tracker_backup_new (void);
VALA_EXTERN TrackerBackup* tracker_backup_construct (GType object_type);
static GType tracker_backup_get_type_once (void);
static void _dbus_tracker_backup_save (TrackerBackup* self,
                                GVariant* _parameters_,
                                GDBusMethodInvocation* invocation);
static void _dbus_tracker_backup_save_ready (GObject * source_object,
                                      GAsyncResult * _res_,
                                      gpointer _user_data_);
static void _dbus_tracker_backup_restore (TrackerBackup* self,
                                   GVariant* _parameters_,
                                   GDBusMethodInvocation* invocation);
static void _dbus_tracker_backup_restore_ready (GObject * source_object,
                                         GAsyncResult * _res_,
                                         gpointer _user_data_);
static void tracker_backup_dbus_interface_method_call (GDBusConnection* connection,
                                                const gchar* sender,
                                                const gchar* object_path,
                                                const gchar* interface_name,
                                                const gchar* method_name,
                                                GVariant* parameters,
                                                GDBusMethodInvocation* invocation,
                                                gpointer user_data);
static GVariant* tracker_backup_dbus_interface_get_property (GDBusConnection* connection,
                                                      const gchar* sender,
                                                      const gchar* object_path,
                                                      const gchar* interface_name,
                                                      const gchar* property_name,
                                                      GError** error,
                                                      gpointer user_data);
static gboolean tracker_backup_dbus_interface_set_property (GDBusConnection* connection,
                                                     const gchar* sender,
                                                     const gchar* object_path,
                                                     const gchar* interface_name,
                                                     const gchar* property_name,
                                                     GVariant* value,
                                                     GError** error,
                                                     gpointer user_data);
static void _tracker_backup_unregister_object (gpointer user_data);

static const GDBusArgInfo _tracker_backup_dbus_arg_info_save_destination_uri = {-1, "destination_uri", "s", NULL};
static const GDBusArgInfo * const _tracker_backup_dbus_arg_info_save_in[] = {&_tracker_backup_dbus_arg_info_save_destination_uri, NULL};
static const GDBusArgInfo * const _tracker_backup_dbus_arg_info_save_out[] = {NULL};
static const GDBusMethodInfo _tracker_backup_dbus_method_info_save = {-1, "Save", (GDBusArgInfo **) (&_tracker_backup_dbus_arg_info_save_in), (GDBusArgInfo **) (&_tracker_backup_dbus_arg_info_save_out), NULL};
static const GDBusArgInfo _tracker_backup_dbus_arg_info_restore_journal_uri = {-1, "journal_uri", "s", NULL};
static const GDBusArgInfo * const _tracker_backup_dbus_arg_info_restore_in[] = {&_tracker_backup_dbus_arg_info_restore_journal_uri, NULL};
static const GDBusArgInfo * const _tracker_backup_dbus_arg_info_restore_out[] = {NULL};
static const GDBusMethodInfo _tracker_backup_dbus_method_info_restore = {-1, "Restore", (GDBusArgInfo **) (&_tracker_backup_dbus_arg_info_restore_in), (GDBusArgInfo **) (&_tracker_backup_dbus_arg_info_restore_out), NULL};
static const GDBusMethodInfo * const _tracker_backup_dbus_method_info[] = {&_tracker_backup_dbus_method_info_save, &_tracker_backup_dbus_method_info_restore, NULL};
static const GDBusSignalInfo * const _tracker_backup_dbus_signal_info[] = {NULL};
static const GDBusPropertyInfo * const _tracker_backup_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _tracker_backup_dbus_interface_info = {-1, "org.freedesktop.Tracker1.Backup", (GDBusMethodInfo **) (&_tracker_backup_dbus_method_info), (GDBusSignalInfo **) (&_tracker_backup_dbus_signal_info), (GDBusPropertyInfo **) (&_tracker_backup_dbus_property_info), NULL};
static const GDBusInterfaceVTable _tracker_backup_dbus_interface_vtable = {tracker_backup_dbus_interface_method_call, tracker_backup_dbus_interface_get_property, tracker_backup_dbus_interface_set_property};

static void
tracker_backup_save_data_free (gpointer _data)
{
	TrackerBackupSaveData* _data_;
	_data_ = _data;
	_g_free0 (_data_->sender);
	_g_free0 (_data_->destination_uri);
	_g_object_unref0 (_data_->self);
	g_slice_free (TrackerBackupSaveData, _data_);
}

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

void
tracker_backup_save (TrackerBackup* self,
                     const char* sender,
                     const gchar* destination_uri,
                     GAsyncReadyCallback _callback_,
                     gpointer _user_data_)
{
	TrackerBackupSaveData* _data_;
	TrackerBackup* _tmp0_;
	char* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	g_return_if_fail (destination_uri != NULL);
	_data_ = g_slice_new0 (TrackerBackupSaveData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, tracker_backup_save_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (sender);
	_g_free0 (_data_->sender);
	_data_->sender = _tmp1_;
	_tmp2_ = g_strdup (destination_uri);
	_g_free0 (_data_->destination_uri);
	_data_->destination_uri = _tmp2_;
	tracker_backup_save_co (_data_);
}

void
tracker_backup_save_finish (TrackerBackup* self,
                            GAsyncResult* _res_,
                            GError** error)
{
	TrackerBackupSaveData* _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_)) {
		TrackerBackup* self;
		self = _data1_->self;
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static Block2Data*
block2_data_ref (Block2Data* _data2_)
{
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}

static void
block2_data_unref (void * _userdata_)
{
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		TrackerBackup* self;
		self = _data2_->_data1_->self;
		_g_error_free0 (_data2_->backup_error);
		block1_data_unref (_data2_->_data1_);
		_data2_->_data1_ = NULL;
		g_slice_free (Block2Data, _data2_);
	}
}

static void
tracker_backup_save_ready (GObject* source_object,
                           GAsyncResult* _res_,
                           gpointer _user_data_)
{
	TrackerBackupSaveData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	tracker_backup_save_co (_data_);
}

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

static void
___lambda15_ (Block2Data* _data2_,
              GError* _error_)
{
	Block1Data* _data1_;
	TrackerBackup* self;
	GError* _tmp0_;
	_data1_ = _data2_->_data1_;
	self = _data1_->self;
	g_return_if_fail (_error_ != NULL);
	_tmp0_ = _g_error_copy0 (_error_);
	_g_error_free0 (_data2_->backup_error);
	_data2_->backup_error = _tmp0_;
	tracker_backup_save_co (_data1_->_async_data_);
}

static void
____lambda15__tracker_data_backup_finished (GError* _error_,
                                            gpointer self)
{
	___lambda15_ (self, _error_);
}

static gboolean
tracker_backup_save_co (TrackerBackupSaveData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		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_ = tracker_dbus_get_object (TRACKER_TYPE_RESOURCES);
	_data_->resources = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, TRACKER_TYPE_RESOURCES, TrackerResources);
	_data_->_tmp1_ = _data_->resources;
	if (_data_->_tmp1_ != NULL) {
		tracker_store_disable_signals ();
		tracker_events_shutdown ();
	}
	_data_->_tmp2_ = tracker_dbus_request_begin ((const gchar*) _data_->sender, "D-Bus request to save backup into '%s'", _data_->destination_uri, NULL);
	_data_->request = _data_->_tmp2_;
	{
		_data_->_data2_ = g_slice_new0 (Block2Data);
		_data_->_data2_->_ref_count_ = 1;
		_data_->_data2_->_data1_ = block1_data_ref (_data_->_data1_);
		_data_->_tmp3_ = g_file_new_for_uri (_data_->destination_uri);
		_data_->destination = _data_->_tmp3_;
		_data_->_tmp5_ = _data_->destination;
		if (_data_->_tmp5_ == NULL) {
			_data_->_tmp4_ = TRUE;
		} else {
			_data_->_tmp6_ = _data_->destination;
			_data_->_tmp7_ = g_file_get_path (_data_->_tmp6_);
			_data_->_tmp8_ = _data_->_tmp7_;
			_data_->_tmp4_ = _data_->_tmp8_ == NULL;
			_g_free0 (_data_->_tmp8_);
		}
		if (_data_->_tmp4_) {
			_data_->_tmp9_ = g_strconcat ("'", _data_->destination_uri, NULL);
			_data_->_tmp10_ = _data_->_tmp9_;
			_data_->_tmp11_ = g_strconcat (_data_->_tmp10_, "' is not a valid uri", NULL);
			_data_->_tmp12_ = _data_->_tmp11_;
			_data_->_tmp13_ = g_error_new_literal (TRACKER_DATA_BACKUP_ERROR, TRACKER_DATA_BACKUP_ERROR_INVALID_URI, _data_->_tmp12_);
			_data_->_tmp14_ = _data_->_tmp13_;
			_g_free0 (_data_->_tmp12_);
			_g_free0 (_data_->_tmp10_);
			_data_->_inner_error0_ = _data_->_tmp14_;
			_g_object_unref0 (_data_->destination);
			block2_data_unref (_data_->_data2_);
			_data_->_data2_ = NULL;
			goto __catch0_g_error;
		}
		_data_->_state_ = 1;
		tracker_store_pause (tracker_backup_save_ready, _data_);
		return FALSE;
		_state_1:
		tracker_store_pause_finish (_data_->_res_);
		_data_->_data2_->backup_error = NULL;
		_data_->_tmp15_ = tracker_main_get_data_manager ();
		_data_->_tmp16_ = _g_object_ref0 (_data_->_tmp15_);
		_data_->data_manager = _data_->_tmp16_;
		_data_->_tmp17_ = _data_->data_manager;
		_data_->_tmp18_ = _data_->destination;
		_data_->_tmp19_ = _data_->destination;
		tracker_data_backup_save (_data_->_tmp17_, _data_->_tmp18_, _data_->_tmp19_, ____lambda15__tracker_data_backup_finished, block2_data_ref (_data_->_data2_), block2_data_unref);
		_data_->_state_ = 2;
		return FALSE;
		_state_2:
		;
		_data_->_tmp20_ = _data_->_data2_->backup_error;
		if (_data_->_tmp20_ != NULL) {
			_data_->_tmp21_ = _data_->_data2_->backup_error;
			_data_->_tmp22_ = _g_error_copy0 (_data_->_tmp21_);
			_data_->_inner_error0_ = _data_->_tmp22_;
			_g_object_unref0 (_data_->data_manager);
			_g_object_unref0 (_data_->destination);
			block2_data_unref (_data_->_data2_);
			_data_->_data2_ = NULL;
			goto __catch0_g_error;
		}
		_data_->_tmp23_ = _data_->request;
		tracker_dbus_request_end (_data_->_tmp23_, NULL);
		_g_object_unref0 (_data_->data_manager);
		_g_object_unref0 (_data_->destination);
		block2_data_unref (_data_->_data2_);
		_data_->_data2_ = NULL;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp24_ = _data_->request;
		_data_->_tmp25_ = _data_->e;
		tracker_dbus_request_end (_data_->_tmp24_, _data_->_tmp25_);
		_data_->_tmp26_ = _data_->e;
		_data_->_tmp27_ = _g_error_copy0 (_data_->_tmp26_);
		_data_->_inner_error0_ = _data_->_tmp27_;
		_g_error_free0 (_data_->e);
		goto __finally0;
	}
	__finally0:
	{
		_data_->_tmp28_ = _data_->resources;
		if (_data_->_tmp28_ != NULL) {
			tracker_events_init ();
			tracker_store_enable_signals ();
		}
		tracker_store_resume ();
	}
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->resources);
		block1_data_unref (_data_->_data1_);
		_data_->_data1_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->resources);
	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 void
tracker_backup_restore_data_free (gpointer _data)
{
	TrackerBackupRestoreData* _data_;
	_data_ = _data;
	_g_free0 (_data_->sender);
	_g_free0 (_data_->journal_uri);
	_g_object_unref0 (_data_->self);
	g_slice_free (TrackerBackupRestoreData, _data_);
}

void
tracker_backup_restore (TrackerBackup* self,
                        const char* sender,
                        const gchar* journal_uri,
                        GAsyncReadyCallback _callback_,
                        gpointer _user_data_)
{
	TrackerBackupRestoreData* _data_;
	TrackerBackup* _tmp0_;
	char* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	g_return_if_fail (journal_uri != NULL);
	_data_ = g_slice_new0 (TrackerBackupRestoreData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, tracker_backup_restore_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (sender);
	_g_free0 (_data_->sender);
	_data_->sender = _tmp1_;
	_tmp2_ = g_strdup (journal_uri);
	_g_free0 (_data_->journal_uri);
	_data_->journal_uri = _tmp2_;
	tracker_backup_restore_co (_data_);
}

void
tracker_backup_restore_finish (TrackerBackup* self,
                               GAsyncResult* _res_,
                               GError** error)
{
	TrackerBackupRestoreData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
tracker_backup_restore_ready (GObject* source_object,
                              GAsyncResult* _res_,
                              gpointer _user_data_)
{
	TrackerBackupRestoreData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	tracker_backup_restore_co (_data_);
}

static gboolean
tracker_backup_restore_co (TrackerBackupRestoreData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = tracker_dbus_get_object (TRACKER_TYPE_RESOURCES);
	_data_->resources = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp0_, TRACKER_TYPE_RESOURCES, TrackerResources);
	_data_->_tmp1_ = _data_->resources;
	if (_data_->_tmp1_ != NULL) {
		tracker_store_disable_signals ();
		tracker_events_shutdown ();
	}
	_data_->_tmp2_ = tracker_dbus_request_begin ((const gchar*) _data_->sender, "D-Bus request to restore backup from '%s'", _data_->journal_uri, NULL);
	_data_->request = _data_->_tmp2_;
	{
		_data_->_state_ = 1;
		tracker_store_pause (tracker_backup_restore_ready, _data_);
		return FALSE;
		_state_1:
		tracker_store_pause_finish (_data_->_res_);
		_data_->_tmp3_ = g_file_new_for_uri (_data_->journal_uri);
		_data_->journal = _data_->_tmp3_;
		_data_->_tmp5_ = _data_->journal;
		if (_data_->_tmp5_ == NULL) {
			_data_->_tmp4_ = TRUE;
		} else {
			_data_->_tmp6_ = _data_->journal;
			_data_->_tmp7_ = g_file_get_path (_data_->_tmp6_);
			_data_->_tmp8_ = _data_->_tmp7_;
			_data_->_tmp4_ = _data_->_tmp8_ == NULL;
			_g_free0 (_data_->_tmp8_);
		}
		if (_data_->_tmp4_) {
			_data_->_tmp9_ = g_strconcat ("'", _data_->journal_uri, NULL);
			_data_->_tmp10_ = _data_->_tmp9_;
			_data_->_tmp11_ = g_strconcat (_data_->_tmp10_, "' is not a valid uri", NULL);
			_data_->_tmp12_ = _data_->_tmp11_;
			_data_->_tmp13_ = g_error_new_literal (TRACKER_DATA_BACKUP_ERROR, TRACKER_DATA_BACKUP_ERROR_INVALID_URI, _data_->_tmp12_);
			_data_->_tmp14_ = _data_->_tmp13_;
			_g_free0 (_data_->_tmp12_);
			_g_free0 (_data_->_tmp10_);
			_data_->_inner_error0_ = _data_->_tmp14_;
			_g_object_unref0 (_data_->journal);
			goto __catch0_g_error;
		}
		_data_->_tmp15_ = tracker_dbus_get_object (TRACKER_TYPE_STATUS);
		_data_->notifier = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp15_, TRACKER_TYPE_STATUS, TrackerStatus);
		_data_->_tmp16_ = _data_->notifier;
		_data_->_tmp17_ = NULL;
		_data_->_tmp18_ = NULL;
		_data_->_tmp19_ = tracker_status_get_callback (_data_->_tmp16_, &_data_->_tmp17_, &_data_->_tmp18_);
		_data_->busy_callback = _data_->_tmp19_;
		_data_->busy_callback_target = _data_->_tmp17_;
		_data_->busy_callback_target_destroy_notify = _data_->_tmp18_;
		_data_->_tmp20_ = tracker_main_get_data_manager ();
		_data_->_tmp21_ = _g_object_ref0 (_data_->_tmp20_);
		_data_->data_manager = _data_->_tmp21_;
		_data_->_tmp22_ = _data_->data_manager;
		_data_->_tmp23_ = _data_->journal;
		_data_->_tmp24_ = _data_->busy_callback;
		_data_->_tmp24__target = _data_->busy_callback_target;
		tracker_data_backup_restore (_data_->_tmp22_, _data_->_tmp23_, NULL, NULL, NULL, _data_->_tmp24_, _data_->_tmp24__target, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->data_manager);
			(_data_->busy_callback_target_destroy_notify == NULL) ? NULL : (_data_->busy_callback_target_destroy_notify (_data_->busy_callback_target), NULL);
			_data_->busy_callback = NULL;
			_data_->busy_callback_target = NULL;
			_data_->busy_callback_target_destroy_notify = NULL;
			_g_object_unref0 (_data_->notifier);
			_g_object_unref0 (_data_->journal);
			goto __catch0_g_error;
		}
		_data_->_tmp25_ = _data_->request;
		tracker_dbus_request_end (_data_->_tmp25_, NULL);
		_g_object_unref0 (_data_->data_manager);
		(_data_->busy_callback_target_destroy_notify == NULL) ? NULL : (_data_->busy_callback_target_destroy_notify (_data_->busy_callback_target), NULL);
		_data_->busy_callback = NULL;
		_data_->busy_callback_target = NULL;
		_data_->busy_callback_target_destroy_notify = NULL;
		_g_object_unref0 (_data_->notifier);
		_g_object_unref0 (_data_->journal);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp26_ = _data_->request;
		_data_->_tmp27_ = _data_->e;
		tracker_dbus_request_end (_data_->_tmp26_, _data_->_tmp27_);
		_data_->_tmp28_ = _data_->e;
		_data_->_tmp29_ = _g_error_copy0 (_data_->_tmp28_);
		_data_->_inner_error0_ = _data_->_tmp29_;
		_g_error_free0 (_data_->e);
		goto __finally0;
	}
	__finally0:
	{
		_data_->_tmp30_ = _data_->resources;
		if (_data_->_tmp30_ != NULL) {
			tracker_events_init ();
			tracker_store_enable_signals ();
		}
		tracker_store_resume ();
	}
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->resources);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->resources);
	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;
}

TrackerBackup*
tracker_backup_construct (GType object_type)
{
	TrackerBackup * self = NULL;
	self = (TrackerBackup*) g_object_new (object_type, NULL);
	return self;
}

TrackerBackup*
tracker_backup_new (void)
{
	return tracker_backup_construct (TRACKER_TYPE_BACKUP);
}

static void
tracker_backup_class_init (TrackerBackupClass * klass,
                           gpointer klass_data)
{
	tracker_backup_parent_class = g_type_class_peek_parent (klass);
}

static void
tracker_backup_instance_init (TrackerBackup * self,
                              gpointer klass)
{
}

static GType
tracker_backup_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (TrackerBackupClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tracker_backup_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TrackerBackup), 0, (GInstanceInitFunc) tracker_backup_instance_init, NULL };
	GType tracker_backup_type_id;
	tracker_backup_type_id = g_type_register_static (G_TYPE_OBJECT, "TrackerBackup", &g_define_type_info, 0);
	g_type_set_qdata (tracker_backup_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) tracker_backup_register_object);
	return tracker_backup_type_id;
}

GType
tracker_backup_get_type (void)
{
	static volatile gsize tracker_backup_type_id__once = 0;
	if (g_once_init_enter (&tracker_backup_type_id__once)) {
		GType tracker_backup_type_id;
		tracker_backup_type_id = tracker_backup_get_type_once ();
		g_once_init_leave (&tracker_backup_type_id__once, tracker_backup_type_id);
	}
	return tracker_backup_type_id__once;
}

static void
_dbus_tracker_backup_save (TrackerBackup* self,
                           GVariant* _parameters_,
                           GDBusMethodInvocation* invocation)
{
	GVariantIter _arguments_iter;
	TrackerBackupSaveReadyData* _ready_data;
	GVariant* _tmp0_;
	g_variant_iter_init (&_arguments_iter, _parameters_);
	_ready_data = g_slice_new0 (TrackerBackupSaveReadyData);
	_ready_data->_invocation_ = invocation;
	_tmp0_ = g_variant_iter_next_value (&_arguments_iter);
	_ready_data->destination_uri = g_variant_dup_string (_tmp0_, NULL);
	g_variant_unref (_tmp0_);
	tracker_backup_save (self, g_dbus_method_invocation_get_sender (invocation), _ready_data->destination_uri, (GAsyncReadyCallback) _dbus_tracker_backup_save_ready, _ready_data);
	_error:
	;
}

static void
_dbus_tracker_backup_save_ready (GObject * source_object,
                                 GAsyncResult * _res_,
                                 gpointer _user_data_)
{
	TrackerBackupSaveReadyData* _ready_data;
	GDBusMethodInvocation* invocation;
	GError* error = NULL;
	GDBusMessage* _reply_message = NULL;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	_ready_data = _user_data_;
	invocation = _ready_data->_invocation_;
	tracker_backup_save_finish ((TrackerBackup*) source_object, _res_, &error);
	if (error) {
		g_dbus_method_invocation_take_error (invocation, error);
		goto _error;
	}
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
	_error:
	_g_free0 (_ready_data->destination_uri);
	g_slice_free (TrackerBackupSaveReadyData, _ready_data);
}

static void
_dbus_tracker_backup_restore (TrackerBackup* self,
                              GVariant* _parameters_,
                              GDBusMethodInvocation* invocation)
{
	GVariantIter _arguments_iter;
	TrackerBackupRestoreReadyData* _ready_data;
	GVariant* _tmp1_;
	g_variant_iter_init (&_arguments_iter, _parameters_);
	_ready_data = g_slice_new0 (TrackerBackupRestoreReadyData);
	_ready_data->_invocation_ = invocation;
	_tmp1_ = g_variant_iter_next_value (&_arguments_iter);
	_ready_data->journal_uri = g_variant_dup_string (_tmp1_, NULL);
	g_variant_unref (_tmp1_);
	tracker_backup_restore (self, g_dbus_method_invocation_get_sender (invocation), _ready_data->journal_uri, (GAsyncReadyCallback) _dbus_tracker_backup_restore_ready, _ready_data);
	_error:
	;
}

static void
_dbus_tracker_backup_restore_ready (GObject * source_object,
                                    GAsyncResult * _res_,
                                    gpointer _user_data_)
{
	TrackerBackupRestoreReadyData* _ready_data;
	GDBusMethodInvocation* invocation;
	GError* error = NULL;
	GDBusMessage* _reply_message = NULL;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	_ready_data = _user_data_;
	invocation = _ready_data->_invocation_;
	tracker_backup_restore_finish ((TrackerBackup*) source_object, _res_, &error);
	if (error) {
		g_dbus_method_invocation_take_error (invocation, error);
		goto _error;
	}
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
	_error:
	_g_free0 (_ready_data->journal_uri);
	g_slice_free (TrackerBackupRestoreReadyData, _ready_data);
}

static void
tracker_backup_dbus_interface_method_call (GDBusConnection* connection,
                                           const gchar* sender,
                                           const gchar* object_path,
                                           const gchar* interface_name,
                                           const gchar* method_name,
                                           GVariant* parameters,
                                           GDBusMethodInvocation* invocation,
                                           gpointer user_data)
{
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	if (strcmp (method_name, "Save") == 0) {
		_dbus_tracker_backup_save (object, parameters, invocation);
	} else if (strcmp (method_name, "Restore") == 0) {
		_dbus_tracker_backup_restore (object, parameters, invocation);
	} else {
		g_object_unref (invocation);
	}
}

static GVariant*
tracker_backup_dbus_interface_get_property (GDBusConnection* connection,
                                            const gchar* sender,
                                            const gchar* object_path,
                                            const gchar* interface_name,
                                            const gchar* property_name,
                                            GError** error,
                                            gpointer user_data)
{
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	return NULL;
}

static gboolean
tracker_backup_dbus_interface_set_property (GDBusConnection* connection,
                                            const gchar* sender,
                                            const gchar* object_path,
                                            const gchar* interface_name,
                                            const gchar* property_name,
                                            GVariant* value,
                                            GError** error,
                                            gpointer user_data)
{
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	return FALSE;
}

guint
tracker_backup_register_object (gpointer object,
                                GDBusConnection* connection,
                                const gchar* path,
                                GError** error)
{
	guint result;
	gpointer *data;
	data = g_new (gpointer, 3);
	data[0] = g_object_ref (object);
	data[1] = g_object_ref (connection);
	data[2] = g_strdup (path);
	result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_tracker_backup_dbus_interface_info), &_tracker_backup_dbus_interface_vtable, data, _tracker_backup_unregister_object, error);
	if (!result) {
		return 0;
	}
	return result;
}

static void
_tracker_backup_unregister_object (gpointer user_data)
{
	gpointer* data;
	data = user_data;
	g_object_unref (data[0]);
	g_object_unref (data[1]);
	g_free (data[2]);
	g_free (data);
}

