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 #ifndef HISYSEVENT_BASE_LISTENER_H 17 #define HISYSEVENT_BASE_LISTENER_H 18 19 #include <string> 20 #include <memory> 21 22 #include "hisysevent_record.h" 23 #include "hisysevent_listener.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 class HiSysEventListenningOperate; 28 class HiSysEventBaseListener { 29 public: 30 HiSysEventBaseListener() = default; HiSysEventBaseListener(std::shared_ptr<HiSysEventListener> listener)31 HiSysEventBaseListener(std::shared_ptr<HiSysEventListener> listener): listener(listener) {} ~HiSysEventBaseListener()32 virtual ~HiSysEventBaseListener() {} 33 34 public: OnEvent(const std::string & domain,const std::string & eventName,const int eventType,const std::string & eventDetail)35 virtual void OnEvent(const std::string& domain, const std::string& eventName, const int eventType, 36 const std::string& eventDetail) 37 { 38 if (listener != nullptr) { 39 std::shared_ptr<HiSysEventRecord> sysEvent = std::make_shared<HiSysEventRecord>(eventDetail); 40 listener->OnEvent(sysEvent); 41 } 42 } 43 OnServiceDied()44 virtual void OnServiceDied() 45 { 46 if (listener != nullptr) { 47 listener->OnServiceDied(); 48 } 49 } 50 51 protected: 52 HiSysEventListenningOperate* listenerProxy = nullptr; 53 54 private: 55 HiSysEventBaseListener(const HiSysEventBaseListener&) = delete; 56 HiSysEventBaseListener& operator=(const HiSysEventBaseListener&) = delete; 57 HiSysEventBaseListener(const HiSysEventBaseListener&&) = delete; 58 HiSysEventBaseListener& operator=(const HiSysEventBaseListener&&) = delete; 59 60 private: 61 std::shared_ptr<HiSysEventListener> listener; 62 63 friend class HiSysEventBaseManager; 64 }; 65 } // namespace HiviewDFX 66 } // namespace OHOS 67 68 #endif // HISYSEVENT_BASE_LISTENER_H 69