From 6ab61bac9d825849fc017e50c6311d09428ec437 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 19 Jun 2018 13:41:30 +0200 Subject: linux: Detect hardware that needs more polling after event When an event happens on the power line, and we are using a particular device (in this case a MacBook or MacBookAir), we might need to poll more aggressively after the event. This adds a function to detect and export this. --- src/linux/Makefile.am | 1 + src/linux/up-backend-linux-private.h | 29 +++++++++++++++++++++++++++++ src/linux/up-backend.c | 25 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 src/linux/up-backend-linux-private.h diff --git a/src/linux/Makefile.am b/src/linux/Makefile.am index 0121067..aec0b31 100644 --- a/src/linux/Makefile.am +++ b/src/linux/Makefile.am @@ -42,6 +42,7 @@ libupshared_la_SOURCES = \ up-input.c \ up-input.h \ up-backend.c \ + up-backend-linux-private.h \ up-native.c \ hidpp-device.c \ hidpp-device.h \ diff --git a/src/linux/up-backend-linux-private.h b/src/linux/up-backend-linux-private.h new file mode 100644 index 0000000..0e6e77c --- /dev/null +++ b/src/linux/up-backend-linux-private.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2018 Bastien Nocera + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __UP_BACKEND_LINUX_PRIVATE_H +#define __UP_BACKEND_LINUX_PRIVATE_H + +#include + +gboolean up_backend_needs_poll_after_uevent (void); + +#endif /* __UP_BACKEND_LINUX_PRIVATE_H */ diff --git a/src/linux/up-backend.c b/src/linux/up-backend.c index a9981ac..bffc8fa 100644 --- a/src/linux/up-backend.c +++ b/src/linux/up-backend.c @@ -31,9 +31,12 @@ #include #include "up-backend.h" +#include "up-backend-linux-private.h" #include "up-daemon.h" #include "up-device.h" +#include "sysfs-utils.h" + #include "up-device-supply.h" #include "up-device-csr.h" #include "up-device-unifying.h" @@ -277,6 +280,28 @@ up_backend_uevent_signal_handler_cb (GUdevClient *client, const gchar *action, } } +static gpointer +is_macbook (gpointer data) +{ + char *product; + gboolean ret = FALSE; + + product = sysfs_get_string ("/sys/devices/virtual/dmi/id/", "product_name"); + if (product == NULL) + return GINT_TO_POINTER(ret); + ret = g_str_has_prefix (product, "MacBook"); + g_free (product); + return GINT_TO_POINTER(ret); +} + +gboolean +up_backend_needs_poll_after_uevent (void) +{ + static GOnce dmi_once = G_ONCE_INIT; + g_once (&dmi_once, is_macbook, NULL); + return GPOINTER_TO_INT(dmi_once.retval); +} + static gboolean is_battery_iface_proxy (GDBusProxy *interface_proxy) { -- cgit v1.2.1