1 /* 2 * Copyright (c) 2022 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 IAM_RESOURCE_NODE_POOL_H 17 #define IAM_RESOURCE_NODE_POOL_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <memory> 22 23 #include "resource_node.h" 24 25 namespace OHOS { 26 namespace UserIam { 27 namespace UserAuth { 28 class ResourceNodePool { 29 public: 30 class ResourceNodePoolListener { 31 public: 32 virtual ~ResourceNodePoolListener() = default; 33 virtual void OnResourceNodePoolInsert(const std::shared_ptr<ResourceNode> &resource) = 0; 34 virtual void OnResourceNodePoolDelete(const std::shared_ptr<ResourceNode> &resource) = 0; 35 virtual void OnResourceNodePoolUpdate(const std::shared_ptr<ResourceNode> &resource) = 0; 36 }; 37 static ResourceNodePool &Instance(); 38 virtual ~ResourceNodePool() = default; 39 virtual bool Insert(const std::shared_ptr<ResourceNode> &resource) = 0; 40 virtual bool Delete(uint64_t executorIndex) = 0; 41 virtual void DeleteAll() = 0; 42 virtual std::weak_ptr<ResourceNode> Select(uint64_t executorIndex) const = 0; 43 virtual uint32_t GetPoolSize() const = 0; 44 virtual void Enumerate(std::function<void(const std::weak_ptr<ResourceNode> &)> action) const = 0; 45 virtual bool RegisterResourceNodePoolListener(const std::shared_ptr<ResourceNodePoolListener> &listener) = 0; 46 virtual bool DeregisterResourceNodePoolListener(const std::shared_ptr<ResourceNodePoolListener> &listener) = 0; 47 }; 48 } // namespace UserAuth 49 } // namespace UserIam 50 } // namespace OHOS 51 #endif // IAM_RESOURCE_NODE_POOL_H