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
16 #include "hiappevent_pack.h"
17
18 #include <memory>
19 #include <vector>
20
21 #include "hiappevent_base.h"
22 #include "hiappevent_write.h"
23
24 namespace OHOS {
25 namespace HiviewDFX {
CreateEventPack(const std::string & eventName,int eventType)26 std::shared_ptr<AppEventPack> CreateEventPack(const std::string& eventName, int eventType)
27 {
28 return std::make_shared<AppEventPack>(eventName, eventType);
29 }
30
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key)31 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key)
32 {
33 if (appEventPack == nullptr) {
34 return;
35 }
36 appEventPack->AddParam(key);
37 }
38
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,bool b)39 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, bool b)
40 {
41 if (appEventPack == nullptr) {
42 return;
43 }
44 appEventPack->AddParam(key, b);
45 }
46
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,char c)47 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, char c)
48 {
49 if (appEventPack == nullptr) {
50 return;
51 }
52 appEventPack->AddParam(key, c);
53 }
54
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,short s)55 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, short s)
56 {
57 if (appEventPack == nullptr) {
58 return;
59 }
60 appEventPack->AddParam(key, s);
61 }
62
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,int i)63 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, int i)
64 {
65 if (appEventPack == nullptr) {
66 return;
67 }
68 appEventPack->AddParam(key, i);
69 }
70
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,long l)71 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, long l)
72 {
73 if (appEventPack == nullptr) {
74 return;
75 }
76 appEventPack->AddParam(key, l);
77 }
78
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,long long l)79 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, long long l)
80 {
81 if (appEventPack == nullptr) {
82 return;
83 }
84 appEventPack->AddParam(key, l);
85 }
86
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,float f)87 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, float f)
88 {
89 if (appEventPack == nullptr) {
90 return;
91 }
92 appEventPack->AddParam(key, f);
93 }
94
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,double d)95 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, double d)
96 {
97 if (appEventPack == nullptr) {
98 return;
99 }
100 appEventPack->AddParam(key, d);
101 }
102
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const char * s)103 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, const char *s)
104 {
105 if (appEventPack == nullptr) {
106 return;
107 }
108 appEventPack->AddParam(key, s);
109 }
110
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::string & s)111 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, const std::string& s)
112 {
113 if (appEventPack == nullptr) {
114 return;
115 }
116 appEventPack->AddParam(key, s);
117 }
118
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<bool> & bs)119 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, const std::vector<bool>& bs)
120 {
121 if (appEventPack == nullptr) {
122 return;
123 }
124 appEventPack->AddParam(key, bs);
125 }
126
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<char> & cs)127 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, const std::vector<char>& cs)
128 {
129 if (appEventPack == nullptr) {
130 return;
131 }
132 appEventPack->AddParam(key, cs);
133 }
134
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<short> & shs)135 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, const std::vector<short>& shs)
136 {
137 if (appEventPack == nullptr) {
138 return;
139 }
140 appEventPack->AddParam(key, shs);
141 }
142
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<int> & is)143 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, const std::vector<int>& is)
144 {
145 if (appEventPack == nullptr) {
146 return;
147 }
148 appEventPack->AddParam(key, is);
149 }
150
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<long> & ls)151 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, const std::vector<long>& ls)
152 {
153 if (appEventPack == nullptr) {
154 return;
155 }
156 appEventPack->AddParam(key, ls);
157 }
158
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<long long> & lls)159 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key,
160 const std::vector<long long>& lls)
161 {
162 if (appEventPack == nullptr) {
163 return;
164 }
165 appEventPack->AddParam(key, lls);
166 }
167
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<float> & fs)168 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, const std::vector<float>& fs)
169 {
170 if (appEventPack == nullptr) {
171 return;
172 }
173 appEventPack->AddParam(key, fs);
174 }
175
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<double> & ds)176 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key, const std::vector<double>& ds)
177 {
178 if (appEventPack == nullptr) {
179 return;
180 }
181 appEventPack->AddParam(key, ds);
182 }
183
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<const char * > & cps)184 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key,
185 const std::vector<const char*>& cps)
186 {
187 if (appEventPack == nullptr) {
188 return;
189 }
190 appEventPack->AddParam(key, cps);
191 }
192
AddEventParam(std::shared_ptr<AppEventPack> appEventPack,const std::string & key,const std::vector<const std::string> & strs)193 void AddEventParam(std::shared_ptr<AppEventPack> appEventPack, const std::string& key,
194 const std::vector<const std::string>& strs)
195 {
196 if (appEventPack == nullptr) {
197 return;
198 }
199 appEventPack->AddParam(key, strs);
200 }
201 } // HiviewDFX
202 } // OHOS