shared: event: Replace with DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK 57/297357/3
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 17 Aug 2023 06:24:29 +0000 (15:24 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 17 Aug 2023 09:49:33 +0000 (18:49 +0900)
Replace event_acquire_wakelock() with DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK
attribute by using resource-mangaer in libsyscommon and then remove
event_acquire_wakelock().

Change-Id: I7f0dbc7a46f0753c14ef4ecbecb0bf27e300f61e
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
plugins/iot-headless/input/input-handler.c
src/battery/power-supply.c
src/shared/event.c [deleted file]
src/shared/event.h

index 17446f4..85a8efc 100644 (file)
 #include <libsyscommon/libgdbus.h>
 #include <libsyscommon/list.h>
 #include <libsyscommon/log.h>
+#include <libsyscommon/resource-manager.h>
+#include <system/syscommon-plugin-deviced-common-interface.h>
+#include <system/syscommon-plugin-deviced-power-interface.h>
 
 #include "shared/device-notifier.h"
-#include "shared/event.h"
 
 #include "input-config.h"
 #include "input/input.h"
@@ -51,7 +53,10 @@ static gboolean level_event_detected(gpointer data)
                event_broadcast_id(ieu->id);
 
        if (ieu->wakelock_duration > 0)
-               event_acquire_wakelock(ieu->id, ieu->wakelock_duration);
+               syscommon_resman_set_resource_attr_uint64_2(
+                       SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
+                       DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK,
+                       ieu->id, ieu->wakelock_duration);
 
        if (ieu->notifier)
                syscommon_notifier_emit_notify(ieu->notifier, ieu->user_data);
@@ -72,7 +77,10 @@ static void edge_event_detected(struct input_event_unit *ieu)
                event_broadcast_id(ieu->id);
 
        if (ieu->wakelock_duration > 0)
-               event_acquire_wakelock(ieu->id, ieu->wakelock_duration);
+               syscommon_resman_set_resource_attr_uint64_2(
+                       SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
+                       DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK,
+                       ieu->id, ieu->wakelock_duration);
 
        if (ieu->notifier)
                syscommon_notifier_emit_notify(ieu->notifier, ieu->user_data);
index 433e3a2..d1af11b 100644 (file)
@@ -25,7 +25,9 @@
 #include <hal/device/hal-battery.h>
 #include <sys/stat.h>
 #include <libsyscommon/ini-parser.h>
+#include <libsyscommon/resource-manager.h>
 #include <system/syscommon-plugin-deviced-common-interface.h>
+#include <system/syscommon-plugin-deviced-power-interface.h>
 
 #include "shared/devices.h"
 #include "shared/device-notifier.h"
@@ -662,8 +664,12 @@ static void notify_charger_event(int notifier)
                                event_handlers[i]->id);
 
                        if (event_handlers[i]->wakelock_duration)
-                               event_acquire_wakelock(event_handlers[i]->id,
-                                               event_handlers[i]->wakelock_duration);
+                               syscommon_resman_set_resource_attr_uint64_2(
+                                       SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
+                                       DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK,
+                                       event_handlers[i]->id,
+                                       event_handlers[i]->wakelock_duration);
+
 
                        if (event_handlers[i]->broadcast)
                                event_broadcast_id(event_handlers[i]->id);
diff --git a/src/shared/event.c b/src/shared/event.c
deleted file mode 100644 (file)
index f0d64ad..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * deviced
- *
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-#include <stdint.h>
-
-#include "device-notifier.h"
-#include "log.h"
-
-static int wakelock_counter;
-
-static gboolean event_release_wakelock(gpointer data)
-{
-       int eventid = (int)(intptr_t) data;
-
-       --wakelock_counter;
-
-       _D("Decreased counter=%d, eventid=%d", wakelock_counter, eventid);
-
-       if (wakelock_counter == 0)
-               syscommon_notifier_emit_notify(DEVICED_NOTIFIER_EVENT_RELEASE_WAKELOCK, NULL);
-
-       return G_SOURCE_REMOVE;
-}
-
-void event_acquire_wakelock(int eventid, int timeout)
-{
-       if (timeout <= 0)
-               return;
-
-       ++wakelock_counter;
-
-       _D("Increased counter=%d, eventid=%d, timeout=%d", wakelock_counter, eventid, timeout);
-       g_timeout_add_seconds(timeout, event_release_wakelock, (gpointer)(intptr_t) eventid);
-
-       if (wakelock_counter == 1)
-               syscommon_notifier_emit_notify(DEVICED_NOTIFIER_EVENT_ACQUIRE_WAKELOCK, NULL);
-}
index 44821e5..5c29125 100644 (file)
@@ -36,10 +36,4 @@ static inline void event_broadcast_id(int id)
                g_variant_new("(i)", id));
 }
 
-/**
- * Hold wakelock for a specified timeout.
- * The parameter eventid is only used for logging
- */
-void event_acquire_wakelock(int eventid, int timeout);
-
 #endif //__DD_EVENT_H__