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

/*
 * Copyright (C) 2011-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 <stdlib.h>
#include <string.h>
#include <fsobasics.h>
#include <fsoresource.h>
#include <fsodevice.h>
#include <fsoframework.h>


#define AMBIENT_LIGHT_TYPE_N900 (ambient_light_n900_get_type ())
#define AMBIENT_LIGHT_N900(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AMBIENT_LIGHT_TYPE_N900, AmbientLightN900))
#define AMBIENT_LIGHT_N900_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AMBIENT_LIGHT_TYPE_N900, AmbientLightN900Class))
#define AMBIENT_LIGHT_IS_N900(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AMBIENT_LIGHT_TYPE_N900))
#define AMBIENT_LIGHT_IS_N900_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AMBIENT_LIGHT_TYPE_N900))
#define AMBIENT_LIGHT_N900_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AMBIENT_LIGHT_TYPE_N900, AmbientLightN900Class))

typedef struct _AmbientLightN900 AmbientLightN900;
typedef struct _AmbientLightN900Class AmbientLightN900Class;

#define POWER_SUPPLY_TYPE_N900 (power_supply_n900_get_type ())
#define POWER_SUPPLY_N900(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POWER_SUPPLY_TYPE_N900, PowerSupplyN900))
#define POWER_SUPPLY_N900_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), POWER_SUPPLY_TYPE_N900, PowerSupplyN900Class))
#define POWER_SUPPLY_IS_N900(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POWER_SUPPLY_TYPE_N900))
#define POWER_SUPPLY_IS_N900_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), POWER_SUPPLY_TYPE_N900))
#define POWER_SUPPLY_N900_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), POWER_SUPPLY_TYPE_N900, PowerSupplyN900Class))

typedef struct _PowerSupplyN900 PowerSupplyN900;
typedef struct _PowerSupplyN900Class PowerSupplyN900Class;

#define PROXIMITY_TYPE_N900 (proximity_n900_get_type ())
#define PROXIMITY_N900(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PROXIMITY_TYPE_N900, ProximityN900))
#define PROXIMITY_N900_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PROXIMITY_TYPE_N900, ProximityN900Class))
#define PROXIMITY_IS_N900(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PROXIMITY_TYPE_N900))
#define PROXIMITY_IS_N900_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PROXIMITY_TYPE_N900))
#define PROXIMITY_N900_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PROXIMITY_TYPE_N900, ProximityN900Class))

typedef struct _ProximityN900 ProximityN900;
typedef struct _ProximityN900Class ProximityN900Class;

#define PROXIMITY_TYPE_PROXIMITY_RESOURCE (proximity_proximity_resource_get_type ())
#define PROXIMITY_PROXIMITY_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PROXIMITY_TYPE_PROXIMITY_RESOURCE, ProximityProximityResource))
#define PROXIMITY_PROXIMITY_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PROXIMITY_TYPE_PROXIMITY_RESOURCE, ProximityProximityResourceClass))
#define PROXIMITY_IS_PROXIMITY_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PROXIMITY_TYPE_PROXIMITY_RESOURCE))
#define PROXIMITY_IS_PROXIMITY_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PROXIMITY_TYPE_PROXIMITY_RESOURCE))
#define PROXIMITY_PROXIMITY_RESOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PROXIMITY_TYPE_PROXIMITY_RESOURCE, ProximityProximityResourceClass))

typedef struct _ProximityProximityResource ProximityProximityResource;
typedef struct _ProximityProximityResourceClass ProximityProximityResourceClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#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;


extern AmbientLightN900* ambientlight;
AmbientLightN900* ambientlight = NULL;
extern PowerSupplyN900* powersupply;
PowerSupplyN900* powersupply = NULL;
extern ProximityN900* proximity;
ProximityN900* proximity = NULL;
extern ProximityProximityResource* proximity_resource;
ProximityProximityResource* proximity_resource = NULL;
extern GList* resources;
GList* resources = NULL;
extern GList* instances;
GList* instances = NULL;

#define N900_MODULE_NAME "fsodevice.n900_quirks"
GType ambient_light_n900_get_type (void) G_GNUC_CONST;
GType ambient_light_n900_register_type (GTypeModule * module);
GType power_supply_n900_get_type (void) G_GNUC_CONST;
GType power_supply_n900_register_type (GTypeModule * module);
GType proximity_n900_get_type (void) G_GNUC_CONST;
GType proximity_n900_register_type (GTypeModule * module);
GType proximity_proximity_resource_get_type (void) G_GNUC_CONST;
GType proximity_proximity_resource_register_type (GTypeModule * module);
gchar* fso_factory_function (FsoFrameworkSubsystem* subsystem, GError** error);
#define AMBIENT_LIGHT_DEFAULT_NODE "class/i2c-adapter/i2c-2/2-0029/"
AmbientLightN900* ambient_light_n900_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
AmbientLightN900* ambient_light_n900_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
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);
GType n900_bluetooth_power_control_get_type (void) G_GNUC_CONST;
GType n900_bluetooth_power_control_register_type (GTypeModule * module);
PowerSupplyN900* power_supply_n900_new (FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
PowerSupplyN900* power_supply_n900_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* sysfsnode);
ProximityN900* proximity_n900_new (FsoFrameworkSubsystem* subsystem, const gchar* node);
ProximityN900* proximity_n900_construct (GType object_type, FsoFrameworkSubsystem* subsystem, const gchar* node);
ProximityProximityResource* proximity_proximity_resource_new (FsoFrameworkSubsystem* subsystem, ProximityN900* instance);
ProximityProximityResource* proximity_proximity_resource_construct (GType object_type, FsoFrameworkSubsystem* subsystem, ProximityN900* instance);
void fso_register_function (GTypeModule* module);


/**
 * 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.
 **/
static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static const gchar* string_to_string (const gchar* self) {
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}


gchar* fso_factory_function (FsoFrameworkSubsystem* subsystem, GError** error) {
	gchar* result = NULL;
	FsoFrameworkSmartKeyFile* _tmp0_;
	FsoFrameworkSmartKeyFile* _tmp1_;
	FsoFrameworkSmartKeyFile* config;
	FsoFrameworkSmartKeyFile* _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* sysfs_root;
	FsoFrameworkSmartKeyFile* _tmp4_;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_;
	gboolean _tmp8_ = FALSE;
	gboolean _tmp9_;
	FsoFrameworkSmartKeyFile* _tmp18_;
	const gchar* _tmp19_ = NULL;
	gchar* _tmp20_ = NULL;
	gchar* _tmp21_;
	gboolean _tmp22_ = FALSE;
	gboolean _tmp23_;
	FsoFrameworkSmartKeyFile* _tmp34_;
	const gchar* _tmp35_ = NULL;
	gchar* _tmp36_ = NULL;
	gchar* _tmp37_;
	gboolean _tmp38_ = FALSE;
	gboolean _tmp39_;
	FsoFrameworkSmartKeyFile* _tmp45_;
	const gchar* _tmp46_ = NULL;
	gchar* _tmp47_ = NULL;
	gchar* _tmp48_;
	gboolean _tmp49_ = FALSE;
	gboolean _tmp50_;
	gchar* _tmp62_;
	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", "sysfs_root", "/sys");
	sysfs_root = _tmp3_;
	_tmp4_ = config;
	_tmp5_ = string_to_string (N900_MODULE_NAME);
	_tmp6_ = g_strconcat (_tmp5_, "/ambientlight", NULL);
	_tmp7_ = _tmp6_;
	_tmp8_ = fso_framework_smart_key_file_hasSection (_tmp4_, _tmp7_);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	if (_tmp9_) {
		const gchar* _tmp10_;
		gchar* _tmp11_ = NULL;
		gchar* dirname;
		const gchar* _tmp12_;
		gboolean _tmp13_ = FALSE;
		_tmp10_ = sysfs_root;
		_tmp11_ = g_build_filename (_tmp10_, AMBIENT_LIGHT_DEFAULT_NODE, NULL);
		dirname = _tmp11_;
		_tmp12_ = dirname;
		_tmp13_ = fso_framework_file_handling_isPresent (_tmp12_);
		if (_tmp13_) {
			FsoFrameworkSubsystem* _tmp14_;
			const gchar* _tmp15_;
			AmbientLightN900* _tmp16_;
			_tmp14_ = subsystem;
			_tmp15_ = dirname;
			_tmp16_ = ambient_light_n900_new (_tmp14_, _tmp15_);
			_g_object_unref0 (ambientlight);
			ambientlight = _tmp16_;
		} else {
			FsoFrameworkLogger* _tmp17_;
			_tmp17_ = fso_framework_theLogger;
			fso_framework_logger_error (_tmp17_, "No ambient light device found; ambient light object will not be availa" \
"ble");
		}
		_g_free0 (dirname);
	}
	_tmp18_ = config;
	_tmp19_ = string_to_string (N900_MODULE_NAME);
	_tmp20_ = g_strconcat (_tmp19_, "/powercontrol", NULL);
	_tmp21_ = _tmp20_;
	_tmp22_ = fso_framework_smart_key_file_hasSection (_tmp18_, _tmp21_);
	_tmp23_ = _tmp22_;
	_g_free0 (_tmp21_);
	if (_tmp23_) {
		const gchar* _tmp24_;
		gchar* _tmp25_ = NULL;
		gchar* hci_h4p;
		const gchar* _tmp26_;
		gchar* _tmp27_ = NULL;
		gchar* wl12xx;
		FsoFrameworkSubsystem* _tmp28_;
		const gchar* _tmp29_;
		const gchar* _tmp30_;
		N900BluetoothPowerControl* _tmp31_;
		N900BluetoothPowerControl* bto;
		N900BluetoothPowerControl* _tmp32_;
		FsoDeviceBasePowerControl* _tmp33_;
		_tmp24_ = sysfs_root;
		_tmp25_ = g_build_filename (_tmp24_, "devices", "platform", "hci_h4p", NULL);
		hci_h4p = _tmp25_;
		_tmp26_ = sysfs_root;
		_tmp27_ = g_build_filename (_tmp26_, "devices", "platform", "wl12xx", NULL);
		wl12xx = _tmp27_;
		_tmp28_ = subsystem;
		_tmp29_ = hci_h4p;
		_tmp30_ = wl12xx;
		_tmp31_ = n900_bluetooth_power_control_new (_tmp28_, _tmp29_, _tmp30_);
		bto = _tmp31_;
		_tmp32_ = bto;
		_tmp33_ = _g_object_ref0 ((FsoDeviceBasePowerControl*) _tmp32_);
		instances = g_list_append (instances, _tmp33_);
		_g_object_unref0 (bto);
		_g_free0 (wl12xx);
		_g_free0 (hci_h4p);
	}
	_tmp34_ = config;
	_tmp35_ = string_to_string (N900_MODULE_NAME);
	_tmp36_ = g_strconcat (_tmp35_, "/powersupply", NULL);
	_tmp37_ = _tmp36_;
	_tmp38_ = fso_framework_smart_key_file_hasSection (_tmp34_, _tmp37_);
	_tmp39_ = _tmp38_;
	_g_free0 (_tmp37_);
	if (_tmp39_) {
		const gchar* _tmp40_;
		gchar* _tmp41_ = NULL;
		gchar* sys_devices_platform_msusb_hdrc;
		FsoFrameworkSubsystem* _tmp42_;
		const gchar* _tmp43_;
		PowerSupplyN900* _tmp44_;
		_tmp40_ = sysfs_root;
		_tmp41_ = g_strdup_printf ("%s/devices/platform/musb_hdrc", _tmp40_);
		sys_devices_platform_msusb_hdrc = _tmp41_;
		_tmp42_ = subsystem;
		_tmp43_ = sys_devices_platform_msusb_hdrc;
		_tmp44_ = power_supply_n900_new (_tmp42_, _tmp43_);
		_g_object_unref0 (powersupply);
		powersupply = _tmp44_;
		_g_free0 (sys_devices_platform_msusb_hdrc);
	}
	_tmp45_ = config;
	_tmp46_ = string_to_string (N900_MODULE_NAME);
	_tmp47_ = g_strconcat (_tmp46_, "/proximity", NULL);
	_tmp48_ = _tmp47_;
	_tmp49_ = fso_framework_smart_key_file_hasSection (_tmp45_, _tmp48_);
	_tmp50_ = _tmp49_;
	_g_free0 (_tmp48_);
	if (_tmp50_) {
		const gchar* _tmp51_;
		gchar* _tmp52_ = NULL;
		gchar* dirname;
		const gchar* _tmp53_;
		gboolean _tmp54_ = FALSE;
		_tmp51_ = sysfs_root;
		_tmp52_ = g_build_filename (_tmp51_, "devices", "platform", "gpio-switch", "proximity", NULL);
		dirname = _tmp52_;
		_tmp53_ = dirname;
		_tmp54_ = fso_framework_file_handling_isPresent (_tmp53_);
		if (_tmp54_) {
			FsoFrameworkSubsystem* _tmp55_;
			const gchar* _tmp56_;
			ProximityN900* _tmp57_;
			FsoFrameworkSubsystem* _tmp58_;
			ProximityN900* _tmp59_;
			ProximityProximityResource* _tmp60_;
			_tmp55_ = subsystem;
			_tmp56_ = dirname;
			_tmp57_ = proximity_n900_new (_tmp55_, _tmp56_);
			_g_object_unref0 (proximity);
			proximity = _tmp57_;
			_tmp58_ = subsystem;
			_tmp59_ = proximity;
			_tmp60_ = proximity_proximity_resource_new (_tmp58_, _tmp59_);
			_g_object_unref0 (proximity_resource);
			proximity_resource = _tmp60_;
		} else {
			FsoFrameworkLogger* _tmp61_;
			_tmp61_ = fso_framework_theLogger;
			fso_framework_logger_error (_tmp61_, "No proximity device found; proximity object will not be available");
		}
		_g_free0 (dirname);
	}
	_tmp62_ = g_strdup ("fsodevice.n900_quirks");
	result = _tmp62_;
	_g_free0 (sysfs_root);
	_g_object_unref0 (config);
	return result;
}


void fso_register_function (GTypeModule* module) {
	FsoFrameworkLogger* _tmp0_;
	g_return_if_fail (module != NULL);
	n900_bluetooth_power_control_register_type (module);
	n900_wi_fi_power_control_register_type (module);
	ambient_light_n900_register_type (module);
	power_supply_n900_register_type (module);
	proximity_n900_register_type (module);
	proximity_proximity_resource_register_type (module);
	_tmp0_ = fso_framework_theLogger;
	fso_framework_logger_debug (_tmp0_, "fsodevice.n900_quirks fso_register_function()");
}



