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

/*
 * Copyright (C) 2009-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 THINKPAD_TYPE_BLUETOOTH_POWER_CONTROL (thinkpad_bluetooth_power_control_get_type ())
#define THINKPAD_BLUETOOTH_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THINKPAD_TYPE_BLUETOOTH_POWER_CONTROL, ThinkpadBluetoothPowerControl))
#define THINKPAD_BLUETOOTH_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THINKPAD_TYPE_BLUETOOTH_POWER_CONTROL, ThinkpadBluetoothPowerControlClass))
#define THINKPAD_IS_BLUETOOTH_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THINKPAD_TYPE_BLUETOOTH_POWER_CONTROL))
#define THINKPAD_IS_BLUETOOTH_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THINKPAD_TYPE_BLUETOOTH_POWER_CONTROL))
#define THINKPAD_BLUETOOTH_POWER_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THINKPAD_TYPE_BLUETOOTH_POWER_CONTROL, ThinkpadBluetoothPowerControlClass))

typedef struct _ThinkpadBluetoothPowerControl ThinkpadBluetoothPowerControl;
typedef struct _ThinkpadBluetoothPowerControlClass ThinkpadBluetoothPowerControlClass;
typedef struct _ThinkpadBluetoothPowerControlPrivate ThinkpadBluetoothPowerControlPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _ThinkpadBluetoothPowerControl {
	FsoDeviceBasePowerControl parent_instance;
	ThinkpadBluetoothPowerControlPrivate * priv;
};

struct _ThinkpadBluetoothPowerControlClass {
	FsoDeviceBasePowerControlClass parent_class;
};

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


static gpointer thinkpad_bluetooth_power_control_parent_class = NULL;
static GType thinkpad_bluetooth_power_control_type_id = 0;
extern GList* instances;
GList* instances = NULL;
extern gchar* procfs_root;
gchar* procfs_root = NULL;

GType thinkpad_bluetooth_power_control_get_type (void) G_GNUC_CONST;
GType thinkpad_bluetooth_power_control_register_type (GTypeModule * module);
#define THINKPAD_BLUETOOTH_POWER_CONTROL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), THINKPAD_TYPE_BLUETOOTH_POWER_CONTROL, ThinkpadBluetoothPowerControlPrivate))
enum  {
	THINKPAD_BLUETOOTH_POWER_CONTROL_DUMMY_PROPERTY
};
ThinkpadBluetoothPowerControl* thinkpad_bluetooth_power_control_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
ThinkpadBluetoothPowerControl* thinkpad_bluetooth_power_control_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
static void thinkpad_bluetooth_power_control_finalize (GObject* obj);
gchar* fso_factory_function (FsoFrameworkSubsystem* subsystem, GError** error);
void fso_register_function (GTypeModule* module);


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


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


ThinkpadBluetoothPowerControl* thinkpad_bluetooth_power_control_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode) {
	return thinkpad_bluetooth_power_control_construct (THINKPAD_TYPE_BLUETOOTH_POWER_CONTROL, subsystem, sysfsnode);
}


static void thinkpad_bluetooth_power_control_class_init (ThinkpadBluetoothPowerControlClass * klass) {
	thinkpad_bluetooth_power_control_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ThinkpadBluetoothPowerControlPrivate));
	G_OBJECT_CLASS (klass)->finalize = thinkpad_bluetooth_power_control_finalize;
}


static void thinkpad_bluetooth_power_control_instance_init (ThinkpadBluetoothPowerControl * self) {
	self->priv = THINKPAD_BLUETOOTH_POWER_CONTROL_GET_PRIVATE (self);
}


static void thinkpad_bluetooth_power_control_finalize (GObject* obj) {
	ThinkpadBluetoothPowerControl * self;
	self = THINKPAD_BLUETOOTH_POWER_CONTROL (obj);
	_g_object_unref0 (self->priv->subsystem);
	_g_free0 (self->priv->sysfsnode);
	_g_free0 (self->priv->name);
	G_OBJECT_CLASS (thinkpad_bluetooth_power_control_parent_class)->finalize (obj);
}


/**
 * Bluetooth power control for IBM Thinkpad ACPI
 **/
GType thinkpad_bluetooth_power_control_get_type (void) {
	return thinkpad_bluetooth_power_control_type_id;
}


GType thinkpad_bluetooth_power_control_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (ThinkpadBluetoothPowerControlClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) thinkpad_bluetooth_power_control_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ThinkpadBluetoothPowerControl), 0, (GInstanceInitFunc) thinkpad_bluetooth_power_control_instance_init, NULL };
	thinkpad_bluetooth_power_control_type_id = g_type_module_register_type (module, FSO_DEVICE_TYPE_BASE_POWER_CONTROL, "ThinkpadBluetoothPowerControl", &g_define_type_info, 0);
	return thinkpad_bluetooth_power_control_type_id;
}


/**
 * This function gets called on plugin initialization time.
 * @return the name of your plugin here
 * @note that it needs to be a name in the format <subsystem>.<plugin>
 * else your module will be unloaded immediately.
 **/
gchar* fso_factory_function (FsoFrameworkSubsystem* subsystem, GError** error) {
	gchar* result = NULL;
	FsoFrameworkSmartKeyFile* _tmp0_;
	FsoFrameworkSmartKeyFile* _tmp1_;
	FsoFrameworkSmartKeyFile* config;
	FsoFrameworkSmartKeyFile* _tmp2_;
	gchar* _tmp3_ = NULL;
	const gchar* _tmp4_;
	gchar* _tmp5_ = NULL;
	gchar* bluetooth;
	const gchar* _tmp6_;
	gboolean _tmp7_ = FALSE;
	gchar* _tmp11_;
	g_return_val_if_fail (subsystem != NULL, NULL);
	_tmp0_ = fso_framework_theConfig;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	config = _tmp1_;
	_tmp2_ = config;
	_tmp3_ = fso_framework_smart_key_file_stringValue (_tmp2_, "cornucopia", "procfs_root", "/proc");
	_g_free0 (procfs_root);
	procfs_root = _tmp3_;
	_tmp4_ = procfs_root;
	_tmp5_ = g_build_filename (_tmp4_, "bluetooth", NULL);
	bluetooth = _tmp5_;
	_tmp6_ = bluetooth;
	_tmp7_ = fso_framework_file_handling_isPresent (_tmp6_);
	if (_tmp7_) {
		FsoFrameworkSubsystem* _tmp8_;
		const gchar* _tmp9_;
		ThinkpadBluetoothPowerControl* _tmp10_;
		_tmp8_ = subsystem;
		_tmp9_ = bluetooth;
		_tmp10_ = thinkpad_bluetooth_power_control_new (_tmp8_, _tmp9_);
		instances = g_list_append (instances, (FsoDeviceBasePowerControl*) _tmp10_);
	}
	_tmp11_ = g_strdup ("fsodevice.thinkpad_powercontrol");
	result = _tmp11_;
	_g_free0 (bluetooth);
	_g_object_unref0 (config);
	return result;
}


void fso_register_function (GTypeModule* module) {
	FsoFrameworkLogger* _tmp0_;
	g_return_if_fail (module != NULL);
	thinkpad_bluetooth_power_control_register_type (module);
	_tmp0_ = fso_framework_theLogger;
	fso_framework_logger_debug (_tmp0_, "fsodevice.thinkpad_powercontrol fso_register_function()");
}



