mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-03 19:28:00 +02:00
openbsd: Use separate 'static' devices for ac and battery
Move UpApmNative object to its own header for use by UpBackend Signed-off-by: Richard Hughes <richard@hughsie.com>
This commit is contained in:
parent
a5e0d246e0
commit
c9296f51ba
3 changed files with 61 additions and 36 deletions
37
src/openbsd/up-apm-native.h
Normal file
37
src/openbsd/up-apm-native.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef __UP_APM_NATIVE_H__
|
||||
#define __UP_APM_NATIVE_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define UP_TYPE_APM_NATIVE (up_apm_native_get_type ())
|
||||
#define UP_APM_NATIVE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_APM_NATIVE, UpApmNative))
|
||||
#define UP_APM_NATIVE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_APM_NATIVE, UpApmNativeClass))
|
||||
#define UP_IS_APM_NATIVE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_APM_NATIVE))
|
||||
#define UP_IS_APM_NATIVE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_APM_NATIVE))
|
||||
#define UP_APM_NATIVE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_APM_NATIVE, UpApmNativeClass))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObject parent;
|
||||
gchar* path;
|
||||
} UpApmNative;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} UpApmNativeClass;
|
||||
|
||||
|
||||
// XX in .c ?
|
||||
//GType up_apm_native_get_type (void);
|
||||
//G_DEFINE_TYPE (UpApmNative, up_apm_native, G_TYPE_OBJECT)
|
||||
|
||||
UpApmNative* up_apm_native_new (const char*);
|
||||
const gchar * up_apm_native_get_path(UpApmNative*);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
@ -8,6 +8,8 @@
|
|||
/* APM macros */
|
||||
#include <machine/apmvar.h>
|
||||
|
||||
#include "up-apm-native.h"
|
||||
|
||||
#include "up-backend.h"
|
||||
#include "up-daemon.h"
|
||||
#include "up-marshal.h"
|
||||
|
|
@ -24,9 +26,8 @@ static void up_backend_finalize (GObject *object);
|
|||
struct UpBackendPrivate
|
||||
{
|
||||
UpDaemon *daemon;
|
||||
UpDevice *device;
|
||||
UpDeviceList *device_list; /* unused */
|
||||
GObject *native;
|
||||
UpDevice *ac;
|
||||
UpDevice *battery;
|
||||
GThread *apm_thread;
|
||||
int apm_fd;
|
||||
};
|
||||
|
|
@ -47,12 +48,17 @@ G_DEFINE_TYPE (UpBackend, up_backend, G_TYPE_OBJECT)
|
|||
static gboolean
|
||||
up_backend_add_cb (UpBackend *backend)
|
||||
{
|
||||
UpApmNative *acnative = up_apm_native_new("/ac");
|
||||
UpApmNative *battnative = up_apm_native_new("/batt");
|
||||
/* coldplug */
|
||||
if (!up_device_coldplug (backend->priv->device, backend->priv->daemon, backend->priv->native))
|
||||
g_warning ("failed to coldplug");
|
||||
/* emit */
|
||||
if (!up_device_coldplug (backend->priv->ac, backend->priv->daemon, G_OBJECT(acnative)))
|
||||
g_warning ("failed to coldplug ac");
|
||||
else
|
||||
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, backend->priv->native, backend->priv->device);
|
||||
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, acnative, backend->priv->ac);
|
||||
if (!up_device_coldplug (backend->priv->battery, backend->priv->daemon, G_OBJECT(battnative)))
|
||||
g_warning ("failed to coldplug battery");
|
||||
else
|
||||
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, battnative, backend->priv->battery);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +80,6 @@ gboolean
|
|||
up_backend_coldplug (UpBackend *backend, UpDaemon *daemon)
|
||||
{
|
||||
backend->priv->daemon = g_object_ref (daemon);
|
||||
backend->priv->device_list = up_daemon_get_device_list (daemon);
|
||||
/* small delay until first device is added */
|
||||
g_timeout_add_seconds (1, (GSourceFunc) up_backend_add_cb, backend);
|
||||
|
||||
|
|
@ -189,7 +194,7 @@ up_backend_apm_powerchange_event_cb(gpointer object)
|
|||
g_message("Got event, in callback, percentage=%d", a.battery_life);
|
||||
|
||||
g_get_current_time (&timeval);
|
||||
g_object_set (backend->priv->device,
|
||||
g_object_set (backend->priv->battery,
|
||||
"state", up_backend_apm_get_battery_state_value(a.battery_state),
|
||||
"percentage", a.battery_life,
|
||||
"update-time", (guint64) timeval.tv_sec,
|
||||
|
|
@ -299,9 +304,8 @@ up_backend_init (UpBackend *backend)
|
|||
|
||||
backend->priv = UP_BACKEND_GET_PRIVATE (backend);
|
||||
backend->priv->daemon = NULL;
|
||||
backend->priv->device_list = NULL;
|
||||
backend->priv->native = g_object_new (UP_TYPE_DEVICE, NULL);
|
||||
backend->priv->device = up_device_new ();
|
||||
backend->priv->ac = up_device_new ();
|
||||
backend->priv->battery = up_device_new ();
|
||||
|
||||
g_thread_init (NULL);
|
||||
/* creates thread */
|
||||
|
|
@ -312,6 +316,7 @@ up_backend_init (UpBackend *backend)
|
|||
}
|
||||
|
||||
/* setup dummy */
|
||||
/*
|
||||
g_object_set (backend->priv->device,
|
||||
"native-path", "/hal/blows/goats",
|
||||
"vendor", "hughsie",
|
||||
|
|
@ -332,6 +337,7 @@ up_backend_init (UpBackend *backend)
|
|||
"energy-rate", 5.0f,
|
||||
"percentage", 50.0f,
|
||||
NULL);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -348,10 +354,10 @@ up_backend_finalize (GObject *object)
|
|||
|
||||
if (backend->priv->daemon != NULL)
|
||||
g_object_unref (backend->priv->daemon);
|
||||
if (backend->priv->device_list != NULL)
|
||||
g_object_unref (backend->priv->device_list);
|
||||
g_object_unref (backend->priv->native);
|
||||
g_object_unref (backend->priv->device);
|
||||
if (backend->priv->battery != NULL)
|
||||
g_object_unref (backend->priv->battery);
|
||||
if (backend->priv->ac != NULL)
|
||||
g_object_unref (backend->priv->ac);
|
||||
/* XXX stop apm_thread ? */
|
||||
|
||||
G_OBJECT_CLASS (up_backend_parent_class)->finalize (object);
|
||||
|
|
|
|||
|
|
@ -1,27 +1,9 @@
|
|||
#include "up-apm-native.h"
|
||||
#include "up-native.h"
|
||||
|
||||
#define UP_TYPE_APM_NATIVE (up_apm_native_get_type ())
|
||||
#define UP_APM_NATIVE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_APM_NATIVE, UpApmNative))
|
||||
#define UP_APM_NATIVE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_APM_NATIVE, UpApmNativeClass))
|
||||
#define UP_IS_APM_NATIVE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_APM_NATIVE))
|
||||
#define UP_IS_APM_NATIVE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_APM_NATIVE))
|
||||
#define UP_APM_NATIVE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_APM_NATIVE, UpApmNativeClass))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObject parent;
|
||||
gchar* path;
|
||||
} UpApmNative;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} UpApmNativeClass;
|
||||
|
||||
/* XXX why does this macro needs to be in the .c ? */
|
||||
G_DEFINE_TYPE (UpApmNative, up_apm_native, G_TYPE_OBJECT)
|
||||
|
||||
GType up_apm_native_get_type(void);
|
||||
|
||||
static void
|
||||
up_apm_native_class_init (UpApmNativeClass *klass)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue