• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "continuation_manager/notifier_info.h"
17 
18 namespace OHOS {
19 namespace DistributedSchedule {
GetNotifier(const std::string & cbType) const20 sptr<IRemoteObject> NotifierInfo::GetNotifier(const std::string& cbType) const
21 {
22     auto iter = notifierMap_.find(cbType);
23     if (iter == notifierMap_.end()) {
24         return nullptr;
25     }
26     return iter->second;
27 }
28 
SetNotifier(const std::string & cbType,const sptr<IRemoteObject> & notifier)29 void NotifierInfo::SetNotifier(const std::string& cbType, const sptr<IRemoteObject>& notifier)
30 {
31     notifierMap_[cbType] = notifier;
32 }
33 
DeleteNotifier(const std::string & cbType)34 void NotifierInfo::DeleteNotifier(const std::string& cbType)
35 {
36     auto iter = notifierMap_.find(cbType);
37     if (iter != notifierMap_.end()) {
38         notifierMap_.erase(iter);
39     }
40 }
41 
QueryNotifier(const sptr<IRemoteObject> & notifier) const42 bool NotifierInfo::QueryNotifier(const sptr<IRemoteObject>& notifier) const
43 {
44     for (auto iter = notifierMap_.begin(); iter != notifierMap_.end(); iter++) {
45         if (iter->second == notifier) {
46             return true;
47         }
48     }
49     return false;
50 }
51 
IsNotifierMapEmpty()52 bool NotifierInfo::IsNotifierMapEmpty()
53 {
54     if (notifierMap_.empty()) {
55         return true;
56     }
57     return false;
58 }
59 
RemoveDeathRecipient(const sptr<IRemoteObject::DeathRecipient> & notifierDeathRecipient,const std::string & cbType)60 void NotifierInfo::RemoveDeathRecipient(const sptr<IRemoteObject::DeathRecipient>& notifierDeathRecipient,
61     const std::string& cbType)
62 {
63     if (cbType.empty()) {
64         for (auto iter = notifierMap_.begin(); iter != notifierMap_.end(); iter++) {
65             iter->second->RemoveDeathRecipient(notifierDeathRecipient);
66         }
67         return;
68     }
69     auto it = notifierMap_.find(cbType);
70     if (it != notifierMap_.end()) {
71         it->second->RemoveDeathRecipient(notifierDeathRecipient);
72     }
73 }
74 
GetConnectStatusInfo() const75 std::shared_ptr<ConnectStatusInfo> NotifierInfo::GetConnectStatusInfo() const
76 {
77     return connectStatusInfo_;
78 }
79 
SetConnectStatusInfo(const std::shared_ptr<ConnectStatusInfo> & connectStatusInfo)80 void NotifierInfo::SetConnectStatusInfo(const std::shared_ptr<ConnectStatusInfo>& connectStatusInfo)
81 {
82     connectStatusInfo_ = connectStatusInfo;
83 }
84 } // namespace DistributedSchedule
85 } // namespace OHOS