2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "stc-manager.h"
20 #include "stc-manager-plugin-monitor.h"
22 static gboolean stc_plugin_enabled = FALSE;
23 static void *handle_plugin;
24 static stc_plugin_monitor_s *stc_plugin;
27 API int stc_plugin_monitor_init(void)
29 __STC_LOG_FUNC_ENTER__;
31 handle_plugin = dlopen(STC_PLUGIN_MONITOR_FILEPATH, RTLD_NOW);
33 STC_LOGE("Can't load %s: %s", STC_PLUGIN_MONITOR_FILEPATH, dlerror());
34 __STC_LOG_FUNC_EXIT__;
35 return STC_ERROR_UNINITIALIZED;
38 stc_plugin = dlsym(handle_plugin, "stc_plugin_monitor");
40 STC_LOGE("Can't load symbol: %s", dlerror());
41 dlclose(handle_plugin);
42 __STC_LOG_FUNC_EXIT__;
43 return STC_ERROR_UNINITIALIZED;
46 stc_plugin->initialize_plugin();
47 stc_plugin_enabled = TRUE;
49 __STC_LOG_FUNC_EXIT__;
50 return STC_ERROR_NONE;
53 API int stc_plugin_monitor_deinit(void)
55 __STC_LOG_FUNC_ENTER__;
57 if (!stc_plugin_enabled)
58 return STC_ERROR_UNINITIALIZED;
60 stc_plugin->deinitialize_plugin();
61 stc_plugin_enabled = FALSE;
62 dlclose(handle_plugin);
64 __STC_LOG_FUNC_EXIT__;
65 return STC_ERROR_NONE;
68 API int stc_plugin_monitor_add_app(uint32_t classid,
71 const stc_app_value_s value)
73 if (!stc_plugin_enabled) {
75 STC_LOGE("Plugin wasn't enabled");
76 return STC_ERROR_UNINITIALIZED;
81 STC_LOGE("Plugin wasn't loaded");
82 return STC_ERROR_UNINITIALIZED;
85 return stc_plugin->add_application(classid, app_id, pkg_id, value);
88 API int stc_plugin_monitor_remove_app(uint32_t classid,
91 if (!stc_plugin_enabled) {
93 STC_LOGE("Plugin wasn't enabled");
94 return STC_ERROR_UNINITIALIZED;
99 STC_LOGE("Plugin wasn't loaded");
100 return STC_ERROR_UNINITIALIZED;
103 return stc_plugin->remove_application(classid, app_id);
106 API int stc_plugin_monitor_lookup_app(uint32_t classid)
108 if (!stc_plugin_enabled) {
110 STC_LOGE("Plugin wasn't enabled");
111 return STC_ERROR_UNINITIALIZED;
116 STC_LOGE("Plugin wasn't loaded");
117 return STC_ERROR_UNINITIALIZED;
120 return stc_plugin->lookup_application(classid);
123 API int stc_plugin_monitor_add_rstn(table_restrictions_info *info)
125 if (!stc_plugin_enabled) {
127 STC_LOGE("Plugin wasn't enabled");
128 return STC_ERROR_UNINITIALIZED;
133 STC_LOGE("Plugin wasn't loaded");
134 return STC_ERROR_UNINITIALIZED;
137 return stc_plugin->add_restriction(info);
140 API int stc_plugin_monitor_remove_rstn(table_restrictions_info *info)
142 if (!stc_plugin_enabled) {
144 STC_LOGE("Plugin wasn't enabled");
145 return STC_ERROR_UNINITIALIZED;
150 STC_LOGE("Plugin wasn't loaded");
151 return STC_ERROR_UNINITIALIZED;
154 return stc_plugin->remove_restriction(info);
157 API int stc_plugin_monitor_init_connection(stc_s *stc)
159 if (!stc_plugin_enabled) {
161 STC_LOGE("Plugin wasn't enabled");
162 return STC_ERROR_UNINITIALIZED;
167 STC_LOGE("Plugin wasn't loaded");
168 return STC_ERROR_UNINITIALIZED;
171 return stc_plugin->init_connection(stc);
174 API int stc_plugin_monitor_deinit_connection(stc_s *stc)
176 if (!stc_plugin_enabled) {
178 STC_LOGE("Plugin wasn't enabled");
179 return STC_ERROR_UNINITIALIZED;
183 STC_LOGE("Plugin wasn't loaded");
184 return STC_ERROR_UNINITIALIZED;
187 return stc_plugin->deinit_connection(stc);
190 API int stc_plugin_monitor_add_proc(uint32_t classid,
191 const char *app_id, const stc_proc_value_s value)
193 if (!stc_plugin_enabled) {
195 STC_LOGE("Plugin wasn't enabled");
196 return STC_ERROR_UNINITIALIZED;
201 STC_LOGE("Plugin wasn't loaded");
202 return STC_ERROR_UNINITIALIZED;
205 return stc_plugin->add_process(classid, app_id, value);
208 API int stc_plugin_monitor_remove_proc(uint32_t classid, pid_t pid)
210 if (!stc_plugin_enabled) {
212 STC_LOGE("Plugin wasn't enabled");
213 return STC_ERROR_UNINITIALIZED;
218 STC_LOGE("Plugin wasn't loaded");
219 return STC_ERROR_UNINITIALIZED;
222 return stc_plugin->remove_process(classid, pid);
225 API int stc_plugin_monitor_move_proc(uint32_t from, uint32_t to)
227 if (!stc_plugin_enabled) {
229 STC_LOGE("Plugin wasn't enabled");
230 return STC_ERROR_UNINITIALIZED;
235 STC_LOGE("Plugin wasn't loaded");
236 return STC_ERROR_UNINITIALIZED;
239 return stc_plugin->move_process(from, to);
242 API int stc_plugin_monitor_update_proc_ground(uint32_t classid,
243 const char *app_id, const stc_proc_value_s value)
245 if (!stc_plugin_enabled) {
247 STC_LOGE("Plugin wasn't enabled");
248 return STC_ERROR_UNINITIALIZED;
253 STC_LOGE("Plugin wasn't loaded");
254 return STC_ERROR_UNINITIALIZED;
257 return stc_plugin->update_process_ground(classid, app_id, value);