Implement pkgmgrinfo_pkginfo_set_installed_storage
[platform/core/appfw/pkgmgr-info.git] / src / common / 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 <string>
21
22 #include <sys/types.h>
23 #include <sqlite3.h>
24
25 namespace pkgmgr_common {
26 namespace database {
27
28 #ifndef EXPORT_API
29 #define EXPORT_API __attribute__((visibility("default")))
30 #endif
31
32 class EXPORT_API AbstractDBHandler {
33  public:
34   enum DBType {
35     DB_TYPE_NONE,
36     DB_TYPE_FILE_PKGDB,
37     DB_TYPE_FILE_CERTDB,
38     DB_TYPE_MEMORY_PKGDB,
39   };
40   enum OperationType {
41     OPERATION_TYPE_NONE,
42     OPERATION_TYPE_READ,
43     OPERATION_TYPE_WRITE
44   };
45
46   AbstractDBHandler(uid_t uid);
47   virtual ~AbstractDBHandler();
48   virtual bool Execute() = 0;
49   void SetLocale(const std::string& locale);
50   void SetDBType(DBType type);
51   void SetOpType(OperationType type);
52   OperationType GetOpType();
53
54  protected:
55   bool Connect();
56   sqlite3* GetConnection();
57   std::string GetLocale();
58
59  private:
60   std::string GetDBPath();
61   DBType db_type_ = DB_TYPE_NONE;
62   OperationType op_type_ = OPERATION_TYPE_NONE;
63   uid_t uid_;
64   std::string locale_;
65   sqlite3* db_ = nullptr;
66 };
67
68 }  // namespace database
69 }  // namespace pkgmgr_common
70
71 #endif  // ABSTRACT_DB_HANDLER_HH_
72