2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef SERVER_DB_HANDLE_PROVIDER_HH_
18 #define SERVER_DB_HANDLE_PROVIDER_HH_
22 #include <sys/types.h>
27 #include <unordered_map>
30 #include "shared_object.hh"
32 namespace pkgmgr_common {
35 #define EXPORT_API __attribute__((visibility("default")))
38 class EXPORT_API DBHandleProvider {
40 ~DBHandleProvider() = default;
41 static DBHandleProvider& GetInst(uid_t uid);
42 std::vector<std::string> GetParserDBPath(int pid);
43 std::string GetCertDBPath(int pid);
44 void SetMemoryMode(int pid, bool flag);
47 DBHandleProvider(uid_t uid);
48 sqlite3* GetMemoryDBHandle(const std::string& filedb_path,
49 const std::string& memorydb_path);
52 static std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>> provider_;
54 std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*> global_parser_memory_db_handle_;
55 std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*> parser_memory_db_handle_;
56 std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*> cert_memory_db_handle_;
57 std::string parser_memory_db_path_;
58 std::string global_parser_memory_db_path_;
59 std::string parser_file_db_path_;
60 std::string global_parser_file_db_path_;
61 std::string cert_memory_db_path_;
62 std::string cert_file_db_path_;
63 static bool is_memory_;
64 static std::vector<pid_t> pid_list_;
68 } // namespace pkgmgr_common
70 #endif // SERVER_DB_HANDLE_PROVIDER_HH_