1 /*
2 * Copyright (c) 2024 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 #include "app_event.h"
16
17 #include "hiappevent_base.h"
18 #include "hiappevent_verify.h"
19 #include "hiappevent_write.h"
20
21 namespace OHOS {
22 namespace HiviewDFX {
23 namespace HiAppEvent {
Event(const std::string & domain,const std::string & name,EventType type)24 Event::Event(const std::string& domain, const std::string& name, EventType type)
25 {
26 eventPack_ = std::make_shared<AppEventPack>(domain, name, type);
27 }
28
AddParam(const std::string & key,bool value)29 void Event::AddParam(const std::string& key, bool value)
30 {
31 eventPack_->AddParam(key, value);
32 }
33
AddParam(const std::string & key,int32_t value)34 void Event::AddParam(const std::string& key, int32_t value)
35 {
36 eventPack_->AddParam(key, value);
37 }
38
AddParam(const std::string & key,int64_t value)39 void Event::AddParam(const std::string& key, int64_t value)
40 {
41 eventPack_->AddParam(key, value);
42 }
43
AddParam(const std::string & key,double value)44 void Event::AddParam(const std::string& key, double value)
45 {
46 eventPack_->AddParam(key, value);
47 }
48
AddParam(const std::string & key,const std::string & value)49 void Event::AddParam(const std::string& key, const std::string& value)
50 {
51 eventPack_->AddParam(key, value);
52 }
53
AddParam(const std::string & key,const std::vector<bool> & value)54 void Event::AddParam(const std::string& key, const std::vector<bool>& value)
55 {
56 eventPack_->AddParam(key, value);
57 }
58
AddParam(const std::string & key,const std::vector<int32_t> & value)59 void Event::AddParam(const std::string& key, const std::vector<int32_t>& value)
60 {
61 eventPack_->AddParam(key, value);
62 }
63
AddParam(const std::string & key,const std::vector<int64_t> & value)64 void Event::AddParam(const std::string& key, const std::vector<int64_t>& value)
65 {
66 eventPack_->AddParam(key, value);
67 }
68
AddParam(const std::string & key,const std::vector<double> & value)69 void Event::AddParam(const std::string& key, const std::vector<double>& value)
70 {
71 eventPack_->AddParam(key, value);
72 }
73
AddParam(const std::string & key,const std::vector<std::string> & value)74 void Event::AddParam(const std::string& key, const std::vector<std::string>& value)
75 {
76 eventPack_->AddParam(key, value);
77 }
78
Write(const Event & event)79 int Write(const Event& event)
80 {
81 if (!IsApp()) {
82 return ErrorCode::ERROR_NOT_APP;
83 }
84 int ret = VerifyAppEvent(event.eventPack_);
85 if (ret >= 0) {
86 auto appEventPack = event.eventPack_;
87 SubmitWritingTask(appEventPack, "app_event");
88 }
89 return ret;
90 }
91 } // namespace HiAppEvent
92 } // namespace HiviewDFX
93 } // namespace OHOS
94