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 "common_event_subscriber.h" 17 18 namespace OHOS { 19 namespace EventFwk { CommonEventSubscriber()20CommonEventSubscriber::CommonEventSubscriber() : result_(nullptr) 21 {} 22 CommonEventSubscriber(const CommonEventSubscribeInfo & subscribeInfo)23CommonEventSubscriber::CommonEventSubscriber(const CommonEventSubscribeInfo& subscribeInfo) 24 : subscribeInfo_(subscribeInfo), result_(nullptr) 25 { 26 (void)subscribeInfo; 27 } 28 ~CommonEventSubscriber()29CommonEventSubscriber::~CommonEventSubscriber() 30 {} 31 GetSubscribeInfo() const32const CommonEventSubscribeInfo& CommonEventSubscriber::GetSubscribeInfo() const 33 { 34 return subscribeInfo_; 35 } 36 SetCode(const int & code)37bool CommonEventSubscriber::SetCode(const int& code) 38 { 39 return result_->SetCode(code); 40 } 41 GetCode() const42int CommonEventSubscriber::GetCode() const 43 { 44 return result_->GetCode(); 45 } 46 SetData(const std::string & data)47bool CommonEventSubscriber::SetData(const std::string& data) 48 { 49 return result_->SetData(data); 50 } 51 GetData() const52std::string CommonEventSubscriber::GetData() const 53 { 54 return result_->GetData(); 55 } 56 SetCodeAndData(const int & code,const std::string & data)57bool CommonEventSubscriber::SetCodeAndData(const int& code, const std::string& data) 58 { 59 return result_->SetCodeAndData(code, data); 60 } 61 AbortCommonEvent()62bool CommonEventSubscriber::AbortCommonEvent() 63 { 64 return result_->AbortCommonEvent(); 65 } 66 ClearAbortCommonEvent()67bool CommonEventSubscriber::ClearAbortCommonEvent() 68 { 69 return result_->ClearAbortCommonEvent(); 70 } 71 GetAbortCommonEvent() const72bool CommonEventSubscriber::GetAbortCommonEvent() const 73 { 74 return result_->GetAbortCommonEvent(); 75 } 76 GoAsyncCommonEvent()77std::shared_ptr<AsyncCommonEventResult> CommonEventSubscriber::GoAsyncCommonEvent() 78 { 79 std::shared_ptr<AsyncCommonEventResult> res = result_; 80 result_ = nullptr; 81 return res; 82 } 83 IsOrderedCommonEvent() const84bool CommonEventSubscriber::IsOrderedCommonEvent() const 85 { 86 return (result_ != nullptr) ? result_->IsOrderedCommonEvent() : false; 87 } 88 IsStickyCommonEvent() const89bool CommonEventSubscriber::IsStickyCommonEvent() const 90 { 91 return (result_ != nullptr) ? result_->IsStickyCommonEvent() : false; 92 } 93 SetAsyncCommonEventResult(const std::shared_ptr<AsyncCommonEventResult> & result)94bool CommonEventSubscriber::SetAsyncCommonEventResult(const std::shared_ptr<AsyncCommonEventResult>& result) 95 { 96 result_ = result; 97 98 return true; 99 } 100 GetAsyncCommonEventResult()101std::shared_ptr<AsyncCommonEventResult> CommonEventSubscriber::GetAsyncCommonEventResult() 102 { 103 return result_; 104 } 105 CheckSynchronous() const106bool CommonEventSubscriber::CheckSynchronous() const 107 { 108 return true; 109 } 110 } // namespace EventFwk 111 } // namespace OHOS