resource: Add display resource driver 86/270786/3
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 8 Feb 2022 10:22:29 +0000 (19:22 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 10 Feb 2022 04:11:49 +0000 (13:11 +0900)
The resource-display.c provides the display information
like FPS (Frame Per Second) as the display resource driver.
This version supportsthe only DISPLAY_FPS attribute.

Change-Id: I105fb0d463e4ce55cff48ddf291f642ea5ca723d
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
CMakeLists.txt
lib/tmonitor/tmonitor.h
src/resource/resource-display.c [new file with mode: 0644]

index 6b0d426..f30a5eb 100644 (file)
@@ -43,6 +43,7 @@ SET(SRCS
        src/resource/resource-bus.c
        src/resource/resource-gpu.c
        src/resource/resource-memory.c
+       src/resource/resource-display.c
        src/monitor/monitor.c
        src/monitor/monitor-thread.c
        src/monitor/monitor-command.c
index 344ae45..59853b4 100644 (file)
@@ -35,6 +35,7 @@ extern "C" {
 #define RESOURCE_TYPE_MEMORY           4
 #define RESOURCE_TYPE_BATTERY          5
 #define RESOURCE_TYPE_PROCESS          6
+#define RESOURCE_TYPE_DISPLAY          7
 #define RESOURCE_TYPE_NONSTANDARD      99
 
 /**
@@ -73,6 +74,8 @@ extern "C" {
 #define BATTERY_CHARGING_STATUS                BIT(1)
 #define BATTERY_TEMPERATURE            BIT(2)
 
+#define DISPLAY_FPS                    BIT(0)
+
 /**
  * @brief Initialize the tizen monitor
  * @param[in] Timer period (unit: millisecond, minimum value is 100ms)
diff --git a/src/resource/resource-display.c b/src/resource/resource-display.c
new file mode 100644 (file)
index 0000000..d1a8e08
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * PASS (Power Aware System Service) - Display Resource Driver
+ *
+ * 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.
+ */
+
+/**
+ * @file       resource-display.c
+ * @brief      TBD
+ * @ingroup    TBD
+ */
+
+#include <glib.h>
+
+#include <hal/hal-power.h>
+
+#include <util/common.h>
+#include <util/log.h>
+#include <util/resource.h>
+#include <util/gdbus-util.h>
+
+#include <tmonitor/tmonitor.h>
+
+#define DBUS_ENLIGHTENMENT_NAME                "org.enlightenment.wm"
+#define DBUS_ENLIGHTENMENT_PATH                "/org/enlightenment/wm"
+#define DBUS_ENLIGHTENMENT_INTERFACE   "org.enlightenment.wm.info"
+#define DBUS_ENLIGHTENMENT_FPS_FUNC    "get_fps_info"
+
+struct display_fps_data {
+       unsigned int type;
+       char output[128];
+       int zpos;
+       unsigned int window;
+       double fps;
+};
+
+static int display_get_fps(const struct resource *res,
+                               const struct resource_attribute *attr,
+                               void **data, void *user_data)
+{
+       GDBusConnection *conn;
+       GDBusMessage *msg, *reply;
+       GVariant *result, *value;
+       GError *err = NULL;
+       struct display_fps_data fps_data;
+       int ret = 0;
+
+       if (!res || !attr || !data)
+               return -EINVAL;
+
+       /* Connect dbus interface and receive message */
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (err) {
+               g_clear_error(&err);
+               return -EINVAL;
+       }
+
+       msg = g_dbus_message_new_method_call(DBUS_ENLIGHTENMENT_NAME,
+                                       DBUS_ENLIGHTENMENT_PATH,
+                                       DBUS_ENLIGHTENMENT_INTERFACE,
+                                       DBUS_ENLIGHTENMENT_FPS_FUNC);
+       if (!msg) {
+               ret = -EINVAL;
+               goto err_conn;
+       }
+
+       reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
+                                       G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+                                       G_MAXINT, NULL, NULL, &err);
+       if (err) {
+               g_clear_error(&err);
+               ret = -EINVAL;
+               goto err_msg;
+       }
+
+       if (g_dbus_message_get_message_type(reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
+               ret = -EINVAL;
+               goto err_reply;
+       }
+
+       /* Parse the received data */
+       result = g_variant_get_child_value(g_dbus_message_get_body(reply), 0);
+       if (g_variant_n_children(result) <= res->index) {
+               ret = -EINVAL;
+               goto err_reply;
+       }
+
+       /* Get the fps information according to the index of resource_device */
+       value = g_variant_get_child_value(result, res->index);
+       g_variant_get(value, "(usiud)",
+                       &fps_data.type, fps_data.output, &fps_data.zpos,
+                       &fps_data.window, &fps_data.fps);
+
+       *data = (void *)(intptr_t)fps_data.fps;
+
+err_reply:
+       g_object_unref(reply);
+err_msg:
+       g_object_unref(msg);
+err_conn:
+       g_dbus_connection_flush(conn, NULL, NULL, NULL);
+
+       return ret;
+}
+
+static const struct resource_attribute display_attrs[] = {
+       {
+               .name   = "DISPLAY_FPS",
+               .id     = DISPLAY_FPS,
+               .type   = DATA_TYPE_DOUBLE,
+               .ops    = {
+                       .get = display_get_fps,
+               },
+       },
+};
+
+static const struct resource_driver display_resource_driver = {
+       .name           = "DISPLAY",
+       .type           = RESOURCE_TYPE_DISPLAY,
+       .attrs          = display_attrs,
+       .num_attrs      = ARRAY_SIZE(display_attrs),
+};
+RESOURCE_DRIVER_REGISTER(&display_resource_driver)