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>
28 #include <unordered_set>
31 #include "shared_object.hh"
33 namespace pkgmgr_server {
37 #define EXPORT_API __attribute__((visibility("default")))
40 class EXPORT_API DBHandleProvider {
42 ~DBHandleProvider() = default;
43 static DBHandleProvider& GetInst(uid_t uid);
44 static bool IsCrashedWriteRequest();
45 std::vector<std::pair<std::string, uid_t>> GetParserDBPath(int pid, bool write);
46 std::string GetCertDBPath(int pid, bool write);
47 void SetMemoryMode(pid_t pid, bool flag);
50 DBHandleProvider(uid_t uid);
51 sqlite3* GetMemoryDBHandle(const std::string& filedb_path,
52 const std::string& memorydb_path);
55 static std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>> provider_;
56 static bool is_memory_global_;
57 static std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
58 global_parser_memory_db_handle_;
59 static std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
60 cert_memory_db_handle_;
61 static std::string global_parser_memory_db_path_;
62 static std::string global_parser_file_db_path_;
63 static std::string cert_memory_db_path_;
64 static std::string cert_file_db_path_;
65 static std::unordered_set<pid_t> pid_list_;
66 static std::recursive_mutex lock_;
70 std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*> parser_memory_db_handle_;
71 std::string parser_memory_db_path_;
72 std::string parser_file_db_path_;
75 } // namespace database
76 } // namespace pkgmgr_server
78 #endif // SERVER_DB_HANDLE_PROVIDER_HH_