From: Chanwoo Choi Date: Thu, 17 Aug 2023 06:24:00 +0000 (+0900) Subject: power: resource: Add new DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK X-Git-Tag: accepted/tizen/unified/20230821.162310~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f1c66215a10c54a0162bfc814578015b40dbdda7;p=platform%2Fcore%2Fsystem%2Fdeviced.git power: resource: Add new DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK attribute provides the setter function to acquire the wakelock in order to prevent the suspending. [Detailed description of newly added attribute] - attr id : DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK - setter : O - getter : X - 1st param : Event ID - 2nd param : Timeout to release the wakelock count Change-Id: I9ffdecac5ddd538b22ae2cd9397abb0fe93dd98a Signed-off-by: Chanwoo Choi --- diff --git a/src/power/resource-power.c b/src/power/resource-power.c index fedd659..4ad739d 100644 --- a/src/power/resource-power.c +++ b/src/power/resource-power.c @@ -73,6 +73,50 @@ static int get_wakeup_reason(int resource_id, 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", @@ -101,6 +145,15 @@ static const struct syscommon_resman_resource_attribute power_attrs[] = { .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, + }, } };