2 * PASS (Power Aware System Service)
4 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <util/device-notifier.h>
23 #include <util/devices.h>
24 #include <util/gdbus-util.h>
25 #include <monitor/monitor.h>
27 #include <libsyscommon/resource-manager.h>
29 static struct monitor g_monitor;
30 static gboolean g_debug_mode;
32 static SystemPassMonitor *g_gdbus_instance;
34 struct monitor *monitor_get(void)
39 gboolean monitor_get_debug_mode(void)
44 void monitor_set_debug_mode(gboolean on)
49 static gboolean dbus_cb_monitor_set_debug(SystemPassMonitor *obj,
50 GDBusMethodInvocation *invoc,
54 if (monitor_get_debug_mode() != on) {
55 monitor_set_debug_mode(on);
56 _I("PASS Resource Monitor debug mode is set to %s", on ? "on" : "off");
59 g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", 0));
64 static struct gdbus_signal_info g_gdbus_signal_infos[] = {
66 .handler = DBUS_MONITOR_I_SET_DEBUG_HANDLER,
67 .cb = G_CALLBACK(dbus_cb_monitor_set_debug),
73 static int monitor_setup(void *data, void *user_data)
77 syscommon_resman_init_resource_drivers();
79 ret = request_server_init();
81 _E("failed to initialize request server\n");
85 ret = monitor_thread_init(&g_monitor);
87 _E("failed to initialize monitor thread\n");
88 request_server_exit();
95 static void monitor_init(void *data)
97 /* This is the case of daemon creation: DO NOTHING */
100 static void monitor_exit(void *data)
102 monitor_thread_exit(&g_monitor);
103 request_server_exit();
104 syscommon_resman_exit_resource_drivers();
105 unregister_notifier(DEVICE_NOTIFIER_INIT_DONE, monitor_setup, NULL);
108 static int monitor_probe(void *data)
112 g_gdbus_instance = gdbus_get_instance_monitor();
113 if (g_gdbus_instance == NULL) {
114 _E("failed to get instance for the %s interface\n",
115 DBUS_MONITOR_INTERFACE);
119 ret = gdbus_connect_signal(g_gdbus_instance,
120 ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos);
122 _E("failed to register dbus methods\n");
127 ret = gdbus_export_interface(PASS_DBUS_CORE,
128 g_gdbus_instance, DBUS_MONITOR_PATH);
130 _E("cannot export the dbus interface '%s' at the object path '%s'\n",
131 DBUS_MONITOR_INTERFACE,
138 * Register a notifier for the booting-done event. The actual
139 * initialization of the daemon is performed by this notifier after
140 * booting is completely done.
142 ret = register_notifier(DEVICE_NOTIFIER_INIT_DONE,
143 monitor_setup, NULL);
145 _E("cannot register a callback function \
146 for the booting-done event (%d)\n", ret);
153 gdbus_disconnect_signal(g_gdbus_instance,
154 ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos);
156 gdbus_put_instance_monitor(&g_gdbus_instance);
162 static const struct device_ops monitor_device_ops = {
164 .probe = monitor_probe,
165 .init = monitor_init,
166 .exit = monitor_exit,
169 DEVICE_OPS_REGISTER(&monitor_device_ops)