ecf404d33be56e5464665b6aee9a5d37dfcfe7f6
[platform/core/connectivity/stc-manager.git] / src / monitor / include / stc-monitor-rstn.h
1 /*
2  * Copyright (c) 2017 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_RSTN_H__
18 #define __STC_MONITOR_RSTN_H__
19
20 #include <glib.h>
21
22 #include "stc-error.h"
23 #include "stc-manager.h"
24 #include "stc-monitor-context.h"
25 #include "stc-connection.h"
26 #include "stc-restriction.h"
27 #include "table-restrictions.h"
28
29 #define GRANULARITY 10
30
31 #define MAX_INT_LENGTH 128
32 #define MAX_KEY_LENGTH 128
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 typedef struct {
50         uint32_t classid;
51         char *app_id;
52         stc_iface_type_e iftype;
53         char *ifname;
54         char *subscriber_id;
55         stc_roaming_type_e roaming;
56         char *mac;
57
58         uint64_t restriction_id;
59         stc_rstn_state_e rstn_state;
60         stc_rstn_type_e rstn_type;
61
62         int64_t counter[STC_RSTN_LIMIT_TYPE_MAX];
63         int64_t limit[STC_RSTN_LIMIT_TYPE_MAX];
64         int32_t limit_exceeded;
65         int32_t limit_notified;
66
67         int month_start_date;
68         time_t month_start_ts;
69 } stc_rstn_data_s;
70
71 typedef struct {
72         GSList *rules;
73 } stc_rstn_value_s;
74
75 typedef struct {
76         time_t month_start_ts;
77         time_t week_start_ts;
78         time_t day_start_ts;
79         int64_t monthly_stat;
80         int64_t weekly_stat;
81         int64_t daily_stat;
82 } stc_rstn_cumulative_data_s;
83
84 void stc_monitor_rstn_reset_time_counters_if_required(void);
85
86 void stc_monitor_rstn_update_counter(gpointer data,
87                                         gpointer user_data);
88
89 void stc_monitor_rstn_update_iface_counter(classid_bytes_context_s *context);
90
91 void stc_monitor_rstn_action_when_limit_exceeded(stc_rstn_limit_type_e limit_type,
92                                                 stc_rstn_data_s *rstn_data,
93                                                 classid_bytes_context_s *context);
94
95 gboolean stc_monitor_rstn_flush_contr_to_db(gpointer user_data);
96
97 stc_error_e stc_monitor_rstn_add(const table_restrictions_info *info);
98
99 void stc_monitor_rstn_add_for_app(uint32_t classid);
100
101 void stc_monitor_rstn_add_by_connection(stc_connection_s *conn);
102
103 stc_error_e stc_monitor_rstn_remove(const table_restrictions_info *info);
104
105 void stc_monitor_rstn_remove_for_app(uint32_t classid);
106
107 void stc_monitor_rstn_remove_by_connection(stc_connection_s *conn);
108
109 void stc_monitor_rstns_load(void);
110
111 GHashTable *stc_monitor_rstns_init(void);
112
113 #endif /* __STC_MONITOR_RSTN_H__ */