a240994199c9a66f1bc4f880d35cb97806d68b73
[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         unsigned int snd_count;
61         unsigned int rcv_count;
62         unsigned int delta_snd;
63         unsigned int delta_rcv;
64
65 #ifndef CONFIG_DATAUSAGE_NFACCT
66         pid_t pid;
67         int ifindex;
68 #endif
69         stc_roaming_type_e is_roaming;
70
71         /* foreground/background state is here,
72          * not in classid_iftype_key, it means
73          * we'll not able to handle simultaneously
74          * counter per one application for background and
75          * foreground within one counting cycle,
76          * so every time application goes to background/foreground
77          * we'll request its counter update */
78         stc_app_state_e ground;
79 } stc_db_app_stats;
80
81 typedef struct {
82         uint32_t classid;
83         int iftype;
84         /* pointer to telephony's imsi */
85         char *imsi;
86         char ifname[MAX_IFACE_LENGTH];
87 } stc_db_classid_iftype_key;
88
89 /**
90  * @desc This funciton init db oversize erase timer.
91  */
92 stc_error_e stc_init_db_guard(void);
93
94 /**
95  * @desc This funciton deinit db oversize erase timer.
96  */
97 void stc_deinit_db_guard(void);
98
99 /**
100  * @desc This funciton initializes storage module.
101  */
102 gboolean stc_db_initialize(void);
103
104 /**
105  * @desc This funciton deinitializes storage module.
106  */
107 gboolean stc_db_deinitialize(void);
108
109 #endif /* _STC_DB_H_ */