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

/*
 * Copyright (C) 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.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <libtracker-common/tracker-common.h>
#include <libtracker-data/tracker-ontologies.h>
#include <libtracker-data/tracker-class.h>
#include <gio/gio.h>


#define TRACKER_TYPE_STATISTICS (tracker_statistics_get_type ())
#define TRACKER_STATISTICS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TRACKER_TYPE_STATISTICS, TrackerStatistics))
#define TRACKER_STATISTICS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_STATISTICS, TrackerStatisticsClass))
#define TRACKER_IS_STATISTICS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TRACKER_TYPE_STATISTICS))
#define TRACKER_IS_STATISTICS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_STATISTICS))
#define TRACKER_STATISTICS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_STATISTICS, TrackerStatisticsClass))

typedef struct _TrackerStatistics TrackerStatistics;
typedef struct _TrackerStatisticsClass TrackerStatisticsClass;
typedef struct _TrackerStatisticsPrivate TrackerStatisticsPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (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)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

struct _TrackerStatistics {
	GObject parent_instance;
	TrackerStatisticsPrivate * priv;
};

struct _TrackerStatisticsClass {
	GObjectClass parent_class;
};


static gpointer tracker_statistics_parent_class = NULL;

GType tracker_statistics_get_type (void) G_GNUC_CONST;
guint tracker_statistics_register_object (void* object, GDBusConnection* connection, const gchar* path, GError** error);
enum  {
	TRACKER_STATISTICS_DUMMY_PROPERTY
};
#define TRACKER_STATISTICS_PATH "/org/freedesktop/Tracker1/Statistics"
GVariant* tracker_statistics_get (TrackerStatistics* self, const char* sender);
TrackerStatistics* tracker_statistics_new (void);
TrackerStatistics* tracker_statistics_construct (GType object_type);
static void _dbus_tracker_statistics_get (TrackerStatistics* self, GVariant* parameters, GDBusMethodInvocation* invocation);
static void tracker_statistics_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_statistics_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_statistics_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_statistics_unregister_object (gpointer user_data);

static const GDBusArgInfo _tracker_statistics_dbus_arg_info_get_result = {-1, "result", "aas"};
static const GDBusArgInfo * const _tracker_statistics_dbus_arg_info_get_in[] = {NULL};
static const GDBusArgInfo * const _tracker_statistics_dbus_arg_info_get_out[] = {&_tracker_statistics_dbus_arg_info_get_result, NULL};
static const GDBusMethodInfo _tracker_statistics_dbus_method_info_get = {-1, "Get", (GDBusArgInfo **) (&_tracker_statistics_dbus_arg_info_get_in), (GDBusArgInfo **) (&_tracker_statistics_dbus_arg_info_get_out)};
static const GDBusMethodInfo * const _tracker_statistics_dbus_method_info[] = {&_tracker_statistics_dbus_method_info_get, NULL};
static const GDBusSignalInfo * const _tracker_statistics_dbus_signal_info[] = {NULL};
static const GDBusPropertyInfo * const _tracker_statistics_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _tracker_statistics_dbus_interface_info = {-1, "org.freedesktop.Tracker1.Statistics", (GDBusMethodInfo **) (&_tracker_statistics_dbus_method_info), (GDBusSignalInfo **) (&_tracker_statistics_dbus_signal_info), (GDBusPropertyInfo **) (&_tracker_statistics_dbus_property_info)};
static const GDBusInterfaceVTable _tracker_statistics_dbus_interface_vtable = {tracker_statistics_dbus_interface_method_call, tracker_statistics_dbus_interface_get_property, tracker_statistics_dbus_interface_set_property};

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


GVariant* tracker_statistics_get (TrackerStatistics* self, const char* sender) {
	GVariant* result = NULL;
	TrackerDBusRequest* _tmp0_ = NULL;
	TrackerDBusRequest* request;
	GVariantBuilder* _tmp1_ = NULL;
	GVariantBuilder* builder;
	gint _tmp2_;
	TrackerClass** _tmp3_ = NULL;
	GVariant* _tmp10_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (sender != NULL, NULL);
	_tmp0_ = tracker_dbus_request_begin ((const gchar*) sender, "Statistics.Get", NULL);
	request = _tmp0_;
	_tmp1_ = g_variant_builder_new ((GVariantType*) "aas");
	builder = _tmp1_;
	_tmp3_ = tracker_ontologies_get_classes (&_tmp2_);
	{
		TrackerClass** cl_collection;
		int cl_collection_length1;
		int cl_it;
		cl_collection = _tmp3_;
		cl_collection_length1 = _tmp2_;
		for (cl_it = 0; cl_it < _tmp2_; cl_it = cl_it + 1) {
			TrackerClass* _tmp4_;
			TrackerClass* cl;
			_tmp4_ = _g_object_ref0 (cl_collection[cl_it]);
			cl = _tmp4_;
			{
				gint _tmp5_;
				const gchar* _tmp6_ = NULL;
				gint _tmp7_;
				gchar* _tmp8_ = NULL;
				gchar* _tmp9_;
				_tmp5_ = tracker_class_get_count (cl);
				if (_tmp5_ == 0) {
					_g_object_unref0 (cl);
					continue;
				}
				g_variant_builder_open (builder, (GVariantType*) "as");
				_tmp6_ = tracker_class_get_name (cl);
				g_variant_builder_add (builder, "s", _tmp6_, NULL);
				_tmp7_ = tracker_class_get_count (cl);
				_tmp8_ = g_strdup_printf ("%i", _tmp7_);
				_tmp9_ = _tmp8_;
				g_variant_builder_add (builder, "s", _tmp9_, NULL);
				_g_free0 (_tmp9_);
				g_variant_builder_close (builder);
				_g_object_unref0 (cl);
			}
		}
	}
	tracker_dbus_request_end (request, NULL);
	_tmp10_ = g_variant_builder_end (builder);
	result = g_variant_ref_sink (_tmp10_);
	_g_variant_builder_unref0 (builder);
	return result;
}


TrackerStatistics* tracker_statistics_construct (GType object_type) {
	TrackerStatistics * self = NULL;
	self = (TrackerStatistics*) g_object_new (object_type, NULL);
	return self;
}


TrackerStatistics* tracker_statistics_new (void) {
	return tracker_statistics_construct (TRACKER_TYPE_STATISTICS);
}


static void tracker_statistics_class_init (TrackerStatisticsClass * klass) {
	tracker_statistics_parent_class = g_type_class_peek_parent (klass);
}


static void tracker_statistics_instance_init (TrackerStatistics * self) {
}


GType tracker_statistics_get_type (void) {
	static volatile gsize tracker_statistics_type_id__volatile = 0;
	if (g_once_init_enter (&tracker_statistics_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (TrackerStatisticsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tracker_statistics_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TrackerStatistics), 0, (GInstanceInitFunc) tracker_statistics_instance_init, NULL };
		GType tracker_statistics_type_id;
		tracker_statistics_type_id = g_type_register_static (G_TYPE_OBJECT, "TrackerStatistics", &g_define_type_info, 0);
		g_type_set_qdata (tracker_statistics_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) tracker_statistics_register_object);
		g_once_init_leave (&tracker_statistics_type_id__volatile, tracker_statistics_type_id);
	}
	return tracker_statistics_type_id__volatile;
}


static void _dbus_tracker_statistics_get (TrackerStatistics* 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 = tracker_statistics_get (self, g_dbus_method_invocation_get_sender (invocation));
	_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 tracker_statistics_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, "Get") == 0) {
		_dbus_tracker_statistics_get (object, parameters, invocation);
	} else {
		g_object_unref (invocation);
	}
}


static GVariant* tracker_statistics_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_statistics_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_statistics_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_statistics_dbus_interface_info), &_tracker_statistics_dbus_interface_vtable, data, _tracker_statistics_unregister_object, error);
	if (!result) {
		return 0;
	}
	return result;
}


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



