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 static struct monitor g_monitor;
28 static gboolean g_debug_mode;
30 static SystemPassMonitor *g_gdbus_instance;
32 struct monitor *monitor_get(void)
37 gboolean monitor_get_debug_mode(void)
42 void monitor_set_debug_mode(gboolean on)
47 static gboolean dbus_cb_monitor_set_debug(SystemPassMonitor *obj,
48 GDBusMethodInvocation *invoc,
52 if (monitor_get_debug_mode() != on) {
53 monitor_set_debug_mode(on);
54 _I("PASS Resource Monitor debug mode is set to %s", on ? "on" : "off");
57 g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", 0));
62 static struct gdbus_signal_info g_gdbus_signal_infos[] = {
64 .handler = DBUS_MONITOR_I_SET_DEBUG_HANDLER,
65 .cb = G_CALLBACK(dbus_cb_monitor_set_debug),
71 static int monitor_setup(void *data, void *user_data)
75 syscommon_resman_init_resource_drivers();
77 ret = request_server_init();
79 _E("failed to initialize request server\n");
83 ret = monitor_thread_init(&g_monitor);
85 _E("failed to initialize monitor thread\n");
86 request_server_exit();
93 static void monitor_init(void *data)
95 /* This is the case of daemon creation: DO NOTHING */
98 static void monitor_exit(void *data)
100 monitor_thread_exit(&g_monitor);
101 request_server_exit();
102 syscommon_resman_exit_resource_drivers();
103 unregister_notifier(DEVICE_NOTIFIER_INIT_DONE, monitor_setup, NULL);
106 static int monitor_probe(void *data)
110 g_gdbus_instance = gdbus_get_instance_monitor();
111 if (g_gdbus_instance == NULL) {
112 _E("failed to get instance for the %s interface\n",
113 DBUS_MONITOR_INTERFACE);
117 ret = gdbus_connect_signal(g_gdbus_instance,
118 ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos);
120 _E("failed to register dbus methods\n");
125 ret = gdbus_export_interface(PASS_DBUS_CORE,
126 g_gdbus_instance, DBUS_MONITOR_PATH);
128 _E("cannot export the dbus interface '%s' at the object path '%s'\n",
129 DBUS_MONITOR_INTERFACE,
136 * Register a notifier for the booting-done event. The actual
137 * initialization of the daemon is performed by this notifier after
138 * booting is completely done.
140 ret = register_notifier(DEVICE_NOTIFIER_INIT_DONE,
141 monitor_setup, NULL);
143 _E("cannot register a callback function \
144 for the booting-done event (%d)\n", ret);
151 gdbus_disconnect_signal(g_gdbus_instance,
152 ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos);
154 gdbus_put_instance_monitor(&g_gdbus_instance);
160 static const struct device_ops monitor_device_ops = {
162 .probe = monitor_probe,
163 .init = monitor_init,
164 .exit = monitor_exit,
167 DEVICE_OPS_REGISTER(&monitor_device_ops)