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