1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ABILITY_COMPONENT_ABILITY_COMPONENT_CONTROLLER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ABILITY_COMPONENT_ABILITY_COMPONENT_CONTROLLER_H 18 19 #include <string> 20 #include <functional> 21 22 #include "base/memory/ace_type.h" 23 24 namespace OHOS::Ace { 25 26 class ACE_EXPORT AbilityComponentController : public AceType { 27 DECLARE_ACE_TYPE(AbilityComponentController, AceType); 28 29 public: 30 AbilityComponentController() = default; 31 ~AbilityComponentController() override = default; 32 StartAbility(const std::string & want)33 void StartAbility(const std::string& want) const 34 { 35 if (startAbilityImpl_) { 36 startAbilityImpl_(want); 37 } 38 } 39 PerformBackPress()40 void PerformBackPress() const 41 { 42 if (performBackPressImpl_) { 43 performBackPressImpl_(); 44 } 45 } 46 GetStackCount()47 int32_t GetStackCount() const 48 { 49 if (getStackCountImpl_) { 50 return getStackCountImpl_(); 51 } 52 return 0; 53 } 54 SetStartAbilityImpl(const std::function<void (const std::string &)> & startAbilityImpl)55 void SetStartAbilityImpl(const std::function<void(const std::string&)>& startAbilityImpl) 56 { 57 startAbilityImpl_ = startAbilityImpl; 58 } 59 SetPerformBackPressImpl(std::function<void ()> performBackPressImpl)60 void SetPerformBackPressImpl(std::function<void()> performBackPressImpl) 61 { 62 performBackPressImpl_ = performBackPressImpl; 63 } 64 SetGetStackCountImpl(std::function<int32_t ()> getStackCountImpl)65 void SetGetStackCountImpl(std::function<int32_t()> getStackCountImpl) 66 { 67 getStackCountImpl_ = getStackCountImpl; 68 } 69 70 private: 71 std::function<void(const std::string&)> startAbilityImpl_; 72 std::function<void()> performBackPressImpl_; 73 std::function<int32_t()> getStackCountImpl_; 74 }; 75 76 } // namespace OHOS::Ace 77 78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ABILITY_COMPONENT_ABILITY_COMPONENT_CONTROLLER_H 79