160 lines
5.9 KiB
Text
160 lines
5.9 KiB
Text
|
https://gitlab.freedesktop.org/upower/upower/-/issues/201
|
||
|
|
||
|
Index: src/openbsd/up-backend.c
|
||
|
--- src/openbsd/up-backend.c.orig
|
||
|
+++ src/openbsd/up-backend.c
|
||
|
@@ -33,6 +33,7 @@ static void up_backend_init (UpBackend *backend);
|
||
|
static void up_backend_finalize (GObject *object);
|
||
|
|
||
|
static gboolean up_backend_apm_get_power_info(struct apm_power_info*);
|
||
|
+static gpointer up_backend_apm_event_thread(gpointer object);
|
||
|
UpDeviceState up_backend_apm_get_battery_state_value(u_char battery_state);
|
||
|
static void up_backend_update_acpibat_state(UpDevice*, struct sensordev);
|
||
|
static void up_backend_update_lid_status(UpDaemon*);
|
||
|
@@ -127,10 +128,63 @@ up_apm_device_get_online (UpDevice *device, gboolean *
|
||
|
gboolean
|
||
|
up_backend_coldplug (UpBackend *backend, UpDaemon *daemon)
|
||
|
{
|
||
|
- backend->priv->daemon = g_object_ref (daemon);
|
||
|
+ GError *err = NULL;
|
||
|
+ UpDeviceClass *device_class;
|
||
|
+ gint64 current_time;
|
||
|
|
||
|
+ backend->priv = up_backend_get_instance_private (backend);
|
||
|
+ backend->priv->daemon = g_object_ref (daemon);
|
||
|
+ backend->priv->is_laptop = up_native_is_laptop();
|
||
|
+ g_debug("is_laptop:%d",backend->priv->is_laptop);
|
||
|
if (backend->priv->is_laptop)
|
||
|
{
|
||
|
+ UpApmNative *acnative = NULL;
|
||
|
+ UpApmNative *battnative = NULL;
|
||
|
+
|
||
|
+ acnative = up_apm_native_new("/ac");
|
||
|
+ battnative = up_apm_native_new("/batt");
|
||
|
+
|
||
|
+ backend->priv->ac = UP_DEVICE(up_device_new (backend->priv->daemon, G_OBJECT(acnative)));
|
||
|
+ backend->priv->battery = UP_DEVICE(up_device_new (backend->priv->daemon, G_OBJECT(battnative)));
|
||
|
+
|
||
|
+ g_object_unref (acnative);
|
||
|
+ g_object_unref (battnative);
|
||
|
+
|
||
|
+ device_class = UP_DEVICE_GET_CLASS (backend->priv->battery);
|
||
|
+ device_class->get_on_battery = up_apm_device_get_on_battery;
|
||
|
+ device_class->get_online = up_apm_device_get_online;
|
||
|
+ device_class->refresh = up_apm_device_refresh;
|
||
|
+ device_class = UP_DEVICE_GET_CLASS (backend->priv->ac);
|
||
|
+ device_class->get_on_battery = up_apm_device_get_on_battery;
|
||
|
+ device_class->get_online = up_apm_device_get_online;
|
||
|
+ device_class->refresh = up_apm_device_refresh;
|
||
|
+ /* creates thread */
|
||
|
+ if((backend->priv->apm_thread = (GThread*) g_thread_try_new("apm-poller",(GThreadFunc)up_backend_apm_event_thread, (void*) backend, &err)) == NULL)
|
||
|
+ {
|
||
|
+ g_warning("Thread create failed: %s", err->message);
|
||
|
+ g_error_free (err);
|
||
|
+ }
|
||
|
+
|
||
|
+ /* setup dummy */
|
||
|
+ current_time = g_get_real_time () / G_USEC_PER_SEC;
|
||
|
+ g_object_set (backend->priv->battery,
|
||
|
+ "type", UP_DEVICE_KIND_BATTERY,
|
||
|
+ "power-supply", TRUE,
|
||
|
+ "is-present", TRUE,
|
||
|
+ "is-rechargeable", TRUE,
|
||
|
+ "has-history", TRUE,
|
||
|
+ "state", UP_DEVICE_STATE_UNKNOWN,
|
||
|
+ "percentage", 0.0f,
|
||
|
+ "time-to-empty", (gint64) 0,
|
||
|
+ "update-time", (guint64) current_time,
|
||
|
+ (void*) NULL);
|
||
|
+ g_object_set (backend->priv->ac,
|
||
|
+ "type", UP_DEVICE_KIND_LINE_POWER,
|
||
|
+ "online", TRUE,
|
||
|
+ "power-supply", TRUE,
|
||
|
+ "update-time", (guint64) current_time,
|
||
|
+ (void*) NULL);
|
||
|
+
|
||
|
up_backend_update_lid_status(daemon);
|
||
|
if (!g_initable_init (G_INITABLE (backend->priv->ac), NULL, NULL))
|
||
|
g_warning ("failed to coldplug ac");
|
||
|
@@ -142,7 +196,6 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *dae
|
||
|
else
|
||
|
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, backend->priv->battery);
|
||
|
}
|
||
|
-
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
@@ -259,7 +312,7 @@ up_backend_update_battery_state(UpDevice* device)
|
||
|
gdouble percentage;
|
||
|
gboolean ret, is_present;
|
||
|
struct sensordev sdev;
|
||
|
- UpDeviceState cur_state, new_state;
|
||
|
+ UpDeviceState cur_state, new_state = UP_DEVICE_STATE_UNKNOWN;
|
||
|
gint64 cur_time_to_empty, new_time_to_empty;
|
||
|
struct apm_power_info a;
|
||
|
|
||
|
@@ -597,63 +650,7 @@ up_backend_class_init (UpBackendClass *klass)
|
||
|
static void
|
||
|
up_backend_init (UpBackend *backend)
|
||
|
{
|
||
|
- GError *err = NULL;
|
||
|
- UpDeviceClass *device_class;
|
||
|
- gint64 current_time;
|
||
|
-
|
||
|
backend->priv = up_backend_get_instance_private (backend);
|
||
|
- backend->priv->is_laptop = up_native_is_laptop();
|
||
|
- g_debug("is_laptop:%d",backend->priv->is_laptop);
|
||
|
- if (backend->priv->is_laptop)
|
||
|
- {
|
||
|
- UpApmNative *acnative = NULL;
|
||
|
- UpApmNative *battnative = NULL;
|
||
|
-
|
||
|
- acnative = up_apm_native_new("/ac");
|
||
|
- battnative = up_apm_native_new("/batt");
|
||
|
-
|
||
|
- backend->priv->ac = UP_DEVICE(up_device_new (backend->priv->daemon, G_OBJECT(acnative)));
|
||
|
- backend->priv->battery = UP_DEVICE(up_device_new (backend->priv->daemon, G_OBJECT(battnative)));
|
||
|
-
|
||
|
- g_object_unref (acnative);
|
||
|
- g_object_unref (battnative);
|
||
|
-
|
||
|
- device_class = UP_DEVICE_GET_CLASS (backend->priv->battery);
|
||
|
- device_class->get_on_battery = up_apm_device_get_on_battery;
|
||
|
- device_class->get_online = up_apm_device_get_online;
|
||
|
- device_class->refresh = up_apm_device_refresh;
|
||
|
- device_class = UP_DEVICE_GET_CLASS (backend->priv->ac);
|
||
|
- device_class->get_on_battery = up_apm_device_get_on_battery;
|
||
|
- device_class->get_online = up_apm_device_get_online;
|
||
|
- device_class->refresh = up_apm_device_refresh;
|
||
|
- /* creates thread */
|
||
|
- if((backend->priv->apm_thread = (GThread*) g_thread_try_new("apm-poller",(GThreadFunc)up_backend_apm_event_thread, (void*) backend, &err)) == NULL)
|
||
|
- {
|
||
|
- g_warning("Thread create failed: %s", err->message);
|
||
|
- g_error_free (err);
|
||
|
- }
|
||
|
-
|
||
|
- /* setup dummy */
|
||
|
- current_time = g_get_real_time () / G_USEC_PER_SEC;
|
||
|
- g_object_set (backend->priv->battery,
|
||
|
- "type", UP_DEVICE_KIND_BATTERY,
|
||
|
- "power-supply", TRUE,
|
||
|
- "is-present", TRUE,
|
||
|
- "is-rechargeable", TRUE,
|
||
|
- "has-history", TRUE,
|
||
|
- "state", UP_DEVICE_STATE_UNKNOWN,
|
||
|
- "percentage", 0.0f,
|
||
|
- "time-to-empty", (gint64) 0,
|
||
|
- "update-time", (guint64) current_time,
|
||
|
- (void*) NULL);
|
||
|
- g_object_set (backend->priv->ac,
|
||
|
- "type", UP_DEVICE_KIND_LINE_POWER,
|
||
|
- "online", TRUE,
|
||
|
- "power-supply", TRUE,
|
||
|
- "update-time", (guint64) current_time,
|
||
|
- (void*) NULL);
|
||
|
- }
|
||
|
-
|
||
|
backend->priv->config = up_config_new ();
|
||
|
backend->priv->seat_manager_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
||
|
0,
|