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 ABSTRACT_DB_HANDLER_HH_
18 #define ABSTRACT_DB_HANDLER_HH_
20 #include <shared_mutex>
24 #include <sys/types.h>
28 #include "query_parcelable.hh"
30 namespace pkgmgr_server {
34 #define EXPORT_API __attribute__((visibility("default")))
37 class EXPORT_API AbstractDBHandler {
39 AbstractDBHandler(uid_t uid, pid_t pid)
40 : db_type_(pkgmgr_common::DBType::DB_TYPE_NONE),
41 op_type_(pkgmgr_common::DBOperationType::OPERATION_TYPE_NONE),
42 uid_(uid), pid_(pid) {};
43 virtual ~AbstractDBHandler();
44 virtual int Execute() = 0;
45 void SetLocale(std::string locale);
46 void SetDBType(pkgmgr_common::DBType type);
47 void SetOpType(pkgmgr_common::DBOperationType type);
48 pkgmgr_common::DBOperationType GetOpType();
51 virtual bool Connect();
54 std::vector<std::pair<std::string, uid_t>> GetDBPath();
55 virtual std::vector<std::pair<sqlite3*, uid_t>> GetConnection();
57 const std::string& GetLocale();
58 static uid_t GetDefaultUser();
60 static std::shared_timed_mutex lock_;
63 pkgmgr_common::DBType db_type_;
64 pkgmgr_common::DBOperationType op_type_;
68 std::vector<std::pair<sqlite3*, uid_t>> db_handle_list_;
71 } // namespace database
72 } // namespace pkgmgr_server
74 #endif // ABSTRACT_DB_HANDLER_HH_