Merge "Monitoring application wise background data usage." into tizen
[platform/core/connectivity/stc-manager.git] / src / stc-manager-plugin.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <dlfcn.h>
18
19 #include "stc-manager.h"
20 #include "stc-plugin.h"
21 #include "stc-manager-plugin.h"
22
23 static gboolean stc_plugin_enabled = FALSE;
24 static void *handle_plugin;
25 static stc_plugin_s *stc_plugin;
26
27 void stc_manager_plugin_init(void)
28 {
29         __STC_LOG_FUNC_ENTER__;
30
31         handle_plugin = dlopen(STC_PLUGIN_FILEPATH, RTLD_NOW);
32         if (!handle_plugin) {
33                 STC_LOGE("Can't load %s: %s", STC_PLUGIN_FILEPATH, dlerror());
34                 return;
35         }
36
37         stc_plugin = dlsym(handle_plugin, "stc_plugin");
38         if (!stc_plugin) {
39                 STC_LOGE("Can't load symbol: %s", dlerror());
40                 dlclose(handle_plugin);
41                 return;
42         }
43
44         stc_plugin_enabled = TRUE;
45
46         __STC_LOG_FUNC_EXIT__;
47 }
48
49 void stc_manager_plugin_deinit(void)
50 {
51         __STC_LOG_FUNC_ENTER__;
52
53         if (!stc_plugin_enabled)
54                 return;
55
56         stc_plugin_enabled = FALSE;
57         dlclose(handle_plugin);
58
59         __STC_LOG_FUNC_EXIT__;
60 }
61
62 int stc_send_warn_message_to_net_popup(const char *content,
63                 const char *type, const char *app_id, const char *iftype, const char *warn)
64 {
65         __STC_LOG_FUNC_ENTER__;
66
67         if (!stc_plugin_enabled) {
68                 STC_LOGE("Plugin wasn't enabled");
69                 return 0;
70         }
71
72         if (!stc_plugin) {
73                 STC_LOGE("Plugin wasn't loaded");
74                 return 0;
75         }
76
77         return stc_plugin->send_warn_message_to_net_popup(content, type, app_id, iftype, warn);
78 }
79
80 int stc_send_restriction_message_to_net_popup(const char *content,
81                 const char *type, const char *app_id, const char *iftype, const char *limit)
82 {
83         __STC_LOG_FUNC_ENTER__;
84
85         if (!stc_plugin_enabled) {
86                 STC_LOGE("Plugin wasn't enabled");
87                 return 0;
88         }
89
90         if (!stc_plugin) {
91                 STC_LOGE("Plugin wasn't loaded");
92                 return 0;
93         }
94
95         return stc_plugin->send_restriction_message_to_net_popup(content, type, app_id, iftype, limit);
96 }
97