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

/*
 * Copyright (C) 2011-2012 Klaus 'mrmoku' Kurzmann <mok@fluxnetz.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser 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 <fsodevice.h>
#include <fsoframework.h>
#include <stdlib.h>
#include <string.h>
#include <freesmartphone.h>
#include <fsobasics.h>
#include <unistd.h>


#define GTA04_TYPE_GPS_POWER_CONTROL (gta04_gps_power_control_get_type ())
#define GTA04_GPS_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTA04_TYPE_GPS_POWER_CONTROL, Gta04GpsPowerControl))
#define GTA04_GPS_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTA04_TYPE_GPS_POWER_CONTROL, Gta04GpsPowerControlClass))
#define GTA04_IS_GPS_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTA04_TYPE_GPS_POWER_CONTROL))
#define GTA04_IS_GPS_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTA04_TYPE_GPS_POWER_CONTROL))
#define GTA04_GPS_POWER_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTA04_TYPE_GPS_POWER_CONTROL, Gta04GpsPowerControlClass))

typedef struct _Gta04GpsPowerControl Gta04GpsPowerControl;
typedef struct _Gta04GpsPowerControlClass Gta04GpsPowerControlClass;
typedef struct _Gta04GpsPowerControlPrivate Gta04GpsPowerControlPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _Gta04GpsPowerControl {
	FsoDeviceBasePowerControl parent_instance;
	Gta04GpsPowerControlPrivate * priv;
};

struct _Gta04GpsPowerControlClass {
	FsoDeviceBasePowerControlClass parent_class;
};

struct _Gta04GpsPowerControlPrivate {
	FsoFrameworkSubsystem* subsystem;
	gchar* sysfsnode;
	gchar* name;
};


static gpointer gta04_gps_power_control_parent_class = NULL;
static GType gta04_gps_power_control_type_id = 0;

GType gta04_gps_power_control_get_type (void) G_GNUC_CONST;
GType gta04_gps_power_control_register_type (GTypeModule * module);
#define GTA04_GPS_POWER_CONTROL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTA04_TYPE_GPS_POWER_CONTROL, Gta04GpsPowerControlPrivate))
enum  {
	GTA04_GPS_POWER_CONTROL_DUMMY_PROPERTY
};
Gta04GpsPowerControl* gta04_gps_power_control_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
Gta04GpsPowerControl* gta04_gps_power_control_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
static void gta04_gps_power_control_real_setPower (FsoDeviceBasePowerControl* base, gboolean on);
static void gta04_gps_power_control_finalize (GObject* obj);


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


Gta04GpsPowerControl* gta04_gps_power_control_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode) {
	Gta04GpsPowerControl * self = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_;
	FsoFrameworkSubsystem* _tmp3_;
	FsoFrameworkSubsystem* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_ = NULL;
	FsoFrameworkSubsystem* _tmp9_;
	FsoFrameworkLogger* _tmp10_;
	g_return_val_if_fail (subsystem != NULL, NULL);
	g_return_val_if_fail (sysfsnode != NULL, NULL);
	_tmp0_ = sysfsnode;
	_tmp1_ = g_build_filename (_tmp0_, "value", NULL);
	_tmp2_ = _tmp1_;
	self = (Gta04GpsPowerControl*) fso_device_base_power_control_construct (object_type, _tmp2_, "1", "0", (guint) 3);
	_g_free0 (_tmp2_);
	_tmp3_ = subsystem;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_g_object_unref0 (self->priv->subsystem);
	self->priv->subsystem = _tmp4_;
	_tmp5_ = sysfsnode;
	_tmp6_ = g_strdup (_tmp5_);
	_g_free0 (self->priv->sysfsnode);
	self->priv->sysfsnode = _tmp6_;
	_tmp7_ = sysfsnode;
	_tmp8_ = g_path_get_basename (_tmp7_);
	_g_free0 (self->priv->name);
	self->priv->name = _tmp8_;
	_tmp9_ = subsystem;
	fso_framework_subsystem_registerObjectForServiceWithPrefix (_tmp9_, FREE_SMARTPHONE_DEVICE_TYPE_POWER_CONTROL, (GBoxedCopyFunc) g_object_ref, g_object_unref, FSO_FRAMEWORK_DEVICE_ServiceDBusName, FSO_FRAMEWORK_DEVICE_PowerControlServicePath, (FreeSmartphoneDevicePowerControl*) self);
	_tmp10_ = ((FsoFrameworkAbstractObject*) self)->logger;
	fso_framework_logger_info (_tmp10_, "created.");
	return self;
}


Gta04GpsPowerControl* gta04_gps_power_control_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode) {
	return gta04_gps_power_control_construct (GTA04_TYPE_GPS_POWER_CONTROL, subsystem, sysfsnode);
}


static void gta04_gps_power_control_real_setPower (FsoDeviceBasePowerControl* base, gboolean on) {
	Gta04GpsPowerControl * self;
	gboolean _tmp0_;
	self = (Gta04GpsPowerControl*) base;
	_tmp0_ = on;
	if (_tmp0_) {
		FSO_DEVICE_BASE_POWER_CONTROL_CLASS (gta04_gps_power_control_parent_class)->setPower (FSO_DEVICE_BASE_POWER_CONTROL (self), TRUE);
		usleep ((guint) 200);
		FSO_DEVICE_BASE_POWER_CONTROL_CLASS (gta04_gps_power_control_parent_class)->setPower (FSO_DEVICE_BASE_POWER_CONTROL (self), FALSE);
		usleep ((guint) 200);
		FSO_DEVICE_BASE_POWER_CONTROL_CLASS (gta04_gps_power_control_parent_class)->setPower (FSO_DEVICE_BASE_POWER_CONTROL (self), TRUE);
	} else {
		FSO_DEVICE_BASE_POWER_CONTROL_CLASS (gta04_gps_power_control_parent_class)->setPower (FSO_DEVICE_BASE_POWER_CONTROL (self), FALSE);
	}
}


static void gta04_gps_power_control_class_init (Gta04GpsPowerControlClass * klass) {
	gta04_gps_power_control_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (Gta04GpsPowerControlPrivate));
	FSO_DEVICE_BASE_POWER_CONTROL_CLASS (klass)->setPower = gta04_gps_power_control_real_setPower;
	G_OBJECT_CLASS (klass)->finalize = gta04_gps_power_control_finalize;
}


static void gta04_gps_power_control_instance_init (Gta04GpsPowerControl * self) {
	self->priv = GTA04_GPS_POWER_CONTROL_GET_PRIVATE (self);
}


static void gta04_gps_power_control_finalize (GObject* obj) {
	Gta04GpsPowerControl * self;
	self = GTA04_GPS_POWER_CONTROL (obj);
	_g_object_unref0 (self->priv->subsystem);
	_g_free0 (self->priv->sysfsnode);
	_g_free0 (self->priv->name);
	G_OBJECT_CLASS (gta04_gps_power_control_parent_class)->finalize (obj);
}


/**
     * GPS device power control for Openmoko GTA04
     **/
GType gta04_gps_power_control_get_type (void) {
	return gta04_gps_power_control_type_id;
}


GType gta04_gps_power_control_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (Gta04GpsPowerControlClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gta04_gps_power_control_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Gta04GpsPowerControl), 0, (GInstanceInitFunc) gta04_gps_power_control_instance_init, NULL };
	gta04_gps_power_control_type_id = g_type_module_register_type (module, FSO_DEVICE_TYPE_BASE_POWER_CONTROL, "Gta04GpsPowerControl", &g_define_type_info, 0);
	return gta04_gps_power_control_type_id;
}



