OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file provides a thin binary wrapper around the BattOr Agent | 5 // This file provides a thin binary wrapper around the BattOr Agent |
6 // library. This binary wrapper provides a means for non-C++ tracing | 6 // library. This binary wrapper provides a means for non-C++ tracing |
7 // controllers, such as Telemetry and Android Systrace, to issue high-level | 7 // controllers, such as Telemetry and Android Systrace, to issue high-level |
8 // tracing commands to the BattOr.. | 8 // tracing commands to the BattOr.. |
9 | 9 |
10 #include <iostream> | 10 #include <iostream> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 void PrintSupportsExplicitClockSync() { | 43 void PrintSupportsExplicitClockSync() { |
44 std::cout << battor::BattOrAgent::SupportsExplicitClockSync() << endl; | 44 std::cout << battor::BattOrAgent::SupportsExplicitClockSync() << endl; |
45 } | 45 } |
46 | 46 |
47 // Retrieves argument argnum from the argument list, printing the usage | 47 // Retrieves argument argnum from the argument list, printing the usage |
48 // guidelines and exiting with an error code if the argument doesn't exist. | 48 // guidelines and exiting with an error code if the argument doesn't exist. |
49 std::string GetArg(int argnum, int argc, char* argv[]) { | 49 std::string GetArg(int argnum, int argc, char* argv[]) { |
50 if (argnum >= argc) { | 50 if (argnum >= argc) { |
51 PrintUsage(); | 51 PrintUsage(); |
52 exit(1); | 52 PLOG(FATAL); |
53 } | 53 } |
54 | 54 |
55 return argv[argnum]; | 55 return argv[argnum]; |
56 } | 56 } |
57 | 57 |
58 // Checks if an error occurred and, if it did, prints the error and exits | 58 // Checks if an error occurred and, if it did, prints the error and exits |
59 // with an error code. | 59 // with an error code. |
60 void CheckError(battor::BattOrError error) { | 60 void CheckError(battor::BattOrError error) { |
61 if (error != battor::BATTOR_ERROR_NONE) | 61 if (error != battor::BATTOR_ERROR_NONE) { |
62 LOG(FATAL) << "Fatal error when communicating with the BattOr: " << error; | 62 LOG(ERROR) << "Fatal error when communicating with the BattOr: " << error; |
| 63 PLOG(FATAL); |
| 64 } |
63 } | 65 } |
64 | 66 |
65 // Prints an error message and exits due to a required thread failing to start. | 67 // Prints an error message and exits due to a required thread failing to start. |
66 void ExitFromThreadStartFailure(const std::string& thread_name) { | 68 void ExitFromThreadStartFailure(const std::string& thread_name) { |
67 LOG(FATAL) << "Failed to start " << thread_name; | 69 LOG(ERROR) << "Failed to start " << thread_name; |
| 70 PLOG(FATAL); |
68 } | 71 } |
69 | 72 |
70 } // namespace | 73 } // namespace |
71 | 74 |
72 namespace battor { | 75 namespace battor { |
73 | 76 |
74 // Wrapper class containing all state necessary for an independent binary to | 77 // Wrapper class containing all state necessary for an independent binary to |
75 // use a BattOrAgent to communicate with a BattOr. | 78 // use a BattOrAgent to communicate with a BattOr. |
76 class BattOrAgentBin : public BattOrAgent::Listener { | 79 class BattOrAgentBin : public BattOrAgent::Listener { |
77 public: | 80 public: |
78 BattOrAgentBin() | 81 BattOrAgentBin() |
79 : done_(false, false), | 82 : done_(false, false), |
80 io_thread_(kIoThreadName), | 83 io_thread_(kIoThreadName), |
81 file_thread_(kFileThreadName), | 84 file_thread_(kFileThreadName), |
82 ui_thread_(kUiThreadName) {} | 85 ui_thread_(kUiThreadName) {} |
83 | 86 |
84 ~BattOrAgentBin() { DCHECK(!agent_); } | 87 ~BattOrAgentBin() { |
| 88 DCHECK(!agent_); |
| 89 } |
85 | 90 |
86 // Runs the BattOr binary and returns the exit code. | 91 // Runs the BattOr binary and returns the exit code. |
87 int Run(int argc, char* argv[]) { | 92 int Run(int argc, char* argv[]) { |
88 std::string cmd = GetArg(1, argc, argv); | 93 std::string cmd = GetArg(1, argc, argv); |
89 | 94 |
90 // SupportsExplicitClockSync doesn't need to use the serial connection, so | 95 // SupportsExplicitClockSync doesn't need to use the serial connection, so |
91 // handle it separately. | 96 // handle it separately. |
92 if (cmd == "SupportsExplicitClockSync") { | 97 if (cmd == "SupportsExplicitClockSync") { |
93 PrintSupportsExplicitClockSync(); | 98 PrintSupportsExplicitClockSync(); |
94 return 0; | 99 return 0; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 scoped_ptr<BattOrAgent> agent_; | 211 scoped_ptr<BattOrAgent> agent_; |
207 }; | 212 }; |
208 | 213 |
209 } // namespace battor | 214 } // namespace battor |
210 | 215 |
211 int main(int argc, char* argv[]) { | 216 int main(int argc, char* argv[]) { |
212 base::AtExitManager exit_manager; | 217 base::AtExitManager exit_manager; |
213 battor::BattOrAgentBin bin; | 218 battor::BattOrAgentBin bin; |
214 return bin.Run(argc, argv); | 219 return bin.Run(argc, argv); |
215 } | 220 } |
OLD | NEW |