From: Junghyun Yeon Date: Thu, 29 Jul 2021 02:31:43 +0000 (+0900) Subject: Add skeleton codes for rsc-copy tool X-Git-Tag: accepted/tizen/unified/20210824.123803~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F24%2F261924%2F10;p=platform%2Fcore%2Fappfw%2Fpkgmgr-tool.git Add skeleton codes for rsc-copy tool Change-Id: I3cdeb756b7acfc38b205cadb343312ac1e6ca553 Signed-off-by: Junghyun Yeon --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d583b18..82e0da3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ SET(TARGET_PKG_GETSIZE "pkg_getsize") SET(TARGET_PKG_CLEARDATA "pkg_cleardata") SET(TARGET_INSTALL_PRELOAD_PKG "install_preload_pkg") SET(TARGET_PKG_UPGRADE "pkg_upgrade") +SET(TARGET_RSC_COPY "rsc-copy") SET(TARGET_RSC_SLICE "rsc-slice") SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 123e9bb..8f985ad 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -110,6 +110,7 @@ update-mime-database %{_datadir}/mime %{_bindir}/pkg_cleardata %{_bindir}/pkginfo %{_bindir}/rsc-slice +%{_bindir}/rsc-copy %{_bindir}/pkg_upgrade %attr(0755,root,root) %{_bindir}/install_preload_pkg %{_datadir}/mime/packages/mime.wac.xml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 18fdd25..3812999 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,4 +4,5 @@ ADD_SUBDIRECTORY(pkg_getsize) ADD_SUBDIRECTORY(pkg_upgrade) ADD_SUBDIRECTORY(pkgcmd) ADD_SUBDIRECTORY(pkginfo) +ADD_SUBDIRECTORY(rsc-copy) ADD_SUBDIRECTORY(rsc-slice) diff --git a/src/rsc-copy/CMakeLists.txt b/src/rsc-copy/CMakeLists.txt new file mode 100644 index 0000000..1f6532c --- /dev/null +++ b/src/rsc-copy/CMakeLists.txt @@ -0,0 +1,16 @@ +# Target - sources +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) + +# Target - definition +ADD_EXECUTABLE(${TARGET_RSC_COPY} ${SRCS}) + +# Dependency +APPLY_PKG_CONFIG(${TARGET_RSC_COPY} PUBLIC + AUL_DEPS + GLIB_DEPS + BUNDLE_DEPS +) + +# Install +INSTALL(TARGETS ${TARGET_RSC_COPY} DESTINATION bin) \ No newline at end of file diff --git a/src/rsc-copy/include/abstract_request_handler.hh b/src/rsc-copy/include/abstract_request_handler.hh new file mode 100644 index 0000000..5f54917 --- /dev/null +++ b/src/rsc-copy/include/abstract_request_handler.hh @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 ABSTRACT_REQUEST_HANDLER_HH_ +#define ABSTRACT_REQUEST_HANDLER_HH_ + +#include +#include + +#include "include/error_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +class AbstractRequestHandler { + public: + AbstractRequestHandler(std::string pkgid, std::list path_list) : + pkgid_(pkgid), path_list_(path_list) {}; + + virtual ErrorType Execute() = 0; + + protected: + std::string GetRootPath(); + + private: + std::string pkgid_; + std::list path_list_; +}; + +} // rsc_handler + +#endif // ABSTRACT_REQUEST_HANDLER_HH_ diff --git a/src/rsc-copy/include/condition_validator.hh b/src/rsc-copy/include/condition_validator.hh new file mode 100644 index 0000000..1c681f9 --- /dev/null +++ b/src/rsc-copy/include/condition_validator.hh @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 CONDITION_VALIDATOR_HH_ +#define CONDITION_VALIDATOR_HH_ + +#include +#include + +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +class ConditionValidator { + public: + ConditionValidator(std::list list); + bool ValidateCondition(); + + private: + std::list path_info_list_; +}; + +} // rsc_handler + +#endif // CONDITION_VALIDATOR_HH_ diff --git a/src/rsc-copy/include/copy_request_handler.hh b/src/rsc-copy/include/copy_request_handler.hh new file mode 100644 index 0000000..8993cf3 --- /dev/null +++ b/src/rsc-copy/include/copy_request_handler.hh @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 COPY_REQUEST_HANDLER_HH_ +#define COPY_REQUEST_HANDLER_HH_ + +#include +#include + +#include "include/abstract_request_handler.hh" +#include "include/error_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +class CopyRequestHandler : public AbstractRequestHandler { + public: + ErrorType Execute() override; +}; + +} // rsc_handler + +#endif // COPY_REQUEST_HANDLER_HH_ diff --git a/src/rsc-copy/include/error_type.hh b/src/rsc-copy/include/error_type.hh new file mode 100644 index 0000000..c6684c4 --- /dev/null +++ b/src/rsc-copy/include/error_type.hh @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#ifndef ERROR_TYPE_HH_ +#define ERROR_TYPE_HH_ + +namespace rsc_handler { + +enum ErrorType { + ERROR_NONE = 0, + ERROR_INVALID_PARAMETER, + ERROR_PKG_NOT_FOUND, + ERROR_PERMISSION_DENIED, + ERROR_SYSTEM_ERROR, + ERROR_OUT_OF_SPACE, + ERROR_OUT_OF_MEMORY +}; + +} // namespace rsc_handler + +#endif // ERROR_TYPE_HH_ diff --git a/src/rsc-copy/include/event_signal_sender.hh b/src/rsc-copy/include/event_signal_sender.hh new file mode 100644 index 0000000..dd4fd43 --- /dev/null +++ b/src/rsc-copy/include/event_signal_sender.hh @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 EVENT_SIGNAL_SENDER_HH_ +#define EVENT_SIGNAL_SENDER_HH_ + +#include + +#include "include/request_type.hh" + +namespace rsc_handler { + +class EventSignalSender { + public: + EventSignalSender(std::string pkgid, ReqType req_type); + bool SendStart(); + bool SendOK(); + bool SendFail(); + + private: + std::string pkgid_; + ReqType req_type_; +}; + +} // rsc_handler + +#endif // PARAM_CHECKER_HH_ diff --git a/src/rsc-copy/include/logging.hh b/src/rsc-copy/include/logging.hh new file mode 100644 index 0000000..814e875 --- /dev/null +++ b/src/rsc-copy/include/logging.hh @@ -0,0 +1,180 @@ +// Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved +// 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_ + +#include + +#ifndef PROJECT_TAG +#define PROJECT_TAG "PKGMGR_TOOL" +#endif + +#ifdef LOG +#undef LOG +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef __FILENAME__ +#define __FILENAME__ \ + (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) +#endif + +namespace utils { + +enum class LogLevel { + LOG_ERROR, + LOG_WARNING, + LOG_INFO, + LOG_DEBUG, +}; + +log_priority LogLevelToPriority(LogLevel level); + +template struct LogTag; +template<> struct LogTag { + static constexpr const char* value = "\033[1;31m| ERROR |\033[0m"; +}; +template<> struct LogTag { + static constexpr const char* value = "\033[1;33m| WARNING |\033[0m"; +}; +template<> struct LogTag { + static constexpr const char* value = "\033[1;32m| INFO |\033[0m"; +}; +template<> struct LogTag { + static constexpr const char* value = "\033[0m| DEBUG |\033[0m"; +}; + +template > +class StringStream : private std::basic_ostringstream { + public: + using std::basic_ostringstream::str; + + template + StringStream& operator<<(const T& value) { + static_cast &>(*this) << value; + return *this; + } +}; + +// Interface class for logging backends. The custom LogBackend which wants +// log using LOG() macro should be implement following interface. +class ILogBackend { + public: + virtual void WriteLog(LogLevel level, const std::string& tag, + const std::string& logstr) = 0; +}; + +class DLogBackend : public ILogBackend { + public: + void WriteLog(LogLevel level, const std::string& tag, + const std::string& logstr) override { + dlog_print(LogLevelToPriority(level), tag.c_str(), "%s", + Escape(logstr).c_str()); + } + + private: + // Since LogCatcher passes input to dlog_print(), the input which contains + // format string(such as %d, %n) can cause unexpected result. + // This is simple function to escape '%'. + // NOTE: Is there any gorgeous way instead of this? + std::string Escape(const std::string& str) const { + std::string escaped = std::string(str); + size_t start_pos = 0; + std::string from = "%"; + std::string to = "%%"; + while ((start_pos = escaped.find(from, start_pos)) != std::string::npos) { + escaped.replace(start_pos, from.length(), to); + start_pos += to.length(); + } + return escaped; + } +}; + +class LogCore { + public: + // Do not call this function at destructor of global object + static LogCore& GetCore() { + static LogCore core; + return core; + } + + void AddLogBackend(std::shared_ptr backend) { + backend_list_.emplace_back(backend); + } + + void Log(LogLevel level, const std::string& tag, const std::string& log) { + for (auto& backend : backend_list_) + backend->WriteLog(level, tag, log); + } + + private: + LogCore() { + // add default dlog backend + AddLogBackend(std::shared_ptr(new DLogBackend())); + } + ~LogCore() = default; + LogCore(const LogCore&) = delete; + LogCore& operator=(const LogCore&) = delete; + + std::vector> backend_list_; +}; + +class LogCatcher { + public: + LogCatcher(LogLevel level, const char* tag) + : level_(level), tag_(tag) { } + + void operator&(const StringStream& str) const { + LogCore::GetCore().Log(level_, tag_, str.str()); + } + + private: + LogLevel level_; + std::string tag_; +}; + +} // namespace utils + + +inline static const constexpr char* __tag_for_logging() { + return ""; +} + +inline static const constexpr char* __tag_for_project() { + return PROJECT_TAG; +} + +// To be defined in class namespace if user want different log tag for given +// scope +#define SCOPE_LOG_TAG(TAG) \ + inline static const constexpr char* __tag_for_logging() { \ + return #TAG; \ + } \ + +// Simple logging macro of following usage: +// LOG(LEVEL) << object_1 << object_2 << object_n; +// where: +// LEVEL = ERROR | WARNING | INFO | DEBUG +#define LOG(LEVEL) \ + ::utils::LogCatcher( \ + ::utils::LogLevel::LOG_ ## LEVEL, __tag_for_project()) \ + & ::utils::StringStream() \ + << std::string(::utils::LogTag<::utils::LogLevel::LOG_ ## LEVEL>::value) \ + << " " << std::setw(25) << std::left << __tag_for_logging() \ + << " : " << std::setw(36) \ + << (std::string(__FILENAME__) + ":" + std::to_string(__LINE__)).c_str() \ + << std::setw(0) << " : " \ + +#endif // LOGGING_HH_ diff --git a/src/rsc-copy/include/param_checker.hh b/src/rsc-copy/include/param_checker.hh new file mode 100644 index 0000000..5ab1ab5 --- /dev/null +++ b/src/rsc-copy/include/param_checker.hh @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 PARAM_CHECKER_HH_ +#define PARAM_CHECKER_HH_ + +#include +#include + +#include "include/request_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +class ParamChecker { + public: + ParamChecker(int argc, char* argv[]); + ReqType GetRequestType(); + std::string GetPkgID() const; + const std::list& GetPathList() const; + bool Validate(); + + private: + std::list path_info_list_; +}; + +} // rsc_handler + +#endif // PARAM_CHECKER_HH_ diff --git a/src/rsc-copy/include/remove_request_handler.hh b/src/rsc-copy/include/remove_request_handler.hh new file mode 100644 index 0000000..04a906b --- /dev/null +++ b/src/rsc-copy/include/remove_request_handler.hh @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 REMOVE_REQUEST_HANDLER_HH_ +#define REMOVE_REQUEST_HANDLER_HH_ + +#include +#include + +#include "include/abstract_request_handler.hh" +#include "include/error_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +class RemoveRequestHandler : public AbstractRequestHandler { + public: + ErrorType Execute() override; +}; + +} // rsc_handler + +#endif // REMOVE_REQUEST_HANDLER_HH_ diff --git a/src/rsc-copy/include/request_handler_invoker.hh b/src/rsc-copy/include/request_handler_invoker.hh new file mode 100644 index 0000000..187e4b3 --- /dev/null +++ b/src/rsc-copy/include/request_handler_invoker.hh @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 REQUEST_HANDLER_INVOKER_HH_ +#define REQUEST_HANDLER_INVOKER_HH_ + +#include "include/param_checker.hh" +#include "include/event_signal_sender.hh" + +namespace rsc_handler { + +class RequestHandlerInvoker { + public: + + RequestHandlerInvoker(ParamChecker option, EventSignalSender signal); + + bool Validate(); + bool Execute(); + + private: + ParamChecker option_; + EventSignalSender signal_; +}; + +} // rsc_handler + +#endif // REQUEST_HANDLER_INVOKER_HH_ diff --git a/src/rsc-copy/include/request_type.hh b/src/rsc-copy/include/request_type.hh new file mode 100644 index 0000000..dbd5022 --- /dev/null +++ b/src/rsc-copy/include/request_type.hh @@ -0,0 +1,31 @@ +/* + * 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. + */ + +#ifndef REQUEST_TYPE_HH_ +#define REQUEST_TYPE_HH_ + +namespace rsc_handler { + +enum ReqType { + REQ_TYPE_NEW = 0, + REQ_TYPE_REMOVE = 1, + REQ_TYPE_UNINSTALL, + REQ_TYPE_UNKNOWN +}; + +} // namespace rsc_handler + +#endif // REQUEST_TYPE_HH_ diff --git a/src/rsc-copy/include/rsc_handler.hh b/src/rsc-copy/include/rsc_handler.hh new file mode 100644 index 0000000..9eeb314 --- /dev/null +++ b/src/rsc-copy/include/rsc_handler.hh @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 RSC_HANDLER_HH_ +#define RSC_HANDLER_HH_ + +#include + +#include "include/request_handler_invoker.hh" + +namespace rsc_handler { + +class RscHandler { + public: + RscHandler() {}; + //~RscHandler(); + bool Init(int argc, char* argv[]); + bool Run(); + + private: + std::unique_ptr handler_; +}; + +} // rsc_handler + +#endif // RSC_HANDLER_HH_ diff --git a/src/rsc-copy/include/rsc_path_info.hh b/src/rsc-copy/include/rsc_path_info.hh new file mode 100644 index 0000000..089bb84 --- /dev/null +++ b/src/rsc-copy/include/rsc_path_info.hh @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 RSC_PATH_INFO_HH_ +#define RSC_PATH_INFO_HH_ + +#include + +namespace rsc_handler { + +class RscPathInfo { + public: + RscPathInfo(std::string src, std::string dst); + + const std::string& GetSrcPath() const; + const std::string& GetDstPath() const; + + private: + std::string src_; + std::string dst_; +}; + +} // rsc_handler + +#endif // RSC_PATH_INFO_HH_ diff --git a/src/rsc-copy/include/uninstall_request_handler.hh b/src/rsc-copy/include/uninstall_request_handler.hh new file mode 100644 index 0000000..d0dd127 --- /dev/null +++ b/src/rsc-copy/include/uninstall_request_handler.hh @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 UNINSTALL_REQUEST_HANDLER_HH_ +#define UNINSTALL_REQUEST_HANDLER_HH_ + +#include +#include + +#include "include/abstract_request_handler.hh" +#include "include/error_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +class UninstallRequestHandler : public AbstractRequestHandler { + public: + ErrorType Execute() override; +}; + +} // rsc_handler + +#endif // UNINSTALL_REQUEST_HANDLER_HH_ diff --git a/src/rsc-copy/src/abstract_request_handler.cc b/src/rsc-copy/src/abstract_request_handler.cc new file mode 100644 index 0000000..6b4fe48 --- /dev/null +++ b/src/rsc-copy/src/abstract_request_handler.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/abstract_request_handler.hh" + +#include + +#include "include/request_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +std::string AbstractRequestHandler::GetRootPath() { + std::cout << "AbstractRequestHandler::GetRootPath" << std::endl; + + std::string root_path("to_be_added_with_tzplatform/"); + root_path += pkgid_; + + return root_path; +} + + +} // namesapce rsc_handler diff --git a/src/rsc-copy/src/condition_validator.cc b/src/rsc-copy/src/condition_validator.cc new file mode 100644 index 0000000..82ac9cd --- /dev/null +++ b/src/rsc-copy/src/condition_validator.cc @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/condition_validator.hh" + +#include + +#include "include/request_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +ConditionValidator::ConditionValidator(std::list list) : + path_info_list_(list) {} + +bool ConditionValidator::ValidateCondition() { + std::cout << "ConditionValidator::ValidateCondition" << std::endl; + + return true; +} + +} // namespace rsc_handler diff --git a/src/rsc-copy/src/copy_request_handler.cc b/src/rsc-copy/src/copy_request_handler.cc new file mode 100644 index 0000000..1d649db --- /dev/null +++ b/src/rsc-copy/src/copy_request_handler.cc @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/copy_request_handler.hh" + +#include + +#include "include/error_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +ErrorType CopyRequestHandler::Execute() { + std::cout << "CopyRequestHandler::Execute" << std::endl; + + return ErrorType::ERROR_NONE; +} + +} // namespace rsc_handler diff --git a/src/rsc-copy/src/event_signal_sender.cc b/src/rsc-copy/src/event_signal_sender.cc new file mode 100644 index 0000000..f4abe30 --- /dev/null +++ b/src/rsc-copy/src/event_signal_sender.cc @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/event_signal_sender.hh" + +#include +#include + +#include "include/request_type.hh" + +namespace rsc_handler { + +EventSignalSender::EventSignalSender(std::string pkgid, ReqType req_type) : + pkgid_(pkgid), req_type_(req_type) {} + +bool EventSignalSender::SendStart() { + std::cout << "EventSignalSender::SendStart" << std::endl; + + return true; +} + +bool SendOK() { + std::cout << "EventSignalSender::SendOK" << std::endl; + + return true; +} + +bool SendFail() { + std::cout << "EventSignalSender::SendFail" << std::endl; + + return true; +} + +} // namespace rsc_handler diff --git a/src/rsc-copy/src/logging.cc b/src/rsc-copy/src/logging.cc new file mode 100644 index 0000000..5e2a5d6 --- /dev/null +++ b/src/rsc-copy/src/logging.cc @@ -0,0 +1,24 @@ +// Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include "logging.hh" + +namespace utils { + +log_priority LogLevelToPriority(LogLevel level) { + switch (level) { + case LogLevel::LOG_ERROR: + return log_priority::DLOG_ERROR; + case LogLevel::LOG_WARNING: + return log_priority::DLOG_WARN; + case LogLevel::LOG_INFO: + return log_priority::DLOG_INFO; + case LogLevel::LOG_DEBUG: + return log_priority::DLOG_DEBUG; + default: + return log_priority::DLOG_UNKNOWN; + } +} + +} // namespace utils diff --git a/src/rsc-copy/src/param_checker.cc b/src/rsc-copy/src/param_checker.cc new file mode 100644 index 0000000..caa109b --- /dev/null +++ b/src/rsc-copy/src/param_checker.cc @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/param_checker.hh" + +#include + +#include "include/request_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +ParamChecker::ParamChecker(int argc, char* argv[]) { + std::cout << "ParamChecker::ParamChecker" << std::endl; +} + +std::string ParamChecker::GetPkgID() const { + std::cout << "ParamChecker::GetPkgID" << std::endl; + + return "test_text"; +} + +ReqType ParamChecker::GetRequestType() { + std::cout << "ParamChecker::GetRequestType" << std::endl; + + return ReqType::REQ_TYPE_UNKNOWN; +} + +const std::list& ParamChecker::GetPathList() const { + std::cout << "ParamChecker::GetPathList()" << std::endl; + + return path_info_list_; +} + +bool ParamChecker::Validate() { + std::cout << "ParamChecker::Validate" << std::endl; + + return true; +} + +} // namespace rsc_handler diff --git a/src/rsc-copy/src/remove_request_handler.cc b/src/rsc-copy/src/remove_request_handler.cc new file mode 100644 index 0000000..eeb0088 --- /dev/null +++ b/src/rsc-copy/src/remove_request_handler.cc @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/remove_request_handler.hh" + +#include + +#include "include/error_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +ErrorType RemoveRequestHandler::Execute() { + std::cout << "RemoveRequestHandler::Execute" << std::endl; + + return ErrorType::ERROR_NONE; +} + +} // namespace rsc_handler diff --git a/src/rsc-copy/src/request_handler_invoker.cc b/src/rsc-copy/src/request_handler_invoker.cc new file mode 100644 index 0000000..5335434 --- /dev/null +++ b/src/rsc-copy/src/request_handler_invoker.cc @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/request_handler_invoker.hh" + +#include + +#include "include/event_signal_sender.hh" +#include "include/param_checker.hh" +#include "include/request_type.hh" + +namespace rsc_handler { + +RequestHandlerInvoker::RequestHandlerInvoker( + ParamChecker option, EventSignalSender signal) : + option_(option), signal_(signal) {} + +bool RequestHandlerInvoker::Validate() { + std::cout << "RequestHandlerInvoker::Validate" << std::endl; + + return true; +} + +bool RequestHandlerInvoker::Execute() { + std::cout << "RequestHandlerInvoker::Execute" << std::endl; + + return true; +} + +} // namespace rsc_handler diff --git a/src/rsc-copy/src/rsc_copy_main.cc b/src/rsc-copy/src/rsc_copy_main.cc new file mode 100644 index 0000000..445baf3 --- /dev/null +++ b/src/rsc-copy/src/rsc_copy_main.cc @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#include + +#include "include/rsc_handler.hh" +#include "include/logging.hh" + +int main(int argc, char *argv[]) { + try { + rsc_handler::RscHandler handler; + if (!handler.Init(argc, argv)) { + LOG(ERROR) << "Failed to initliaze handler"; + return -1; + } + + if (!handler.Run()) { + LOG(ERROR) << "Failed to handle request"; + return -1; + } + } catch (...) { + LOG(ERROR) << "Exception occured"; + return -1; + } + + return 0; +} diff --git a/src/rsc-copy/src/rsc_handler.cc b/src/rsc-copy/src/rsc_handler.cc new file mode 100644 index 0000000..f7c8ecb --- /dev/null +++ b/src/rsc-copy/src/rsc_handler.cc @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/rsc_handler.hh" + +#include + +#include "include/event_signal_sender.hh" +#include "include/param_checker.hh" +#include "include/request_handler_invoker.hh" + +namespace rsc_handler { + +bool RscHandler::Init(int argc, char* argv[]) { + std::cout << "RscHandler::Init" << std::endl; + + rsc_handler::ParamChecker option(argc, argv); + if (!option.Validate()) { + // TODO(jungh.yeon) : error logs + return false; + } + + rsc_handler::EventSignalSender signal( + option.GetPkgID(), option.GetRequestType()); + + rsc_handler::RequestHandlerInvoker handler(option, signal); + if (!handler.Validate()) { + // TODO(jungh.yeon) : error logs + return false; + } + + return true; +} + +bool RscHandler::Run() { + std::cout << "RscHandler::Run" << std::endl; + + return true; +} + +} // namespace rsc_handler diff --git a/src/rsc-copy/src/rsc_path_info.cc b/src/rsc-copy/src/rsc_path_info.cc new file mode 100644 index 0000000..8e4e37f --- /dev/null +++ b/src/rsc-copy/src/rsc_path_info.cc @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/rsc_path_info.hh" + +#include +#include + +namespace rsc_handler { + +RscPathInfo::RscPathInfo(std::string src, std::string dst) : + src_(src), dst_(dst) {} + +const std::string& RscPathInfo::GetSrcPath() const { + return src_; +} + +const std::string& RscPathInfo::GetDstPath() const { + return dst_; +} + +} // namespace rsc_handler diff --git a/src/rsc-copy/src/uninstall_request_handler.cc b/src/rsc-copy/src/uninstall_request_handler.cc new file mode 100644 index 0000000..1d84396 --- /dev/null +++ b/src/rsc-copy/src/uninstall_request_handler.cc @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 "include/uninstall_request_handler.hh" + +#include + +#include "include/error_type.hh" +#include "include/rsc_path_info.hh" + +namespace rsc_handler { + +ErrorType UninstallRequestHandler::Execute() { + std::cout << "UninstallRequestHandler::Execute" << std::endl; + + return ErrorType::ERROR_NONE; +} + + +} // namespace rsc_handler