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

/*
 * Copyright (C) 2010-2012 Michael 'Mickey' Lauer <mlauer@vanille-media.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>


#define N900_TYPE_BLUETOOTH_POWER_CONTROL (n900_bluetooth_power_control_get_type ())
#define N900_BLUETOOTH_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), N900_TYPE_BLUETOOTH_POWER_CONTROL, N900BluetoothPowerControl))
#define N900_BLUETOOTH_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), N900_TYPE_BLUETOOTH_POWER_CONTROL, N900BluetoothPowerControlClass))
#define N900_IS_BLUETOOTH_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), N900_TYPE_BLUETOOTH_POWER_CONTROL))
#define N900_IS_BLUETOOTH_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), N900_TYPE_BLUETOOTH_POWER_CONTROL))
#define N900_BLUETOOTH_POWER_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), N900_TYPE_BLUETOOTH_POWER_CONTROL, N900BluetoothPowerControlClass))

typedef struct _N900BluetoothPowerControl N900BluetoothPowerControl;
typedef struct _N900BluetoothPowerControlClass N900BluetoothPowerControlClass;
typedef struct _N900BluetoothPowerControlPrivate N900BluetoothPowerControlPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define N900_TYPE_WI_FI_POWER_CONTROL (n900_wi_fi_power_control_get_type ())
#define N900_WI_FI_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), N900_TYPE_WI_FI_POWER_CONTROL, N900WiFiPowerControl))
#define N900_WI_FI_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), N900_TYPE_WI_FI_POWER_CONTROL, N900WiFiPowerControlClass))
#define N900_IS_WI_FI_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), N900_TYPE_WI_FI_POWER_CONTROL))
#define N900_IS_WI_FI_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), N900_TYPE_WI_FI_POWER_CONTROL))
#define N900_WI_FI_POWER_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), N900_TYPE_WI_FI_POWER_CONTROL, N900WiFiPowerControlClass))

typedef struct _N900WiFiPowerControl N900WiFiPowerControl;
typedef struct _N900WiFiPowerControlClass N900WiFiPowerControlClass;
typedef struct _N900WiFiPowerControlPrivate N900WiFiPowerControlPrivate;

struct _N900BluetoothPowerControl {
	FsoDeviceBasePowerControl parent_instance;
	N900BluetoothPowerControlPrivate * priv;
};

struct _N900BluetoothPowerControlClass {
	FsoDeviceBasePowerControlClass parent_class;
};

struct _N900BluetoothPowerControlPrivate {
	FsoFrameworkSubsystem* subsystem;
	gchar* sysfsnode;
	gchar* name;
	gchar* wl12xx;
};

struct _N900WiFiPowerControl {
	FsoDeviceBasePowerControl parent_instance;
	N900WiFiPowerControlPrivate * priv;
};

struct _N900WiFiPowerControlClass {
	FsoDeviceBasePowerControlClass parent_class;
};

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


static gpointer n900_bluetooth_power_control_parent_class = NULL;
static GType n900_bluetooth_power_control_type_id = 0;
static gpointer n900_wi_fi_power_control_parent_class = NULL;
static GType n900_wi_fi_power_control_type_id = 0;

GType n900_bluetooth_power_control_get_type (void) G_GNUC_CONST;
GType n900_bluetooth_power_control_register_type (GTypeModule * module);
#define N900_BLUETOOTH_POWER_CONTROL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), N900_TYPE_BLUETOOTH_POWER_CONTROL, N900BluetoothPowerControlPrivate))
enum  {
	N900_BLUETOOTH_POWER_CONTROL_DUMMY_PROPERTY
};
N900BluetoothPowerControl* n900_bluetooth_power_control_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode, const gchar* wl12xx);
N900BluetoothPowerControl* n900_bluetooth_power_control_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode, const gchar* wl12xx);
static gboolean n900_bluetooth_power_control_real_getPower (FsoDeviceBasePowerControl* base);
static void n900_bluetooth_power_control_real_setPower (FsoDeviceBasePowerControl* base, gboolean on);
static void n900_bluetooth_power_control_finalize (GObject* obj);
GType n900_wi_fi_power_control_get_type (void) G_GNUC_CONST;
GType n900_wi_fi_power_control_register_type (GTypeModule * module);
#define N900_WI_FI_POWER_CONTROL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), N900_TYPE_WI_FI_POWER_CONTROL, N900WiFiPowerControlPrivate))
enum  {
	N900_WI_FI_POWER_CONTROL_DUMMY_PROPERTY
};
N900WiFiPowerControl* n900_wi_fi_power_control_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
N900WiFiPowerControl* n900_wi_fi_power_control_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
static gboolean n900_wi_fi_power_control_real_getPower (FsoDeviceBasePowerControl* base);
static void n900_wi_fi_power_control_real_setPower (FsoDeviceBasePowerControl* base, gboolean on);
static void n900_wi_fi_power_control_finalize (GObject* obj);


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


N900BluetoothPowerControl* n900_bluetooth_power_control_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode, const gchar* wl12xx) {
	N900BluetoothPowerControl * 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;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	FsoFrameworkSubsystem* _tmp11_;
	FsoFrameworkLogger* _tmp12_;
	g_return_val_if_fail (subsystem != NULL, NULL);
	g_return_val_if_fail (sysfsnode != NULL, NULL);
	g_return_val_if_fail (wl12xx != NULL, NULL);
	_tmp0_ = sysfsnode;
	_tmp1_ = g_build_filename (_tmp0_, "power_on", NULL);
	_tmp2_ = _tmp1_;
	self = (N900BluetoothPowerControl*) 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_ = wl12xx;
	_tmp10_ = g_strdup (_tmp9_);
	_g_free0 (self->priv->wl12xx);
	self->priv->wl12xx = _tmp10_;
	_tmp11_ = subsystem;
	fso_framework_subsystem_registerObjectForServiceWithPrefix (_tmp11_, FREE_SMARTPHONE_DEVICE_TYPE_POWER_CONTROL, (GBoxedCopyFunc) g_object_ref, g_object_unref, FSO_FRAMEWORK_DEVICE_ServiceDBusName, FSO_FRAMEWORK_DEVICE_PowerControlServicePath, (FreeSmartphoneDevicePowerControl*) self);
	_tmp12_ = ((FsoFrameworkAbstractObject*) self)->logger;
	fso_framework_logger_info (_tmp12_, "Created.");
	return self;
}


N900BluetoothPowerControl* n900_bluetooth_power_control_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode, const gchar* wl12xx) {
	return n900_bluetooth_power_control_construct (N900_TYPE_BLUETOOTH_POWER_CONTROL, subsystem, sysfsnode, wl12xx);
}


static gboolean n900_bluetooth_power_control_real_getPower (FsoDeviceBasePowerControl* base) {
	N900BluetoothPowerControl * self;
	gboolean result = FALSE;
	self = (N900BluetoothPowerControl*) base;
	result = FALSE;
	return result;
}


static void n900_bluetooth_power_control_real_setPower (FsoDeviceBasePowerControl* base, gboolean on) {
	N900BluetoothPowerControl * self;
	gboolean _tmp0_;
	const gchar* _tmp4_;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_ = NULL;
	gchar* _tmp9_;
	self = (N900BluetoothPowerControl*) base;
	_tmp0_ = on;
	if (!_tmp0_) {
		const gchar* _tmp1_;
		gchar* _tmp2_ = NULL;
		gchar* _tmp3_;
		system ("killall bluetoothd; killall -9 bluetoothd");
		system ("modprobe -r hci_h4p");
		_tmp1_ = self->priv->wl12xx;
		_tmp2_ = g_build_filename (_tmp1_, "bt_coex_mode", NULL);
		_tmp3_ = _tmp2_;
		fso_framework_file_handling_write ("0", _tmp3_, FALSE);
		_g_free0 (_tmp3_);
		return;
	}
	system ("modprobe hci_h4p");
	_tmp4_ = self->priv->sysfsnode;
	_tmp5_ = g_build_filename (_tmp4_, "bdaddr", NULL);
	_tmp6_ = _tmp5_;
	fso_framework_file_handling_write ("00:11:22:33:44:55", _tmp6_, FALSE);
	_g_free0 (_tmp6_);
	system ("modprobe -r hci_h4p");
	system ("modprobe hci_h4p");
	_tmp7_ = self->priv->wl12xx;
	_tmp8_ = g_build_filename (_tmp7_, "bt_coex_mode", NULL);
	_tmp9_ = _tmp8_;
	fso_framework_file_handling_write ("1", _tmp9_, FALSE);
	_g_free0 (_tmp9_);
}


static void n900_bluetooth_power_control_class_init (N900BluetoothPowerControlClass * klass) {
	n900_bluetooth_power_control_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (N900BluetoothPowerControlPrivate));
	FSO_DEVICE_BASE_POWER_CONTROL_CLASS (klass)->getPower = n900_bluetooth_power_control_real_getPower;
	FSO_DEVICE_BASE_POWER_CONTROL_CLASS (klass)->setPower = n900_bluetooth_power_control_real_setPower;
	G_OBJECT_CLASS (klass)->finalize = n900_bluetooth_power_control_finalize;
}


static void n900_bluetooth_power_control_instance_init (N900BluetoothPowerControl * self) {
	self->priv = N900_BLUETOOTH_POWER_CONTROL_GET_PRIVATE (self);
}


static void n900_bluetooth_power_control_finalize (GObject* obj) {
	N900BluetoothPowerControl * self;
	self = N900_BLUETOOTH_POWER_CONTROL (obj);
	_g_object_unref0 (self->priv->subsystem);
	_g_free0 (self->priv->sysfsnode);
	_g_free0 (self->priv->name);
	_g_free0 (self->priv->wl12xx);
	G_OBJECT_CLASS (n900_bluetooth_power_control_parent_class)->finalize (obj);
}


/**
     * Bluetooth power control for Nokia N900
     **/
GType n900_bluetooth_power_control_get_type (void) {
	return n900_bluetooth_power_control_type_id;
}


GType n900_bluetooth_power_control_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (N900BluetoothPowerControlClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) n900_bluetooth_power_control_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (N900BluetoothPowerControl), 0, (GInstanceInitFunc) n900_bluetooth_power_control_instance_init, NULL };
	n900_bluetooth_power_control_type_id = g_type_module_register_type (module, FSO_DEVICE_TYPE_BASE_POWER_CONTROL, "N900BluetoothPowerControl", &g_define_type_info, 0);
	return n900_bluetooth_power_control_type_id;
}


N900WiFiPowerControl* n900_wi_fi_power_control_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode) {
	N900WiFiPowerControl * 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_, NULL, NULL);
	_tmp2_ = _tmp1_;
	self = (N900WiFiPowerControl*) 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;
}


N900WiFiPowerControl* n900_wi_fi_power_control_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode) {
	return n900_wi_fi_power_control_construct (N900_TYPE_WI_FI_POWER_CONTROL, subsystem, sysfsnode);
}


static gboolean n900_wi_fi_power_control_real_getPower (FsoDeviceBasePowerControl* base) {
	N900WiFiPowerControl * self;
	gboolean result = FALSE;
	self = (N900WiFiPowerControl*) base;
	result = FALSE;
	return result;
}


static void n900_wi_fi_power_control_real_setPower (FsoDeviceBasePowerControl* base, gboolean on) {
	N900WiFiPowerControl * self;
	self = (N900WiFiPowerControl*) base;
}


static void n900_wi_fi_power_control_class_init (N900WiFiPowerControlClass * klass) {
	n900_wi_fi_power_control_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (N900WiFiPowerControlPrivate));
	FSO_DEVICE_BASE_POWER_CONTROL_CLASS (klass)->getPower = n900_wi_fi_power_control_real_getPower;
	FSO_DEVICE_BASE_POWER_CONTROL_CLASS (klass)->setPower = n900_wi_fi_power_control_real_setPower;
	G_OBJECT_CLASS (klass)->finalize = n900_wi_fi_power_control_finalize;
}


static void n900_wi_fi_power_control_instance_init (N900WiFiPowerControl * self) {
	self->priv = N900_WI_FI_POWER_CONTROL_GET_PRIVATE (self);
}


static void n900_wi_fi_power_control_finalize (GObject* obj) {
	N900WiFiPowerControl * self;
	self = N900_WI_FI_POWER_CONTROL (obj);
	_g_object_unref0 (self->priv->subsystem);
	_g_free0 (self->priv->sysfsnode);
	_g_free0 (self->priv->name);
	G_OBJECT_CLASS (n900_wi_fi_power_control_parent_class)->finalize (obj);
}


/**
     * WiFi power control for Nokia N900
     **/
GType n900_wi_fi_power_control_get_type (void) {
	return n900_wi_fi_power_control_type_id;
}


GType n900_wi_fi_power_control_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (N900WiFiPowerControlClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) n900_wi_fi_power_control_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (N900WiFiPowerControl), 0, (GInstanceInitFunc) n900_wi_fi_power_control_instance_init, NULL };
	n900_wi_fi_power_control_type_id = g_type_module_register_type (module, FSO_DEVICE_TYPE_BASE_POWER_CONTROL, "N900WiFiPowerControl", &g_define_type_info, 0);
	return n900_wi_fi_power_control_type_id;
}



