plugin-api: Fix the prefix for pkg_check_modules of CMakeLists.txt
[platform/core/system/libsyscommon.git] / src / plugin-api / resourced / src / syscommon-plugin-resourced-memory-lmk.c
1 /**
2  * MIT License
3  *
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24
25 #include <glib.h>
26
27 #include "syscommon-plugin-common.h"
28
29 #include "common.h"
30 #include "syscommon-plugin-resourced-memory-lmk.h"
31 #include "syscommon-plugin-resourced-memory-lmk-interface.h"
32
33 #ifndef EXPORT
34 #define EXPORT __attribute__((visibility("default")))
35 #endif
36
37 static syscommon_plugin_backend_resourced_memory_lmk_funcs *funcs = NULL;
38
39 EXPORT
40 int syscommon_plugin_resourced_memory_lmk_get_backend(void)
41 {
42         int ret = 0;
43
44         if (funcs)
45                 return 0;
46
47         ret = syscommon_plugin_common_get_backend(
48                                 SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK,
49                                 (void **)&funcs);
50         if (ret < 0) {
51                 _E("Failed to get resourced_memory_lmk backend: %d", ret);
52                 return ret;
53         }
54
55         _I("Success to get resourced_memory_lmk backend: %d", ret);
56
57         return 0;
58 }
59
60 EXPORT
61 int syscommon_plugin_resourced_memory_lmk_put_backend(void)
62 {
63         int ret = 0;
64
65         if (!funcs)
66                 return 0;
67
68         ret = syscommon_plugin_common_put_backend(
69                                 SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK,
70                                 (void *)funcs);
71         if (ret < 0) {
72                 _E("Failed to put resourced_memory_lmk backend: %d", ret);
73                 return ret;
74         }
75         funcs = NULL;
76
77         _I("Success to put resourced_memory_lmk backend: %d", ret);
78
79         return 0;
80 }
81
82 EXPORT
83 int syscommon_plugin_resourced_memory_lmk_get_kill_candidates(
84                                                 GArray *candidates,
85                                                 GArray *task_info_app_array,
86                                                 GArray *task_info_proc_array,
87                                                 unsigned long totalram_kb)
88 {
89         int ret = 0;
90
91         if (!funcs) {
92                 ret = syscommon_plugin_resourced_memory_lmk_get_backend();
93                 if (ret < 0)
94                         return ret;
95         }
96
97         if (!funcs || !funcs->get_kill_candidates) {
98                 _E("No backend or no \"get_kill_candidates\" function");
99                 return -ENOTSUP;
100         }
101
102         return funcs->get_kill_candidates(candidates,
103                                         task_info_app_array,
104                                         task_info_proc_array,
105                                         totalram_kb);
106 }