Refactor pkgmgr-info
[platform/core/appfw/pkgmgr-info.git] / src / server / pkgmgrinfo_internal.h
index cef3d7c..5e5d315 100644 (file)
@@ -1,18 +1,18 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 
 #ifndef __PKGMGRINFO_INTERNAL_H__
 #define __PKGMGRINFO_INTERNAL_H__
 #include <stdbool.h>
 #include <unistd.h>
 #include <sys/types.h>
-
 #include <sqlite3.h>
 
+#include <string_view>
+
+#include <database.hpp>
 #include "pkgmgr_parser.h"
 #include "pkgmgrinfo_private.h"
 #include "pkgmgrinfo_type.h"
 #include "pkgmgr-info.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
-    int len;
-    GList *argument;
-} query_args;
-
-#define __BEGIN_TRANSACTION(db)                                                \
-do {                                                                           \
-       if (sqlite3_exec(db, "BEGIN DEFERRED", NULL, NULL, NULL) !=            \
-                       SQLITE_OK) {                                           \
-               _LOGE("begin transaction failed: %s", sqlite3_errmsg(db));     \
-               return -1;                                                     \
-       }                                                                      \
-} while (0)                                                                    \
-
-#define __DO_TRANSACTION(db, func)                                             \
-do {                                                                           \
-       if (func) {                                                            \
-               _LOGE("transaction failed: %s, rollback", sqlite3_errmsg(db)); \
-               if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) !=          \
-                               SQLITE_OK)                                     \
-                       _LOGE("roll back transaction failed: %s",              \
-                                       sqlite3_errmsg(db));                   \
-               return -1;                                                     \
-       }                                                                      \
-} while (0)                                                                    \
-
-#define __END_TRANSACTION(db)                                                  \
-do {                                                                           \
-       if (sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) !=                    \
-                       SQLITE_OK) {                                           \
-               _LOGE("commit failed: %s, rollback", sqlite3_errmsg(db));      \
-               if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) !=          \
-                               SQLITE_OK)                                     \
-                       _LOGE("roll back transaction failed: %s",              \
-                                       sqlite3_errmsg(db));                   \
-               return -1;                                                     \
-       }                                                                      \
-} while (0)                                                                    \
 
-#define __BIND_TEXT(db, stmt, i, text)                                         \
-do {                                                                           \
-       if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\
-               _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db));      \
-               sqlite3_finalize(stmt);                                        \
-               return -1;                                                     \
-       }                                                                      \
-} while (0)
 
-#define __BIND_INT(db, stmt, i, int)                                           \
-do {                                                                           \
-       if (sqlite3_bind_int(stmt, i, int) != SQLITE_OK) {                     \
-               _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db));      \
-               sqlite3_finalize(stmt);                                        \
-               return -1;                                                     \
-       }                                                                      \
-} while (0)
+namespace pkgmgr_server::internal {
+
+void SetEnableUnitTest(bool enable);
+int CertInfoGet(const tizen_base::Database& db,
+    std::string_view pkgid, uid_t uid, pkgmgrinfo_certinfo_h certinfo);
+int CertInfoSet(const tizen_base::Database& db,
+    std::string_view pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid);
+int InitializeDb(const tizen_base::Database& db, uid_t uid);
+int InsertPkgInfo(const tizen_base::Database& db, manifest_x* mfx, uid_t uid);
+int UpdatePkgInfo(const tizen_base::Database& db, manifest_x* mfx, uid_t uid);
+int DeletePkgInfo(const tizen_base::Database& db, const char* package, uid_t uid);
+bool CheckPackageStorageStatus(pkgmgrinfo_filter_x* tmp_filter);
+int ExecuteWriteQueries(const tizen_base::Database& db,
+    const std::vector<std::string>& queries,
+    const std::vector<std::vector<std::optional<std::string>>>& args_list);
+int GetQueryResult(const tizen_base::Database& db,
+    const std::string& query,
+    const std::vector<std::optional<std::string>>& param,
+    std::vector<std::vector<std::optional<std::string>>>& result);
+bool CheckAppStorageStatus(pkgmgrinfo_filter_x* tmp_filter);
+int GetAppInfo(const tizen_base::Database& db,
+    pkgmgrinfo_appinfo_filter_h filter, uid_t db_uid, uid_t uid,
+    const std::string& locale,
+    std::vector<std::shared_ptr<application_x>>& appinfo_list);
+int GetPkgInfo(const tizen_base::Database& db,
+    pkgmgrinfo_pkginfo_filter_h filter, uid_t uid,
+    const std::string& locale,
+    std::map<std::string, std::shared_ptr<package_x>>& pkginfo_list);
+int GetDependsOn(const tizen_base::Database& db, const std::string& pkgid,
+    std::vector<dependency_x*>& dep_list);
+
+}  // namespace pkgmgr_server::internal
 
-int pkginfo_internal_filter_get_list(sqlite3 *db, pkgmgrinfo_pkginfo_filter_h filter, uid_t uid, const char *locale, GHashTable *list);
-int certinfo_internal_get(sqlite3 *db, const char *pkgid, uid_t uid, pkgmgrinfo_certinfo_h certinfo);
-int certinfo_internal_set(sqlite3 *db, const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid);
-int get_query_result(sqlite3 *db, const char *query, GList *param, GList **list, int *row, int *col);
-int execute_write_queries(sqlite3 *db, GList *queries, GList *params_list);
-int pkginfo_internal_filter_get_depends_on(sqlite3 *db, const char *pkgid, GList **list);
-
-bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter);
-void _save_column_int(sqlite3_stmt *stmt, int idx, int *i);
-void _save_column_str(sqlite3_stmt *stmt, int idx, char **str);
-
-int pkgmgr_parser_insert_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid);
-int pkgmgr_parser_update_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid);
-int pkgmgr_parser_delete_pkg_info(sqlite3 *db, const char *package, uid_t uid);
-
-int pkgmgr_parser_internal_initialize_db(sqlite3 *db, uid_t uid);
-
-/** @} */
-#ifdef __cplusplus
-}
-#endif
 #endif                         /* __PKGMGRINFO_INTERNAL_H__ */
-/**
- * @}
- * @}
- */
-