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.
17 #ifndef __STC_MONITOR_H__
18 #define __STC_MONITOR_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"
29 #define CONTR_TIMER_INTERVAL 1
30 #define IPV4_IPADDRESS_LEN 16
33 * @brief enumeration for data limit types
36 STC_RSTN_LIMIT_TYPE_DATA_WARN,
37 STC_RSTN_LIMIT_TYPE_DATA,
38 STC_RSTN_LIMIT_TYPE_MONTHLY,
39 STC_RSTN_LIMIT_TYPE_WEEKLY,
40 STC_RSTN_LIMIT_TYPE_DAILY,
41 STC_RSTN_LIMIT_TYPE_MAX
42 } stc_rstn_limit_type_e;
46 * @brief key for processes tree
49 stc_app_state_e ground; /**< application state foreground/background */
50 } stc_process_value_s;
53 * @brief value for processes tree
56 pid_t pid; /**< process id */
60 * @brief key for apps tree
63 gchar *pkg_id; /**< package id */
64 gchar *app_id; /**< application id */
68 * @brief value for apps tree
71 uint32_t classid; /**< classid for a package */
72 stc_app_type_e type; /**< type of application */
73 stc_data_counter_s data_usage;
74 stc_data_counter_s counter;
75 GTree *processes; /**< applications instances */
76 char ipaddr[IPV4_IPADDRESS_LEN+1]; /**< application ip address */
80 * @brief key for rstn_rules tree
86 stc_iface_type_e iftype;
87 stc_roaming_type_e roaming;
91 * @brief value for rstn_rules tree
94 uint64_t restriction_id;
96 stc_rstn_state_e rstn_state;
97 stc_rstn_type_e rstn_type;
99 int64_t counter[STC_RSTN_LIMIT_TYPE_MAX];
100 int64_t limit[STC_RSTN_LIMIT_TYPE_MAX];
101 int32_t limit_exceeded;
102 int32_t limit_notified;
104 int month_start_date;
105 time_t month_start_ts;
109 * @brief structure to store system info
112 int contr_sock; /**< socket used for getting kernel counters */
113 guint contr_timer_id; /**< timer id for periodically getting kernel counters */
114 guint contr_gsource_id;
115 stc_data_counter_s du_curr; /**< current data usage */
116 GTree *rstns; /**< restriction rules */
117 gboolean rstns_tree_updated;
118 GTree *apps; /**< monitored applications */
119 gboolean apps_tree_updated;
120 guint background_state;
121 time_t last_month_ts;
124 int month_start_date;
128 * @brief initializes stc monitor module
130 stc_error_e stc_monitor_init(void);
133 * @brief deinitializes stc monitor module
135 stc_error_e stc_monitor_deinit(void);
138 * @brief creates an application entry
140 stc_error_e stc_monitor_application_add(const stc_app_key_s app_key,
141 const stc_app_value_s app_value);
144 * @brief deletes an application entry
146 stc_error_e stc_monitor_application_remove(const stc_app_key_s app_key);
149 * @brief associates process to an application
151 stc_error_e stc_monitor_process_add(const stc_app_key_s app_key,
152 const stc_process_key_s proc_key,
153 const stc_process_value_s proc_value);
156 * @brief removes associated process from respective application
158 stc_error_e stc_monitor_process_remove(pid_t pid);
161 * @brief updates process's ground attribute
163 stc_error_e stc_monitor_process_update_ground(const stc_app_key_s app_key,
164 const stc_process_key_s proc_key,
165 stc_app_state_e ground);
167 void stc_monitor_update_rstn_by_default_connection(void *default_connection);
169 stc_error_e stc_monitor_rstns_tree_add(const table_restrictions_info *info);
171 stc_error_e stc_monitor_rstns_tree_remove(const table_restrictions_info *info);
173 stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline);
175 int stc_monitor_get_counter_socket(void);
177 #endif /* __STC_MONITOR_H__ */