From e651b07633f5a9a3bd499a2e3aaf2f8b7e4f8cef Mon Sep 17 00:00:00 2001
From: Dylan Van Assche <me@dylanvanassche.be>
Date: Sun, 23 Apr 2023 16:54:10 +0200
Subject: [PATCH 1/8] iio-sensor-proxy: depend on libssc

Add libssc library to iio-sensor-proxy and discover FastRPC
devices as possible subsystems for sensors. The presence of
FastRPC devices indicate the support for Qualcomm Snapdragon Sensor
Core (SSC).
---
 meson.build            |  3 +++
 meson_options.txt      |  4 ++++
 src/iio-sensor-proxy.c | 15 ++++++++++++++-
 src/meson.build        |  7 +++++++
 4 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 767e539..fe97a27 100644
--- a/meson.build
+++ b/meson.build
@@ -46,6 +46,9 @@ gio_dep = dependency('gio-2.0')
 gudev_dep = dependency('gudev-1.0', version: '>= 237')
 polkit_gobject_dep = dependency('polkit-gobject-1', version: '>= 0.91')
 polkit_policy_directory = polkit_gobject_dep.get_pkgconfig_variable('policydir')
+if get_option('ssc-support')
+  libssc_dep = dependency('libssc-glib')
+endif
 
 xmllint = find_program('xmllint', required: false)
 
diff --git a/meson_options.txt b/meson_options.txt
index de5fbf4..2b60f82 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -18,6 +18,10 @@ option('geoclue-user',
        description: 'The USER (existing) as which geoclue service is running',
        type: 'string',
        value: 'geoclue')
+option('ssc-support',
+       description: 'Enable Qualcomm SSC support',
+       type: 'boolean',
+       value: false)
 option('gtk_doc',
        type: 'boolean',
        value: false,
diff --git a/src/iio-sensor-proxy.c b/src/iio-sensor-proxy.c
index 1884839..220dc71 100644
--- a/src/iio-sensor-proxy.c
+++ b/src/iio-sensor-proxy.c
@@ -124,6 +124,11 @@ find_sensors (GUdevClient *client,
 	platform = g_udev_client_query_by_subsystem (client, "platform");
 	devices = g_list_concat (devices, input);
 	devices = g_list_concat (devices, platform);
+#ifdef HAS_LIBSSC
+	GList *fastrpc;
+	fastrpc = g_udev_client_query_by_subsystem (client, "misc");
+	devices = g_list_concat (devices, fastrpc);
+#endif
 
 	/* Find the devices */
 	for (l = devices; l != NULL; l = l->next) {
@@ -686,7 +691,15 @@ name_acquired_handler (GDBusConnection *connection,
 		       gpointer         user_data)
 {
 	SensorData *data = user_data;
-	const gchar * const subsystems[] = { "iio", "input", "platform", NULL };
+	const gchar * const subsystems[] = {
+        "iio",
+        "input",
+        "platform",
+#ifdef HAS_LIBSSC
+        "misc",
+#endif
+        NULL
+    };
 	guint i;
 
 	data->client = g_udev_client_new (subsystems);
diff --git a/src/meson.build b/src/meson.build
index 4b822fc..3e503de 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,5 +1,8 @@
 config_h = configuration_data()
 config_h.set_quoted('VERSION', meson.project_version())
+if get_option('ssc-support')
+  config_h.set_quoted('HAS_LIBSSC', '1')
+endif
 config_h_files = configure_file(
   output: 'config.h',
   configuration: config_h
@@ -7,6 +10,10 @@ config_h_files = configure_file(
 
 deps = [ gio_dep, gudev_dep, mathlib_dep, polkit_gobject_dep ]
 
+if get_option('ssc-support')
+  deps = deps + [ libssc_dep ]
+endif
+
 resources = gnome.compile_resources(
     'iio-sensor-proxy-resources', 'iio-sensor-proxy.gresource.xml',
     c_name: 'iio_sensor_proxy',
-- 
2.45.1

