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


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "glibtop/mem.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_MEM_PROVIDER (mem_provider_get_type ())
#define MEM_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MEM_PROVIDER, MemProvider))
#define MEM_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MEM_PROVIDER, MemProviderClass))
#define IS_MEM_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MEM_PROVIDER))
#define IS_MEM_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MEM_PROVIDER))
#define MEM_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MEM_PROVIDER, MemProviderClass))

typedef struct _MemProvider MemProvider;
typedef struct _MemProviderClass MemProviderClass;
typedef struct _MemProviderPrivate MemProviderPrivate;

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

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

struct _MemProvider {
	Provider parent_instance;
	MemProviderPrivate * priv;
};

struct _MemProviderClass {
	ProviderClass parent_class;
};


static gpointer mem_provider_parent_class = NULL;

GType provider_get_type (void) G_GNUC_CONST;
GType mem_provider_get_type (void) G_GNUC_CONST;
enum  {
	MEM_PROVIDER_DUMMY_PROPERTY
};
MemProvider* mem_provider_new (void);
MemProvider* mem_provider_construct (GType object_type);
Provider* provider_construct (GType object_type, const gchar* id, gchar** keys, int keys_length1, gchar displaytype);
static void mem_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);


MemProvider* mem_provider_construct (GType object_type) {
	MemProvider * self = NULL;
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar** _tmp6_ = NULL;
	gchar** _tmp7_ = NULL;
	gint _tmp7__length1 = 0;
	_tmp0_ = g_strdup ("user");
	_tmp1_ = g_strdup ("shared");
	_tmp2_ = g_strdup ("buffer");
	_tmp3_ = g_strdup ("cached");
	_tmp4_ = g_strdup ("total");
	_tmp5_ = g_strdup ("used");
	_tmp6_ = g_new0 (gchar*, 6 + 1);
	_tmp6_[0] = _tmp0_;
	_tmp6_[1] = _tmp1_;
	_tmp6_[2] = _tmp2_;
	_tmp6_[3] = _tmp3_;
	_tmp6_[4] = _tmp4_;
	_tmp6_[5] = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp7__length1 = 6;
	self = (MemProvider*) provider_construct (object_type, "mem", _tmp7_, 6, 'i');
	_tmp7_ = (_vala_array_free (_tmp7_, _tmp7__length1, (GDestroyNotify) g_free), NULL);
	return self;
}


MemProvider* mem_provider_new (void) {
	return mem_provider_construct (TYPE_MEM_PROVIDER);
}


static void mem_provider_real_update (Provider* base) {
	MemProvider * self;
	glibtop_mem mem = {0};
	glibtop_mem _tmp0_ = {0};
	gdouble* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	gdouble* _tmp2_ = NULL;
	gint _tmp2__length1 = 0;
	glibtop_mem _tmp3_ = {0};
	guint64 _tmp4_ = 0ULL;
	gdouble _tmp5_ = 0.0;
	gdouble* _tmp6_ = NULL;
	gint _tmp6__length1 = 0;
	gdouble* _tmp7_ = NULL;
	gint _tmp7__length1 = 0;
	glibtop_mem _tmp8_ = {0};
	guint64 _tmp9_ = 0ULL;
	gdouble _tmp10_ = 0.0;
	gdouble* _tmp11_ = NULL;
	gint _tmp11__length1 = 0;
	gdouble* _tmp12_ = NULL;
	gint _tmp12__length1 = 0;
	glibtop_mem _tmp13_ = {0};
	guint64 _tmp14_ = 0ULL;
	gdouble _tmp15_ = 0.0;
	gdouble* _tmp16_ = NULL;
	gint _tmp16__length1 = 0;
	gdouble* _tmp17_ = NULL;
	gint _tmp17__length1 = 0;
	glibtop_mem _tmp18_ = {0};
	guint64 _tmp19_ = 0ULL;
	gdouble _tmp20_ = 0.0;
	gdouble* _tmp21_ = NULL;
	gint _tmp21__length1 = 0;
	gdouble* _tmp22_ = NULL;
	gint _tmp22__length1 = 0;
	glibtop_mem _tmp23_ = {0};
	guint64 _tmp24_ = 0ULL;
	gdouble _tmp25_ = 0.0;
	gdouble* _tmp26_ = NULL;
	gint _tmp26__length1 = 0;
	gdouble* _tmp27_ = NULL;
	gint _tmp27__length1 = 0;
	glibtop_mem _tmp28_ = {0};
	guint64 _tmp29_ = 0ULL;
	glibtop_mem _tmp30_ = {0};
	guint64 _tmp31_ = 0ULL;
	glibtop_mem _tmp32_ = {0};
	guint64 _tmp33_ = 0ULL;
	gdouble _tmp34_ = 0.0;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_MEM_PROVIDER, MemProvider);
	glibtop_get_mem (&_tmp0_);
	mem = _tmp0_;
	_tmp1_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp1__length1);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	_tmp3_ = mem;
	_tmp4_ = _tmp3_.user;
	_tmp2_[0] = (gdouble) _tmp4_;
	_tmp5_ = _tmp2_[0];
	_tmp6_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp6__length1);
	_tmp7_ = _tmp6_;
	_tmp7__length1 = _tmp6__length1;
	_tmp8_ = mem;
	_tmp9_ = _tmp8_.shared;
	_tmp7_[1] = (gdouble) _tmp9_;
	_tmp10_ = _tmp7_[1];
	_tmp11_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp11__length1);
	_tmp12_ = _tmp11_;
	_tmp12__length1 = _tmp11__length1;
	_tmp13_ = mem;
	_tmp14_ = _tmp13_.buffer;
	_tmp12_[2] = (gdouble) _tmp14_;
	_tmp15_ = _tmp12_[2];
	_tmp16_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp16__length1);
	_tmp17_ = _tmp16_;
	_tmp17__length1 = _tmp16__length1;
	_tmp18_ = mem;
	_tmp19_ = _tmp18_.cached;
	_tmp17_[3] = (gdouble) _tmp19_;
	_tmp20_ = _tmp17_[3];
	_tmp21_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp21__length1);
	_tmp22_ = _tmp21_;
	_tmp22__length1 = _tmp21__length1;
	_tmp23_ = mem;
	_tmp24_ = _tmp23_.total;
	_tmp22_[4] = (gdouble) _tmp24_;
	_tmp25_ = _tmp22_[4];
	_tmp26_ = provider_get_values (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_PROVIDER, Provider), &_tmp26__length1);
	_tmp27_ = _tmp26_;
	_tmp27__length1 = _tmp26__length1;
	_tmp28_ = mem;
	_tmp29_ = _tmp28_.shared;
	_tmp30_ = mem;
	_tmp31_ = _tmp30_.buffer;
	_tmp32_ = mem;
	_tmp33_ = _tmp32_.cached;
	_tmp27_[5] = (gdouble) ((_tmp29_ + _tmp31_) + _tmp33_);
	_tmp34_ = _tmp27_[5];
}


static void mem_provider_class_init (MemProviderClass * klass) {
	mem_provider_parent_class = g_type_class_peek_parent (klass);
	PROVIDER_CLASS (klass)->update = mem_provider_real_update;
}


static void mem_provider_instance_init (MemProvider * 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 mem_provider_get_type (void) {
	static volatile gsize mem_provider_type_id__volatile = 0;
	if (g_once_init_enter (&mem_provider_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (MemProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mem_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MemProvider), 0, (GInstanceInitFunc) mem_provider_instance_init, NULL };
		GType mem_provider_type_id;
		mem_provider_type_id = g_type_register_static (TYPE_PROVIDER, "MemProvider", &g_define_type_info, 0);
		g_once_init_leave (&mem_provider_type_id__volatile, mem_provider_type_id);
	}
	return mem_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);
}



