Release version 0.26.11
[platform/core/appfw/pkgmgr-info.git] / src / server / database / abstract_db_handler.hh
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef ABSTRACT_DB_HANDLER_HH_
18 #define ABSTRACT_DB_HANDLER_HH_
19
20 #include <shared_mutex>
21 #include <string>
22 #include <vector>
23
24 #include <sys/types.h>
25 #include <sqlite3.h>
26
27 #include <database.hpp>
28 #include "db_type.hh"
29 #include "query_parcelable.hh"
30
31 namespace pkgmgr_server {
32 namespace database {
33
34 #ifndef EXPORT_API
35 #define EXPORT_API __attribute__((visibility("default")))
36 #endif
37
38 class EXPORT_API AbstractDBHandler {
39  public:
40   AbstractDBHandler(uid_t uid, pid_t pid)
41       : db_type_(pkgmgr_common::DBType::DB_TYPE_NONE),
42         op_type_(pkgmgr_common::DBOperationType::OPERATION_TYPE_NONE),
43         uid_(uid), pid_(pid) {};
44   virtual ~AbstractDBHandler();
45   virtual int Execute() = 0;
46   void SetLocale(std::string locale);
47   void SetDBType(pkgmgr_common::DBType type);
48   void SetOpType(pkgmgr_common::DBOperationType type);
49   pkgmgr_common::DBOperationType GetOpType();
50
51  protected:
52   virtual bool Connect();
53   virtual const std::vector<std::pair<tizen_base::Database, uid_t>>&
54       GetConnection();
55   int GetPID();
56   uid_t GetUID();
57   std::vector<std::pair<std::string, uid_t>> GetDBPath();
58   void ClearDBHandle();
59   const std::string& GetLocale();
60   static uid_t GetDefaultUser();
61
62  protected:
63   static std::shared_mutex lock_;
64
65  private:
66   pkgmgr_common::DBType db_type_;
67   pkgmgr_common::DBOperationType op_type_;
68   uid_t uid_;
69   pid_t pid_;
70   std::string locale_;
71   std::vector<std::pair<tizen_base::Database, uid_t>> db_handle_list_;
72 };
73
74 }  // namespace database
75 }  // namespace pkgmgr_server
76
77 #endif  // ABSTRACT_DB_HANDLER_HH_