monitor: Add dbus interface for turning on/off debug mode 67/281167/3
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 13 Sep 2022 06:00:28 +0000 (15:00 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Wed, 14 Sep 2022 10:37:46 +0000 (19:37 +0900)
In order to provide the way to change debug mode dynamically, the new
dbus interface is now applied as below:
 - dbus path: /Org/Tizen/System/Pass/Monitor
 - dbus interface: org.tizen.system.pass.monitor
 - dbus method:  org.tizen.system.pass.monitor.SetDebug
 - parameter:  boolean value for representing debug mode is enabled

Change-Id: I431182809d23b1b7ee795c392bdeb84f9ef741bf
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
CMakeLists.txt
include/util/gdbus-definition.h
include/util/gdbus-util.h
scripts/monitor-dbus.xml [new file with mode: 0644]
scripts/pass.conf
src/monitor/monitor.c
src/util/gdbus-util.c

index 18f595b..8b44fa6 100644 (file)
@@ -55,6 +55,8 @@ SET(SRCS
        src/monitor/monitor-thread.c
        src/monitor/monitor-command.c
        src/monitor/request-handler.c
+       #Generated by a custom command 'gdbus-codegen' below
+       src/monitor/monitor-dbus-stub.c
 )
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
@@ -115,6 +117,13 @@ ADD_CUSTOM_COMMAND(
                                --output-directory src/thermal/
                                scripts/thermal-dbus.xml
        COMMENT "Generating GDBus stub for thermal interface")
+ADD_CUSTOM_COMMAND(
+        OUTPUT src/monitor/monitor-dbus-stub.c
+        COMMAND gdbus-codegen --interface-prefix org.tizen.
+                               --generate-c-code monitor-dbus-stub
+                               --output-directory src/monitor/
+                               scripts/monitor-dbus.xml
+       COMMENT "Generating GDBus stub for monitor interface")
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl -lm)
index 5072341..86ea5cb 100644 (file)
@@ -42,6 +42,10 @@ typedef enum {
 #define DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER  "handle_ultra_power_saving"
 #define DBUS_PMQOS_I_SET_SCENARIO_HANDLER      "handle_set_scenario"
 
+#define DBUS_MONITOR_INTERFACE                 "org.tizen.system.pass.monitor"
+#define DBUS_MONITOR_PATH                      "/Org/Tizen/System/Pass/Monitor"
+#define DBUS_MONITOR_I_SET_DEBUG_HANDLER       "handle_set_debug"
+
 #define DBUS_THERMAL_BUS_NAME                  "org.tizen.system.thermal"
 #define DBUS_THERMAL_INTERFACE                 "org.tizen.system.thermal"
 #define DBUS_THERMAL_PATH                      "/Org/Tizen/System/Thermal"
index a5dbc44..dcb1bd5 100644 (file)
@@ -26,6 +26,7 @@
 #include "pass/pass-dbus-stub.h"
 #include "pmqos/pmqos-dbus-stub.h"
 #include "thermal/thermal-dbus-stub.h"
+#include "monitor/monitor-dbus-stub.h"
 
 #include "gdbus-definition.h"
 
@@ -54,6 +55,8 @@ SystemPassCore *gdbus_get_instance_core(void);
 void gdbus_put_instance_core(SystemPassCore **instance);
 SystemPassPmqos *gdbus_get_instance_pmqos(void);
 void gdbus_put_instance_pmqos(SystemPassPmqos **instance);
+SystemPassMonitor *gdbus_get_instance_monitor(void);
+void gdbus_put_instance_monitor(SystemPassMonitor **instance);
 SystemThermal *gdbus_get_instance_thermal(void);
 void gdbus_put_instance_thermal(SystemThermal **instance);
 
diff --git a/scripts/monitor-dbus.xml b/scripts/monitor-dbus.xml
new file mode 100644 (file)
index 0000000..39606ef
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<node name="/Org/Tizen/System/Pass/Monitor">
+  <interface name="org.tizen.system.pass.monitor">
+    <method name="SetDebug">
+      <arg type="b" name="on" direction="in" />
+      <arg type="i" name="return_code" direction="out" />
+    </method>
+  </interface>
+</node>
index abfdfdd..a2f7e72 100644 (file)
@@ -6,6 +6,8 @@
                send_interface="org.tizen.system.pass.core"/>
         <allow send_destination="org.tizen.system.pass"
                send_interface="org.tizen.system.pass.pmqos"/>
+        <allow send_destination="org.tizen.system.pass"
+               send_interface="org.tizen.system.pass.monitor"/>
         <allow send_destination="org.tizen.system.thermal"
                send_interface="org.tizen.system.thermal"/>
     </policy>
index b412f93..0fc9a1a 100644 (file)
 #include <util/device-notifier.h>
 #include <util/log.h>
 #include <util/devices.h>
+#include <util/gdbus-util.h>
 #include <monitor/monitor.h>
 
 static struct monitor g_monitor;
 static gboolean g_debug_mode;
 
+static SystemPassMonitor *g_gdbus_instance;
+
 struct monitor *monitor_get(void)
 {
        return &g_monitor;
@@ -41,6 +44,30 @@ void monitor_set_debug_mode(gboolean on)
        g_debug_mode = on;
 }
 
+static gboolean dbus_cb_monitor_set_debug(SystemPassMonitor *obj,
+               GDBusMethodInvocation *invoc,
+               gboolean on,
+               gpointer user_data)
+{
+       if (monitor_get_debug_mode() != on) {
+               monitor_set_debug_mode(on);
+               _I("PASS Resource Monitor debug mode is set to %s", on ? "on" : "off");
+       }
+
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", 0));
+
+       return TRUE;
+}
+
+static struct gdbus_signal_info g_gdbus_signal_infos[] = {
+       {
+               .handler = DBUS_MONITOR_I_SET_DEBUG_HANDLER,
+               .cb = G_CALLBACK(dbus_cb_monitor_set_debug),
+               .cb_data = NULL,
+               .ret_id = 0,
+       },
+};
+
 static int monitor_setup(void *data, void *user_data)
 {
        int ret;
@@ -80,6 +107,31 @@ static int monitor_probe(void *data)
 {
        int ret = 0;
 
+       g_gdbus_instance = gdbus_get_instance_monitor();
+       if (g_gdbus_instance == NULL) {
+               _E("failed to get instance for the %s interface\n",
+                               DBUS_MONITOR_INTERFACE);
+               return -EINVAL;
+       }
+
+       ret = gdbus_connect_signal(g_gdbus_instance,
+                       ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos);
+       if (ret < 0) {
+               _E("failed to register dbus methods\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = gdbus_export_interface(PASS_DBUS_CORE,
+                       g_gdbus_instance, DBUS_MONITOR_PATH);
+       if (ret < 0) {
+               _E("cannot export the dbus interface '%s' at the object path '%s'\n",
+                               DBUS_MONITOR_INTERFACE,
+                               DBUS_MONITOR_PATH);
+               ret = -EINVAL;
+               goto out_disconnect;
+       }
+
        /*
         * Register a notifier for the booting-done event. The actual
         * initialization of the daemon is performed by this notifier after
@@ -90,10 +142,19 @@ static int monitor_probe(void *data)
        if (ret < 0) {
                _E("cannot register a callback function \
                                for the booting-done event (%d)\n", ret);
-               return ret;
+               goto out_disconnect;
        }
 
        return 0;
+
+out_disconnect:
+       gdbus_disconnect_signal(g_gdbus_instance,
+                       ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos);
+out:
+       gdbus_put_instance_monitor(&g_gdbus_instance);
+
+       return ret;
+
 }
 
 static const struct device_ops monitor_device_ops = {
index 17c25c2..b0db944 100644 (file)
@@ -193,6 +193,16 @@ void gdbus_put_instance_pmqos(SystemPassPmqos **instance)
        put_instance((gpointer *)instance);
 }
 
+SystemPassMonitor *gdbus_get_instance_monitor(void)
+{
+       return system_pass_monitor_skeleton_new();
+}
+
+void gdbus_put_instance_monitor(SystemPassMonitor **instance)
+{
+       put_instance((gpointer *)instance);
+}
+
 SystemThermal *gdbus_get_instance_thermal(void)
 {
        return system_thermal_skeleton_new();