• 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 "location_dumper.h"
17 
18 #include <functional>
19 #include <numeric>
20 #include <string>
21 #include <vector>
22 
23 #include "location_log.h"
24 
25 namespace OHOS {
26 namespace Location {
27 const std::string ARGS_HELP = "-h";
28 
PrintArgs(const std::vector<std::string> & vecArgs)29 void LocationDumper::PrintArgs(const std::vector<std::string>& vecArgs)
30 {
31     std::string strArgs = std::accumulate(vecArgs.begin(), vecArgs.end(), std::string(""),
32     [vecArgs](const std::string &strArgs, const std::string &each) {
33         return strArgs + each + "|";
34     });
35     LBSLOGI(COMMON_UTILS, "Dumper[%{public}zu] args: %{public}s", vecArgs.size(), strArgs.c_str());
36 }
37 
GeocodeDump(std::function<void (std::string &)> saBasicDumpFunc,const std::vector<std::string> & vecArgs,std::string & result)38 bool LocationDumper::GeocodeDump(std::function<void(std::string&)> saBasicDumpFunc,
39     const std::vector<std::string>& vecArgs, std::string& result)
40 {
41     PrintArgs(vecArgs);
42     result.clear();
43     if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
44         result.append("Geocode dump options:\n")
45             .append("  [-h]\n")
46             .append("  description of the cmd option:\n")
47             .append("    -h: show help.\n");
48         return true;
49     }
50 
51     saBasicDumpFunc(result);
52     return true;
53 }
54 
GnssDump(std::function<void (std::string &)> saBasicDumpFunc,const std::vector<std::string> & vecArgs,std::string & result)55 bool LocationDumper::GnssDump(std::function<void(std::string&)> saBasicDumpFunc,
56     const std::vector<std::string>& vecArgs, std::string& result)
57 {
58     PrintArgs(vecArgs);
59     result.clear();
60     if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
61         result.append("Gnss dump options:\n")
62             .append("  [-h]\n")
63             .append("  description of the cmd option:\n")
64             .append("    -h: show help.\n");
65         return true;
66     }
67 
68     saBasicDumpFunc(result);
69     return true;
70 }
71 
LocatorDump(std::function<void (std::string &)> saBasicDumpFunc,const std::vector<std::string> & vecArgs,std::string & result)72 bool LocationDumper::LocatorDump(std::function<void(std::string&)> saBasicDumpFunc,
73     const std::vector<std::string>& vecArgs, std::string& result)
74 {
75     PrintArgs(vecArgs);
76     result.clear();
77     if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
78         result.append("Locator dump options:\n")
79             .append("  [-h]\n")
80             .append("  description of the cmd option:\n")
81             .append("    -h: show help.\n");
82         return true;
83     }
84 
85     saBasicDumpFunc(result);
86     return true;
87 }
88 
NetWorkDump(std::function<void (std::string &)> saBasicDumpFunc,const std::vector<std::string> & vecArgs,std::string & result)89 bool LocationDumper::NetWorkDump(std::function<void(std::string&)> saBasicDumpFunc,
90     const std::vector<std::string>& vecArgs, std::string& result)
91 {
92     PrintArgs(vecArgs);
93     result.clear();
94     if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
95         result.append("Network dump options:\n")
96             .append("  [-h]\n")
97             .append("  description of the cmd option:\n")
98             .append("    -h: show help.\n");
99         return true;
100     }
101 
102     saBasicDumpFunc(result);
103     return true;
104 }
105 
PassiveDump(std::function<void (std::string &)> saBasicDumpFunc,const std::vector<std::string> & vecArgs,std::string & result)106 bool LocationDumper::PassiveDump(std::function<void(std::string&)> saBasicDumpFunc,
107     const std::vector<std::string>& vecArgs, std::string& result)
108 {
109     PrintArgs(vecArgs);
110     result.clear();
111     if (!vecArgs.empty() && vecArgs[0] == ARGS_HELP) {
112         result.append("Passive dump options:\n")
113             .append("  [-h]\n")
114             .append("  description of the cmd option:\n")
115             .append("    -h: show help.\n");
116         return true;
117     }
118 
119     saBasicDumpFunc(result);
120     return true;
121 }
122 }  // namespace Location
123 }  // namespace OHOS
124