Added new vconf key for VCONFKEY_SETAPPL_DATA_RESTRICTION_INT
[platform/core/connectivity/stc-manager.git] / src / monitor / include / stc-monitor.h
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 #ifndef __STC_MONITOR_H__
18 #define __STC_MONITOR_H__
19
20 #include <glib.h>
21 #include "stc-error.h"
22 #include "stc-manager.h"
23 #include "stc-restriction.h"
24 #include "stc-manager-util.h"
25 #include "table-restrictions.h"
26 #include "helper-nl.h"
27
28 /* 1 seconds */
29 #define CONTR_TIMER_INTERVAL 1
30
31 /**
32  * @brief enumeration for data limit types
33  */
34 typedef enum {
35         STC_RSTN_LIMIT_TYPE_DATA_WARN,
36         STC_RSTN_LIMIT_TYPE_DATA,
37         STC_RSTN_LIMIT_TYPE_MONTHLY,
38         STC_RSTN_LIMIT_TYPE_WEEKLY,
39         STC_RSTN_LIMIT_TYPE_DAILY,
40         STC_RSTN_LIMIT_TYPE_MAX
41 } stc_rstn_limit_type_e;
42
43 typedef enum {
44         STC_RSTN_STATE_INIT = -1,
45         STC_RSTN_STATE_UNSET,
46         STC_RSTN_STATE_SET,
47 } stc_rstn_noti_state_e;
48
49 /**
50  * @brief key for processes tree
51  */
52 typedef struct {
53         stc_app_state_e ground;  /**< application state foreground/background */
54 } stc_process_value_s;
55
56 /**
57  * @brief value for processes tree
58  */
59 typedef struct {
60         pid_t pid;  /**< process id */
61 } stc_process_key_s;
62
63 /**
64  * @brief key for apps tree
65  */
66 typedef struct {
67         gchar *pkg_id;  /**< package id */
68         gchar *app_id;  /**< application id */
69 } stc_app_key_s;
70
71 /**
72  * @brief value for apps tree
73  */
74 typedef struct {
75         uint32_t classid;  /**< classid for a package */
76         stc_app_type_e type;  /**< type of application */
77         stc_data_counter_s data_usage;
78         stc_data_counter_s counter;
79         GTree *processes;  /**< applications instances */
80 } stc_app_value_s;
81
82 /**
83  * @brief key for rstn_rules tree
84  */
85 typedef struct {
86         gchar *app_id;
87         gchar *ifname;
88         gchar *subscriber_id;
89         stc_iface_type_e iftype;
90         stc_roaming_type_e roaming;
91 } stc_rstn_key_s;
92
93 /**
94  * @brief value for rstn_rules tree
95  */
96 typedef struct {
97         uint64_t restriction_id;
98         uint32_t classid;
99         stc_rstn_state_e rstn_state;
100         stc_rstn_type_e rstn_type;
101
102         int64_t counter[STC_RSTN_LIMIT_TYPE_MAX];
103         int64_t limit[STC_RSTN_LIMIT_TYPE_MAX];
104         int32_t limit_exceeded;
105         int32_t limit_notified;
106
107         int month_start_date;
108         time_t month_start_ts;
109 } stc_rstn_value_s;
110
111 /**
112  * @brief structure to store system info
113  */
114 typedef struct {
115         int contr_sock;  /**< socket used for getting kernel counters */
116         guint contr_timer_id;  /**< timer id for periodically getting kernel counters */
117         guint contr_gsource_id;
118         stc_data_counter_s du_curr;  /**< current data usage */
119         GTree *rstns;  /**< restriction rules */
120         gboolean rstns_tree_updated;
121         GTree *apps;  /**< monitored applications */
122         gboolean apps_tree_updated;
123         guint background_state;
124         time_t last_month_ts;
125         time_t last_week_ts;
126         time_t last_day_ts;
127         int month_start_date;
128 } stc_system_s;
129
130 /**
131  * @brief initializes stc monitor module
132  */
133 stc_error_e stc_monitor_init(void);
134
135 /**
136  * @brief deinitializes stc monitor module
137  */
138 stc_error_e stc_monitor_deinit(void);
139
140 /**
141  * @brief creates an application entry
142  */
143 stc_error_e stc_monitor_application_add(const stc_app_key_s app_key,
144                                         const stc_app_value_s app_value);
145
146 /**
147  * @brief associates process to an application
148  */
149 stc_error_e stc_monitor_process_add(const stc_app_key_s app_key,
150                                     const stc_process_key_s proc_key,
151                                     const stc_process_value_s proc_value);
152
153 /**
154  * @brief removes associated process from respective application
155  */
156 stc_error_e stc_monitor_process_remove(pid_t pid);
157
158 /**
159  * @brief updates process's ground attribute
160  */
161 stc_error_e stc_monitor_process_update_ground(const stc_app_key_s app_key,
162                                               const stc_process_key_s proc_key,
163                                               stc_app_state_e ground);
164
165 void stc_monitor_update_rstn_by_default_connection(void *default_connection);
166
167 stc_error_e stc_monitor_rstns_tree_add(const table_restrictions_info *info);
168
169 stc_error_e stc_monitor_rstns_tree_remove(const table_restrictions_info *info);
170
171 stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline);
172
173 int stc_monitor_get_counter_socket(void);
174
175 #endif /* __STC_MONITOR_H__ */