1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <google/protobuf/text_format.h>
18
19 #include <fstream>
20 #include <string>
21
22 #include "GraphicsDetector.h"
23 #include "GraphicsDetector.pb.h"
24
25 namespace {
26
WriteToFile(const std::string & filename,const std::string & contents)27 bool WriteToFile(const std::string& filename, const std::string& contents) {
28 std::ofstream ofs(filename);
29 if (!ofs.is_open()) {
30 return false;
31 }
32 ofs << contents;
33 ofs.close();
34 return !ofs.fail();
35 }
36
37 } // namespace
38
main(int argc,char * argv[])39 int main(int argc, char* argv[]) {
40 const auto availability = ::gfxstream::DetectGraphicsAvailability();
41
42 std::string availabilityString;
43 if (!google::protobuf::TextFormat::PrintToString(availability, &availabilityString)) {
44 std::cerr << "Failed to convert availability to string." << std::endl;
45 return -1;
46 }
47
48 if (argc > 1) {
49 const std::string filename = argv[1];
50 if (!WriteToFile(filename, availabilityString)) {
51 std::cerr << "Failed to write to '" << filename << "'.";
52 return -1;
53 }
54 } else {
55 std::cout << availabilityString << std::endl;
56 }
57
58 return 0;
59 }