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

/*
 * SPDX-License-Identifier: LGPL-2.0-or-later
 * SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
 */

#include "display.h"
#include <glib.h>
#include <gio/gio.h>
#include <string.h>
#include <glib-object.h>
#include <stdlib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

typedef GDBusProxy DisplaySensorProxyProxy;
typedef GDBusProxyClass DisplaySensorProxyProxyClass;
enum  {
	DISPLAY_SENSOR_MANAGER_0_PROPERTY,
	DISPLAY_SENSOR_MANAGER_HAS_ACCELEROMETER_PROPERTY,
	DISPLAY_SENSOR_MANAGER_NUM_PROPERTIES
};
static GParamSpec* display_sensor_manager_properties[DISPLAY_SENSOR_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _DisplaySensorManagerPrivate {
	gboolean _has_accelerometer;
};

static gint DisplaySensorManager_private_offset;
static gpointer display_sensor_manager_parent_class = NULL;
static GOnce display_sensor_manager_instance;
static GOnce display_sensor_manager_instance = G_ONCE_INIT;

static GType display_sensor_proxy_get_type_once (void);
static void display_sensor_proxy_proxy_g_signal (GDBusProxy* proxy,
                                          const gchar* sender_name,
                                          const gchar* signal_name,
                                          GVariant* parameters);
static gboolean display_sensor_proxy_dbus_proxy_get_has_accelerometer (DisplaySensorProxy* self);
static void display_sensor_proxy_proxy_display_sensor_proxy_interface_init (DisplaySensorProxyIface* iface);
static void display_sensor_proxy_dbus_interface_method_call (GDBusConnection* connection,
                                                      const gchar* sender,
                                                      const gchar* object_path,
                                                      const gchar* interface_name,
                                                      const gchar* method_name,
                                                      GVariant* parameters,
                                                      GDBusMethodInvocation* invocation,
                                                      gpointer user_data);
static GVariant* display_sensor_proxy_dbus_interface_get_property (GDBusConnection* connection,
                                                            const gchar* sender,
                                                            const gchar* object_path,
                                                            const gchar* interface_name,
                                                            const gchar* property_name,
                                                            GError** error,
                                                            gpointer user_data);
static GVariant* _dbus_display_sensor_proxy_get_has_accelerometer (DisplaySensorProxy* self);
static gboolean display_sensor_proxy_dbus_interface_set_property (GDBusConnection* connection,
                                                           const gchar* sender,
                                                           const gchar* object_path,
                                                           const gchar* interface_name,
                                                           const gchar* property_name,
                                                           GVariant* value,
                                                           GError** error,
                                                           gpointer user_data);
static void _display_sensor_proxy_unregister_object (gpointer user_data);
static DisplaySensorManager* __lambda18_ (void);
static DisplaySensorManager* display_sensor_manager_new (void);
static DisplaySensorManager* display_sensor_manager_construct (GType object_type);
static gpointer ___lambda18__gthread_func (gpointer self);
static void display_sensor_manager_set_has_accelerometer (DisplaySensorManager* self,
                                                   gboolean value);
static GObject * display_sensor_manager_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void display_sensor_manager_finalize (GObject * obj);
static GType display_sensor_manager_get_type_once (void);
static void _vala_display_sensor_manager_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_display_sensor_manager_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const GDBusMethodInfo * const _display_sensor_proxy_dbus_method_info[] = {NULL};
static const GDBusSignalInfo * const _display_sensor_proxy_dbus_signal_info[] = {NULL};
static const GDBusPropertyInfo _display_sensor_proxy_dbus_property_info_has_accelerometer = {-1, "HasAccelerometer", "b", G_DBUS_PROPERTY_INFO_FLAGS_READABLE, NULL};
static const GDBusPropertyInfo * const _display_sensor_proxy_dbus_property_info[] = {&_display_sensor_proxy_dbus_property_info_has_accelerometer, NULL};
static const GDBusInterfaceInfo _display_sensor_proxy_dbus_interface_info = {-1, "net.hadess.SensorProxy", (GDBusMethodInfo **) (&_display_sensor_proxy_dbus_method_info), (GDBusSignalInfo **) (&_display_sensor_proxy_dbus_signal_info), (GDBusPropertyInfo **) (&_display_sensor_proxy_dbus_property_info), NULL};
static const GDBusInterfaceVTable _display_sensor_proxy_dbus_interface_vtable = {display_sensor_proxy_dbus_interface_method_call, display_sensor_proxy_dbus_interface_get_property, display_sensor_proxy_dbus_interface_set_property};

gboolean
display_sensor_proxy_get_has_accelerometer (DisplaySensorProxy* self)
{
	DisplaySensorProxyIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = DISPLAY_SENSOR_PROXY_GET_INTERFACE (self);
	if (_iface_->get_has_accelerometer) {
		return _iface_->get_has_accelerometer (self);
	}
	return FALSE;
}

static void
display_sensor_proxy_default_init (DisplaySensorProxyIface * iface,
                                   gpointer iface_data)
{
}

static GType
display_sensor_proxy_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DisplaySensorProxyIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) display_sensor_proxy_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType display_sensor_proxy_type_id;
	display_sensor_proxy_type_id = g_type_register_static (G_TYPE_INTERFACE, "DisplaySensorProxy", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (display_sensor_proxy_type_id, g_dbus_proxy_get_type ());
	g_type_set_qdata (display_sensor_proxy_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) display_sensor_proxy_proxy_get_type);
	g_type_set_qdata (display_sensor_proxy_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "net.hadess.SensorProxy");
	g_type_set_qdata (display_sensor_proxy_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_display_sensor_proxy_dbus_interface_info));
	g_type_set_qdata (display_sensor_proxy_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) display_sensor_proxy_register_object);
	return display_sensor_proxy_type_id;
}

GType
display_sensor_proxy_get_type (void)
{
	static volatile gsize display_sensor_proxy_type_id__once = 0;
	if (g_once_init_enter (&display_sensor_proxy_type_id__once)) {
		GType display_sensor_proxy_type_id;
		display_sensor_proxy_type_id = display_sensor_proxy_get_type_once ();
		g_once_init_leave (&display_sensor_proxy_type_id__once, display_sensor_proxy_type_id);
	}
	return display_sensor_proxy_type_id__once;
}

G_DEFINE_TYPE_EXTENDED (DisplaySensorProxyProxy, display_sensor_proxy_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (DISPLAY_TYPE_SENSOR_PROXY, display_sensor_proxy_proxy_display_sensor_proxy_interface_init) )
static void
display_sensor_proxy_proxy_class_init (DisplaySensorProxyProxyClass* klass)
{
	G_DBUS_PROXY_CLASS (klass)->g_signal = display_sensor_proxy_proxy_g_signal;
}

static void
display_sensor_proxy_proxy_g_signal (GDBusProxy* proxy,
                                     const gchar* sender_name,
                                     const gchar* signal_name,
                                     GVariant* parameters)
{
}

static void
display_sensor_proxy_proxy_init (DisplaySensorProxyProxy* self)
{
	g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_display_sensor_proxy_dbus_interface_info));
}

static gboolean
display_sensor_proxy_dbus_proxy_get_has_accelerometer (DisplaySensorProxy* self)
{
	GVariant *_inner_reply;
	gboolean _result;
	_inner_reply = g_dbus_proxy_get_cached_property ((GDBusProxy *) self, "HasAccelerometer");
	if (!_inner_reply) {
		GVariant *_arguments;
		GVariant *_reply;
		GVariantBuilder _arguments_builder;
		g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
		g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("net.hadess.SensorProxy"));
		g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("HasAccelerometer"));
		_arguments = g_variant_builder_end (&_arguments_builder);
		_reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
		if (!_reply) {
			gboolean _tmp375_ = FALSE;
			return _tmp375_;
		}
		g_variant_get (_reply, "(v)", &_inner_reply);
		g_variant_unref (_reply);
	}
	_result = g_variant_get_boolean (_inner_reply);
	g_variant_unref (_inner_reply);
	return _result;
}

static void
display_sensor_proxy_proxy_display_sensor_proxy_interface_init (DisplaySensorProxyIface* iface)
{
	iface->get_has_accelerometer = display_sensor_proxy_dbus_proxy_get_has_accelerometer;
}

static void
display_sensor_proxy_dbus_interface_method_call (GDBusConnection* connection,
                                                 const gchar* sender,
                                                 const gchar* object_path,
                                                 const gchar* interface_name,
                                                 const gchar* method_name,
                                                 GVariant* parameters,
                                                 GDBusMethodInvocation* invocation,
                                                 gpointer user_data)
{
	g_object_unref (invocation);
}

static GVariant*
_dbus_display_sensor_proxy_get_has_accelerometer (DisplaySensorProxy* self)
{
	gboolean result;
	GVariant* _reply;
	result = display_sensor_proxy_get_has_accelerometer (self);
	_reply = g_variant_new_boolean (result);
	return _reply;
}

static GVariant*
display_sensor_proxy_dbus_interface_get_property (GDBusConnection* connection,
                                                  const gchar* sender,
                                                  const gchar* object_path,
                                                  const gchar* interface_name,
                                                  const gchar* property_name,
                                                  GError** error,
                                                  gpointer user_data)
{
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	if (strcmp (property_name, "HasAccelerometer") == 0) {
		return _dbus_display_sensor_proxy_get_has_accelerometer (object);
	}
	return NULL;
}

static gboolean
display_sensor_proxy_dbus_interface_set_property (GDBusConnection* connection,
                                                  const gchar* sender,
                                                  const gchar* object_path,
                                                  const gchar* interface_name,
                                                  const gchar* property_name,
                                                  GVariant* value,
                                                  GError** error,
                                                  gpointer user_data)
{
	return FALSE;
}

guint
display_sensor_proxy_register_object (gpointer object,
                                      GDBusConnection* connection,
                                      const gchar* path,
                                      GError** error)
{
	guint result;
	gpointer *data;
	data = g_new (gpointer, 3);
	data[0] = g_object_ref (object);
	data[1] = g_object_ref (connection);
	data[2] = g_strdup (path);
	result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_display_sensor_proxy_dbus_interface_info), &_display_sensor_proxy_dbus_interface_vtable, data, _display_sensor_proxy_unregister_object, error);
	if (!result) {
		return 0;
	}
	return result;
}

static void
_display_sensor_proxy_unregister_object (gpointer user_data)
{
	gpointer* data;
	data = user_data;
	g_object_unref (data[0]);
	g_object_unref (data[1]);
	g_free (data[2]);
	g_free (data);
}

static inline gpointer
display_sensor_manager_get_instance_private (DisplaySensorManager* self)
{
	return G_STRUCT_MEMBER_P (self, DisplaySensorManager_private_offset);
}

static DisplaySensorManager*
__lambda18_ (void)
{
	DisplaySensorManager* _tmp0_;
	DisplaySensorManager* result;
	_tmp0_ = display_sensor_manager_new ();
	result = _tmp0_;
	return result;
}

static gpointer
___lambda18__gthread_func (gpointer self)
{
	gpointer result;
	result = __lambda18_ ();
	return result;
}

DisplaySensorManager*
display_sensor_manager_get_default (void)
{
	gconstpointer _tmp0_;
	DisplaySensorManager* result;
	_tmp0_ = g_once (&display_sensor_manager_instance, ___lambda18__gthread_func, NULL);
	result = (DisplaySensorManager*) _tmp0_;
	return result;
}

static DisplaySensorManager*
display_sensor_manager_construct (GType object_type)
{
	DisplaySensorManager * self = NULL;
	self = (DisplaySensorManager*) g_object_new (object_type, NULL);
	return self;
}

static DisplaySensorManager*
display_sensor_manager_new (void)
{
	return display_sensor_manager_construct (DISPLAY_TYPE_SENSOR_MANAGER);
}

gboolean
display_sensor_manager_get_has_accelerometer (DisplaySensorManager* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_has_accelerometer;
	return result;
}

static void
display_sensor_manager_set_has_accelerometer (DisplaySensorManager* self,
                                              gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = display_sensor_manager_get_has_accelerometer (self);
	if (old_value != value) {
		self->priv->_has_accelerometer = value;
		g_object_notify_by_pspec ((GObject *) self, display_sensor_manager_properties[DISPLAY_SENSOR_MANAGER_HAS_ACCELEROMETER_PROPERTY]);
	}
}

static GObject *
display_sensor_manager_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	DisplaySensorManager * self;
	GError* _inner_error0_ = NULL;
	parent_class = G_OBJECT_CLASS (display_sensor_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DISPLAY_TYPE_SENSOR_MANAGER, DisplaySensorManager);
	{
		DisplaySensorProxy* sensor_proxy = NULL;
		DisplaySensorProxy* _tmp0_;
		DisplaySensorProxy* _tmp1_;
		gboolean _tmp2_;
		gboolean _tmp3_;
		_tmp0_ = (DisplaySensorProxy*) g_initable_new (DISPLAY_TYPE_SENSOR_PROXY_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "net.hadess.SensorProxy", "g-bus-type", G_BUS_TYPE_SYSTEM, "g-object-path", "/net/hadess/SensorProxy", "g-interface-name", "net.hadess.SensorProxy", NULL);
		sensor_proxy = (DisplaySensorProxy*) _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp1_ = sensor_proxy;
		_tmp2_ = display_sensor_proxy_get_has_accelerometer (_tmp1_);
		_tmp3_ = _tmp2_;
		display_sensor_manager_set_has_accelerometer (self, _tmp3_);
		_g_object_unref0 (sensor_proxy);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp4_;
		const gchar* _tmp5_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp4_ = e;
		_tmp5_ = _tmp4_->message;
		g_info ("SensorManager.vala:27: Unable to connect to SensorProxy bus, probably " \
"means no accelerometer supported: %s", _tmp5_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
	}
	return obj;
}

static void
display_sensor_manager_class_init (DisplaySensorManagerClass * klass,
                                   gpointer klass_data)
{
	display_sensor_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DisplaySensorManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_display_sensor_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_display_sensor_manager_set_property;
	G_OBJECT_CLASS (klass)->constructor = display_sensor_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = display_sensor_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DISPLAY_SENSOR_MANAGER_HAS_ACCELEROMETER_PROPERTY, display_sensor_manager_properties[DISPLAY_SENSOR_MANAGER_HAS_ACCELEROMETER_PROPERTY] = g_param_spec_boolean ("has-accelerometer", "has-accelerometer", "has-accelerometer", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
display_sensor_manager_instance_init (DisplaySensorManager * self,
                                      gpointer klass)
{
	self->priv = display_sensor_manager_get_instance_private (self);
}

static void
display_sensor_manager_finalize (GObject * obj)
{
	DisplaySensorManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DISPLAY_TYPE_SENSOR_MANAGER, DisplaySensorManager);
	G_OBJECT_CLASS (display_sensor_manager_parent_class)->finalize (obj);
}

static GType
display_sensor_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DisplaySensorManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) display_sensor_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DisplaySensorManager), 0, (GInstanceInitFunc) display_sensor_manager_instance_init, NULL };
	GType display_sensor_manager_type_id;
	display_sensor_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "DisplaySensorManager", &g_define_type_info, 0);
	DisplaySensorManager_private_offset = g_type_add_instance_private (display_sensor_manager_type_id, sizeof (DisplaySensorManagerPrivate));
	return display_sensor_manager_type_id;
}

GType
display_sensor_manager_get_type (void)
{
	static volatile gsize display_sensor_manager_type_id__once = 0;
	if (g_once_init_enter (&display_sensor_manager_type_id__once)) {
		GType display_sensor_manager_type_id;
		display_sensor_manager_type_id = display_sensor_manager_get_type_once ();
		g_once_init_leave (&display_sensor_manager_type_id__once, display_sensor_manager_type_id);
	}
	return display_sensor_manager_type_id__once;
}

static void
_vala_display_sensor_manager_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	DisplaySensorManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DISPLAY_TYPE_SENSOR_MANAGER, DisplaySensorManager);
	switch (property_id) {
		case DISPLAY_SENSOR_MANAGER_HAS_ACCELEROMETER_PROPERTY:
		g_value_set_boolean (value, display_sensor_manager_get_has_accelerometer (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_display_sensor_manager_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	DisplaySensorManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DISPLAY_TYPE_SENSOR_MANAGER, DisplaySensorManager);
	switch (property_id) {
		case DISPLAY_SENSOR_MANAGER_HAS_ACCELEROMETER_PROPERTY:
		display_sensor_manager_set_has_accelerometer (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

