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


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "glibtop/loadavg.h"
#include <float.h>
#include <math.h>
#include "glibtop.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_LOAD_PROVIDER (load_provider_get_type ())
#define LOAD_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LOAD_PROVIDER, LoadProvider))
#define LOAD_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LOAD_PROVIDER, LoadProviderClass))
#define IS_LOAD_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LOAD_PROVIDER))
#define IS_LOAD_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LOAD_PROVIDER))
#define LOAD_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LOAD_PROVIDER, LoadProviderClass))

typedef struct _LoadProvider LoadProvider;
typedef struct _LoadProviderClass LoadProviderClass;
typedef struct _LoadProviderPrivate LoadProviderPrivate;

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

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

struct _LoadProvider {
	Provider parent_instance;
	LoadProviderPrivate * priv;
};

struct _LoadProviderClass {
	ProviderClass parent_class;
};


static gpointer load_provider_parent_class = NULL;

GType provider_get_type (void) G_GNUC_CONST;
GType load_provider_get_type (void) G_GNUC_CONST;
enum  {
	LOAD_PROVIDER_DUMMY_PROPERTY
};
LoadProvider* load_provider_new (void);
LoadProvider* load_provider_construct (GType object_type);
Provider* provider_construct (GType object_type, const gchar* id, gchar** keys, int keys_length1, gchar displaytype);
static void load_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);


LoadProvider* load_provider_construct (GType object_type) {
	LoadProvider * self = NULL;
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar** _tmp4_ = NULL;
	gchar** _tmp5_ = NULL;
	gint _tmp5__length1 = 0;
	_tmp0_ = g_strdup ("avg");
	_tmp1_ = g_strdup ("avg5");
	_tmp2_ = g_strdup ("avg15");
	_tmp3_ = g_strdup ("cpus");
	_tmp4_ = g_new0 (gchar*, 4 + 1);
	_tmp4_[0] = _tmp0_;
	_tmp4_[1] = _tmp1_;
	_tmp4_[2] = _tmp2_;
	_tmp4_[3] = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp5__length1 = 4;
	self = (LoadProvider*) provider_construct (object_type, "load", _tmp5_, 4, 'd');
	_tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_free), NULL);
	return self;
}


LoadProvider* load_provider_new (void) {
	return load_provider_construct (TYPE_LOAD_PROVIDER);
}


static void load_provider_real_update (Provider* base) {
	LoadProvider * self;
	glibtop_loadavg loadavg = {0};
	glibtop_loadavg _tmp0_ = {0};
	gdouble* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	gdouble* _tmp2_ = NULL;
	gint _tmp2__length1 = 0;
	glibtop_loadavg _tmp3_ = {0};
	gdouble* _tmp4_ = NULL;
	gint _tmp4__length1 = 0;
	gdouble _tmp5_ = 0.0;
	gdouble _tmp6_ = 0.0;
	gdouble* _tmp7_ = NULL;
	gint _tmp7__length1 = 0;
	gdouble* _tmp8_ = NULL;
	gint _tmp8__length1 = 0;
	glibtop_loadavg _tmp9_ = {0};
	gdouble* _tmp10_ = NULL;
	gint _tmp10__length1 = 0;
	gdouble _tmp11_ = 0.0;
	gdouble _tmp12_ = 0.0;
	gdouble* _tmp13_ = NULL;
	gint _tmp13__length1 = 0;
	gdouble* _tmp14_ = NULL;
	gint _tmp14__length1 = 0;
	glibtop_loadavg _tmp15_ = {0};
	gdouble* _tmp16_ = NULL;
	gint _tmp16__length1 = 0;
	gdouble _tmp17_ = 0.0;
	gdouble _tmp18_ = 0.0;
	gdouble* _tmp19_ = NULL;
	gint _tmp19__length1 = 0;
	gdouble* _tmp20_ = NULL;
	gint _tmp20__length1 = 0;
	glibtop* _tmp21_ = NULL;
	gint _tmp22_ = 0;
	gdouble _tmp23_ = 0.0;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_LOAD_PROVIDER, LoadProvider);
	glibtop_get_loadavg (&_tmp0_);
	loadavg = _tmp0_;
	_tmp1_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp1__length1);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	_tmp3_ = loadavg;
	_tmp4_ = _tmp3_.loadavg;
	_tmp4__length1 = -1;
	_tmp5_ = _tmp4_[0];
	_tmp2_[0] = _tmp5_;
	_tmp6_ = _tmp2_[0];
	_tmp7_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp7__length1);
	_tmp8_ = _tmp7_;
	_tmp8__length1 = _tmp7__length1;
	_tmp9_ = loadavg;
	_tmp10_ = _tmp9_.loadavg;
	_tmp10__length1 = -1;
	_tmp11_ = _tmp10_[1];
	_tmp8_[1] = _tmp11_;
	_tmp12_ = _tmp8_[1];
	_tmp13_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp13__length1);
	_tmp14_ = _tmp13_;
	_tmp14__length1 = _tmp13__length1;
	_tmp15_ = loadavg;
	_tmp16_ = _tmp15_.loadavg;
	_tmp16__length1 = -1;
	_tmp17_ = _tmp16_[2];
	_tmp14_[2] = _tmp17_;
	_tmp18_ = _tmp14_[2];
	_tmp19_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp19__length1);
	_tmp20_ = _tmp19_;
	_tmp20__length1 = _tmp19__length1;
	_tmp21_ = glibtop_global_server;
	_tmp22_ = (*_tmp21_).ncpu;
	_tmp20_[3] = (gdouble) (_tmp22_ + 1);
	_tmp23_ = _tmp20_[3];
}


static void load_provider_class_init (LoadProviderClass * klass) {
	load_provider_parent_class = g_type_class_peek_parent (klass);
	PROVIDER_CLASS (klass)->update = load_provider_real_update;
}


static void load_provider_instance_init (LoadProvider * 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 load_provider_get_type (void) {
	static volatile gsize load_provider_type_id__volatile = 0;
	if (g_once_init_enter (&load_provider_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (LoadProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) load_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LoadProvider), 0, (GInstanceInitFunc) load_provider_instance_init, NULL };
		GType load_provider_type_id;
		load_provider_type_id = g_type_register_static (TYPE_PROVIDER, "LoadProvider", &g_define_type_info, 0);
		g_once_init_leave (&load_provider_type_id__volatile, load_provider_type_id);
	}
	return load_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);
}



