device: Move daemon/native object into construct only properties

Rather than this weird situation where they are immediately passed in
through the "coldplug" method. Doing this is the first step to make
UpDevice into an initable object (removing the "coldplug" method).
This commit is contained in:
Benjamin Berg 2022-04-01 11:32:24 +02:00
parent 77a20b84e4
commit bd488facf1
20 changed files with 164 additions and 84 deletions

View file

@ -91,7 +91,7 @@ up_backend_add_cb (UpBackend *backend)
} }
/* emit */ /* emit */
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, backend->priv->native, backend->priv->device); g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, backend->priv->device);
/* setup poll */ /* setup poll */
timer_id = g_timeout_add_seconds (2, (GSourceFunc) up_backend_changed_time_cb, backend); timer_id = g_timeout_add_seconds (2, (GSourceFunc) up_backend_changed_time_cb, backend);
@ -202,13 +202,13 @@ up_backend_class_init (UpBackendClass *klass)
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_added), G_STRUCT_OFFSET (UpBackendClass, device_added),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); G_TYPE_NONE, 1, UP_TYPE_DEVICE);
signals [SIGNAL_DEVICE_REMOVED] = signals [SIGNAL_DEVICE_REMOVED] =
g_signal_new ("device-removed", g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_removed), G_STRUCT_OFFSET (UpBackendClass, device_removed),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); G_TYPE_NONE, 1, UP_TYPE_DEVICE);
} }
/** /**

View file

@ -185,8 +185,8 @@ up_backend_create_new_device (UpBackend *backend, UpAcpiNative *native)
UpDevice *device; UpDevice *device;
gboolean ret; gboolean ret;
device = UP_DEVICE (up_device_supply_new ()); device = UP_DEVICE (up_device_supply_new (backend->priv->daemon, G_OBJECT (native)));
ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (native)); ret = up_device_coldplug (device);
if (!ret) if (!ret)
g_object_unref (device); g_object_unref (device);
else { else {
@ -209,7 +209,7 @@ up_backend_create_new_device (UpBackend *backend, UpAcpiNative *native)
} }
} }
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, native, device); g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device);
} }
return ret; return ret;
@ -395,13 +395,13 @@ up_backend_class_init (UpBackendClass *klass)
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_added), G_STRUCT_OFFSET (UpBackendClass, device_added),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); G_TYPE_NONE, 1, UP_TYPE_DEVICE);
signals [SIGNAL_DEVICE_REMOVED] = signals [SIGNAL_DEVICE_REMOVED] =
g_signal_new ("device-removed", g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_removed), G_STRUCT_OFFSET (UpBackendClass, device_removed),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); G_TYPE_NONE, 1, UP_TYPE_DEVICE);
} }
/** /**

View file

@ -485,8 +485,11 @@ up_device_supply_class_init (UpDeviceSupplyClass *klass)
* up_device_supply_new: * up_device_supply_new:
**/ **/
UpDeviceSupply * UpDeviceSupply *
up_device_supply_new (void) up_device_supply_new (UpDaemon *daemon,
GObject *native)
{ {
return g_object_new (UP_TYPE_DEVICE_SUPPLY, NULL); return UP_DEVICE_SUPPLY (g_object_new (UP_TYPE_DEVICE_SUPPLY,
"daemon", daemon,
"native", native,
NULL));
} }

View file

@ -48,7 +48,8 @@ typedef struct
} UpDeviceSupplyClass; } UpDeviceSupplyClass;
GType up_device_supply_get_type (void); GType up_device_supply_get_type (void);
UpDeviceSupply *up_device_supply_new (void); UpDeviceSupply *up_device_supply_new (UpDaemon *daemon,
GObject *native);
G_END_DECLS G_END_DECLS

View file

@ -122,11 +122,11 @@ up_backend_device_new (UpBackend *backend, GUdevDevice *native)
if (g_strcmp0 (subsys, "power_supply") == 0) { if (g_strcmp0 (subsys, "power_supply") == 0) {
/* are we a valid power supply */ /* are we a valid power supply */
device = UP_DEVICE (up_device_supply_new ()); device = UP_DEVICE (up_device_supply_new (backend->priv->daemon, G_OBJECT (native)));
g_object_set (G_OBJECT(device), g_object_set (G_OBJECT(device),
"ignore-system-percentage", GPOINTER_TO_INT (is_macbook (NULL)), "ignore-system-percentage", GPOINTER_TO_INT (is_macbook (NULL)),
NULL); NULL);
ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (native)); ret = up_device_coldplug (device);
if (ret) if (ret)
goto out; goto out;
@ -136,8 +136,8 @@ up_backend_device_new (UpBackend *backend, GUdevDevice *native)
} else if (g_strcmp0 (subsys, "tty") == 0) { } else if (g_strcmp0 (subsys, "tty") == 0) {
/* see if this is a Watts Up Pro device */ /* see if this is a Watts Up Pro device */
device = UP_DEVICE (up_device_wup_new ()); device = UP_DEVICE (up_device_wup_new (backend->priv->daemon, G_OBJECT (native)));
ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (native)); ret = up_device_coldplug (device);
if (ret) if (ret)
goto out; goto out;
@ -148,16 +148,16 @@ up_backend_device_new (UpBackend *backend, GUdevDevice *native)
#ifdef HAVE_IDEVICE #ifdef HAVE_IDEVICE
/* see if this is an iDevice */ /* see if this is an iDevice */
device = UP_DEVICE (up_device_idevice_new ()); device = UP_DEVICE (up_device_idevice_new (backend->priv->daemon, G_OBJECT (native)));
ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (native)); ret = up_device_coldplug (device);
if (ret) if (ret)
goto out; goto out;
g_object_unref (device); g_object_unref (device);
#endif /* HAVE_IDEVICE */ #endif /* HAVE_IDEVICE */
/* try to detect a HID UPS */ /* try to detect a HID UPS */
device = UP_DEVICE (up_device_hid_new ()); device = UP_DEVICE (up_device_hid_new (backend->priv->daemon, G_OBJECT (native)));
ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (native)); ret = up_device_coldplug (device);
if (ret) if (ret)
goto out; goto out;
@ -247,7 +247,7 @@ up_backend_device_add (UpBackend *backend, GUdevDevice *native, const char *was_
g_warning ("treated %s event as add on %s", was_event, g_udev_device_get_sysfs_path (native)); g_warning ("treated %s event as add on %s", was_event, g_udev_device_get_sysfs_path (native));
/* emit */ /* emit */
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, native, device); g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device);
out: out:
g_clear_object (&object); g_clear_object (&object);
return ret; return ret;
@ -269,7 +269,7 @@ up_backend_device_remove (UpBackend *backend, GUdevDevice *native)
device = UP_DEVICE (object); device = UP_DEVICE (object);
/* emit */ /* emit */
g_debug ("emitting device-removed: %s", g_udev_device_get_sysfs_path (native)); g_debug ("emitting device-removed: %s", g_udev_device_get_sysfs_path (native));
g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, native, device); g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, device);
out: out:
g_clear_object (&object); g_clear_object (&object);
@ -358,7 +358,7 @@ bluez_interface_removed (GDBusObjectManager *manager,
return; return;
g_debug ("emitting device-removed: %s", g_dbus_object_get_object_path (bus_object)); g_debug ("emitting device-removed: %s", g_dbus_object_get_object_path (bus_object));
g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, bus_object, UP_DEVICE (object)); g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, UP_DEVICE (object));
g_object_unref (object); g_object_unref (object);
} }
@ -383,15 +383,15 @@ bluez_interface_added (GDBusObjectManager *manager,
return; return;
} }
device = UP_DEVICE (up_device_bluez_new ()); device = UP_DEVICE (up_device_bluez_new (backend->priv->daemon, G_OBJECT (bus_object)));
ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (bus_object)); ret = up_device_coldplug (device);
if (!ret) { if (!ret) {
g_object_unref (device); g_object_unref (device);
return; return;
} }
g_debug ("emitting device-added: %s", g_dbus_object_get_object_path (bus_object)); g_debug ("emitting device-added: %s", g_dbus_object_get_object_path (bus_object));
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, bus_object, device); g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device);
} }
static void static void
@ -470,7 +470,7 @@ bluez_vanished (GDBusConnection *connection,
object = G_DBUS_OBJECT (up_device_get_native (device)); object = G_DBUS_OBJECT (up_device_get_native (device));
g_debug ("emitting device-removed: %s", g_dbus_object_get_object_path (object)); g_debug ("emitting device-removed: %s", g_dbus_object_get_object_path (object));
g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, object, UP_DEVICE (object)); g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, UP_DEVICE (object));
} }
} }
@ -785,13 +785,13 @@ up_backend_class_init (UpBackendClass *klass)
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_added), G_STRUCT_OFFSET (UpBackendClass, device_added),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); G_TYPE_NONE, 1, UP_TYPE_DEVICE);
signals [SIGNAL_DEVICE_REMOVED] = signals [SIGNAL_DEVICE_REMOVED] =
g_signal_new ("device-removed", g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_removed), G_STRUCT_OFFSET (UpBackendClass, device_removed),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); G_TYPE_NONE, 1, UP_TYPE_DEVICE);
} }
static void static void

View file

@ -291,8 +291,11 @@ up_device_bluez_class_init (UpDeviceBluezClass *klass)
} }
UpDeviceBluez * UpDeviceBluez *
up_device_bluez_new (void) up_device_bluez_new (UpDaemon *daemon,
GObject *native)
{ {
return g_object_new (UP_TYPE_DEVICE_BLUEZ, NULL); return UP_DEVICE_BLUEZ (g_object_new (UP_TYPE_DEVICE_BLUEZ,
"daemon", daemon,
"native", native,
NULL));
} }

View file

@ -46,7 +46,8 @@ typedef struct
} UpDeviceBluezClass; } UpDeviceBluezClass;
GType up_device_bluez_get_type (void); GType up_device_bluez_get_type (void);
UpDeviceBluez *up_device_bluez_new (void); UpDeviceBluez *up_device_bluez_new (UpDaemon *daemon,
GObject *native);
void up_device_bluez_update (UpDeviceBluez *bluez, void up_device_bluez_update (UpDeviceBluez *bluez,
GVariant *properties); GVariant *properties);

View file

@ -518,8 +518,11 @@ up_device_hid_class_init (UpDeviceHidClass *klass)
* up_device_hid_new: * up_device_hid_new:
**/ **/
UpDeviceHid * UpDeviceHid *
up_device_hid_new (void) up_device_hid_new (UpDaemon *daemon,
GObject *native)
{ {
return g_object_new (UP_TYPE_DEVICE_HID, NULL); return UP_DEVICE_HID (g_object_new (UP_TYPE_DEVICE_HID,
"daemon", daemon,
"native", native,
NULL));
} }

View file

@ -47,7 +47,8 @@ typedef struct
} UpDeviceHidClass; } UpDeviceHidClass;
GType up_device_hid_get_type (void); GType up_device_hid_get_type (void);
UpDeviceHid *up_device_hid_new (void); UpDeviceHid *up_device_hid_new (UpDaemon *daemon,
GObject *native);
G_END_DECLS G_END_DECLS

View file

@ -424,8 +424,11 @@ up_device_idevice_class_init (UpDeviceIdeviceClass *klass)
* up_device_idevice_new: * up_device_idevice_new:
**/ **/
UpDeviceIdevice * UpDeviceIdevice *
up_device_idevice_new (void) up_device_idevice_new (UpDaemon *daemon,
GObject *native)
{ {
return g_object_new (UP_TYPE_DEVICE_IDEVICE, NULL); return UP_DEVICE_IDEVICE (g_object_new (UP_TYPE_DEVICE_IDEVICE,
"daemon", daemon,
"native", native,
NULL));
} }

View file

@ -49,7 +49,8 @@ typedef struct
} UpDeviceIdeviceClass; } UpDeviceIdeviceClass;
GType up_device_idevice_get_type (void); GType up_device_idevice_get_type (void);
UpDeviceIdevice *up_device_idevice_new (void); UpDeviceIdevice *up_device_idevice_new (UpDaemon *daemon,
GObject *native);
G_END_DECLS G_END_DECLS

View file

@ -1363,8 +1363,11 @@ up_device_supply_class_init (UpDeviceSupplyClass *klass)
* up_device_supply_new: * up_device_supply_new:
**/ **/
UpDeviceSupply * UpDeviceSupply *
up_device_supply_new (void) up_device_supply_new (UpDaemon *daemon,
GObject *native)
{ {
return g_object_new (UP_TYPE_DEVICE_SUPPLY, NULL); return UP_DEVICE_SUPPLY (g_object_new (UP_TYPE_DEVICE_SUPPLY,
"daemon", daemon,
"native", native,
NULL));
} }

View file

@ -47,8 +47,9 @@ typedef struct
UpDeviceClass parent_class; UpDeviceClass parent_class;
} UpDeviceSupplyClass; } UpDeviceSupplyClass;
GType up_device_supply_get_type (void); GType up_device_supply_get_type (void);
UpDeviceSupply *up_device_supply_new (void); UpDeviceSupply *up_device_supply_new (UpDaemon *daemon,
GObject *native);
G_END_DECLS G_END_DECLS

View file

@ -465,8 +465,11 @@ up_device_wup_class_init (UpDeviceWupClass *klass)
* up_device_wup_new: * up_device_wup_new:
**/ **/
UpDeviceWup * UpDeviceWup *
up_device_wup_new (void) up_device_wup_new (UpDaemon *daemon,
GObject *native)
{ {
return g_object_new (UP_TYPE_DEVICE_WUP, NULL); return UP_DEVICE_WUP (g_object_new (UP_TYPE_DEVICE_WUP,
"daemon", daemon,
"native", native,
NULL));
} }

View file

@ -47,7 +47,8 @@ typedef struct
} UpDeviceWupClass; } UpDeviceWupClass;
GType up_device_wup_get_type (void); GType up_device_wup_get_type (void);
UpDeviceWup *up_device_wup_new (void); UpDeviceWup *up_device_wup_new (UpDaemon *daemon,
GObject *native);
G_END_DECLS G_END_DECLS

View file

@ -125,24 +125,20 @@ up_apm_device_get_online (UpDevice *device, gboolean * online)
gboolean gboolean
up_backend_coldplug (UpBackend *backend, UpDaemon *daemon) up_backend_coldplug (UpBackend *backend, UpDaemon *daemon)
{ {
UpApmNative *acnative = NULL;
UpApmNative *battnative = NULL;
backend->priv->daemon = g_object_ref (daemon); backend->priv->daemon = g_object_ref (daemon);
if (backend->priv->is_laptop) if (backend->priv->is_laptop)
{ {
up_backend_update_lid_status(daemon); up_backend_update_lid_status(daemon);
acnative = up_apm_native_new("/ac"); if (!up_device_coldplug (backend->priv->ac))
if (!up_device_coldplug (backend->priv->ac, backend->priv->daemon, G_OBJECT(acnative)))
g_warning ("failed to coldplug ac"); g_warning ("failed to coldplug ac");
else else
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, acnative, backend->priv->ac); g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, backend->priv->ac);
battnative = up_apm_native_new("/batt"); if (!up_device_coldplug (backend->priv->battery))
if (!up_device_coldplug (backend->priv->battery, backend->priv->daemon, G_OBJECT(battnative)))
g_warning ("failed to coldplug battery"); g_warning ("failed to coldplug battery");
else else
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, battnative, backend->priv->battery); g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, backend->priv->battery);
} }
return TRUE; return TRUE;
@ -576,13 +572,13 @@ up_backend_class_init (UpBackendClass *klass)
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_added), G_STRUCT_OFFSET (UpBackendClass, device_added),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); G_TYPE_NONE, 1, UP_TYPE_DEVICE);
signals [SIGNAL_DEVICE_REMOVED] = signals [SIGNAL_DEVICE_REMOVED] =
g_signal_new ("device-removed", g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_removed), G_STRUCT_OFFSET (UpBackendClass, device_removed),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); G_TYPE_NONE, 1, UP_TYPE_DEVICE);
} }
/** /**
@ -600,8 +596,18 @@ up_backend_init (UpBackend *backend)
g_debug("is_laptop:%d",backend->priv->is_laptop); g_debug("is_laptop:%d",backend->priv->is_laptop);
if (backend->priv->is_laptop) if (backend->priv->is_laptop)
{ {
backend->priv->ac = UP_DEVICE(up_device_new()); UpApmNative *acnative = NULL;
backend->priv->battery = UP_DEVICE(up_device_new ()); 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 = UP_DEVICE_GET_CLASS (backend->priv->battery);
device_class->get_on_battery = up_apm_device_get_on_battery; device_class->get_on_battery = up_apm_device_get_on_battery;
device_class->get_online = up_apm_device_get_online; device_class->get_online = up_apm_device_get_online;

View file

@ -1009,17 +1009,16 @@ up_daemon_resume_poll (UpDaemon *daemon)
* up_daemon_device_added_cb: * up_daemon_device_added_cb:
**/ **/
static void static void
up_daemon_device_added_cb (UpBackend *backend, GObject *native, UpDevice *device, UpDaemon *daemon) up_daemon_device_added_cb (UpBackend *backend, UpDevice *device, UpDaemon *daemon)
{ {
const gchar *object_path; const gchar *object_path;
UpDaemonPrivate *priv = daemon->priv; UpDaemonPrivate *priv = daemon->priv;
g_return_if_fail (UP_IS_DAEMON (daemon)); g_return_if_fail (UP_IS_DAEMON (daemon));
g_return_if_fail (UP_IS_DEVICE (device)); g_return_if_fail (UP_IS_DEVICE (device));
g_return_if_fail (G_IS_OBJECT (native));
/* add to device list */ /* add to device list */
up_device_list_insert (priv->power_devices, native, G_OBJECT (device)); up_device_list_insert (priv->power_devices, up_device_get_native (device), G_OBJECT (device));
/* connect, so we get changes */ /* connect, so we get changes */
g_signal_connect (device, "notify", g_signal_connect (device, "notify",
@ -1031,7 +1030,7 @@ up_daemon_device_added_cb (UpBackend *backend, GObject *native, UpDevice *device
/* don't crash the session */ /* don't crash the session */
if (object_path == NULL) { if (object_path == NULL) {
g_warning ("INTERNAL STATE CORRUPT (device-added): not sending NULL, native:%p, device:%p", native, device); g_warning ("INTERNAL STATE CORRUPT (device-added): not sending NULL, device:%p", device);
return; return;
} }
up_daemon_update_warning_level (daemon); up_daemon_update_warning_level (daemon);
@ -1042,14 +1041,13 @@ up_daemon_device_added_cb (UpBackend *backend, GObject *native, UpDevice *device
* up_daemon_device_removed_cb: * up_daemon_device_removed_cb:
**/ **/
static void static void
up_daemon_device_removed_cb (UpBackend *backend, GObject *native, UpDevice *device, UpDaemon *daemon) up_daemon_device_removed_cb (UpBackend *backend, UpDevice *device, UpDaemon *daemon)
{ {
const gchar *object_path; const gchar *object_path;
UpDaemonPrivate *priv = daemon->priv; UpDaemonPrivate *priv = daemon->priv;
g_return_if_fail (UP_IS_DAEMON (daemon)); g_return_if_fail (UP_IS_DAEMON (daemon));
g_return_if_fail (UP_IS_DEVICE (device)); g_return_if_fail (UP_IS_DEVICE (device));
g_return_if_fail (G_IS_OBJECT (native));
/* remove from list */ /* remove from list */
up_device_list_remove (priv->power_devices, G_OBJECT(device)); up_device_list_remove (priv->power_devices, G_OBJECT(device));
@ -1060,7 +1058,7 @@ up_daemon_device_removed_cb (UpBackend *backend, GObject *native, UpDevice *devi
/* don't crash the session */ /* don't crash the session */
if (object_path == NULL) { if (object_path == NULL) {
g_warning ("INTERNAL STATE CORRUPT (device-removed): not sending NULL, native:%p, device:%p", native, device); g_warning ("INTERNAL STATE CORRUPT (device-removed): not sending NULL, device:%p", device);
return; return;
} }
up_exported_daemon_emit_device_removed (UP_EXPORTED_DAEMON (daemon), object_path); up_exported_daemon_emit_device_removed (UP_EXPORTED_DAEMON (daemon), object_path);
@ -1126,7 +1124,7 @@ up_daemon_init (UpDaemon *daemon)
daemon->priv->critical_action_lock_fd = -1; daemon->priv->critical_action_lock_fd = -1;
daemon->priv->config = up_config_new (); daemon->priv->config = up_config_new ();
daemon->priv->power_devices = up_device_list_new (); daemon->priv->power_devices = up_device_list_new ();
daemon->priv->display_device = up_device_new (); daemon->priv->display_device = up_device_new (daemon, NULL);
daemon->priv->use_percentage_for_policy = up_config_get_boolean (daemon->priv->config, "UsePercentageForPolicy"); daemon->priv->use_percentage_for_policy = up_config_get_boolean (daemon->priv->config, "UsePercentageForPolicy");
load_percentage_policy (daemon, FALSE); load_percentage_policy (daemon, FALSE);

View file

@ -37,14 +37,24 @@
struct UpDevicePrivate struct UpDevicePrivate
{ {
UpDaemon *daemon; UpDaemon *daemon;
UpHistory *history;
GObject *native; GObject *native;
UpHistory *history;
gboolean has_ever_refresh; gboolean has_ever_refresh;
gboolean is_display_device; gboolean is_display_device;
}; };
G_DEFINE_TYPE_WITH_PRIVATE (UpDevice, up_device, UP_TYPE_EXPORTED_DEVICE_SKELETON) G_DEFINE_TYPE_WITH_PRIVATE (UpDevice, up_device, UP_TYPE_EXPORTED_DEVICE_SKELETON)
enum {
PROP_0,
PROP_DAEMON,
PROP_NATIVE,
N_PROPS
};
static GParamSpec *properties[N_PROPS];
#define UP_DEVICES_DBUS_PATH "/org/freedesktop/UPower/devices" #define UP_DEVICES_DBUS_PATH "/org/freedesktop/UPower/devices"
/* This needs to be called when one of those properties changes: /* This needs to be called when one of those properties changes:
@ -396,7 +406,7 @@ up_device_register_device (UpDevice *device)
* Return %TRUE on success, %FALSE if we failed to get data and should be removed * Return %TRUE on success, %FALSE if we failed to get data and should be removed
**/ **/
gboolean gboolean
up_device_coldplug (UpDevice *device, UpDaemon *daemon, GObject *native) up_device_coldplug (UpDevice *device)
{ {
gboolean ret; gboolean ret;
const gchar *native_path; const gchar *native_path;
@ -405,11 +415,7 @@ up_device_coldplug (UpDevice *device, UpDaemon *daemon, GObject *native)
g_return_val_if_fail (UP_IS_DEVICE (device), FALSE); g_return_val_if_fail (UP_IS_DEVICE (device), FALSE);
/* save */ native_path = up_native_get_native_path (device->priv->native);
device->priv->native = g_object_ref (native);
device->priv->daemon = g_object_ref (daemon);
native_path = up_native_get_native_path (native);
up_exported_device_set_native_path (UP_EXPORTED_DEVICE (device), native_path); up_exported_device_set_native_path (UP_EXPORTED_DEVICE (device), native_path);
/* coldplug source */ /* coldplug source */
@ -711,6 +717,30 @@ up_device_dispose (GObject *object)
G_OBJECT_CLASS (up_device_parent_class)->dispose (object); G_OBJECT_CLASS (up_device_parent_class)->dispose (object);
} }
static void
up_device_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
UpDevice *device = UP_DEVICE (object);
UpDevicePrivate *priv = up_device_get_instance_private (device);
switch (prop_id)
{
case PROP_DAEMON:
priv->daemon = g_value_dup_object (value);
break;
case PROP_NATIVE:
priv->native = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
/** /**
* up_device_class_init: * up_device_class_init:
**/ **/
@ -718,16 +748,39 @@ static void
up_device_class_init (UpDeviceClass *klass) up_device_class_init (UpDeviceClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->notify = up_device_notify; object_class->notify = up_device_notify;
object_class->finalize = up_device_finalize; object_class->finalize = up_device_finalize;
object_class->dispose = up_device_dispose; object_class->dispose = up_device_dispose;
object_class->set_property = up_device_set_property;
properties[PROP_DAEMON] =
g_param_spec_object ("daemon",
"UpDaemon",
"UpDaemon reference",
UP_TYPE_DAEMON,
G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_NATIVE] =
g_param_spec_object ("native",
"Native",
"Native Object",
G_TYPE_OBJECT,
G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, N_PROPS, properties);
} }
/** /**
* up_device_new: * up_device_new:
**/ **/
UpDevice * UpDevice *
up_device_new (void) up_device_new (UpDaemon *daemon,
GObject *native)
{ {
return UP_DEVICE (g_object_new (UP_TYPE_DEVICE, NULL)); return UP_DEVICE (g_object_new (UP_TYPE_DEVICE,
"daemon", daemon,
"native", native,
NULL));
} }

View file

@ -57,11 +57,10 @@ typedef struct
} UpDeviceClass; } UpDeviceClass;
GType up_device_get_type (void); GType up_device_get_type (void);
UpDevice *up_device_new (void); UpDevice *up_device_new (UpDaemon *daemon,
gboolean up_device_coldplug (UpDevice *device,
UpDaemon *daemon,
GObject *native); GObject *native);
gboolean up_device_coldplug (UpDevice *device);
gboolean up_device_register_display_device (UpDevice *device, gboolean up_device_register_display_device (UpDevice *device,
UpDaemon *daemon); UpDaemon *daemon);
UpDaemon *up_device_get_daemon (UpDevice *device); UpDaemon *up_device_get_daemon (UpDevice *device);

View file

@ -76,7 +76,7 @@ up_test_device_func (void)
{ {
UpDevice *device; UpDevice *device;
device = up_device_new (); device = up_device_new (NULL, NULL);
g_assert (device != NULL); g_assert (device != NULL);
/* unref */ /* unref */