From c8fc001e7756b0b74f6321e8e48a35071dc8cff2 Mon Sep 17 00:00:00 2001 From: songjindian Date: Wed, 8 Mar 2023 10:27:21 +0800 Subject: [PATCH] =?UTF-8?q?AMS=E6=8F=90=E4=BE=9BAbilityThread=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=B7=A5=E5=8E=82=E7=B1=BB=E7=9A=84=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songjindian --- .../abilitymgr_lite/include/ability_thread.h | 25 ++++++++ .../include/ability_thread_loader.h | 59 ++++++++++++++++++ .../src/ability_thread_loader.cpp | 60 +++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 services/abilitymgr_lite/include/ability_thread.h create mode 100644 services/abilitymgr_lite/include/ability_thread_loader.h create mode 100644 services/abilitymgr_lite/src/ability_thread_loader.cpp diff --git a/services/abilitymgr_lite/include/ability_thread.h b/services/abilitymgr_lite/include/ability_thread.h new file mode 100644 index 0000000..4e8b472 --- /dev/null +++ b/services/abilitymgr_lite/include/ability_thread.h @@ -0,0 +1,25 @@ +// +// Created by dian on 2023/3/9. +// + +#ifndef ABILITYLITE_ABILITY_THREAD_H +#define ABILITYLITE_ABILITY_THREAD_H + +#include + +namespace OHOS { +class AbilityThread { +public: + AbilityThread() = default; + + virtual ~AbilityThread() = default; + + virtual int GetAbilityThreadType() = 0; + + virtual void SetAbilityThreadType(int32_t type) = 0; + +protected: + int32_t threadType_ = 0; +}; +} // namespace OHOS +#endif // ABILITYLITE_ABILITY_THREAD_H \ No newline at end of file diff --git a/services/abilitymgr_lite/include/ability_thread_loader.h b/services/abilitymgr_lite/include/ability_thread_loader.h new file mode 100644 index 0000000..2fbb1ee --- /dev/null +++ b/services/abilitymgr_lite/include/ability_thread_loader.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 Huawei Device 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 ABILITYLITE_ABILITY_THREAD_LOADER_H +#define ABILITYLITE_ABILITY_THREAD_LOADER_H + +#include "ability_thread.h" + +namespace OHOS { +/** + * @brief Method to create AbilityThread. + * + * This method can create an AbilityThread and return a pointer to the AbilityThread. + * + */ +using AbilityThreadCreator = AbilityThread*(*)(); + +enum AbilityThreadCreatorType { + JS_CREATOR, + NATIVE_CREATOR, +}; + +class AbilityThreadLoader { +public: + static AbilityThreadLoader &GetInstance() + { + static AbilityThreadLoader instance; + return instance; + } + + AbilityThreadLoader() = default; + + ~AbilityThreadLoader() = default; + + void SetCreatorFunc(AbilityThreadCreatorType type, AbilityThreadCreator creator); + + AbilityThread *CreateAbilityThread(AbilityThreadCreatorType type) const; + + void unRegister(AbilityThreadCreatorType type); + +private: + AbilityThreadCreator jsAbilityThreadCreator_ = { nullptr }; + + AbilityThreadCreator nativeAbilityThreadCreator_ = { nullptr }; +}; +} // namespace OHOS +#endif //ABILITYLITE_ABILITY_THREAD_LOAD_H \ No newline at end of file diff --git a/services/abilitymgr_lite/src/ability_thread_loader.cpp b/services/abilitymgr_lite/src/ability_thread_loader.cpp new file mode 100644 index 0000000..2967427 --- /dev/null +++ b/services/abilitymgr_lite/src/ability_thread_loader.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 Huawei Device 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 "ability_thread_loader.h" + +namespace OHOS { +void AbilityThreadLoader::SetCreatorFunc(AbilityThreadCreatorType type, AbilityThreadCreator creator) +{ + if (creator == nullptr) { + return; + } + switch (type) { + case AbilityThreadCreatorType::JS_CREATOR: + jsAbilityThreadCreator_ = creator; + break; + case AbilityThreadCreatorType::NATIVE_CREATOR: + nativeAbilityThreadCreator_ = creator; + break; + default: + break; + } +} + +AbilityThread *AbilityThreadLoader::CreateAbilityThread(AbilityThreadCreatorType type) const +{ + if (AbilityThreadCreatorType::JS_CREATOR == type && jsAbilityThreadCreator_ != nullptr) { + return jsAbilityThreadCreator_(); + } + if (AbilityThreadCreatorType::NATIVE_CREATOR == type && nativeAbilityThreadCreator_ != nullptr){ + return nativeAbilityThreadCreator_(); + } + return nullptr; +} + +void AbilityThreadLoader::unRegister(AbilityThreadCreatorType type) +{ + switch (type) { + case AbilityThreadCreatorType::JS_CREATOR: + jsAbilityThreadCreator_ = { nullptr }; + break; + case AbilityThreadCreatorType::NATIVE_CREATOR: + nativeAbilityThreadCreator_ = { nullptr }; + break; + default: + break; + } +} +} \ No newline at end of file -- Gitee