• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "common_hisysevent.h"
17 
18 #include <string>
19 
20 #include <initializer_list>
21 
22 #include "hisysevent.h"
23 
24 #include "location_log.h"
25 
26 namespace OHOS {
27 namespace Location {
28 template<typename... Types>
WriteEvent(const std::string & eventType,Types...args)29 static void WriteEvent(const std::string& eventType, Types... args)
30 {
31     int ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::LOCATION, eventType,
32         HiviewDFX::HiSysEvent::EventType::STATISTIC, args...);
33     if (ret != 0) {
34         LBSLOGE(COMMON_UTILS, "Write event fail: %{public}s", eventType.c_str());
35     }
36 }
37 
WriteGnssStateEvent(const std::string & state,const pid_t pid,const pid_t uid)38 void WriteGnssStateEvent(const std::string& state, const pid_t pid, const pid_t uid)
39 {
40     WriteEvent("GNSS_STATE", "STATE", state, "PID", pid, "UID", uid);
41 }
42 
WriteAppLocatingStateEvent(const std::string & state,const pid_t pid,const pid_t uid)43 void WriteAppLocatingStateEvent(const std::string& state, const pid_t pid, const pid_t uid)
44 {
45     WriteEvent("APP_LOCATING_STATE", "STATE", state, "PID", pid, "UID", uid);
46 }
47 
WriteLocationSwitchStateEvent(const std::string & state)48 void WriteLocationSwitchStateEvent(const std::string& state)
49 {
50     WriteEvent("SWITCH_STATE", "STATE", state);
51 }
52 
WriteLocationInnerEvent(const int event,std::initializer_list<std::string> params)53 void WriteLocationInnerEvent(const int event, std::initializer_list<std::string> params)
54 {
55     std::vector<std::string> names;
56     std::vector<std::string> values;
57     bool flag = true;
58     for (auto x: params) {
59         if (flag) {
60             names.push_back(x);
61         } else {
62             values.push_back(x);
63         }
64         flag = !flag;
65     }
66     WriteEvent("LBS_CHR_INNER_EVENT", "EVENT", event, "NAMES", names, "VALUES", values);
67 }
68 
WriteLocationInnerEvent(const int event,std::vector<std::string> names,std::vector<std::string> & values)69 void WriteLocationInnerEvent(const int event, std::vector<std::string> names, std::vector<std::string>& values)
70 {
71     WriteEvent("LBS_CHR_INNER_EVENT", "EVENT", event, "NAMES", names, "VALUES", values);
72 }
73 }  // namespace Location
74 }  // namespace OHOS
75