From 221e10fc8c441adaabe9a15b1becf5a9b1d1b865 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Thu, 30 Dec 2021 17:50:37 +0900 Subject: [PATCH] Add aulctl tool The aulctl is Application boot sequence management tool. command list: - list-apps [|uid]: Print list of boot sequence apps. - is-active [appid]: Print whether the app is activated.([active|inactive]) - status [|appid]: Print status of the boot sequence app. - list-dependencies [|uid]: Print dependency grach of boot sequence apps. - reload [|uid]: Reload the boot squence app's information. - start [appid]: Start the app according to the dependencies. - stop [appid]: Stop the app. Change-Id: I88325b7c33a216bd2853ebf1afafdd8cdb5e4b00 Signed-off-by: Changgyu Choi --- CMakeLists.txt | 4 +- aul/boot_sequence/app_info.cc | 245 +++++++++++++++++++++ aul/boot_sequence/app_info.hh | 125 +++++++++++ aul/boot_sequence/boot_sequence_manager.cc | 117 ++++++++++ aul/boot_sequence/boot_sequence_manager.hh | 64 ++++++ include/aul.h | 4 +- include/aul_cmd.h | 4 +- include/aul_key.h | 22 ++ packaging/aul.spec | 1 + server/api/aul_boot_sequence.cc | 2 +- server/api/aul_boot_sequence.h | 3 +- src/aul_cmd.c | 3 + tool/aulctl/CMakeLists.txt | 7 +- tool/aulctl/aulctl.cc | 95 ++------ tool/aulctl/operation/help_operation.cc | 55 +++++ tool/aulctl/operation/help_operation.hh | 28 +++ tool/aulctl/operation/is_active_operation.cc | 50 +++++ tool/aulctl/operation/is_active_operation.hh | 33 +++ tool/aulctl/operation/list_apps_operation.cc | 45 ++++ tool/aulctl/operation/list_apps_operation.hh | 33 +++ .../operation/list_dependencies_operation.cc | 84 +++++++ .../operation/list_dependencies_operation.hh | 33 +++ tool/aulctl/operation/operation.hh | 30 +++ tool/aulctl/operation/operation_factory.cc | 97 ++++++++ tool/aulctl/operation/operation_factory.hh | 32 +++ tool/aulctl/operation/reload_operation.cc | 36 +++ tool/aulctl/operation/reload_operation.hh | 33 +++ tool/aulctl/operation/start_operation.cc | 41 ++++ tool/aulctl/operation/start_operation.hh | 34 +++ tool/aulctl/operation/status_all_operation.cc | 115 ++++++++++ tool/aulctl/operation/status_all_operation.hh | 28 +++ tool/aulctl/operation/status_once_operation.cc | 120 ++++++++++ tool/aulctl/operation/status_once_operation.hh | 34 +++ tool/aulctl/operation/stop_operation.cc | 57 +++++ tool/aulctl/operation/stop_operation.hh | 34 +++ 35 files changed, 1658 insertions(+), 90 deletions(-) create mode 100644 aul/boot_sequence/app_info.cc create mode 100644 aul/boot_sequence/app_info.hh create mode 100644 aul/boot_sequence/boot_sequence_manager.cc create mode 100644 aul/boot_sequence/boot_sequence_manager.hh create mode 100644 tool/aulctl/operation/help_operation.cc create mode 100644 tool/aulctl/operation/help_operation.hh create mode 100644 tool/aulctl/operation/is_active_operation.cc create mode 100644 tool/aulctl/operation/is_active_operation.hh create mode 100644 tool/aulctl/operation/list_apps_operation.cc create mode 100644 tool/aulctl/operation/list_apps_operation.hh create mode 100644 tool/aulctl/operation/list_dependencies_operation.cc create mode 100644 tool/aulctl/operation/list_dependencies_operation.hh create mode 100644 tool/aulctl/operation/operation.hh create mode 100644 tool/aulctl/operation/operation_factory.cc create mode 100644 tool/aulctl/operation/operation_factory.hh create mode 100644 tool/aulctl/operation/reload_operation.cc create mode 100644 tool/aulctl/operation/reload_operation.hh create mode 100644 tool/aulctl/operation/start_operation.cc create mode 100644 tool/aulctl/operation/start_operation.hh create mode 100644 tool/aulctl/operation/status_all_operation.cc create mode 100644 tool/aulctl/operation/status_all_operation.hh create mode 100644 tool/aulctl/operation/status_once_operation.cc create mode 100644 tool/aulctl/operation/status_once_operation.hh create mode 100644 tool/aulctl/operation/stop_operation.cc create mode 100644 tool/aulctl/operation/stop_operation.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index b513dd4..4a977fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-zdefs -fvisibility=hidden -g -Wall -Wer SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") SET(CMAKE_C_FLAGS_RELEASE "-O2") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} -std=c++14") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} -std=c++17") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") SET(CMAKE_CXX_FLAGS_RELEASE "-O2") @@ -67,6 +67,7 @@ AUX_SOURCE_DIRECTORY(aul/app_info AUL_APP_INFO_SRCS) AUX_SOURCE_DIRECTORY(aul/common AUL_COMMON_SRCS) AUX_SOURCE_DIRECTORY(aul/component AUL_COMPONENT_SRCS) AUX_SOURCE_DIRECTORY(aul/socket AUL_SOCKET_SRCS) +AUX_SOURCE_DIRECTORY(aul/boot_sequence AUL_BOOT_SEQUENCE_SRCS) ADD_LIBRARY(${TARGET_AUL} SHARED ${SRCS} @@ -78,6 +79,7 @@ ADD_LIBRARY(${TARGET_AUL} SHARED ${AUL_COMMON_SRCS} ${AUL_COMPONENT_SRCS} ${AUL_SOCKET_SRCS} + ${AUL_BOOT_SEQUENCE_SRCS} ) TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL} PUBLIC diff --git a/aul/boot_sequence/app_info.cc b/aul/boot_sequence/app_info.cc new file mode 100644 index 0000000..93483f3 --- /dev/null +++ b/aul/boot_sequence/app_info.cc @@ -0,0 +1,245 @@ +/* + * 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. + */ + +#include "aul/boot_sequence/app_info.hh" + +#include + +#include "include/aul_key.h" +#include "src/aul_util.h" + +namespace aul::internal { +namespace boot_sequence { +namespace { + +constexpr const char METADATA_KEY_ONBOOT_PRIORITY[] = + "http://tizen.org/metadata/on-boot/priority"; +constexpr const int MIN_PRIORITY = 1; +constexpr const int MAX_PRIORITY = 99; +constexpr const char K_BG_LAUNCH[] = "__K_BG_LAUNCH"; +constexpr const unsigned int DEFAULT_TIMEOUT = 5000; + +} // namespace + +AppInfo::Builder& AppInfo::Builder::SetAppId(const tizen_base::Bundle& args) { + appid_ = args.GetString(AUL_K_APPID); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetUid(const tizen_base::Bundle& args) { + uid_ = static_cast(std::stoi(args.GetString(AUL_K_TARGET_UID))); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetPriority( + const tizen_base::Bundle& args) { + priority_ = std::stoi(args.GetString(AUL_K_BOOT_SEQUENCE_PRIORITY)); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetAfter(const tizen_base::Bundle& args) { + auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_AFTER); + after_.insert(apps.begin(), apps.end()); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetBefore(const tizen_base::Bundle& args) { + auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_BEFORE); + before_.insert(apps.begin(), apps.end()); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetRequires( + const tizen_base::Bundle& args) { + auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_REQUIRES); + requires_.insert(apps.begin(), apps.end()); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetConflicts( + const tizen_base::Bundle& args) { + auto apps = args.GetStringArray(AUL_K_BOOT_SEQUENCE_CONFLICTS); + conflicts_.insert(apps.begin(), apps.end()); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetArgs( + const tizen_base::Bundle& args) { + auto arg_json = args.GetString(AUL_K_ARGS); + bundle* b = nullptr; + if (bundle_from_json(arg_json.c_str(), &b) != BUNDLE_ERROR_NONE) + _E("bundle_from_json() is failed"); + else + args_ = tizen_base::Bundle(b, false, true); + + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetBackgroundLaunch( + const tizen_base::Bundle& args) { + background_launch_ = (args.GetString(AUL_K_ALLOWED_BG) == "true"); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetWaitUntilReady( + const tizen_base::Bundle& args) { + wait_until_ready_ = + (args.GetString(AUL_K_BOOT_SEQUENCE_READY_WAIT) == "true"); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetTimeout( + const tizen_base::Bundle& args) { + auto timeout_str = args.GetString(AUL_K_TIMEOUT); + if (isdigit(timeout_str[0])) + timeout_ = static_cast(std::stoi(timeout_str)); + else + timeout_ = DEFAULT_TIMEOUT; + + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetActiveState( + const tizen_base::Bundle& args) { + active_state_ = args.GetString(AUL_K_STATUS); + return *this; +} + +AppInfo::Builder& AppInfo::Builder::SetSubState( + const tizen_base::Bundle& args) { + sub_state_ = args.GetString(AUL_K_SUB_STATUS); + return *this; +} + +AppInfo* AppInfo::Builder::Build() const { + return new (std::nothrow) AppInfo( + std::move(appid_), + uid_, + priority_, + std::move(after_), + std::move(before_), + std::move(requires_), + std::move(conflicts_), + std::move(args_), + std::move(active_state_), + std::move(sub_state_), + background_launch_, + wait_until_ready_, + timeout_); +} + +AppInfo::AppInfo(std::string appid, uid_t uid, int priority, + std::set after, std::set before, + std::set requires, std::set conflicts, + tizen_base::Bundle args, + std::string active_state, std::string sub_state, + bool background_launch, bool wait_until_ready, unsigned int timeout) + : appid_(std::move(appid)), + uid_(uid), + priority_(priority), + after_(std::move(after)), + before_(std::move(before)), + requires_(std::move(requires)), + conflicts_(std::move(conflicts)), + args_(std::move(args)), + active_state_(std::move(active_state)), + background_launch_(background_launch), + wait_until_ready_(wait_until_ready), + timeout_(timeout) { + if (background_launch_) { + args_.Delete(K_BG_LAUNCH); + args_.Add(K_BG_LAUNCH, "enable"); + } +} + +const std::string& AppInfo::GetAppId() const { + return appid_; +} + +uid_t AppInfo::GetUid() const { + return uid_; +} + +int AppInfo::GetPriority() const { + return priority_; +} + +// After +bool AppInfo::AfterContains(const std::string& appid) { + return after_.find(appid) != after_.end(); +} + +const std::set& AppInfo::AfterGet() const { + return after_; +} + +// Before +bool AppInfo::BeforeContains(const std::string& appid) { + return before_.find(appid) != before_.end(); +} + +const std::set& AppInfo::BeforeGet() const { + return before_; +} + +// Requires +bool AppInfo::RequiresContains(const std::string& appid) { + return requires_.find(appid) != requires_.end(); +} + +const std::set& AppInfo::RequiresGet() const { + return requires_; +} + +// Conflicts +bool AppInfo::ConflictsContains(const std::string& appid) { + return conflicts_.find(appid) != conflicts_.end(); +} + +const std::set& AppInfo::ConflictsGet() const { + return conflicts_; +} + +const tizen_base::Bundle& AppInfo::GetArgs() const { + return args_; +} + +bool AppInfo::IsBackgroundLaunch() const { + return background_launch_; +} + +bool AppInfo::WaitUntilReady() const { + return wait_until_ready_; +} + +unsigned int AppInfo::GetTimeout() const { + return timeout_; +} + +const std::string& AppInfo::GetActiveState() const { + return active_state_; +} + +const std::string& AppInfo::GetSubState() const { + return sub_state_; +} + +const std::string& AppInfo::GetStatusMessage() const { + return status_msg_; +} + +} // namespace boot_sequence +} // namespace aul::internal diff --git a/aul/boot_sequence/app_info.hh b/aul/boot_sequence/app_info.hh new file mode 100644 index 0000000..11b1925 --- /dev/null +++ b/aul/boot_sequence/app_info.hh @@ -0,0 +1,125 @@ +/* + * 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. + */ + +/* + * This header is only appfw internal api. + * It is cpp header. + */ + +#ifndef AUL_INTERNAL_BOOT_SEQUENCE_APP_INFO_HH_ +#define AUL_INTERNAL_BOOT_SEQUENCE_APP_INFO_HH_ + +#include + +#include +#include +#include +#include +#include + +namespace aul::internal { + +namespace boot_sequence { + +class AppInfo { + public: + class Builder { + public: + Builder& SetAppId(const tizen_base::Bundle& args); + Builder& SetUid(const tizen_base::Bundle& args); + Builder& SetPriority(const tizen_base::Bundle& args); + Builder& SetAfter(const tizen_base::Bundle& args); + Builder& SetBefore(const tizen_base::Bundle& args); + Builder& SetRequires(const tizen_base::Bundle& args); + Builder& SetConflicts(const tizen_base::Bundle& args); + Builder& SetArgs(const tizen_base::Bundle& args); + Builder& SetBackgroundLaunch(const tizen_base::Bundle& args); + Builder& SetWaitUntilReady(const tizen_base::Bundle& args); + Builder& SetTimeout(const tizen_base::Bundle& args); + Builder& SetActiveState(const tizen_base::Bundle& args); + Builder& SetSubState(const tizen_base::Bundle& args); + AppInfo* Build() const; + + private: + std::string appid_; + uid_t uid_; + int priority_; + std::set after_; + std::set before_; + std::set requires_; + std::set conflicts_; + tizen_base::Bundle args_; + std::string active_state_; + std::string sub_state_; + bool background_launch_; + bool wait_until_ready_; + unsigned int timeout_; + }; + + AppInfo(std::string appid, uid_t uid, int priority, + std::set after, std::set before, + std::set requires, std::set conflicts, + tizen_base::Bundle args, + std::string active_state, std::string sub_state, + bool background_launch, bool wait_until_ready, unsigned int timeout); + + const std::string& GetAppId() const; + uid_t GetUid() const; + int GetPriority() const; + + bool AfterContains(const std::string& appid); + const std::set& AfterGet() const; + + bool BeforeContains(const std::string& appid); + const std::set& BeforeGet() const; + + bool RequiresContains(const std::string& appid); + const std::set& RequiresGet() const; + + bool ConflictsContains(const std::string& appid); + const std::set& ConflictsGet() const; + + const tizen_base::Bundle& GetArgs() const; + bool IsBackgroundLaunch() const; + bool WaitUntilReady() const; + unsigned int GetTimeout() const; + const std::string& GetActiveState() const; + const std::string& GetSubState() const; + const std::string& GetStatusMessage() const; + + private: + std::string appid_; + uid_t uid_; + int priority_; + std::set after_; + std::set before_; + std::set requires_; + std::set conflicts_; + std::vector required_by_; + tizen_base::Bundle args_; + std::string active_state_; + bool background_launch_; + bool wait_until_ready_; + unsigned int timeout_; + std::string sub_state_ = "dead"; + std::string status_msg_; +}; + +} // namespace boot_sequence + +} // namespace aul::internal + +#endif // AUL_INTERNAL_BOOT_SEQUENCE_APP_INFO_HH_ diff --git a/aul/boot_sequence/boot_sequence_manager.cc b/aul/boot_sequence/boot_sequence_manager.cc new file mode 100644 index 0000000..7c43917 --- /dev/null +++ b/aul/boot_sequence/boot_sequence_manager.cc @@ -0,0 +1,117 @@ +/* + * 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 "aul/boot_sequence/boot_sequence_manager.hh" + +#include + +#include + +#include "common/file_descriptor.hh" +#include "include/aul_sock.h" +#include "src/app_request.h" +#include "src/aul_util.h" + +namespace aul::internal { +namespace boot_sequence { + +AppInfoPtr BootSequenceManager::CreateAppInfoFromBundle(tizen_base::Bundle b) { + /* TODO(changyu.choi): Implement decoding appinfo from bundle. */ + auto builder = AppInfo::Builder() + .SetAppId(b) + .SetUid(b) + .SetPriority(b) + .SetBefore(b) + .SetAfter(b) + .SetRequires(b) + .SetConflicts(b) + .SetArgs(b) + .SetTimeout(b) + .SetActiveState(b) + .SetSubState(b); + + return std::shared_ptr(builder.Build()); +} + +void BootSequenceManager::InsertAppInfoCb(app_pkt_t* pkt, void* data) { + if (pkt == nullptr) { + _E("Invalid parameter"); + return; + } + + auto& appinfo_list = *static_cast*>(data); + if (pkt->cmd == APP_GET_INFO_ERROR) { + _E("Failed to get running component context"); + return; + } + + bundle* kb = nullptr; + if (pkt->opt & AUL_SOCK_BUNDLE) + kb = bundle_decode(pkt->data, pkt->len); + + if (kb == nullptr) + return; + + auto app = GetInst().CreateAppInfoFromBundle( + tizen_base::Bundle(kb, false, true)); + if (app == nullptr) { + _E("Failed to create appinfo"); + return; + } + + appinfo_list.push_back(std::move(app)); +} + +BootSequenceManager& BootSequenceManager::GetInst() { + static BootSequenceManager inst; + return inst; +} + +int BootSequenceManager::Reload(uid_t uid) const { + std::unique_lock lock(mutex_); + return AppRequest(BOOT_SEQUENCE_RELOAD, uid).SendSimply(); +} + +int BootSequenceManager::StartApp(const std::string& appid) const { + std::unique_lock lock(mutex_); + tizen_base::Bundle b({{AUL_K_APPID, appid}}); + return AppRequest(BOOT_SEQUENCE_START_APP, getuid()) + .With(std::move(b)) + .SendSimply(); +} + +std::vector BootSequenceManager::GetAppInfoList(uid_t uid) const { + std::unique_lock lock(mutex_); + int fd = AppRequest(BOOT_SEQUENCE_GET_APPINFO_LIST, uid) + .SendSimply(AUL_SOCK_ASYNC); + + if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) { + _E("Failed to send request. error(%d)", fd); + return {}; + } + + std::vector appinfo_list; + int ret = aul_sock_recv_pkt_with_cb(fd, InsertAppInfoCb, &appinfo_list); + if (ret < 0) { + _E("Failed to receive reply packet. error(%d)", ret); + return {}; + } + + return appinfo_list; +} + +} // namespace boot_sequence +} // namespace aul::internal diff --git a/aul/boot_sequence/boot_sequence_manager.hh b/aul/boot_sequence/boot_sequence_manager.hh new file mode 100644 index 0000000..1085de9 --- /dev/null +++ b/aul/boot_sequence/boot_sequence_manager.hh @@ -0,0 +1,64 @@ +/* + * 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. + */ + +/* + * This header is only appfw internal api. + * It is cpp header. + */ + +#ifndef AUL_INTERNAL_BOOT_SEQUENCE_BOOT_SEQUENCE_MANAGER_HH_ +#define AUL_INTERNAL_BOOT_SEQUENCE_BOOT_SEQUENCE_MANAGER_HH_ + +#include + +#include +#include +#include +#include + +#include "include/aul_sock.h" +#include "aul/boot_sequence/app_info.hh" + +namespace aul::internal { +namespace boot_sequence { + +using AppInfoPtr = std::shared_ptr; + +class BootSequenceManager { + public: + static BootSequenceManager& GetInst(); + BootSequenceManager(BootSequenceManager&) = delete; + BootSequenceManager& operator=(BootSequenceManager&) = delete; + + int Reload(uid_t uid) const; + int StartApp(const std::string &appid) const; + std::vector GetAppInfoList(uid_t uid) const; + std::string GetLogs() const; + + private: + BootSequenceManager() = default; + ~BootSequenceManager() = default; + + static void InsertAppInfoCb(app_pkt_t* pkt, void* data); + + AppInfoPtr CreateAppInfoFromBundle(tizen_base::Bundle b); + mutable std::mutex mutex_; +}; + +} // namespace boot_sequence +} // namespace aul::internal + +#endif // AUL_INTERNAL_BOOT_SEQUENCE_BOOT_SEQUENCE_MANAGER_HH_ diff --git a/include/aul.h b/include/aul.h index 8eff785..4026fe6 100644 --- a/include/aul.h +++ b/include/aul.h @@ -3024,7 +3024,5 @@ int aul_set_auto_restart(bundle *b); int aul_unset_auto_restart(); #ifdef __cplusplus - } + } #endif - - diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 1ce5923..a81d045 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -215,7 +215,9 @@ enum app_cmd { APP_CONNECT = 171, APP_SET_AUTO_RESTART = 172, - + BOOT_SEQUENCE_START_APP = 173, + BOOT_SEQUENCE_GET_APPINFO_LIST = 174, + BOOT_SEQUENCE_RELOAD = 175, APP_CMD_MAX }; diff --git a/include/aul_key.h b/include/aul_key.h index 771901b..0ab3311 100644 --- a/include/aul_key.h +++ b/include/aul_key.h @@ -849,3 +849,25 @@ * @since_tizen 7.0 */ #define AUL_K_RESTART_EXTRA "__AUL_RESTART_EXTRA__" + +#define AUL_K_SUB_STATUS "__AUL_SUB_STATUS__" + +#define AUL_K_BOOT_SEQUENCE_CMD "__AUL_BOOT_SEQUENCE_CMD__" + +#define AUL_K_BOOT_SEQUENCE_LOGS "__AUL_BOOT_SEQUENCE_LOGS__" + +#define AUL_K_BOOT_SEQUENCE_PRIORITY "__AUL_BOOT_SEQUENCE_PRIORITY__" + +#define AUL_K_BOOT_SEQUENCE_AFTER "__AUL_BOOT_SEQUENCE_AFTER__" + +#define AUL_K_BOOT_SEQUENCE_BEFORE "__AUL_BOOT_SEQUENCE_BEFORE__" + +#define AUL_K_BOOT_SEQUENCE_REQUIRES "__AUL_BOOT_SEQUENCE_REQUIRES__" + +#define AUL_K_BOOT_SEQUENCE_CONFLICTS "__AUL_BOOT_SEQUENCE_CONFLICTS__" + +#define AUL_K_ARGS "__AUL_ARGS__" + +#define AUL_K_BOOT_SEQUENCE_READY_WAIT "__AUL_BOOT_SEQUENCE_READY_WAIT__" + +#define AUL_K_TIMEOUT "__AUL_TIMEOUT__" diff --git a/packaging/aul.spec b/packaging/aul.spec index 14e9620..5478172 100644 --- a/packaging/aul.spec +++ b/packaging/aul.spec @@ -222,6 +222,7 @@ chmod +x %{_aulresdir}/tpk/install.sh %manifest %{name}.manifest %attr(0644,root,root) %{_libdir}/libaul.so.* %config %{_sysconfdir}/dbus-1/system.d/aul.conf +%{_bindir}/aulctl %{_bindir}/aul_test %{_bindir}/app_launcher %{_bindir}/appgroup_info diff --git a/server/api/aul_boot_sequence.cc b/server/api/aul_boot_sequence.cc index 67d3d27..4141958 100644 --- a/server/api/aul_boot_sequence.cc +++ b/server/api/aul_boot_sequence.cc @@ -132,7 +132,7 @@ extern "C" API int aul_boot_sequence_foreach_usr(uid_t uid, } for (auto& info : infos) { - if (!callback(info.get(), user_data)) + if (!callback(info.get(), uid, user_data)) break; } diff --git a/server/api/aul_boot_sequence.h b/server/api/aul_boot_sequence.h index cd97b43..5324439 100644 --- a/server/api/aul_boot_sequence.h +++ b/server/api/aul_boot_sequence.h @@ -18,6 +18,7 @@ #define __AUL_BOOT_SEQUENCE_H__ #include +#include #include #include @@ -28,7 +29,7 @@ extern "C" { typedef void *aul_boot_sequence_h; -typedef bool (*aul_boot_sequence_cb)(aul_boot_sequence_h handle, void *user_data); +typedef bool (*aul_boot_sequence_cb)(aul_boot_sequence_h, uid_t, void *); int aul_boot_sequence_foreach_usr(uid_t uid, aul_boot_sequence_cb callback, void *user_data); diff --git a/src/aul_cmd.c b/src/aul_cmd.c index b747792..f244c8e 100644 --- a/src/aul_cmd.c +++ b/src/aul_cmd.c @@ -217,6 +217,9 @@ API const char *aul_cmd_convert_to_string(int cmd) "APP_CONNECT", "APP_SET_AUTO_RESTART", + "BOOT_SEQUENCE_START_APP", + "BOOT_SEQUENCE_GET_APPINFO_LIST", + "BOOT_SEQUENCE_RELOAD", "CUSTOM_COMMAND" }; diff --git a/tool/aulctl/CMakeLists.txt b/tool/aulctl/CMakeLists.txt index 1935e29..cc36a8b 100644 --- a/tool/aulctl/CMakeLists.txt +++ b/tool/aulctl/CMakeLists.txt @@ -1,8 +1,13 @@ SET(TARGET_AULCTL "aulctl") AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AULCTL_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/operation OP_SRCS) + +ADD_EXECUTABLE(${TARGET_AULCTL} + ${AULCTL_SRCS} + ${OP_SRCS} +) -ADD_EXECUTABLE(${TARGET_AULCTL} ${AULCTL_SRCS}) SET_TARGET_PROPERTIES(${TARGET_AULCTL} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE") SET_TARGET_PROPERTIES(${TARGET_AULCTL} PROPERTIES diff --git a/tool/aulctl/aulctl.cc b/tool/aulctl/aulctl.cc index 6a7f2d9..d41b68b 100644 --- a/tool/aulctl/aulctl.cc +++ b/tool/aulctl/aulctl.cc @@ -14,88 +14,19 @@ * limitations under the License. */ -#include -#include -#include - -#include - -namespace { - -using HandleFunc = int (*)(int argc, char** argv); - -void PrintUsage(const char* cmdline) { - printf("%s ...\n", cmdline); - printf(" - command list\n"); - printf(" list-apps\n"); -} - -int HandleListApps(int argc, char** argv) { - printf("[%s]\n", argv[1]); - uid_t uid; - if (argc > 2) - uid = atoi(argv[2]); - else - uid = getuid(); - - int count = 0; - int ret = aul_boot_sequence_foreach_usr(uid, - [](aul_boot_sequence_h handle, void* user_data) -> bool { - int* cnt = static_cast(user_data); - if ((*cnt)++ == 0) - printf("==============================================\n"); - else - printf("----------------------------------------------\n"); - - const char* val; - aul_boot_sequence_get_appid(handle, &val); - printf(" appid: %s\n", val); - aul_boot_sequence_get_after(handle, &val); - printf(" after: %s\n", val); - aul_boot_sequence_get_before(handle, &val); - printf(" before: %s\n", val); - aul_boot_sequence_get_requires(handle, &val); - printf(" requires: %s\n", val); - aul_boot_sequence_get_conflicts(handle, &val); - printf(" conflicts: %s\n", val); - aul_boot_sequence_get_vconf(handle, &val); - printf(" vconf: %s\n", val); - aul_boot_sequence_get_path_exists(handle, &val); - printf(" path-exists: %s\n", val); - aul_boot_sequence_get_args(handle, &val); - printf(" args: %s\n", val); - aul_boot_sequence_get_background_launch(handle, &val); - printf(" background-launch: %s\n", val); - aul_boot_sequence_get_wait_until_ready(handle, &val); - printf(" wait-until-ready: %s\n", val); - aul_boot_sequence_get_timeout(handle, &val); - printf(" timeout: %s\n", val); - return true; - }, &count); - if (count > 0) - printf("==============================================\n"); - - printf("[%s] result: %d\n", argv[1], ret); - return ret; -} - -std::map handlers = { - { "list-apps", HandleListApps }, -}; - -} // namespace - -int main(int argc, char** argv) { - if (argc < 2) { - PrintUsage(argv[0]); - return -1; - } - - auto found = handlers.find(argv[1]); - if (found == handlers.end()) { - PrintUsage(argv[0]); - return -1; +#include +#include + +#include "operation/operation_factory.hh" + +int main(int argc, char* argv[]) { + std::vector args(argv + 1, argv + argc); + aul::OperationFactory factory; + auto op = factory.CreateOperation(args); + if (op->Process() == false) { + std::cerr << "Failed operation." << std::endl; + exit(1); } - return found->second(argc, argv); + return 0; } diff --git a/tool/aulctl/operation/help_operation.cc b/tool/aulctl/operation/help_operation.cc new file mode 100644 index 0000000..c2884d1 --- /dev/null +++ b/tool/aulctl/operation/help_operation.cc @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#include "help_operation.hh" + +#include + +namespace aul { +namespace { + +constexpr const char HowTo[] = +R"( - aulctl - + Application boot sequence management tool + + usage: aulctl [cmd] [|args] + + cmd list: + + - list-apps [|uid] : Print list of boot sequence apps. + + - is-active [appid] : Print whether the app is activated.([active|inactive]) + + - status [|appid] : Print status of the boot sequence app. + + - list-dependencies [|uid]: Print dependency grach of boot sequence apps. + + - reload [|uid] : Reload the boot squence app's information. + + - start [appid] : Start the app according to the dependencies. + + - stop [appid] : Stop the app. +)"; + +} // namespace + +bool HelpOperation::Process() { + std::cout << HowTo << std::endl; + + return true; +} + +} // namespace aul diff --git a/tool/aulctl/operation/help_operation.hh b/tool/aulctl/operation/help_operation.hh new file mode 100644 index 0000000..6f2dd5a --- /dev/null +++ b/tool/aulctl/operation/help_operation.hh @@ -0,0 +1,28 @@ +/* + * 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. + */ + +#include "operation.hh" + +namespace aul { + +class HelpOperation : public Operation { + public: + HelpOperation() = default; + ~HelpOperation() = default; + bool Process() override; +}; + +} // namespace aul diff --git a/tool/aulctl/operation/is_active_operation.cc b/tool/aulctl/operation/is_active_operation.cc new file mode 100644 index 0000000..8efd6d0 --- /dev/null +++ b/tool/aulctl/operation/is_active_operation.cc @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#include "is_active_operation.hh" + +#include +#include +#include + +#include "aul/boot_sequence/boot_sequence_manager.hh" + +namespace aul { + +IsActiveOperation::IsActiveOperation(std::string appid) + : appid_(std::move(appid)) { +} + +bool IsActiveOperation::Process() { + auto& manager = internal::boot_sequence::BootSequenceManager::GetInst(); + auto app_list = manager.GetAppInfoList(getuid()); + if (app_list.empty()) { + std::cerr << "Failed to get boot sequence app list." << std::endl; + return false; + } + + for (auto& app : app_list) { + if (app->GetAppId() == appid_) { + std::cout << app->GetActiveState() << std::endl; + return true; + } + } + + std::cerr << "Not found app info." << std::endl; + return false; +} + +} // namespace aul diff --git a/tool/aulctl/operation/is_active_operation.hh b/tool/aulctl/operation/is_active_operation.hh new file mode 100644 index 0000000..58d5b97 --- /dev/null +++ b/tool/aulctl/operation/is_active_operation.hh @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#include + +#include "operation.hh" + +namespace aul { + +class IsActiveOperation : public Operation { + public: + explicit IsActiveOperation(std::string appid); + ~IsActiveOperation() = default; + bool Process() override; + + private: + std::string appid_; +}; + +} // namespace aul diff --git a/tool/aulctl/operation/list_apps_operation.cc b/tool/aulctl/operation/list_apps_operation.cc new file mode 100644 index 0000000..d8bfdeb --- /dev/null +++ b/tool/aulctl/operation/list_apps_operation.cc @@ -0,0 +1,45 @@ +/* + * 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. + */ + +#include "list_apps_operation.hh" + +#include + +#include + +#include "aul/boot_sequence/boot_sequence_manager.hh" + +namespace aul { + +ListAppsOperation::ListAppsOperation(uid_t uid) : uid_(uid) { +} + +bool ListAppsOperation::Process() { + auto& manager = internal::boot_sequence::BootSequenceManager::GetInst(); + auto app_list = manager.GetAppInfoList(uid_); + if (app_list.empty()) { + std::cerr << "Failed to get boot sequence app list." << std::endl; + return false; + } + + std::cout << uid_ << " user boot sequence app list" << std::endl; + for (auto& app : app_list) + std::cout << app->GetAppId() << std::endl; + + return true; +} + +} // namespace aul diff --git a/tool/aulctl/operation/list_apps_operation.hh b/tool/aulctl/operation/list_apps_operation.hh new file mode 100644 index 0000000..f65eec8 --- /dev/null +++ b/tool/aulctl/operation/list_apps_operation.hh @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#include + +#include "operation.hh" + +namespace aul { + +class ListAppsOperation : public Operation { + public: + explicit ListAppsOperation(uid_t uid); + ~ListAppsOperation() = default; + bool Process() override; + + private: + uid_t uid_; +}; + +} // namespace aul diff --git a/tool/aulctl/operation/list_dependencies_operation.cc b/tool/aulctl/operation/list_dependencies_operation.cc new file mode 100644 index 0000000..6b233ae --- /dev/null +++ b/tool/aulctl/operation/list_dependencies_operation.cc @@ -0,0 +1,84 @@ +/* + * 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. + */ + +#include "list_dependencies_operation.hh" + +#include + +#include +#include +#include +#include +#include + +#include "aul/boot_sequence/boot_sequence_manager.hh" + +namespace aul { + +ListDependenciesOperation::ListDependenciesOperation(uid_t uid) : uid_(uid) { +} + +bool ListDependenciesOperation::Process() { + auto& manager = internal::boot_sequence::BootSequenceManager::GetInst(); + auto app_list = manager.GetAppInfoList(uid_); + if (app_list.empty()) { + std::cerr << "Failed to get boot sequence app list." << std::endl; + return false; + } + + std::cout << uid_ << " user boot sequence app dependencies" << std::endl; + std::map infos; + std::map req_cnt; + for (auto& app : app_list) { + infos[app->GetAppId()] = app; + if (req_cnt.find(app->GetAppId()) == req_cnt.end()) + req_cnt[app->GetAppId()] = 0; + + for (auto &appid : app->AfterGet()) + req_cnt[appid]++; + } + + /* depth, appinfo */ + std::stack> stack; + for (auto& [appid, cnt] : req_cnt) { + if (cnt == 0 && infos.find(appid) != infos.end()) + stack.emplace(0, infos[appid]); + } + + while (!stack.empty()) { + auto [cnt, app] = std::move(stack.top()); + stack.pop(); + + for (int i = 0; i < cnt; ++i) + std::cout << "+"; + + std::cout << app->GetAppId() << std::endl; + for (auto& appid : app->AfterGet()) { + if (--req_cnt[appid] == 0 && infos.find(appid) != infos.end()) { + stack.emplace(cnt + 1, infos[appid]); + } else { + for (int i = 0; i < cnt + 1; ++i) + std::cout << "+"; + + std::cout << appid << std::endl; + } + } + } + + return true; +} + +} // namespace aul diff --git a/tool/aulctl/operation/list_dependencies_operation.hh b/tool/aulctl/operation/list_dependencies_operation.hh new file mode 100644 index 0000000..c0a8196 --- /dev/null +++ b/tool/aulctl/operation/list_dependencies_operation.hh @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#include + +#include "operation.hh" + +namespace aul { + +class ListDependenciesOperation : public Operation { + public: + explicit ListDependenciesOperation(uid_t uid); + ~ListDependenciesOperation() = default; + bool Process() override; + + private: + uid_t uid_; +}; + +} // namespace aul diff --git a/tool/aulctl/operation/operation.hh b/tool/aulctl/operation/operation.hh new file mode 100644 index 0000000..fc1abaa --- /dev/null +++ b/tool/aulctl/operation/operation.hh @@ -0,0 +1,30 @@ +/* + * 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 OPERATION_OPERATION_HH_ +#define OPERATION_OPERATION_HH_ + +namespace aul { + +class Operation { + public: + virtual ~Operation() = default; + virtual bool Process() = 0; +}; + +} // namespace aul + +#endif // OPERATION_OPERATION_HH_ diff --git a/tool/aulctl/operation/operation_factory.cc b/tool/aulctl/operation/operation_factory.cc new file mode 100644 index 0000000..450fd27 --- /dev/null +++ b/tool/aulctl/operation/operation_factory.cc @@ -0,0 +1,97 @@ +/* + * 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. + */ + +#include "operation_factory.hh" + +#include + +#include +#include +#include +#include +#include + +#include "help_operation.hh" +#include "is_active_operation.hh" +#include "list_apps_operation.hh" +#include "list_dependencies_operation.hh" +#include "start_operation.hh" +#include "status_all_operation.hh" +#include "status_once_operation.hh" +#include "stop_operation.hh" +#include "reload_operation.hh" + +namespace aul { + +std::unique_ptr OperationFactory::CreateOperation( + const std::vector& args) const { + try { + if (args.empty()) + return std::make_unique(); + + auto cmd = std::string(args[0]); + if (cmd == "list-apps") { + if (args.size() == 1) + return std::make_unique(getuid()); + + return std::make_unique( + static_cast(std::stoi(args[1]))); + } else if (cmd == "list-dependencies") { + if (args.size() == 1) + return std::make_unique(getuid()); + + return std::make_unique( + static_cast(std::stoi(args[1]))); + } else if (cmd == "is-active") { + if (args.size() == 1) + return std::make_unique(); + + auto appid = args[1]; + return std::make_unique(std::move(appid)); + } else if (cmd == "status") { + if (args.size() == 1) + return std::make_unique(); + + auto appid = args[1]; + return std::make_unique(std::move(appid)); + } else if (cmd == "reload") { + if (args.size() == 1) + return std::make_unique(getuid()); + + return std::make_unique( + static_cast(std::stoi(args[1]))); + } else if (cmd == "start") { + if (args.size() == 1) + return std::make_unique(); + + auto appid = args[1]; + return std::make_unique(std::move(appid)); + } else if (cmd == "stop") { + if (args.size() == 1) + return std::make_unique(); + + auto appid = args[1]; + return std::make_unique(std::move(appid)); + } else { + return std::make_unique(); + } + } catch (const std::invalid_argument& error) { + std::cerr << "Invalid patameter: " << error.what() << std::endl; + return std::make_unique(); + } +} + +} // namespace aul diff --git a/tool/aulctl/operation/operation_factory.hh b/tool/aulctl/operation/operation_factory.hh new file mode 100644 index 0000000..96d5114 --- /dev/null +++ b/tool/aulctl/operation/operation_factory.hh @@ -0,0 +1,32 @@ +/* + * 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. + */ + +#include +#include + +#include "operation.hh" + +namespace aul { + +class OperationFactory { + public: + OperationFactory() = default; + ~OperationFactory() = default; + std::unique_ptr CreateOperation( + const std::vector& args) const; +}; + +} // namespace aul diff --git a/tool/aulctl/operation/reload_operation.cc b/tool/aulctl/operation/reload_operation.cc new file mode 100644 index 0000000..3d0079d --- /dev/null +++ b/tool/aulctl/operation/reload_operation.cc @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#include "reload_operation.hh" + +#include + +#include "include/aul.h" +#include "aul/boot_sequence/boot_sequence_manager.hh" + +namespace aul { + +ReloadOperation::ReloadOperation(uid_t uid) : uid_(uid) { +} + +bool ReloadOperation::Process() { + auto &manager = internal::boot_sequence::BootSequenceManager::GetInst(); + int ret = manager.Reload(uid_); + std::cout << "Reload result: " << ret << std::endl; + return ret == AUL_R_OK; +} + +} // namespace aul diff --git a/tool/aulctl/operation/reload_operation.hh b/tool/aulctl/operation/reload_operation.hh new file mode 100644 index 0000000..1fd4b68 --- /dev/null +++ b/tool/aulctl/operation/reload_operation.hh @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#include + +#include "operation.hh" + +namespace aul { + +class ReloadOperation : public Operation { + public: + explicit ReloadOperation(uid_t uid); + ~ReloadOperation() = default; + bool Process() override; + + private: + uid_t uid_; +}; + +} // namespace aul diff --git a/tool/aulctl/operation/start_operation.cc b/tool/aulctl/operation/start_operation.cc new file mode 100644 index 0000000..e910be7 --- /dev/null +++ b/tool/aulctl/operation/start_operation.cc @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#include "start_operation.hh" + +#include + +#include "include/aul.h" +#include "aul/boot_sequence/boot_sequence_manager.hh" + +namespace aul { + +StartOperation::StartOperation(std::string appid) + : appid_(std::move(appid)) { +} + +bool StartOperation::Process() { + auto& manager = internal::boot_sequence::BootSequenceManager::GetInst(); + int ret = manager.StartApp(appid_); + if (ret != AUL_R_OK) { + std::cerr << "Failed to start app(" << appid_ << ")" << std::endl; + return false; + } + + return true; +} + +} // namespace aul diff --git a/tool/aulctl/operation/start_operation.hh b/tool/aulctl/operation/start_operation.hh new file mode 100644 index 0000000..a801bb2 --- /dev/null +++ b/tool/aulctl/operation/start_operation.hh @@ -0,0 +1,34 @@ + +/* + * 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. + */ + +#include + +#include "operation.hh" + +namespace aul { + +class StartOperation : public Operation { + public: + explicit StartOperation(std::string appid); + ~StartOperation() = default; + bool Process() override; + + private: + std::string appid_; +}; + +} // namespace aul diff --git a/tool/aulctl/operation/status_all_operation.cc b/tool/aulctl/operation/status_all_operation.cc new file mode 100644 index 0000000..c5864eb --- /dev/null +++ b/tool/aulctl/operation/status_all_operation.cc @@ -0,0 +1,115 @@ +/* + * 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. + */ + +#include "status_all_operation.hh" + +#include +#include + +#include +#include +#include + +#include "aul/api/aul_app_context.h" +#include "aul/boot_sequence/boot_sequence_manager.hh" + +namespace aul { + +bool StatusAllOperation::Process() { + auto& manager = internal::boot_sequence::BootSequenceManager::GetInst(); + auto app_list = manager.GetAppInfoList(getuid()); + if (app_list.empty()) { + std::cerr << "Failed to get boot sequence app list." << std::endl; + return false; + } + + for (const auto& app : app_list) { + std::cout << "===========================================" << std::endl; + std::cout << "appid: " << app->GetAppId() << std::endl; + + std::cout << "status: " << app->GetActiveState() << std::endl; + + aul_app_context_h context; + int ret = aul_app_context_create(app->GetAppId().c_str(), &context); + if (ret == 0) { + const char* val = nullptr; + aul_app_context_get_app_path(context, const_cast(&val)); + std::cout << "app path: " << val << std::endl; + std::free(const_cast(val)); + pid_t pid = -1; + aul_app_context_get_pid(context, &pid); + std::cout << "pid: " << pid << std::endl; + aul_app_context_destroy(context); + } + + std::cout << "requires: "; + for (auto& appid : app->RequiresGet()) + std::cout << appid << " "; + + std::cout << std::endl; + + std::cout << "before: "; + for (auto& appid : app->BeforeGet()) + std::cout << appid << " "; + + std::cout << std::endl; + + std::cout << "after: "; + for (auto& appid : app->AfterGet()) + std::cout << appid << " "; + + std::cout << std::endl; + + std::cout << "conflict: "; + for (auto& appid : app->ConflictsGet()) + std::cout << appid << " "; + + std::cout << std::endl; + + std::cout << "args: {\n"; + auto& b = app->GetArgs(); + bundle_foreach( + b.GetHandle(), + [](const char* key, const int type, + const bundle_keyval_t* kv, void* data) { + auto& kb = *static_cast(data); + std::cout << key << ": "; + switch (type) { + case BUNDLE_TYPE_STR: + std::cout << kb.GetString(key) << std::endl; + break; + case BUNDLE_TYPE_STR_ARRAY: + std::cout << "[ "; + for (auto& val : kb.GetStringArray(key)) + std::cout << val << ", "; + + std::cout << "]" << std::endl; + break; + default: + break; + } + }, + const_cast(&b)); + std::cout << "}" << std::endl; + + std::cout << "bg-launch: " << app->IsBackgroundLaunch() << std::endl; + std::cout << "===========================================" << std::endl; + } + + return true; +} + +} // namespace aul diff --git a/tool/aulctl/operation/status_all_operation.hh b/tool/aulctl/operation/status_all_operation.hh new file mode 100644 index 0000000..0f081a3 --- /dev/null +++ b/tool/aulctl/operation/status_all_operation.hh @@ -0,0 +1,28 @@ +/* + * 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. + */ + +#include "operation.hh" + +namespace aul { + +class StatusAllOperation : public Operation { + public: + StatusAllOperation() = default; + ~StatusAllOperation() = default; + bool Process() override; +}; + +} // namespace aul diff --git a/tool/aulctl/operation/status_once_operation.cc b/tool/aulctl/operation/status_once_operation.cc new file mode 100644 index 0000000..1a8c96e --- /dev/null +++ b/tool/aulctl/operation/status_once_operation.cc @@ -0,0 +1,120 @@ +/* + * 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. + */ + +#include "status_once_operation.hh" + +#include +#include +#include + +#include "aul/boot_sequence/boot_sequence_manager.hh" +#include "aul_app_context.h" +#include "aul_boot_sequence.h" + +namespace aul { + +StatusOnceOperation::StatusOnceOperation(std::string appid) + : appid_(std::move(appid)) { +} + +bool StatusOnceOperation::Process() { + auto& manager = internal::boot_sequence::BootSequenceManager::GetInst(); + auto app_list = manager.GetAppInfoList(getuid()); + if (app_list.empty()) { + std::cerr << "Failed to get boot sequence app list." << std::endl; + return false; + } + + for (const auto& app : app_list) { + if (app->GetAppId() != appid_) + continue; + + std::cout << "appid: " << app->GetAppId() << std::endl; + + std::cout << "status: " << app->GetActiveState() << std::endl; + + aul_app_context_h context; + int ret = aul_app_context_create(app->GetAppId().c_str(), &context); + if (ret == 0) { + const char* val = nullptr; + aul_app_context_get_app_path(context, const_cast(&val)); + std::cout << "app path: " << val << std::endl; + std::free(const_cast(val)); + pid_t pid = -1; + aul_app_context_get_pid(context, &pid); + std::cout << "pid: " << pid << std::endl; + aul_app_context_destroy(context); + } + + std::cout << "requires: "; + for (auto& appid : app->RequiresGet()) + std::cout << appid << " "; + + std::cout << std::endl; + + std::cout << "before: "; + for (auto& appid : app->BeforeGet()) + std::cout << appid << " "; + + std::cout << std::endl; + + std::cout << "after: "; + for (auto& appid : app->AfterGet()) + std::cout << appid << " "; + + std::cout << std::endl; + + std::cout << "conflict: "; + for (auto& appid : app->ConflictsGet()) + std::cout << appid << " "; + + std::cout << std::endl; + + std::cout << "args: {\n"; + auto& b = app->GetArgs(); + bundle_foreach( + b.GetHandle(), + [](const char* key, const int type, + const bundle_keyval_t* kv, void* data) { + auto& kb = *static_cast(data); + std::cout << key << ": "; + switch (type) { + case BUNDLE_TYPE_STR: + std::cout << kb.GetString(key) << std::endl; + break; + case BUNDLE_TYPE_STR_ARRAY: + std::cout << "[ "; + for (auto& val : kb.GetStringArray(key)) + std::cout << val << ", "; + + std::cout << "]" << std::endl; + break; + default: + break; + } + }, + const_cast(&b)); + std::cout << "}" << std::endl; + + std::cout << "bg-launch: " << app->IsBackgroundLaunch() << std::endl; + return true; + } + + std::cerr << "Not found app info." << std::endl; + return false; +} + +} // namespace aul diff --git a/tool/aulctl/operation/status_once_operation.hh b/tool/aulctl/operation/status_once_operation.hh new file mode 100644 index 0000000..3163919 --- /dev/null +++ b/tool/aulctl/operation/status_once_operation.hh @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#include +#include + +#include "operation.hh" + +namespace aul { + +class StatusOnceOperation : public Operation { + public: + explicit StatusOnceOperation(std::string appid); + ~StatusOnceOperation() = default; + bool Process() override; + + private: + std::string appid_; +}; + +} // namespace aul diff --git a/tool/aulctl/operation/stop_operation.cc b/tool/aulctl/operation/stop_operation.cc new file mode 100644 index 0000000..2286ac9 --- /dev/null +++ b/tool/aulctl/operation/stop_operation.cc @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#include "stop_operation.hh" + +#include + +#include "aul/api/aul_app_context.h" +#include "include/aul.h" +#include "aul/boot_sequence/boot_sequence_manager.hh" + +namespace aul { + +StopOperation::StopOperation(std::string appid) + : appid_(std::move(appid)) { +} + +bool StopOperation::Process() { + auto& manager = internal::boot_sequence::BootSequenceManager::GetInst(); + auto app_list = manager.GetAppInfoList(getuid()); + if (app_list.empty()) { + std::cerr << "Failed to get boot sequence app list." << std::endl; + return false; + } + + for (auto& app : app_list) { + if (app->GetAppId() != appid_) + continue; + + int ret = aul_terminate_app(appid_.c_str()); + if (ret != AUL_R_OK) { + std::cerr << "Failed to terminate app." << std::endl; + return false; + } + + std::cout << "Success to terminate app." << std::endl; + return true; + } + + std::cerr << "Not found app info." << std::endl; + return false; +} + +} // namespace aul diff --git a/tool/aulctl/operation/stop_operation.hh b/tool/aulctl/operation/stop_operation.hh new file mode 100644 index 0000000..4655407 --- /dev/null +++ b/tool/aulctl/operation/stop_operation.hh @@ -0,0 +1,34 @@ + +/* + * 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. + */ + +#include + +#include "operation.hh" + +namespace aul { + +class StopOperation : public Operation { + public: + explicit StopOperation(std::string appid); + ~StopOperation() = default; + bool Process() override; + + private: + std::string appid_; +}; + +} // namespace aul -- 2.7.4