1 /*
2  * Copyright (c) 2024 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 #include "schedule_resource_node_listener.h"
16 
17 #include "iam_check.h"
18 #include "iam_logger.h"
19 
20 #define LOG_TAG "USER_AUTH_SA"
21 
22 namespace OHOS {
23 namespace UserIam {
24 namespace UserAuth {
ScheduleResourceNodeListener(std::weak_ptr<ScheduleNode> weakNode)25 ScheduleResourceNodeListener::ScheduleResourceNodeListener(std::weak_ptr<ScheduleNode> weakNode):  weakNode_(weakNode)
26 {}
27 
OnResourceNodePoolInsert(const std::shared_ptr<ResourceNode> & resource)28 void ScheduleResourceNodeListener::OnResourceNodePoolInsert(const std::shared_ptr<ResourceNode> &resource)
29 {}
30 
OnResourceNodePoolDelete(const std::shared_ptr<ResourceNode> & resource)31 void ScheduleResourceNodeListener::OnResourceNodePoolDelete(const std::shared_ptr<ResourceNode> &resource)
32 {
33     IF_FALSE_LOGE_AND_RETURN(resource != nullptr);
34 
35     auto scheduleNode = weakNode_.lock();
36     IF_FALSE_LOGE_AND_RETURN(scheduleNode != nullptr);
37 
38     auto collector = scheduleNode->GetCollectorExecutor().lock();
39     auto verifier = scheduleNode->GetVerifyExecutor().lock();
40     if (collector == resource || verifier == resource) {
41         IAM_LOGI("resource node is deleted, stop schedule");
42         scheduleNode->StopSchedule(GENERAL_ERROR);
43     }
44 }
45 
OnResourceNodePoolUpdate(const std::shared_ptr<ResourceNode> & resource)46 void ScheduleResourceNodeListener::OnResourceNodePoolUpdate(const std::shared_ptr<ResourceNode> &resource)
47 {}
48 } // namespace UserAuth
49 } // namespace UserIam
50 } // namespace OHOS
51