/* ext-histogram.c generated by valac 0.26.1, the Vala compiler
 * generated from ext-histogram.vala, do not modify */

/* histogram.vala
 *
 * Copyright © 2011 Michal Hruby <michal.mhr@gmail.com>
 * Copyright © 2011 Stefano Candori <stefano.candori@gmail.com>
 *
 * Based upon a Python implementation (2010-2011) by:
 *  Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program 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 Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <string.h>
#include "zeitgeist-engine.h"
#include <stdlib.h>
#include <sqlite3.h>
#include "zeitgeist-internal.h"


#define ZEITGEIST_TYPE_REMOTE_HISTOGRAM (zeitgeist_remote_histogram_get_type ())
#define ZEITGEIST_REMOTE_HISTOGRAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZEITGEIST_TYPE_REMOTE_HISTOGRAM, ZeitgeistRemoteHistogram))
#define ZEITGEIST_IS_REMOTE_HISTOGRAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZEITGEIST_TYPE_REMOTE_HISTOGRAM))
#define ZEITGEIST_REMOTE_HISTOGRAM_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ZEITGEIST_TYPE_REMOTE_HISTOGRAM, ZeitgeistRemoteHistogramIface))

typedef struct _ZeitgeistRemoteHistogram ZeitgeistRemoteHistogram;
typedef struct _ZeitgeistRemoteHistogramIface ZeitgeistRemoteHistogramIface;

#define ZEITGEIST_TYPE_REMOTE_HISTOGRAM_PROXY (zeitgeist_remote_histogram_proxy_get_type ())
typedef GDBusProxy ZeitgeistRemoteHistogramProxy;
typedef GDBusProxyClass ZeitgeistRemoteHistogramProxyClass;
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

#define ZEITGEIST_TYPE_HISTOGRAM (zeitgeist_histogram_get_type ())
#define ZEITGEIST_HISTOGRAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZEITGEIST_TYPE_HISTOGRAM, ZeitgeistHistogram))
#define ZEITGEIST_HISTOGRAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZEITGEIST_TYPE_HISTOGRAM, ZeitgeistHistogramClass))
#define ZEITGEIST_IS_HISTOGRAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZEITGEIST_TYPE_HISTOGRAM))
#define ZEITGEIST_IS_HISTOGRAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZEITGEIST_TYPE_HISTOGRAM))
#define ZEITGEIST_HISTOGRAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZEITGEIST_TYPE_HISTOGRAM, ZeitgeistHistogramClass))

typedef struct _ZeitgeistHistogram ZeitgeistHistogram;
typedef struct _ZeitgeistHistogramClass ZeitgeistHistogramClass;
typedef struct _ZeitgeistHistogramPrivate ZeitgeistHistogramPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
#define _sqlite3_finalize0(var) ((var == NULL) ? NULL : (var = (sqlite3_finalize (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_variant_builder_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_builder_unref (var), NULL)))

struct _ZeitgeistRemoteHistogramIface {
	GTypeInterface parent_iface;
	GVariant* (*get_histogram_data) (ZeitgeistRemoteHistogram* self, GError** error);
};

struct _ZeitgeistHistogram {
	ZeitgeistExtension parent_instance;
	ZeitgeistHistogramPrivate * priv;
};

struct _ZeitgeistHistogramClass {
	ZeitgeistExtensionClass parent_class;
};

struct _ZeitgeistHistogramPrivate {
	guint registration_id;
};


static GType zeitgeist_remote_histogram_type_id = 0;
static gpointer zeitgeist_histogram_parent_class = NULL;
static ZeitgeistRemoteHistogramIface* zeitgeist_histogram_zeitgeist_remote_histogram_parent_iface = NULL;
static GType zeitgeist_histogram_type_id = 0;

GType zeitgeist_remote_histogram_proxy_get_type (void) G_GNUC_CONST;
void zeitgeist_remote_histogram_proxy_register_dynamic_type (GTypeModule* module);
guint zeitgeist_remote_histogram_register_object (void* object, GDBusConnection* connection, const gchar* path, GError** error);
GType zeitgeist_remote_histogram_get_type (void) G_GNUC_CONST;
GType zeitgeist_remote_histogram_register_type (GTypeModule * module);
GVariant* zeitgeist_remote_histogram_get_histogram_data (ZeitgeistRemoteHistogram* self, GError** error);
static void zeitgeist_remote_histogram_proxy_g_signal (GDBusProxy* proxy, const gchar* sender_name, const gchar* signal_name, GVariant* parameters);
static GVariant* zeitgeist_remote_histogram_proxy_get_histogram_data (ZeitgeistRemoteHistogram* self, GError** error);
static void zeitgeist_remote_histogram_proxy_zeitgeist_remote_histogram_interface_init (ZeitgeistRemoteHistogramIface* iface);
static void _dbus_zeitgeist_remote_histogram_get_histogram_data (ZeitgeistRemoteHistogram* self, GVariant* _parameters_, GDBusMethodInvocation* invocation);
static void zeitgeist_remote_histogram_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* zeitgeist_remote_histogram_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 zeitgeist_remote_histogram_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 _zeitgeist_remote_histogram_unregister_object (gpointer user_data);
GType zeitgeist_histogram_get_type (void) G_GNUC_CONST;
GType zeitgeist_histogram_register_type (GTypeModule * module);
#define ZEITGEIST_HISTOGRAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ZEITGEIST_TYPE_HISTOGRAM, ZeitgeistHistogramPrivate))
enum  {
	ZEITGEIST_HISTOGRAM_DUMMY_PROPERTY
};
static void zeitgeist_histogram_real_unload (ZeitgeistExtension* base);
static GVariant* zeitgeist_histogram_real_get_histogram_data (ZeitgeistRemoteHistogram* base, GError** error);
ZeitgeistHistogram* zeitgeist_histogram_new (void);
ZeitgeistHistogram* zeitgeist_histogram_construct (GType object_type);
static GObject * zeitgeist_histogram_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void zeitgeist_histogram_finalize (GObject* obj);
GType zeitgeist_histogram_init (GTypeModule* module);

static const GDBusArgInfo _zeitgeist_remote_histogram_dbus_arg_info_get_histogram_data_result = {-1, "result", "a(xu)"};
static const GDBusArgInfo * const _zeitgeist_remote_histogram_dbus_arg_info_get_histogram_data_in[] = {NULL};
static const GDBusArgInfo * const _zeitgeist_remote_histogram_dbus_arg_info_get_histogram_data_out[] = {&_zeitgeist_remote_histogram_dbus_arg_info_get_histogram_data_result, NULL};
static const GDBusMethodInfo _zeitgeist_remote_histogram_dbus_method_info_get_histogram_data = {-1, "GetHistogramData", (GDBusArgInfo **) (&_zeitgeist_remote_histogram_dbus_arg_info_get_histogram_data_in), (GDBusArgInfo **) (&_zeitgeist_remote_histogram_dbus_arg_info_get_histogram_data_out)};
static const GDBusMethodInfo * const _zeitgeist_remote_histogram_dbus_method_info[] = {&_zeitgeist_remote_histogram_dbus_method_info_get_histogram_data, NULL};
static const GDBusSignalInfo * const _zeitgeist_remote_histogram_dbus_signal_info[] = {NULL};
static const GDBusPropertyInfo * const _zeitgeist_remote_histogram_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _zeitgeist_remote_histogram_dbus_interface_info = {-1, "org.gnome.zeitgeist.Histogram", (GDBusMethodInfo **) (&_zeitgeist_remote_histogram_dbus_method_info), (GDBusSignalInfo **) (&_zeitgeist_remote_histogram_dbus_signal_info), (GDBusPropertyInfo **) (&_zeitgeist_remote_histogram_dbus_property_info)};
static const GDBusInterfaceVTable _zeitgeist_remote_histogram_dbus_interface_vtable = {zeitgeist_remote_histogram_dbus_interface_method_call, zeitgeist_remote_histogram_dbus_interface_get_property, zeitgeist_remote_histogram_dbus_interface_set_property};

GVariant* zeitgeist_remote_histogram_get_histogram_data (ZeitgeistRemoteHistogram* self, GError** error) {
	g_return_val_if_fail (self != NULL, NULL);
	return ZEITGEIST_REMOTE_HISTOGRAM_GET_INTERFACE (self)->get_histogram_data (self, error);
}


static void zeitgeist_remote_histogram_base_init (ZeitgeistRemoteHistogramIface * iface) {
	static gboolean initialized = FALSE;
	if (!initialized) {
		initialized = TRUE;
	}
}


GType zeitgeist_remote_histogram_get_type (void) {
	return zeitgeist_remote_histogram_type_id;
}


GType zeitgeist_remote_histogram_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (ZeitgeistRemoteHistogramIface), (GBaseInitFunc) zeitgeist_remote_histogram_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	zeitgeist_remote_histogram_type_id = g_type_module_register_type (module, G_TYPE_INTERFACE, "ZeitgeistRemoteHistogram", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (zeitgeist_remote_histogram_type_id, G_TYPE_OBJECT);
	g_type_set_qdata (zeitgeist_remote_histogram_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) zeitgeist_remote_histogram_proxy_get_type);
	g_type_set_qdata (zeitgeist_remote_histogram_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.gnome.zeitgeist.Histogram");
	g_type_set_qdata (zeitgeist_remote_histogram_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_zeitgeist_remote_histogram_dbus_interface_info));
	g_type_set_qdata (zeitgeist_remote_histogram_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) zeitgeist_remote_histogram_register_object);
	return zeitgeist_remote_histogram_type_id;
}


G_DEFINE_DYNAMIC_TYPE_EXTENDED (ZeitgeistRemoteHistogramProxy, zeitgeist_remote_histogram_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE_DYNAMIC (ZEITGEIST_TYPE_REMOTE_HISTOGRAM, zeitgeist_remote_histogram_proxy_zeitgeist_remote_histogram_interface_init) )
static void zeitgeist_remote_histogram_proxy_class_init (ZeitgeistRemoteHistogramProxyClass* klass) {
	G_DBUS_PROXY_CLASS (klass)->g_signal = zeitgeist_remote_histogram_proxy_g_signal;
}


static void zeitgeist_remote_histogram_proxy_g_signal (GDBusProxy* proxy, const gchar* sender_name, const gchar* signal_name, GVariant* parameters) {
}


static void zeitgeist_remote_histogram_proxy_class_finalize (ZeitgeistRemoteHistogramProxyClass* klass) {
}


void zeitgeist_remote_histogram_proxy_register_dynamic_type (GTypeModule* module) {
	zeitgeist_remote_histogram_proxy_register_type (module);
}


static void zeitgeist_remote_histogram_proxy_init (ZeitgeistRemoteHistogramProxy* self) {
}


static GVariant* zeitgeist_remote_histogram_proxy_get_histogram_data (ZeitgeistRemoteHistogram* self, GError** error) {
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	GVariant *_reply;
	GVariantIter _reply_iter;
	GVariant* _result;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.gnome.zeitgeist.Histogram", "GetHistogramData");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_message_set_body (_message, _arguments);
	_reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error);
	g_object_unref (_message);
	if (!_reply_message) {
		return NULL;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		g_object_unref (_reply_message);
		return NULL;
	}
	_reply = g_dbus_message_get_body (_reply_message);
	g_variant_iter_init (&_reply_iter, _reply);
	_result = g_variant_iter_next_value (&_reply_iter);
	g_object_unref (_reply_message);
	return _result;
}


static void zeitgeist_remote_histogram_proxy_zeitgeist_remote_histogram_interface_init (ZeitgeistRemoteHistogramIface* iface) {
	iface->get_histogram_data = zeitgeist_remote_histogram_proxy_get_histogram_data;
}


static void _dbus_zeitgeist_remote_histogram_get_histogram_data (ZeitgeistRemoteHistogram* self, GVariant* _parameters_, GDBusMethodInvocation* invocation) {
	GError* error = NULL;
	GVariantIter _arguments_iter;
	GDBusMessage* _reply_message;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	GVariant* result;
	g_variant_iter_init (&_arguments_iter, _parameters_);
	result = zeitgeist_remote_histogram_get_histogram_data (self, &error);
	if (error) {
		g_dbus_method_invocation_return_gerror (invocation, error);
		return;
	}
	_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);
	g_variant_builder_add_value (&_reply_builder, result);
	_g_variant_unref0 (result);
	_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);
}


static void zeitgeist_remote_histogram_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, "GetHistogramData") == 0) {
		_dbus_zeitgeist_remote_histogram_get_histogram_data (object, parameters, invocation);
	} else {
		g_object_unref (invocation);
	}
}


static GVariant* zeitgeist_remote_histogram_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 zeitgeist_remote_histogram_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 zeitgeist_remote_histogram_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 *) (&_zeitgeist_remote_histogram_dbus_interface_info), &_zeitgeist_remote_histogram_dbus_interface_vtable, data, _zeitgeist_remote_histogram_unregister_object, error);
	if (!result) {
		return 0;
	}
	return result;
}


static void _zeitgeist_remote_histogram_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);
}


static void zeitgeist_histogram_real_unload (ZeitgeistExtension* base) {
	ZeitgeistHistogram * self;
	guint _tmp5_ = 0U;
	GError * _inner_error_ = NULL;
	self = (ZeitgeistHistogram*) base;
	{
		GDBusConnection* connection = NULL;
		GDBusConnection* _tmp0_ = NULL;
		guint _tmp1_ = 0U;
		_tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error_);
		connection = _tmp0_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp1_ = self->priv->registration_id;
		if (_tmp1_ != ((guint) 0)) {
			guint _tmp2_ = 0U;
			_tmp2_ = self->priv->registration_id;
			g_dbus_connection_unregister_object (connection, _tmp2_);
			self->priv->registration_id = (guint) 0;
		}
		_g_object_unref0 (connection);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp3_ = NULL;
		const gchar* _tmp4_ = NULL;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = err;
		_tmp4_ = _tmp3_->message;
		g_warning ("ext-histogram.vala:66: %s", _tmp4_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_tmp5_ = ((GObject*) self)->ref_count;
	g_debug ("ext-histogram.vala:69: %s, this.ref_count = %u", "Zeitgeist.Histogram.unload", _tmp5_);
}


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


static GVariant* zeitgeist_histogram_real_get_histogram_data (ZeitgeistRemoteHistogram* base, GError** error) {
	ZeitgeistHistogram * self;
	GVariant* result = NULL;
	GVariantBuilder* builder = NULL;
	GVariantType* _tmp0_ = NULL;
	GVariantType* _tmp1_ = NULL;
	GVariantBuilder* _tmp2_ = NULL;
	GVariantBuilder* _tmp3_ = NULL;
	gchar* sql = NULL;
	gchar* _tmp4_ = NULL;
	sqlite3_stmt* stmt = NULL;
	ZeitgeistSQLiteDatabase* database = NULL;
	ZeitgeistEngine* _tmp5_ = NULL;
	ZeitgeistEngine* _tmp6_ = NULL;
	ZeitgeistSQLiteDatabase* _tmp7_ = NULL;
	ZeitgeistSQLiteDatabase* _tmp8_ = NULL;
	ZeitgeistSQLiteDatabase* _tmp9_ = NULL;
	sqlite3* db = NULL;
	ZeitgeistSQLiteDatabase* _tmp10_ = NULL;
	sqlite3* _tmp11_ = NULL;
	gint rc = 0;
	sqlite3* _tmp12_ = NULL;
	const gchar* _tmp13_ = NULL;
	sqlite3_stmt* _tmp14_ = NULL;
	gint _tmp15_ = 0;
	ZeitgeistSQLiteDatabase* _tmp16_ = NULL;
	gint _tmp17_ = 0;
	ZeitgeistSQLiteDatabase* _tmp28_ = NULL;
	gint _tmp29_ = 0;
	GVariantBuilder* _tmp30_ = NULL;
	GVariant* _tmp31_ = NULL;
	GError * _inner_error_ = NULL;
	self = (ZeitgeistHistogram*) base;
	_tmp0_ = g_variant_type_new ("a(xu)");
	_tmp1_ = _tmp0_;
	_tmp2_ = g_variant_builder_new (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_variant_type_free0 (_tmp1_);
	builder = _tmp3_;
	_tmp4_ = g_strdup ("\n" \
"                SELECT strftime('%s', datetime(timestamp/1000, 'unixep" \
"och',\n" \
"                'localtime'), 'start of day') AS daystamp,\n" \
"                COUNT(*)\n" \
"                FROM event\n" \
"                GROUP BY daystamp\n" \
"                ORDER BY daystamp DESC\n" \
"                ");
	sql = _tmp4_;
	_tmp5_ = zeitgeist_extension_get_engine ((ZeitgeistExtension*) self);
	_tmp6_ = _tmp5_;
	_tmp7_ = zeitgeist_db_reader_get_database ((ZeitgeistDbReader*) _tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = _g_object_ref0 (_tmp8_);
	database = _tmp9_;
	_tmp10_ = database;
	_tmp11_ = _tmp10_->database;
	db = _tmp11_;
	_tmp12_ = db;
	_tmp13_ = sql;
	_tmp15_ = sqlite3_prepare_v2 (_tmp12_, _tmp13_, -1, &_tmp14_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp14_;
	rc = _tmp15_;
	_tmp16_ = database;
	_tmp17_ = rc;
	zeitgeist_sq_lite_database_assert_query_success (_tmp16_, _tmp17_, "ext-histogram.vala:90: SQL error", SQLITE_OK, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (database);
		_sqlite3_finalize0 (stmt);
		_g_free0 (sql);
		_g_variant_builder_unref0 (builder);
		return NULL;
	}
	while (TRUE) {
		sqlite3_stmt* _tmp18_ = NULL;
		gint _tmp19_ = 0;
		gint _tmp20_ = 0;
		gint64 t = 0LL;
		sqlite3_stmt* _tmp21_ = NULL;
		gint64 _tmp22_ = 0LL;
		guint32 count = 0U;
		sqlite3_stmt* _tmp23_ = NULL;
		gint _tmp24_ = 0;
		GVariantBuilder* _tmp25_ = NULL;
		gint64 _tmp26_ = 0LL;
		guint32 _tmp27_ = 0U;
		_tmp18_ = stmt;
		_tmp19_ = sqlite3_step (_tmp18_);
		rc = _tmp19_;
		_tmp20_ = rc;
		if (!(_tmp20_ == SQLITE_ROW)) {
			break;
		}
		_tmp21_ = stmt;
		_tmp22_ = sqlite3_column_int64 (_tmp21_, 0);
		t = _tmp22_;
		_tmp23_ = stmt;
		_tmp24_ = sqlite3_column_int (_tmp23_, 1);
		count = (guint32) _tmp24_;
		_tmp25_ = builder;
		_tmp26_ = t;
		_tmp27_ = count;
		g_variant_builder_add (_tmp25_, "(xu)", _tmp26_, _tmp27_, NULL);
	}
	_tmp28_ = database;
	_tmp29_ = rc;
	zeitgeist_sq_lite_database_assert_query_success (_tmp28_, _tmp29_, "Error in get_histogram_data", SQLITE_DONE, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (database);
		_sqlite3_finalize0 (stmt);
		_g_free0 (sql);
		_g_variant_builder_unref0 (builder);
		return NULL;
	}
	_tmp30_ = builder;
	_tmp31_ = g_variant_builder_end (_tmp30_);
	g_variant_ref_sink (_tmp31_);
	result = _tmp31_;
	_g_object_unref0 (database);
	_sqlite3_finalize0 (stmt);
	_g_free0 (sql);
	_g_variant_builder_unref0 (builder);
	return result;
}


ZeitgeistHistogram* zeitgeist_histogram_construct (GType object_type) {
	ZeitgeistHistogram * self = NULL;
	self = (ZeitgeistHistogram*) zeitgeist_extension_construct (object_type);
	return self;
}


ZeitgeistHistogram* zeitgeist_histogram_new (void) {
	return zeitgeist_histogram_construct (ZEITGEIST_TYPE_HISTOGRAM);
}


static GObject * zeitgeist_histogram_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	ZeitgeistHistogram * self;
	GError * _inner_error_ = NULL;
	parent_class = G_OBJECT_CLASS (zeitgeist_histogram_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ZEITGEIST_TYPE_HISTOGRAM, ZeitgeistHistogram);
	{
		GDBusConnection* connection = NULL;
		GDBusConnection* _tmp0_ = NULL;
		guint _tmp1_ = 0U;
		GDBusConnection* _tmp2_ = NULL;
		guint _tmp3_ = 0U;
		_tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error_);
		connection = _tmp0_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch1_g_error;
		}
		_tmp2_ = connection;
		_tmp3_ = zeitgeist_remote_histogram_register_object ((ZeitgeistRemoteHistogram*) self, _tmp2_, "/org/gnome/zeitgeist/journal/activity", &_inner_error_);
		_tmp1_ = _tmp3_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_object_unref0 (connection);
			goto __catch1_g_error;
		}
		self->priv->registration_id = _tmp1_;
		_g_object_unref0 (connection);
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* err = NULL;
		GError* _tmp4_ = NULL;
		const gchar* _tmp5_ = NULL;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = err;
		_tmp5_ = _tmp4_->message;
		g_warning ("ext-histogram.vala:49: %s", _tmp5_);
		_g_error_free0 (err);
	}
	__finally1:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
	}
	return obj;
}


static void zeitgeist_histogram_class_init (ZeitgeistHistogramClass * klass) {
	zeitgeist_histogram_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ZeitgeistHistogramPrivate));
	((ZeitgeistExtensionClass *) klass)->unload = zeitgeist_histogram_real_unload;
	G_OBJECT_CLASS (klass)->constructor = zeitgeist_histogram_constructor;
	G_OBJECT_CLASS (klass)->finalize = zeitgeist_histogram_finalize;
}


static void zeitgeist_histogram_zeitgeist_remote_histogram_interface_init (ZeitgeistRemoteHistogramIface * iface) {
	zeitgeist_histogram_zeitgeist_remote_histogram_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_histogram_data = (GVariant* (*)(ZeitgeistRemoteHistogram*, GError**)) zeitgeist_histogram_real_get_histogram_data;
}


static void zeitgeist_histogram_instance_init (ZeitgeistHistogram * self) {
	self->priv = ZEITGEIST_HISTOGRAM_GET_PRIVATE (self);
	self->priv->registration_id = (guint) 0;
}


static void zeitgeist_histogram_finalize (GObject* obj) {
	ZeitgeistHistogram * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ZEITGEIST_TYPE_HISTOGRAM, ZeitgeistHistogram);
	G_OBJECT_CLASS (zeitgeist_histogram_parent_class)->finalize (obj);
}


GType zeitgeist_histogram_get_type (void) {
	return zeitgeist_histogram_type_id;
}


GType zeitgeist_histogram_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (ZeitgeistHistogramClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) zeitgeist_histogram_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ZeitgeistHistogram), 0, (GInstanceInitFunc) zeitgeist_histogram_instance_init, NULL };
	static const GInterfaceInfo zeitgeist_remote_histogram_info = { (GInterfaceInitFunc) zeitgeist_histogram_zeitgeist_remote_histogram_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	zeitgeist_histogram_type_id = g_type_module_register_type (module, ZEITGEIST_TYPE_EXTENSION, "ZeitgeistHistogram", &g_define_type_info, 0);
	g_type_module_add_interface (module, zeitgeist_histogram_type_id, ZEITGEIST_TYPE_REMOTE_HISTOGRAM, &zeitgeist_remote_histogram_info);
	return zeitgeist_histogram_type_id;
}


GType zeitgeist_histogram_init (GTypeModule* module) {
	GType result = 0UL;
	g_return_val_if_fail (module != NULL, 0UL);
	zeitgeist_remote_histogram_register_type (module);
	zeitgeist_remote_histogram_proxy_register_dynamic_type (module);
	zeitgeist_histogram_register_type (module);
	result = ZEITGEIST_TYPE_HISTOGRAM;
	return result;
}



