13ae916ae95a0dfed81671b017fbe1d515265182
[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 /*
41  * General structure containing information for storing
42  * app_id - package name as unique application identifier
43  * snd_count - sent bytes
44  * rcv_count - received bytes
45  * pid - process identifier
46  * ifindex - network interface index, iftype holds in key @see stc_iface_type
47  * is_roaming - is traffic consumed at roaming, @see stc_roaming_type
48  */
49 typedef struct {
50         char *app_id;
51         int64_t rcv_count;
52         int64_t snd_count;
53
54 #ifndef CONFIG_DATAUSAGE_NFACCT
55         pid_t pid;
56         int ifindex;
57 #endif
58         stc_roaming_type_e is_roaming;
59
60         /* foreground/background state is here,
61          * not in classid_iftype_key, it means
62          * we'll not able to handle simultaneously
63          * counter per one application for background and
64          * foreground within one counting cycle,
65          * so every time application goes to background/foreground
66          * we'll request its counter update */
67         stc_app_state_e ground;
68 } stc_db_app_stats;
69
70 typedef struct {
71         uint32_t classid;
72         int iftype;
73         /* pointer to telephony's subscriber_id */
74         char *subscriber_id;
75         char ifname[MAX_IFACE_LENGTH];
76 } stc_db_classid_iftype_key;
77
78 /**
79  * @desc This function init db oversize erase timer.
80  */
81 stc_error_e stc_init_db_guard(void);
82
83 /**
84  * @desc This function deinit db oversize erase timer.
85  */
86 void stc_deinit_db_guard(void);
87
88 /**
89  * @desc This function initializes storage module.
90  */
91 gboolean stc_db_initialize(void);
92
93 /**
94  * @desc This function deinitializes storage module.
95  */
96 gboolean stc_db_deinitialize(void);
97
98 #endif /* _STC_DB_H_ */