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 #ifndef HIVIEW_BASE_EVENT_DISPATCHER_H 16 #define HIVIEW_BASE_EVENT_DISPATCHER_H 17 18 #include <map> 19 #include <memory> 20 #include <mutex> 21 #include <string> 22 #include "event.h" 23 #include "plugin.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 class EventDispatcher { 28 public: EventDispatcher()29 EventDispatcher(){}; 30 ~EventDispatcher() = default; 31 32 void AddInterestType(uint32_t type); 33 void ClearInvalidListeners(); 34 void DispatchEvent(Event event); 35 void RegisterListener(std::weak_ptr<EventListener> listener); 36 void RegisterListener(std::weak_ptr<Plugin> listener); 37 38 protected: 39 bool channelPluginFind(std::string name, int32_t type); 40 std::set<uint32_t> types_; 41 std::map<uint32_t, std::list<std::weak_ptr<EventListener>>> channelMapper_; 42 std::map<uint32_t, std::list<std::weak_ptr<Plugin>>> channelPlugin_; 43 44 private: 45 std::mutex lock_; 46 }; 47 } // namespace HiviewDFX 48 } // namespace OHOS 49 #endif // HIVIEW_BASE_EVENT_DISPATCHER_H