1/* 2 * Copyright (c) 2023 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 HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_APP_EVENT_H 16#define HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_APP_EVENT_H 17 18#include <string> 19#include <vector> 20 21namespace OHOS { 22namespace HiviewDFX { 23class AppEventPack; 24namespace HiAppEvent { 25enum EventType { 26 FAULT = 1, 27 STATISTIC = 2, 28 SECURITY = 3, 29 BEHAVIOR = 4 30}; 31 32class Event { 33public: 34 Event(const std::string& domain, const std::string& name, EventType type); 35 ~Event() = default; 36 37 void AddParam(const std::string& key, bool value); 38 void AddParam(const std::string& key, int32_t value); 39 void AddParam(const std::string& key, int64_t value); 40 void AddParam(const std::string& key, double value); 41 /** 42 * Note: To avoid implicit type conversion problems, do not support direct input 43 * of string literal constants, for example: 44 * AddParam("str_key", "str_value") // Not supported 45 */ 46 void AddParam(const std::string& key, const std::string& value); 47 48 void AddParam(const std::string& key, const std::vector<bool>& value); 49 void AddParam(const std::string& key, const std::vector<int32_t>& value); 50 void AddParam(const std::string& key, const std::vector<int64_t>& value); 51 void AddParam(const std::string& key, const std::vector<double>& value); 52 /** 53 * Note: To avoid implicit type conversion problems, do not support direct input of 54 * initialization list and string literal constants, for example: 55 * AddParam("str_key", {"str1"}) // Not supported 56 * AddParam("str_key", {"str1", "str2"}) // Not supported 57 * AddParam("str_key", {str1}) // Not supported 58 * AddParam("str_key", {str1, str2}) // Supported 59 */ 60 void AddParam(const std::string& key, const std::vector<std::string>& value); 61 62 friend int Write(const Event& event); 63 64private: 65 std::shared_ptr<AppEventPack> eventPack_; 66}; 67 68int Write(const Event& event); 69} // namespace HiAppEvent 70} // namespace HiviewDFX 71} // namespace OHOS 72#endif // HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_APP_EVENT_H 73