/* swapprovider.c generated by valac 0.22.1, the Vala compiler
 * generated from swapprovider.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "glibtop/swap.h"
#include <float.h>
#include <math.h>


#define TYPE_PROVIDER (provider_get_type ())
#define PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PROVIDER, Provider))
#define PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PROVIDER, ProviderClass))
#define IS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PROVIDER))
#define IS_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PROVIDER))
#define PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PROVIDER, ProviderClass))

typedef struct _Provider Provider;
typedef struct _ProviderClass ProviderClass;
typedef struct _ProviderPrivate ProviderPrivate;

#define TYPE_SWAP_PROVIDER (swap_provider_get_type ())
#define SWAP_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SWAP_PROVIDER, SwapProvider))
#define SWAP_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SWAP_PROVIDER, SwapProviderClass))
#define IS_SWAP_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SWAP_PROVIDER))
#define IS_SWAP_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SWAP_PROVIDER))
#define SWAP_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SWAP_PROVIDER, SwapProviderClass))

typedef struct _SwapProvider SwapProvider;
typedef struct _SwapProviderClass SwapProviderClass;
typedef struct _SwapProviderPrivate SwapProviderPrivate;

struct _Provider {
	GObject parent_instance;
	ProviderPrivate * priv;
};

struct _ProviderClass {
	GObjectClass parent_class;
	void (*update) (Provider* self);
};

struct _SwapProvider {
	Provider parent_instance;
	SwapProviderPrivate * priv;
};

struct _SwapProviderClass {
	ProviderClass parent_class;
};


static gpointer swap_provider_parent_class = NULL;

GType provider_get_type (void) G_GNUC_CONST;
GType swap_provider_get_type (void) G_GNUC_CONST;
enum  {
	SWAP_PROVIDER_DUMMY_PROPERTY
};
SwapProvider* swap_provider_new (void);
SwapProvider* swap_provider_construct (GType object_type);
Provider* provider_construct (GType object_type, const gchar* id, gchar** keys, int keys_length1, gchar displaytype);
static void swap_provider_real_update (Provider* base);
gdouble* provider_get_values (Provider* self, int* result_length1);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


SwapProvider* swap_provider_construct (GType object_type) {
	SwapProvider * self = NULL;
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar** _tmp2_ = NULL;
	gchar** _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	_tmp0_ = g_strdup ("used");
	_tmp1_ = g_strdup ("total");
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 2;
	self = (SwapProvider*) provider_construct (object_type, "swap", _tmp3_, 2, 'i');
	_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
	return self;
}


SwapProvider* swap_provider_new (void) {
	return swap_provider_construct (TYPE_SWAP_PROVIDER);
}


static void swap_provider_real_update (Provider* base) {
	SwapProvider * self;
	glibtop_swap swap = {0};
	glibtop_swap _tmp0_ = {0};
	gdouble* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	gdouble* _tmp2_ = NULL;
	gint _tmp2__length1 = 0;
	glibtop_swap _tmp3_ = {0};
	guint64 _tmp4_ = 0ULL;
	gdouble _tmp5_ = 0.0;
	guint64 _tmp6_ = 0ULL;
	glibtop_swap _tmp7_ = {0};
	guint64 _tmp8_ = 0ULL;
	gdouble* _tmp11_ = NULL;
	gint _tmp11__length1 = 0;
	gdouble* _tmp12_ = NULL;
	gint _tmp12__length1 = 0;
	guint64 _tmp13_ = 0ULL;
	gdouble _tmp14_ = 0.0;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_SWAP_PROVIDER, SwapProvider);
	glibtop_get_swap (&_tmp0_);
	swap = _tmp0_;
	_tmp1_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp1__length1);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	_tmp3_ = swap;
	_tmp4_ = _tmp3_.used;
	_tmp2_[0] = (gdouble) _tmp4_;
	_tmp5_ = _tmp2_[0];
	_tmp7_ = swap;
	_tmp8_ = _tmp7_.total;
	if (_tmp8_ > ((guint64) 0)) {
		glibtop_swap _tmp9_ = {0};
		guint64 _tmp10_ = 0ULL;
		_tmp9_ = swap;
		_tmp10_ = _tmp9_.total;
		_tmp6_ = _tmp10_;
	} else {
		_tmp6_ = (guint64) 1;
	}
	_tmp11_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp11__length1);
	_tmp12_ = _tmp11_;
	_tmp12__length1 = _tmp11__length1;
	_tmp13_ = _tmp6_;
	_tmp12_[1] = (gdouble) _tmp13_;
	_tmp14_ = _tmp12_[1];
}


static void swap_provider_class_init (SwapProviderClass * klass) {
	swap_provider_parent_class = g_type_class_peek_parent (klass);
	PROVIDER_CLASS (klass)->update = swap_provider_real_update;
}


static void swap_provider_instance_init (SwapProvider * self) {
}


/******************************************************************************
 * Copyright (C) 2011-2013  Michael Hofmann <mh21@mh21.de>                    *
 *                                                                            *
 * This program 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 3 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 General Public License along    *
 * with this program; if not, write to the Free Software Foundation, Inc.,    *
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                *
 ******************************************************************************/
GType swap_provider_get_type (void) {
	static volatile gsize swap_provider_type_id__volatile = 0;
	if (g_once_init_enter (&swap_provider_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (SwapProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) swap_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SwapProvider), 0, (GInstanceInitFunc) swap_provider_instance_init, NULL };
		GType swap_provider_type_id;
		swap_provider_type_id = g_type_register_static (TYPE_PROVIDER, "SwapProvider", &g_define_type_info, 0);
		g_once_init_leave (&swap_provider_type_id__volatile, swap_provider_type_id);
	}
	return swap_provider_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



