1 /* 2 * Copyright (c) 2020 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 #include "ability_stack.h" 17 18 #include "ability_record.h" 19 20 namespace OHOS { GetTopAbility() const21const AbilityRecord *AbilityStack::GetTopAbility() const 22 { 23 if (abilityStack_.Size() != 0) { 24 return abilityStack_.Front(); 25 } 26 return nullptr; 27 } 28 GetAllAbilities(AbilityRecord ** abilityRecords)29int AbilityStack::GetAllAbilities(AbilityRecord **abilityRecords) 30 { 31 int size = abilityStack_.Size(); 32 if (size == 0) { 33 *abilityRecords = nullptr; 34 return 0; 35 } 36 37 auto ars = new AbilityRecord[size]; 38 *abilityRecords = ars; 39 for (auto node = abilityStack_.Begin(); node != abilityStack_.End(); node = node->next_) { 40 if (node->value_ == nullptr) { 41 continue; 42 } 43 AbilityRecord::CopyAbilityRecord(*(node->value_), *ars); 44 ars++; 45 } 46 47 return size; 48 } 49 PushAbility(AbilityRecord * record)50void AbilityStack::PushAbility(AbilityRecord *record) 51 { 52 if (record != nullptr) { 53 abilityStack_.PushFront(record); 54 } 55 } 56 PopAbility()57void AbilityStack::PopAbility() 58 { 59 abilityStack_.PopFront(); 60 } 61 } // namespace OHOS