This will be used until setup vector db.
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
## Targets
+SET(TARGET_TIZEN_ACTION_COMMON "tizen-action-common")
SET(TARGET_TIZEN_ACTION_PLUGIN "tizen-action-plugin")
#ENABLE_TESTING()
PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer)
PKG_CHECK_MODULES(RPC_PORT_DEPS REQUIRED rpc-port)
+PKG_CHECK_MODULES(TIZEN_DATABASE_DEPS REQUIRED tizen-database)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tool)
BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(pkgmgr-installer)
BuildRequires: pkgconfig(rpc-port)
+BuildRequires: pkgconfig(tizen-database)
%if 0%{?gcov:1}
BuildRequires: lcov
%defattr(-,root,root,-)
%manifest %{name}.manifest
%license LICENSE
+%{_libdir}/*.so
%{_sysconfdir}/package-manager/parserlib/metadata/libtizen-action-plugin.so
%{_datarootdir}/parser-plugins/tizen-action-plugin.info
+ADD_SUBDIRECTORY(common)
ADD_SUBDIRECTORY(pkgmgr_plugin_parser)
--- /dev/null
+# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ACTION_COMMON_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/utils ACTION_COMMON_UTILS_SRCS)
+
+ADD_LIBRARY(${TARGET_TIZEN_ACTION_COMMON} SHARED
+# ${ACTION_COMMON_SRCS}
+ ${ACTION_COMMON_UTILS_SRCS}
+)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_ACTION_COMMON} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+APPLY_PKG_CONFIG(${TARGET_TIZEN_ACTION_COMMON} PUBLIC
+ DLOG_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_TIZEN_ACTION_COMMON} DESTINATION ${LIB_INSTALL_DIR})
// Use of this source code is governed by a apache 2.0 license that can be
// found in the LICENSE file.
-#include "utils/logging.h"
+#include "common/utils/logging.hh"
+namespace common {
namespace utils {
log_priority LogLevelToPriority(LogLevel level) {
}
}
+} // namespace common
} // namespace utils
// Use of this source code is governed by a apache 2.0 license that can be
// found in the LICENSE file.
-#ifndef LOGGING_HH_
-#define LOGGING_HH_
+#ifndef COMMON_UTILS_LOGGING_HH_
+#define COMMON_UTILS_LOGGING_HH_
#include <dlog.h>
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
+namespace common {
namespace utils {
enum class LogLevel {
};
} // namespace utils
+} // namespace common
inline static const constexpr char* __tag_for_project() {
return PROJECT_TAG;
// where:
// LEVEL = ERROR | WARNING | INFO | DEBUG
#define LOG(LEVEL) \
- ::utils::LogCatcher( \
- ::utils::LogLevel::LOG_ ## LEVEL, __tag_for_project()) \
- & ::utils::StringStream<char>() \
+ ::common::utils::LogCatcher( \
+ ::common::utils::LogLevel::LOG_ ## LEVEL, __tag_for_project()) \
+ & ::common::utils::StringStream<char>() \
<< std::setw(50) << std::right \
<< (std::string(__FILENAME__) + ": " + std::string(__FUNCTION__) + "(" + \
std::to_string(__LINE__) + ")").c_str() \
<< std::setw(0) << " : " \
-#endif // LOGGING_HH_
+#endif // COMMON_UTILS_LOGGING_HH_
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ACTION_PLUGIN_SRCS)
ADD_LIBRARY(${TARGET_TIZEN_ACTION_PLUGIN} SHARED ${ACTION_PLUGIN_SRCS})
-TARGET_LINK_LIBRARIES(${TARGET_TIZEN_ACTION_PLUGIN} PRIVATE ${TARGET_TIZEN_THEME} ${TARGET_TIZEN_ACTION_PROVIDER})
+TARGET_LINK_LIBRARIES(${TARGET_TIZEN_ACTION_PLUGIN} PRIVATE ${TARGET_TIZEN_ACTION_COMMON})
TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_ACTION_PLUGIN} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
APPLY_PKG_CONFIG(${TARGET_TIZEN_ACTION_PLUGIN} PUBLIC
PKGMGR_INFO_DEPS
PKGMGR_INSTALLER_DEPS
PKGMGR_PARSER_DEPS
+ TIZEN_DATABASE_DEPS
)
INSTALL(TARGETS ${TARGET_TIZEN_ACTION_PLUGIN} DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib/metadata)
#include "common/utils/logging.hh"
#include "pkgmgr_plugin_parser/action_schema_parser.hh"
#include "pkgmgr_plugin_parser/json_action_schema_parser.hh"
+#include "pkgmgr_plugin_parser/sqlite_db.hh"
namespace parser {
}
bool ActionParser::Commit(Operation operation, const ActionSchema& schema) {
- // TODO: insert into DB
- return true;
+ SqliteDb sqlite_db;
+
+ switch (operation) {
+ case Operation::Install:
+ return sqlite_db.Install(schema);
+ case Operation::Update:
+ return sqlite_db.Update(schema);
+ case Operation::Uninstall:
+ return sqlite_db.Uninstall(schema);
+ }
+
+ return false;
}
bool ActionParser::ForceCommit(Operation operation, const ActionSchema& schema) {
~ActionSchema() = default;
std::string GetPkgId() const { return pkgid_; }
- std::string GetId() const { return name_; }
+ std::string GetName() const { return name_; }
std::string GetJsonStr() const { return json_str_; }
private:
--- /dev/null
+/*
+ * Copyright (c) 2025 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.
+ */
+
+#include "pkgmgr_plugin_parser/sqlite_db.hh"
+
+#include <database.hpp>
+
+#include "common/utils/logging.hh"
+
+namespace {
+
+constexpr char kDbPath[] = "/opt/dbspace/.tizen_action.db";
+constexpr char kCreateActionTableQuery[] =
+ "CREATE TABLE IF NOT EXISTS action (\n"
+ " pkgid TEXT,\n"
+ " action_name TEXT,\n"
+ " json_str TEXT,\n"
+ " PRIMARY KEY (pkgid, action_name))";
+constexpr char kInsertQuery[] =
+ "INSERT INTO action (pkgid, action_name, json_str) "
+ "VALUES (?, ?, ?)";
+constexpr char kDeleteQuery[] =
+ "DELETE FROM action WHERE pkgid = ?";
+constexpr char kSelectQuery[] =
+ "SELECT json_str FROM action WHERE pkgid = ?";
+
+} // namespace
+
+namespace parser {
+
+SqliteDb::SqliteDb()
+ : conn_(kDbPath, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE) {
+ if (!static_cast<bool>(conn_.Exec({ kCreateActionTableQuery })))
+ LOG(ERROR) << "Failed to create action table";
+}
+
+bool SqliteDb::Install(const ActionSchema& schema) {
+ auto q = std::move(tizen_base::Database::Sql(kInsertQuery)
+ .Bind(schema.GetPkgId())
+ .Bind(schema.GetName())
+ .Bind(schema.GetJsonStr()));
+ auto r = conn_.Exec(q);
+ if (!static_cast<bool>(r)) {
+ LOG(ERROR) << "Failed to insert action schema: " << schema.GetName();
+ return false;
+ }
+
+ return true;
+}
+
+bool SqliteDb::Update(const ActionSchema& schema) {
+ // delete and insert
+ auto q = std::move(tizen_base::Database::Sql(kDeleteQuery)
+ .Bind(schema.GetPkgId()));
+ auto r = conn_.Exec(q);
+ if (!static_cast<bool>(r)) {
+ LOG(ERROR) << "Failed to delete action schema from DB: "
+ << schema.GetName();
+ return false;
+ }
+
+ q = std::move(tizen_base::Database::Sql(kInsertQuery)
+ .Bind(schema.GetPkgId())
+ .Bind(schema.GetName())
+ .Bind(schema.GetJsonStr()));
+
+ r = conn_.Exec(q);
+ if (!static_cast<bool>(r)) {
+ LOG(ERROR) << "Failed to update action schema into DB: "
+ << schema.GetName();
+ return false;
+ }
+
+ return true;
+}
+
+bool SqliteDb::Uninstall(const ActionSchema& schema) {
+ auto q = std::move(tizen_base::Database::Sql(kDeleteQuery)
+ .Bind(schema.GetPkgId()));
+ auto r = conn_.Exec(q);
+ if (!static_cast<bool>(r)) {
+ LOG(ERROR) << "Failed to delete action schema: " << schema.GetName();
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace parser
--- /dev/null
+/*
+ * Copyright (c) 2025 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 PKGMGR_PLUGIN_PARSER_SQLITE_DB_HH_
+#define PKGMGR_PLUGIN_PARSER_SQLITE_DB_HH_
+
+#include <database.hpp>
+
+#include <string>
+
+#include "pkgmgr_plugin_parser/action_registry.hh"
+#include "pkgmgr_plugin_parser/action_schema.hh"
+
+namespace parser {
+
+class SqliteDb : public IActionRegistry {
+ public:
+ SqliteDb();
+ ~SqliteDb() = default;
+
+ bool Install(const ActionSchema& schema) override;
+ bool Update(const ActionSchema& schema) override;
+ bool Uninstall(const ActionSchema& schema) override;
+
+ private:
+ tizen_base::Database conn_;
+};
+
+} // namespace parser
+
+#endif // PKGMGR_PLUGIN_PARSER_SQLITE_DB_HH_
\ No newline at end of file