1 /* 2 * Copyright (c) 2021 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 "event_source.h" 16 #include "audit.h" 17 #include "hiview_logger.h" 18 namespace OHOS { 19 namespace HiviewDFX { 20 DEFINE_LOG_TAG("HiView-EventSource"); PublishPipelineEvent(std::shared_ptr<PipelineEvent> event)21bool EventSource::PublishPipelineEvent(std::shared_ptr<PipelineEvent> event) 22 { 23 HIVIEW_LOGD("EventSource PublishPipelineEvent"); 24 if (event == nullptr) { 25 return false; 26 } 27 28 if (Audit::IsEnabled()) { 29 auto digest = GetPluginInfo() + Audit::DOMAIN_DELIMITER + event->GetEventInfo(); 30 Audit::WriteAuditEvent(Audit::StatsEvent::PIPELINE_EVENT_CREATE, event->createTime_, digest); 31 } 32 33 for (auto& pipeline : listeners_) { 34 if ((pipeline != nullptr) && (pipeline->CanProcessEvent(event))) { 35 // one event can only be processed by on pipeline 36 pipeline->ProcessEvent(event); 37 return true; 38 } 39 } 40 return false; 41 } 42 AddPipeline(std::shared_ptr<Pipeline> pipeline)43void EventSource::AddPipeline(std::shared_ptr<Pipeline> pipeline) 44 { 45 if (pipeline == nullptr) { 46 HIVIEW_LOGW("Add nullptr pipeline to %{public}s.", GetName().c_str()); 47 return; 48 } 49 HIVIEW_LOGD("EventSource add pipeline %{public}s.", pipeline->GetName().c_str()); 50 listeners_.push_back(pipeline); 51 } 52 StartEventSource()53void EventSource::StartEventSource() 54 { 55 // default non-implement 56 } 57 } // namespace HiviewDFX 58 } // namespace OHOS 59