[STC Manager] Support set/get for total data usage(Tx + Rx) in restriction.
[platform/core/connectivity/stc-manager.git] / src / database / include / stc-db.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_DB_H__
18 #define __STC_DB_H__
19
20 #include "stc-manager.h"
21
22 #define MAX_DB_RETRY_COUNT 20
23 #define MAX_USLEEP_TIMEOUT 500000
24 #define SQLITE_BUSY_TIMEOUT 500000
25 #define MAX_IFACE_LENGTH 32
26
27 /**
28  * @brief Commulative structure for holding stc storage information
29  */
30 typedef struct {
31         stc_data_counter_s cnt;
32 //      stc_db_net_restrictions rst;
33 } stc_db_common_info;
34
35 typedef struct {
36         time_t from;
37         time_t to;
38 } stc_db_tm_interval_s;
39
40 typedef enum {
41         STC_DB_CON_PERIOD_UNKNOWN,              /**< Undefined period */
42         STC_DB_CON_PERIOD_LAST_RECEIVED_DATA,   /**< Last received data */
43         STC_DB_CON_PERIOD_LAST_SENT_DATA,       /**< Last sent data */
44         STC_DB_CON_PERIOD_TOTAL_RECEIVED_DATA,  /**< Total received data */
45         STC_DB_CON_PERIOD_TOTAL_SENT_DATA,      /**< Total sent data */
46         STC_DB_CON_PERIOD_LAST_ELEM
47 } stc_db_connection_period_type;
48
49 /*
50  * General structure containing information for storing
51  * app_id - package name as unique application identifier
52  * snd_count - sent bytes
53  * rcv_count - received bytes
54  * pid - process identifier
55  * ifindex - network interface index, iftype holds in key @see stc_iface_type
56  * is_roaming - is traffic consumed at roaming, @see stc_roaming_type
57  */
58 typedef struct {
59         char *app_id;
60         int64_t rcv_count;
61         int64_t snd_count;
62
63 #ifndef CONFIG_DATAUSAGE_NFACCT
64         pid_t pid;
65         int ifindex;
66 #endif
67         stc_roaming_type_e is_roaming;
68
69         /* foreground/background state is here,
70          * not in classid_iftype_key, it means
71          * we'll not able to handle simultaneously
72          * counter per one application for background and
73          * foreground within one counting cycle,
74          * so every time application goes to background/foreground
75          * we'll request its counter update */
76         stc_app_state_e ground;
77 } stc_db_app_stats;
78
79 typedef struct {
80         uint32_t classid;
81         int iftype;
82         /* pointer to telephony's imsi */
83         char *imsi;
84         char ifname[MAX_IFACE_LENGTH];
85 } stc_db_classid_iftype_key;
86
87 /**
88  * @desc This funciton init db oversize erase timer.
89  */
90 stc_error_e stc_init_db_guard(void);
91
92 /**
93  * @desc This funciton deinit db oversize erase timer.
94  */
95 void stc_deinit_db_guard(void);
96
97 /**
98  * @desc This funciton initializes storage module.
99  */
100 gboolean stc_db_initialize(void);
101
102 /**
103  * @desc This funciton deinitializes storage module.
104  */
105 gboolean stc_db_deinitialize(void);
106
107 #endif /* _STC_DB_H_ */