a102ea3254341c79311836f7609724d740378fdb
[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 key for processes tree
33  */
34 typedef struct {
35         stc_app_state_e ground;  /**< application state foreground/background */
36 } stc_process_value_s;
37
38 /**
39  * @brief value for processes tree
40  */
41 typedef struct {
42         pid_t pid;  /**< process id */
43 } stc_process_key_s;
44
45 /**
46  * @brief key for apps tree
47  */
48 typedef struct {
49         gchar *pkg_id;  /**< package id */
50         gchar *app_id;  /**< application id */
51 } stc_app_key_s;
52
53 /**
54  * @brief value for apps tree
55  */
56 typedef struct {
57         uint32_t classid;  /**< classid for a package */
58         stc_app_type_e type;  /**< type of application */
59         stc_data_counter_s data_usage;
60         stc_data_counter_s counter;
61         GTree *processes;  /**< applications instances */
62 } stc_app_value_s;
63
64 /**
65  * @brief key for rstn_rules tree
66  */
67 typedef struct {
68         gchar *app_id;
69         gchar *ifname;
70         gchar *subscriber_id;
71         stc_iface_type_e iftype;
72         stc_roaming_type_e roaming;
73 } stc_rstn_key_s;
74
75 /**
76  * @brief value for rstn_rules tree
77  */
78 typedef struct {
79         uint64_t restriction_id;
80         uint32_t classid;
81         stc_rstn_state_e rstn_state;
82         stc_rstn_type_e rstn_type;
83         int64_t data_limit;
84         int64_t data_warn_limit;
85         int64_t data_counter;
86         gboolean data_limit_reached;
87         gboolean warn_limit_crossed_notified;
88         gboolean rstn_limit_crossed_notified;
89 } stc_rstn_value_s;
90
91 /**
92  * @brief structure to store system info
93  */
94 typedef struct {
95         int contr_sock;  /**< socket used for getting kernel counters */
96         guint contr_timer_id;  /**< timer id for periodically getting kernel counters */
97         guint contr_gsource_id;
98         stc_data_counter_s du_curr;  /**< current data usage */
99         GTree *rstns;  /**< restriction rules */
100         gboolean rstns_tree_updated;
101         GTree *apps;  /**< monitored applications */
102         gboolean apps_tree_updated;
103         guint background_state;
104 } stc_system_s;
105
106 /**
107  * @brief initializes stc monitor module
108  */
109 stc_error_e stc_monitor_init(void);
110
111 /**
112  * @brief deinitializes stc monitor module
113  */
114 stc_error_e stc_monitor_deinit(void);
115
116 /**
117  * @brief creates an application entry
118  */
119 stc_error_e stc_monitor_application_add(const stc_app_key_s app_key,
120                                         const stc_app_value_s app_value);
121
122 /**
123  * @brief associates process to an application
124  */
125 stc_error_e stc_monitor_process_add(const stc_app_key_s app_key,
126                                     const stc_process_key_s proc_key,
127                                     const stc_process_value_s proc_value);
128
129 /**
130  * @brief removes associated process from respective application
131  */
132 stc_error_e stc_monitor_process_remove(pid_t pid);
133
134 /**
135  * @brief updates process's ground attribute
136  */
137 stc_error_e stc_monitor_process_update_ground(const stc_app_key_s app_key,
138                                               const stc_process_key_s proc_key,
139                                               stc_app_state_e ground);
140
141 void stc_monitor_update_rstn_by_default_connection(void *default_connection);
142
143 stc_error_e stc_monitor_rstns_tree_add(const table_restrictions_info *info);
144
145 stc_error_e stc_monitor_rstns_tree_remove(const table_restrictions_info *info);
146
147 stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline);
148
149 int stc_monitor_get_counter_socket(void);
150
151 #endif /* __STC_MONITOR_H__ */