/* plugin.c generated by valac 0.16.1, the Vala compiler
 * generated from plugin.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 <stdlib.h>
#include <string.h>
#include <fsobasics.h>
#include <freesmartphone.h>
#include <fsodevice.h>
#include <fsoframework.h>
#include <linux/input.h>
#include <gio/gio.h>


#define DUMMY_TYPE_INPUT_DEVICE (dummy_input_device_get_type ())
#define DUMMY_INPUT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DUMMY_TYPE_INPUT_DEVICE, DummyInputDevice))
#define DUMMY_INPUT_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DUMMY_TYPE_INPUT_DEVICE, DummyInputDeviceClass))
#define DUMMY_IS_INPUT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DUMMY_TYPE_INPUT_DEVICE))
#define DUMMY_IS_INPUT_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DUMMY_TYPE_INPUT_DEVICE))
#define DUMMY_INPUT_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DUMMY_TYPE_INPUT_DEVICE, DummyInputDeviceClass))

typedef struct _DummyInputDevice DummyInputDevice;
typedef struct _DummyInputDeviceClass DummyInputDeviceClass;
typedef struct _DummyInputDevicePrivate DummyInputDevicePrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DummyInputDeviceGetIdData DummyInputDeviceGetIdData;
typedef struct _DummyInputDeviceGetCapabilitiesData DummyInputDeviceGetCapabilitiesData;

struct _DummyInputDevice {
	FsoFrameworkAbstractObject parent_instance;
	DummyInputDevicePrivate * priv;
};

struct _DummyInputDeviceClass {
	FsoFrameworkAbstractObjectClass parent_class;
};

struct _DummyInputDevicePrivate {
	FsoFrameworkSubsystem* subsystem;
	gint32 val;
};

struct _DummyInputDeviceGetIdData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	DummyInputDevice* self;
	gchar* result;
	gchar* _tmp0_;
};

struct _DummyInputDeviceGetCapabilitiesData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	DummyInputDevice* self;
	gchar* result;
	gchar* _tmp0_;
};


static gpointer dummy_input_device_parent_class = NULL;
static FreeSmartphoneDeviceInputIface* dummy_input_device_free_smartphone_device_input_parent_iface = NULL;
static FsoDeviceSignallingInputDeviceIface* dummy_input_device_fso_device_signalling_input_device_parent_iface = NULL;
static GType dummy_input_device_type_id = 0;
extern DummyInputDevice* instance;
DummyInputDevice* instance = NULL;

#define DUMMY_DUMMY_INPUT_PLUGIN_NAME "fsodevice.dummy_input"
GType dummy_input_device_get_type (void) G_GNUC_CONST;
GType dummy_input_device_register_type (GTypeModule * module);
#define DUMMY_INPUT_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DUMMY_TYPE_INPUT_DEVICE, DummyInputDevicePrivate))
enum  {
	DUMMY_INPUT_DEVICE_DUMMY_PROPERTY
};
DummyInputDevice* dummy_input_device_new (FsoFrameworkSubsystem* subsystem);
DummyInputDevice* dummy_input_device_construct (GType object_type, FsoFrameworkSubsystem* subsystem);
static gboolean dummy_input_device_emitDummyEvent (DummyInputDevice* self);
static gboolean _dummy_input_device_emitDummyEvent_gsource_func (gpointer self);
static gchar* dummy_input_device_real_repr (FsoFrameworkAbstractObject* base);
static void dummy_input_device_real_get_id_data_free (gpointer _data);
static void dummy_input_device_real_get_id (FreeSmartphoneDeviceInput* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean dummy_input_device_real_get_id_co (DummyInputDeviceGetIdData* _data_);
static void dummy_input_device_real_get_capabilities_data_free (gpointer _data);
static void dummy_input_device_real_get_capabilities (FreeSmartphoneDeviceInput* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean dummy_input_device_real_get_capabilities_co (DummyInputDeviceGetCapabilitiesData* _data_);
static void dummy_input_device_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;
}


static gboolean _dummy_input_device_emitDummyEvent_gsource_func (gpointer self) {
	gboolean result;
	result = dummy_input_device_emitDummyEvent (self);
	return result;
}


DummyInputDevice* dummy_input_device_construct (GType object_type, FsoFrameworkSubsystem* subsystem) {
	DummyInputDevice * self = NULL;
	FsoFrameworkSubsystem* _tmp0_;
	FsoFrameworkSubsystem* _tmp1_;
	FsoFrameworkSubsystem* _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	FsoFrameworkLogger* _tmp5_;
	g_return_val_if_fail (subsystem != NULL, NULL);
	self = (DummyInputDevice*) fso_framework_abstract_object_construct (object_type);
	_tmp0_ = subsystem;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->subsystem);
	self->priv->subsystem = _tmp1_;
	_tmp2_ = subsystem;
	_tmp3_ = g_strdup_printf ("%s/99", FSO_FRAMEWORK_DEVICE_InputServicePath);
	_tmp4_ = _tmp3_;
	fso_framework_subsystem_registerObjectForService (_tmp2_, DUMMY_TYPE_INPUT_DEVICE, (GBoxedCopyFunc) g_object_ref, g_object_unref, FSO_FRAMEWORK_DEVICE_ServiceDBusName, _tmp4_, self);
	_g_free0 (_tmp4_);
	self->priv->val = (gint32) 1;
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 2, _dummy_input_device_emitDummyEvent_gsource_func, g_object_ref (self), g_object_unref);
	_tmp5_ = ((FsoFrameworkAbstractObject*) self)->logger;
	fso_framework_logger_info (_tmp5_, "Created new DummyInputDevice");
	return self;
}


DummyInputDevice* dummy_input_device_new (FsoFrameworkSubsystem* subsystem) {
	return dummy_input_device_construct (DUMMY_TYPE_INPUT_DEVICE, subsystem);
}


static gchar* dummy_input_device_real_repr (FsoFrameworkAbstractObject* base) {
	DummyInputDevice * self;
	gchar* result = NULL;
	gchar* _tmp0_;
	self = (DummyInputDevice*) base;
	_tmp0_ = g_strdup ("<42>");
	result = _tmp0_;
	return result;
}


static gboolean dummy_input_device_emitDummyEvent (DummyInputDevice* self) {
	gboolean result = FALSE;
	gint32 _tmp0_;
	struct input_event _tmp1_ = {0};
	struct input_event event;
	gint32 _tmp2_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->val;
	memset (&_tmp1_, 0, sizeof (struct input_event));
	_tmp1_.type = EV_KEY;
	_tmp1_.code = (guint16) KEY_ESC;
	_tmp1_.value = _tmp0_;
	event = _tmp1_;
	_tmp2_ = self->priv->val;
	self->priv->val = (gint32) (1 - _tmp2_);
	g_signal_emit_by_name ((FsoDeviceSignallingInputDevice*) self, "received-event", &event);
	result = TRUE;
	return result;
}


static void dummy_input_device_real_get_id_data_free (gpointer _data) {
	DummyInputDeviceGetIdData* _data_;
	_data_ = _data;
	_g_free0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (DummyInputDeviceGetIdData, _data_);
}


static void dummy_input_device_real_get_id (FreeSmartphoneDeviceInput* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	DummyInputDevice * self;
	DummyInputDeviceGetIdData* _data_;
	DummyInputDevice* _tmp0_;
	self = (DummyInputDevice*) base;
	_data_ = g_slice_new0 (DummyInputDeviceGetIdData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, dummy_input_device_real_get_id);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, dummy_input_device_real_get_id_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dummy_input_device_real_get_id_co (_data_);
}


static gchar* dummy_input_device_real_get_id_finish (FreeSmartphoneDeviceInput* base, GAsyncResult* _res_, GError** error) {
	gchar* result;
	DummyInputDeviceGetIdData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static gboolean dummy_input_device_real_get_id_co (DummyInputDeviceGetIdData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_strdup ("42");
	_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 dummy_input_device_real_get_capabilities_data_free (gpointer _data) {
	DummyInputDeviceGetCapabilitiesData* _data_;
	_data_ = _data;
	_g_free0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (DummyInputDeviceGetCapabilitiesData, _data_);
}


static void dummy_input_device_real_get_capabilities (FreeSmartphoneDeviceInput* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	DummyInputDevice * self;
	DummyInputDeviceGetCapabilitiesData* _data_;
	DummyInputDevice* _tmp0_;
	self = (DummyInputDevice*) base;
	_data_ = g_slice_new0 (DummyInputDeviceGetCapabilitiesData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, dummy_input_device_real_get_capabilities);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, dummy_input_device_real_get_capabilities_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dummy_input_device_real_get_capabilities_co (_data_);
}


static gchar* dummy_input_device_real_get_capabilities_finish (FreeSmartphoneDeviceInput* base, GAsyncResult* _res_, GError** error) {
	gchar* result;
	DummyInputDeviceGetCapabilitiesData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static gboolean dummy_input_device_real_get_capabilities_co (DummyInputDeviceGetCapabilitiesData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_strdup ("");
	_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 dummy_input_device_class_init (DummyInputDeviceClass * klass) {
	dummy_input_device_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (DummyInputDevicePrivate));
	FSO_FRAMEWORK_ABSTRACT_OBJECT_CLASS (klass)->repr = dummy_input_device_real_repr;
	G_OBJECT_CLASS (klass)->finalize = dummy_input_device_finalize;
}


static void dummy_input_device_free_smartphone_device_input_interface_init (FreeSmartphoneDeviceInputIface * iface) {
	dummy_input_device_free_smartphone_device_input_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = (gchar* (*)(FreeSmartphoneDeviceInput*, GError**)) dummy_input_device_real_get_id;
	iface->get_id_finish = dummy_input_device_real_get_id_finish;
	iface->get_capabilities = (gchar* (*)(FreeSmartphoneDeviceInput*, GError**)) dummy_input_device_real_get_capabilities;
	iface->get_capabilities_finish = dummy_input_device_real_get_capabilities_finish;
}


static void dummy_input_device_fso_device_signalling_input_device_interface_init (FsoDeviceSignallingInputDeviceIface * iface) {
	dummy_input_device_fso_device_signalling_input_device_parent_iface = g_type_interface_peek_parent (iface);
}


static void dummy_input_device_instance_init (DummyInputDevice * self) {
	self->priv = DUMMY_INPUT_DEVICE_GET_PRIVATE (self);
}


static void dummy_input_device_finalize (GObject* obj) {
	DummyInputDevice * self;
	self = DUMMY_INPUT_DEVICE (obj);
	_g_object_unref0 (self->priv->subsystem);
	G_OBJECT_CLASS (dummy_input_device_parent_class)->finalize (obj);
}


/**
 * Implementation of org.freesmartphone.Device.Input for the dummy Input Device
 **/
GType dummy_input_device_get_type (void) {
	return dummy_input_device_type_id;
}


GType dummy_input_device_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (DummyInputDeviceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dummy_input_device_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DummyInputDevice), 0, (GInstanceInitFunc) dummy_input_device_instance_init, NULL };
	static const GInterfaceInfo free_smartphone_device_input_info = { (GInterfaceInitFunc) dummy_input_device_free_smartphone_device_input_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo fso_device_signalling_input_device_info = { (GInterfaceInitFunc) dummy_input_device_fso_device_signalling_input_device_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	dummy_input_device_type_id = g_type_module_register_type (module, FSO_FRAMEWORK_TYPE_ABSTRACT_OBJECT, "DummyInputDevice", &g_define_type_info, 0);
	g_type_module_add_interface (module, dummy_input_device_type_id, FREE_SMARTPHONE_DEVICE_TYPE_INPUT, &free_smartphone_device_input_info);
	g_type_module_add_interface (module, dummy_input_device_type_id, FSO_DEVICE_TYPE_SIGNALLING_INPUT_DEVICE, &fso_device_signalling_input_device_info);
	return dummy_input_device_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;
	FsoFrameworkSubsystem* _tmp0_;
	DummyInputDevice* _tmp1_;
	gchar* _tmp2_;
	g_return_val_if_fail (subsystem != NULL, NULL);
	_tmp0_ = subsystem;
	_tmp1_ = dummy_input_device_new (_tmp0_);
	_g_object_unref0 (instance);
	instance = _tmp1_;
	_tmp2_ = g_strdup (DUMMY_DUMMY_INPUT_PLUGIN_NAME);
	result = _tmp2_;
	return result;
}


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



