return 0;
}
+/**
+ * FIXME: After developing the power abstraction layer, this attribute should
+ * be fixed. Because the suspend-to-ram supports both echo-mem and wakelock
+ * style without any different external interface.
+ */
+static int g_wakelock_counter;
+static gboolean event_release_wakelock(gpointer data)
+{
+ if (g_wakelock_counter < 0)
+ return G_SOURCE_REMOVE;
+
+ --g_wakelock_counter;
+
+ if (g_wakelock_counter == 0)
+ syscommon_notifier_emit_notify(DEVICED_NOTIFIER_EVENT_RELEASE_WAKELOCK, NULL);
+
+ return G_SOURCE_REMOVE;
+}
+
+static int set_wakelock(int resource_id, const struct syscommon_resman_resource_attribute *attr,
+ const void *data1, const void *data2, int count1, int count2)
+{
+ uint64_t event_id;
+ uint64_t timeout;
+
+ if (!data1 || !data2)
+ return -EINVAL;
+
+ event_id = *(uint64_t *) data1;
+ timeout = *(uint64_t *) data2;
+
+ if (timeout <= 0)
+ return -EINVAL;
+
+ ++g_wakelock_counter;
+
+ g_timeout_add_seconds(timeout, event_release_wakelock, (gpointer)(intptr_t) event_id);
+
+ if (g_wakelock_counter == 1)
+ syscommon_notifier_emit_notify(DEVICED_NOTIFIER_EVENT_ACQUIRE_WAKELOCK, NULL);
+
+ return 0;
+}
+
static const struct syscommon_resman_resource_attribute power_attrs[] = {
{
.name = "DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE",
.get = get_wakeup_reason,
.is_supported = syscommon_resman_resource_attr_supported_always,
},
+ }, {
+ .name = "DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK",
+ .id = DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK,
+ .type = SYSCOMMON_RESMAN_DATA_TYPE_UINT64_UINT64,
+ .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
+ .ops = {
+ .set_2_tuple = set_wakelock,
+ .is_supported = syscommon_resman_resource_attr_supported_always,
+ },
}
};