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(
47 std::string GetCertDBPath(int pid, bool write);
48 void SetMemoryMode(pid_t pid);
49 void UnsetMemoryMode(pid_t pid);
52 DBHandleProvider(uid_t uid);
53 sqlite3* GetMemoryDBHandle(const std::string& filedb_path,
54 const std::string& memorydb_path);
55 bool IsMemoryDBActive(pid_t pid, bool write);
58 static std::unordered_map<uid_t,
59 std::unique_ptr<DBHandleProvider>> provider_;
60 static bool is_memory_global_;
61 static std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
62 global_parser_memory_db_handle_;
63 static std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
64 cert_memory_db_handle_;
65 static std::string global_parser_file_db_path_;
66 static std::string cert_file_db_path_;
67 static std::unordered_set<pid_t> pid_list_;
68 static std::recursive_mutex lock_;
72 std::unique_ptr<sqlite3,
73 decltype(sqlite3_close_v2)*> parser_memory_db_handle_;
74 std::string parser_memory_db_path_;
75 std::string parser_file_db_path_;
78 } // namespace database
79 } // namespace pkgmgr_server
81 #endif // SERVER_DB_HANDLE_PROVIDER_HH_