/** * up_device_get_on_battery: * * Note: Only implement for system devices, i.e. ones supplying the system **/ gboolean up_device_get_on_battery (UpDevice *device, gboolean *on_battery) { UpDeviceClass *klass = UP_DEVICE_GET_CLASS (device); g_return_val_if_fail (UP_IS_DEVICE (device), FALSE); /* no support */ if (klass->get_on_battery == NULL) return FALSE; return klass->get_on_battery (device, on_battery); }
/** * up_device_perhaps_changed_cb: **/ static void up_device_perhaps_changed_cb (GObject *object, GParamSpec *pspec, UpDevice *device) { g_return_if_fail (UP_IS_DEVICE (device)); /* don't proxy during coldplug */ if (device->priv->during_coldplug) return; /* save new history */ up_history_set_state (device->priv->history, device->priv->state); up_history_set_charge_data (device->priv->history, device->priv->percentage); up_history_set_rate_data (device->priv->history, device->priv->energy_rate); up_history_set_time_full_data (device->priv->history, device->priv->time_to_full); up_history_set_time_empty_data (device->priv->history, device->priv->time_to_empty); /* The order here matters; we want Device::Changed() before * the DeviceChanged() signal on the main object */ egg_debug ("emitting changed on %s", device->priv->native_path); g_signal_emit (device, signals[SIGNAL_CHANGED], 0); }
GObject * up_device_get_native (UpDevice *device) { g_return_val_if_fail (UP_IS_DEVICE (device), NULL); return device->priv->native; }
/** * up_device_get_object_path: **/ const gchar * up_device_get_object_path (UpDevice *device) { g_return_val_if_fail (UP_IS_DEVICE (device), NULL); return device->priv->object_path; }
/** * up_device_get_history: **/ gboolean up_device_get_history (UpDevice *device, const gchar *type_string, guint timespan, guint resolution, DBusGMethodInvocation *context) { GError *error; GPtrArray *array = NULL; GPtrArray *complex; UpHistoryItem *item; GValue *value; guint i; UpHistoryType type = UP_HISTORY_TYPE_UNKNOWN; g_return_val_if_fail (UP_IS_DEVICE (device), FALSE); g_return_val_if_fail (type_string != NULL, FALSE); /* doesn't even try to support this */ if (!device->priv->has_history) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "device does not support getting history"); dbus_g_method_return_error (context, error); goto out; } /* get the correct data */ if (g_strcmp0 (type_string, "rate") == 0) type = UP_HISTORY_TYPE_RATE; else if (g_strcmp0 (type_string, "charge") == 0) type = UP_HISTORY_TYPE_CHARGE; else if (g_strcmp0 (type_string, "time-full") == 0) type = UP_HISTORY_TYPE_TIME_FULL; else if (g_strcmp0 (type_string, "time-empty") == 0) type = UP_HISTORY_TYPE_TIME_EMPTY; /* something recognised */ if (type != UP_HISTORY_TYPE_UNKNOWN) array = up_history_get_data (device->priv->history, type, timespan, resolution); /* maybe the device doesn't have any history */ if (array == NULL) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "device has no history"); dbus_g_method_return_error (context, error); goto out; } /* copy data to dbus struct */ complex = g_ptr_array_sized_new (array->len); for (i=0; i<array->len; i++) { item = (UpHistoryItem *) g_ptr_array_index (array, i); value = g_new0 (GValue, 1); g_value_init (value, UP_DBUS_STRUCT_UINT_DOUBLE_UINT); g_value_take_boxed (value, dbus_g_type_specialized_construct (UP_DBUS_STRUCT_UINT_DOUBLE_UINT)); dbus_g_type_struct_set (value, 0, up_history_item_get_time (item), 1, up_history_item_get_value (item), 2, up_history_item_get_state (item), -1); g_ptr_array_add (complex, g_value_get_boxed (value)); g_free (value); } dbus_g_method_return (context, complex); out: if (array != NULL) g_ptr_array_unref (array); return TRUE; }