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


#include <glib.h>
#include <glib-object.h>
#include <fsobasics.h>
#include <freesmartphone.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>


#define FSO_DEVICE_TYPE_ISIMPLE_POWER_CONTROL (fso_device_isimple_power_control_get_type ())
#define FSO_DEVICE_ISIMPLE_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_DEVICE_TYPE_ISIMPLE_POWER_CONTROL, FsoDeviceISimplePowerControl))
#define FSO_DEVICE_IS_ISIMPLE_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_DEVICE_TYPE_ISIMPLE_POWER_CONTROL))
#define FSO_DEVICE_ISIMPLE_POWER_CONTROL_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), FSO_DEVICE_TYPE_ISIMPLE_POWER_CONTROL, FsoDeviceISimplePowerControlIface))

typedef struct _FsoDeviceISimplePowerControl FsoDeviceISimplePowerControl;
typedef struct _FsoDeviceISimplePowerControlIface FsoDeviceISimplePowerControlIface;

#define FSO_DEVICE_TYPE_BASE_POWER_CONTROL (fso_device_base_power_control_get_type ())
#define FSO_DEVICE_BASE_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_DEVICE_TYPE_BASE_POWER_CONTROL, FsoDeviceBasePowerControl))
#define FSO_DEVICE_BASE_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FSO_DEVICE_TYPE_BASE_POWER_CONTROL, FsoDeviceBasePowerControlClass))
#define FSO_DEVICE_IS_BASE_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_DEVICE_TYPE_BASE_POWER_CONTROL))
#define FSO_DEVICE_IS_BASE_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FSO_DEVICE_TYPE_BASE_POWER_CONTROL))
#define FSO_DEVICE_BASE_POWER_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FSO_DEVICE_TYPE_BASE_POWER_CONTROL, FsoDeviceBasePowerControlClass))

typedef struct _FsoDeviceBasePowerControl FsoDeviceBasePowerControl;
typedef struct _FsoDeviceBasePowerControlClass FsoDeviceBasePowerControlClass;
typedef struct _FsoDeviceBasePowerControlPrivate FsoDeviceBasePowerControlPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _FsoDeviceBasePowerControlGetPowerData FsoDeviceBasePowerControlGetPowerData;
typedef struct _FsoDeviceBasePowerControlSetPowerData FsoDeviceBasePowerControlSetPowerData;

struct _FsoDeviceISimplePowerControlIface {
	GTypeInterface parent_iface;
	gboolean (*getPower) (FsoDeviceISimplePowerControl* self);
	void (*setPower) (FsoDeviceISimplePowerControl* self, gboolean on);
};

struct _FsoDeviceBasePowerControl {
	FsoFrameworkAbstractObject parent_instance;
	FsoDeviceBasePowerControlPrivate * priv;
};

struct _FsoDeviceBasePowerControlClass {
	FsoFrameworkAbstractObjectClass parent_class;
	gboolean (*getPower) (FsoDeviceBasePowerControl* self);
	void (*setPower) (FsoDeviceBasePowerControl* self, gboolean on);
};

struct _FsoDeviceBasePowerControlPrivate {
	gchar* powernode;
	gchar* onvalue;
	gchar* offvalue;
	guint switchtimeout;
};

struct _FsoDeviceBasePowerControlGetPowerData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	FsoDeviceBasePowerControl* self;
	gboolean result;
	gboolean _tmp0_;
};

struct _FsoDeviceBasePowerControlSetPowerData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	FsoDeviceBasePowerControl* self;
	gboolean on;
	gboolean _tmp0_;
};


static gpointer fso_device_base_power_control_parent_class = NULL;
extern guint fso_device_base_power_control_counter;
guint fso_device_base_power_control_counter = 0U;
static FsoDeviceISimplePowerControlIface* fso_device_base_power_control_fso_device_isimple_power_control_parent_iface = NULL;
static FreeSmartphoneDevicePowerControlIface* fso_device_base_power_control_free_smartphone_device_power_control_parent_iface = NULL;

GType fso_device_isimple_power_control_get_type (void) G_GNUC_CONST;
gboolean fso_device_isimple_power_control_getPower (FsoDeviceISimplePowerControl* self);
void fso_device_isimple_power_control_setPower (FsoDeviceISimplePowerControl* self, gboolean on);
GType fso_device_base_power_control_get_type (void) G_GNUC_CONST;
#define FSO_DEVICE_BASE_POWER_CONTROL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FSO_DEVICE_TYPE_BASE_POWER_CONTROL, FsoDeviceBasePowerControlPrivate))
enum  {
	FSO_DEVICE_BASE_POWER_CONTROL_DUMMY_PROPERTY
};
FsoDeviceBasePowerControl* fso_device_base_power_control_new (const gchar* powernode, const gchar* onvalue, const gchar* offvalue, guint switchtimeout);
FsoDeviceBasePowerControl* fso_device_base_power_control_construct (GType object_type, const gchar* powernode, const gchar* onvalue, const gchar* offvalue, guint switchtimeout);
static gchar* fso_device_base_power_control_real_repr (FsoFrameworkAbstractObject* base);
gboolean fso_device_base_power_control_getPower (FsoDeviceBasePowerControl* self);
static gboolean fso_device_base_power_control_real_getPower (FsoDeviceBasePowerControl* self);
void fso_device_base_power_control_setPower (FsoDeviceBasePowerControl* self, gboolean on);
static void fso_device_base_power_control_real_setPower (FsoDeviceBasePowerControl* self, gboolean on);
static void fso_device_base_power_control_real_get_power_data_free (gpointer _data);
static void fso_device_base_power_control_real_get_power (FreeSmartphoneDevicePowerControl* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean fso_device_base_power_control_real_get_power_co (FsoDeviceBasePowerControlGetPowerData* _data_);
static void fso_device_base_power_control_real_set_power_data_free (gpointer _data);
static void fso_device_base_power_control_real_set_power (FreeSmartphoneDevicePowerControl* base, gboolean on, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean fso_device_base_power_control_real_set_power_co (FsoDeviceBasePowerControlSetPowerData* _data_);
static void fso_device_base_power_control_finalize (GObject* obj);


gboolean fso_device_isimple_power_control_getPower (FsoDeviceISimplePowerControl* self) {
	g_return_val_if_fail (self != NULL, FALSE);
	return FSO_DEVICE_ISIMPLE_POWER_CONTROL_GET_INTERFACE (self)->getPower (self);
}


void fso_device_isimple_power_control_setPower (FsoDeviceISimplePowerControl* self, gboolean on) {
	g_return_if_fail (self != NULL);
	FSO_DEVICE_ISIMPLE_POWER_CONTROL_GET_INTERFACE (self)->setPower (self, on);
}


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


GType fso_device_isimple_power_control_get_type (void) {
	static volatile gsize fso_device_isimple_power_control_type_id__volatile = 0;
	if (g_once_init_enter (&fso_device_isimple_power_control_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FsoDeviceISimplePowerControlIface), (GBaseInitFunc) fso_device_isimple_power_control_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
		GType fso_device_isimple_power_control_type_id;
		fso_device_isimple_power_control_type_id = g_type_register_static (G_TYPE_INTERFACE, "FsoDeviceISimplePowerControl", &g_define_type_info, 0);
		g_type_interface_add_prerequisite (fso_device_isimple_power_control_type_id, G_TYPE_OBJECT);
		g_once_init_leave (&fso_device_isimple_power_control_type_id__volatile, fso_device_isimple_power_control_type_id);
	}
	return fso_device_isimple_power_control_type_id__volatile;
}


FsoDeviceBasePowerControl* fso_device_base_power_control_construct (GType object_type, const gchar* powernode, const gchar* onvalue, const gchar* offvalue, guint switchtimeout) {
	FsoDeviceBasePowerControl * self = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	guint _tmp6_;
	g_return_val_if_fail (onvalue != NULL, NULL);
	g_return_val_if_fail (offvalue != NULL, NULL);
	self = (FsoDeviceBasePowerControl*) fso_framework_abstract_object_construct (object_type);
	_tmp0_ = powernode;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->powernode);
	self->priv->powernode = _tmp1_;
	_tmp2_ = onvalue;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 (self->priv->onvalue);
	self->priv->onvalue = _tmp3_;
	_tmp4_ = offvalue;
	_tmp5_ = g_strdup (_tmp4_);
	_g_free0 (self->priv->offvalue);
	self->priv->offvalue = _tmp5_;
	_tmp6_ = switchtimeout;
	self->priv->switchtimeout = _tmp6_;
	return self;
}


FsoDeviceBasePowerControl* fso_device_base_power_control_new (const gchar* powernode, const gchar* onvalue, const gchar* offvalue, guint switchtimeout) {
	return fso_device_base_power_control_construct (FSO_DEVICE_TYPE_BASE_POWER_CONTROL, powernode, onvalue, offvalue, switchtimeout);
}


static gchar* fso_device_base_power_control_real_repr (FsoFrameworkAbstractObject* base) {
	FsoDeviceBasePowerControl * self;
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_ = NULL;
	self = (FsoDeviceBasePowerControl*) base;
	_tmp0_ = self->priv->powernode;
	_tmp1_ = g_strdup_printf ("<@ powernode %s>", _tmp0_);
	result = _tmp1_;
	return result;
}


static gboolean fso_device_base_power_control_real_getPower (FsoDeviceBasePowerControl* self) {
	gboolean result = FALSE;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* value;
	const gchar* _tmp3_;
	_tmp0_ = self->priv->powernode;
	g_assert (_tmp0_ != NULL);
	_tmp1_ = self->priv->powernode;
	_tmp2_ = fso_framework_file_handling_read (_tmp1_);
	value = _tmp2_;
	_tmp3_ = self->priv->onvalue;
	result = g_strcmp0 (value, _tmp3_) == 0;
	_g_free0 (value);
	return result;
}


gboolean fso_device_base_power_control_getPower (FsoDeviceBasePowerControl* self) {
	g_return_val_if_fail (self != NULL, FALSE);
	return FSO_DEVICE_BASE_POWER_CONTROL_GET_CLASS (self)->getPower (self);
}


static void fso_device_base_power_control_real_setPower (FsoDeviceBasePowerControl* self, gboolean on) {
	const gchar* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_ = NULL;
	gboolean _tmp4_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	_tmp0_ = self->priv->powernode;
	g_assert (_tmp0_ != NULL);
	_tmp1_ = on;
	_tmp2_ = fso_device_base_power_control_getPower (self);
	if (_tmp1_ == _tmp2_) {
		return;
	}
	_tmp4_ = on;
	if (_tmp4_) {
		const gchar* _tmp5_;
		_tmp5_ = self->priv->onvalue;
		_tmp3_ = _tmp5_;
	} else {
		const gchar* _tmp6_;
		_tmp6_ = self->priv->offvalue;
		_tmp3_ = _tmp6_;
	}
	_tmp7_ = _tmp3_;
	_tmp8_ = self->priv->powernode;
	fso_framework_file_handling_write (_tmp7_, _tmp8_, FALSE);
}


void fso_device_base_power_control_setPower (FsoDeviceBasePowerControl* self, gboolean on) {
	g_return_if_fail (self != NULL);
	FSO_DEVICE_BASE_POWER_CONTROL_GET_CLASS (self)->setPower (self, on);
}


static void fso_device_base_power_control_real_get_power_data_free (gpointer _data) {
	FsoDeviceBasePowerControlGetPowerData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FsoDeviceBasePowerControlGetPowerData, _data_);
}


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


static void fso_device_base_power_control_real_get_power (FreeSmartphoneDevicePowerControl* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	FsoDeviceBasePowerControl * self;
	FsoDeviceBasePowerControlGetPowerData* _data_;
	FsoDeviceBasePowerControl* _tmp0_;
	self = (FsoDeviceBasePowerControl*) base;
	_data_ = g_slice_new0 (FsoDeviceBasePowerControlGetPowerData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, fso_device_base_power_control_real_get_power);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, fso_device_base_power_control_real_get_power_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	fso_device_base_power_control_real_get_power_co (_data_);
}


static gboolean fso_device_base_power_control_real_get_power_finish (FreeSmartphoneDevicePowerControl* base, GAsyncResult* _res_, GError** error) {
	gboolean result;
	FsoDeviceBasePowerControlGetPowerData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return FALSE;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	return result;
}


static gboolean fso_device_base_power_control_real_get_power_co (FsoDeviceBasePowerControlGetPowerData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = FALSE;
	_data_->_tmp0_ = fso_device_base_power_control_getPower (_data_->self);
	_data_->result = _data_->_tmp0_;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void fso_device_base_power_control_real_set_power_data_free (gpointer _data) {
	FsoDeviceBasePowerControlSetPowerData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FsoDeviceBasePowerControlSetPowerData, _data_);
}


static void fso_device_base_power_control_real_set_power (FreeSmartphoneDevicePowerControl* base, gboolean on, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	FsoDeviceBasePowerControl * self;
	FsoDeviceBasePowerControlSetPowerData* _data_;
	FsoDeviceBasePowerControl* _tmp0_;
	gboolean _tmp1_;
	self = (FsoDeviceBasePowerControl*) base;
	_data_ = g_slice_new0 (FsoDeviceBasePowerControlSetPowerData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, fso_device_base_power_control_real_set_power);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, fso_device_base_power_control_real_set_power_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = on;
	_data_->on = _tmp1_;
	fso_device_base_power_control_real_set_power_co (_data_);
}


static void fso_device_base_power_control_real_set_power_finish (FreeSmartphoneDevicePowerControl* base, GAsyncResult* _res_, GError** error) {
	FsoDeviceBasePowerControlSetPowerData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static gboolean fso_device_base_power_control_real_set_power_co (FsoDeviceBasePowerControlSetPowerData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->on;
	fso_device_base_power_control_setPower (_data_->self, _data_->_tmp0_);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void fso_device_base_power_control_class_init (FsoDeviceBasePowerControlClass * klass) {
	fso_device_base_power_control_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (FsoDeviceBasePowerControlPrivate));
	FSO_FRAMEWORK_ABSTRACT_OBJECT_CLASS (klass)->repr = fso_device_base_power_control_real_repr;
	FSO_DEVICE_BASE_POWER_CONTROL_CLASS (klass)->getPower = fso_device_base_power_control_real_getPower;
	FSO_DEVICE_BASE_POWER_CONTROL_CLASS (klass)->setPower = fso_device_base_power_control_real_setPower;
	G_OBJECT_CLASS (klass)->finalize = fso_device_base_power_control_finalize;
}


static void fso_device_base_power_control_fso_device_isimple_power_control_interface_init (FsoDeviceISimplePowerControlIface * iface) {
	fso_device_base_power_control_fso_device_isimple_power_control_parent_iface = g_type_interface_peek_parent (iface);
	iface->getPower = (gboolean (*)(FsoDeviceISimplePowerControl*)) fso_device_base_power_control_getPower;
	iface->setPower = (void (*)(FsoDeviceISimplePowerControl*, gboolean)) fso_device_base_power_control_setPower;
}


static void fso_device_base_power_control_free_smartphone_device_power_control_interface_init (FreeSmartphoneDevicePowerControlIface * iface) {
	fso_device_base_power_control_free_smartphone_device_power_control_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_power = (gboolean (*)(FreeSmartphoneDevicePowerControl*, GError**)) fso_device_base_power_control_real_get_power;
	iface->get_power_finish = fso_device_base_power_control_real_get_power_finish;
	iface->set_power = (void (*)(FreeSmartphoneDevicePowerControl*, gboolean, GError**)) fso_device_base_power_control_real_set_power;
	iface->set_power_finish = fso_device_base_power_control_real_set_power_finish;
}


static void fso_device_base_power_control_instance_init (FsoDeviceBasePowerControl * self) {
	self->priv = FSO_DEVICE_BASE_POWER_CONTROL_GET_PRIVATE (self);
}


static void fso_device_base_power_control_finalize (GObject* obj) {
	FsoDeviceBasePowerControl * self;
	self = FSO_DEVICE_BASE_POWER_CONTROL (obj);
	_g_free0 (self->priv->powernode);
	_g_free0 (self->priv->onvalue);
	_g_free0 (self->priv->offvalue);
	G_OBJECT_CLASS (fso_device_base_power_control_parent_class)->finalize (obj);
}


GType fso_device_base_power_control_get_type (void) {
	static volatile gsize fso_device_base_power_control_type_id__volatile = 0;
	if (g_once_init_enter (&fso_device_base_power_control_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FsoDeviceBasePowerControlClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fso_device_base_power_control_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FsoDeviceBasePowerControl), 0, (GInstanceInitFunc) fso_device_base_power_control_instance_init, NULL };
		static const GInterfaceInfo fso_device_isimple_power_control_info = { (GInterfaceInitFunc) fso_device_base_power_control_fso_device_isimple_power_control_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		static const GInterfaceInfo free_smartphone_device_power_control_info = { (GInterfaceInitFunc) fso_device_base_power_control_free_smartphone_device_power_control_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType fso_device_base_power_control_type_id;
		fso_device_base_power_control_type_id = g_type_register_static (FSO_FRAMEWORK_TYPE_ABSTRACT_OBJECT, "FsoDeviceBasePowerControl", &g_define_type_info, 0);
		g_type_add_interface_static (fso_device_base_power_control_type_id, FSO_DEVICE_TYPE_ISIMPLE_POWER_CONTROL, &fso_device_isimple_power_control_info);
		g_type_add_interface_static (fso_device_base_power_control_type_id, FREE_SMARTPHONE_DEVICE_TYPE_POWER_CONTROL, &free_smartphone_device_power_control_info);
		g_once_init_leave (&fso_device_base_power_control_type_id__volatile, fso_device_base_power_control_type_id);
	}
	return fso_device_base_power_control_type_id__volatile;
}



