• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NET_STATS_DATABASE_HELPER_H
17 #define NET_STATS_DATABASE_HELPER_H
18 
19 #include <climits>
20 #include <functional>
21 #include <string>
22 
23 #ifndef USE_SQLITE_SYMBOLS
24 #include "sqlite3.h"
25 #else
26 #include "sqlite3sym.h"
27 #endif
28 
29 #include "net_stats_sqlite_statement.h"
30 #include "net_stats_info.h"
31 
32 namespace OHOS {
33 namespace NetManagerStandard {
34 class NetStatsDatabaseHelper {
35 public:
36     using SqlCallback = sqlite3_callback;
37     explicit NetStatsDatabaseHelper(const std::string &path);
38     NetStatsDatabaseHelper() = delete;
39     ~NetStatsDatabaseHelper();
40 
41     int32_t CreateTable(const std::string &tableName, const std::string &tableInfo);
42     int32_t InsertData(const std::string &tableName, const std::string &paramList,
43                        const NetStatsInfo &info);
44     int32_t SelectData(std::vector<NetStatsInfo> &infos, const std::string &tableName, uint64_t start, uint64_t end);
45     int32_t SelectData(const uint32_t uid, uint64_t start, uint64_t end, std::vector<NetStatsInfo> &infos);
46     int32_t SelectData(const std::string &iface, uint64_t start, uint64_t end, std::vector<NetStatsInfo> &infos);
47     int32_t SelectData(const std::string &iface, const uint32_t uid, uint64_t start, uint64_t end,
48                        std::vector<NetStatsInfo> &infos);
49     int32_t DeleteData(const std::string &tableName, uint64_t start, uint64_t end);
50     int32_t DeleteData(const std::string &tableName, uint64_t uid);
51     int32_t ClearData(const std::string &tableName);
52     int32_t Step(std::vector<NetStatsInfo> &infos);
53     int32_t ExecSql(const std::string &sql, void *recv, SqlCallback callback);
54 
55 private:
56     int32_t Open(const std::string &path);
57     int32_t Close();
58     int32_t BindInt64(int32_t idx, uint64_t start, uint64_t end);
59     sqlite3 *sqlite_ = nullptr;
60     NetStatsSqliteStatement statement_;
61 };
62 } // namespace NetManagerStandard
63 } // namespace OHOS
64 
65 #endif // NET_STATS_DATABASE_HELPER_H
66