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 HIVIEW_BASE_EVENT_REPORT_REPORT_EVENT_H 17 #define HIVIEW_BASE_EVENT_REPORT_REPORT_EVENT_H 18 19 #include <map> 20 #include <string> 21 22 #include "param_value.h" 23 #include "hisysevent.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 class LoggerEvent { 28 public: LoggerEvent(const std::string & name,HiSysEvent::EventType type)29 LoggerEvent(const std::string &name, HiSysEvent::EventType type) 30 : eventName_(name), eventType_(type) {} 31 ~LoggerEvent()32 virtual ~LoggerEvent() {} 33 34 template<typename T> Update(const std::string & name,const T & value)35 void Update(const std::string &name, const T& value) 36 { 37 InnerUpdate(name, ParamValue(value)); 38 } 39 40 ParamValue GetValue(const std::string& name); 41 42 std::string ToJsonString(); 43 44 virtual void Report() = 0; 45 46 protected: 47 virtual void InnerUpdate(const std::string &name, const ParamValue& value); 48 49 protected: 50 std::string eventName_; 51 HiSysEvent::EventType eventType_; 52 std::map<std::string, ParamValue> paramMap_; 53 }; 54 } // namespace HiviewDFX 55 } // namespace OHOS 56 #endif // HIVIEW_BASE_EVENT_REPORT_REPORT_EVENT_H 57