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_CONTEXT_POOL_H 17 #define IAM_CONTEXT_POOL_H 18 19 #include <cstdint> 20 21 #include "context.h" 22 23 namespace OHOS { 24 namespace UserIam { 25 namespace UserAuth { 26 class ContextPool { 27 public: 28 class ContextPoolListener { 29 public: 30 virtual void OnContextPoolInsert(const std::shared_ptr<Context> &context) = 0; 31 virtual void OnContextPoolDelete(const std::shared_ptr<Context> &context) = 0; 32 }; 33 static uint64_t GetNewContextId(); 34 static ContextPool &Instance(); 35 virtual bool Insert(const std::shared_ptr<Context> &context) = 0; 36 virtual bool Delete(uint64_t contextId) = 0; 37 virtual std::weak_ptr<Context> Select(uint64_t contextId) const = 0; 38 virtual std::vector<std::weak_ptr<Context>> Select(ContextType contextType) const = 0; 39 virtual std::shared_ptr<ScheduleNode> SelectScheduleNodeByScheduleId(uint64_t scheduleId) = 0; 40 virtual bool RegisterContextPoolListener(const std::shared_ptr<ContextPoolListener> &listener) = 0; 41 virtual bool DeregisterContextPoolListener(const std::shared_ptr<ContextPoolListener> &listener) = 0; 42 }; 43 } // namespace UserAuth 44 } // namespace UserIam 45 } // namespace OHOS 46 #endif // IAM_CONTEXT_POOL_H 47