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 PLOG(FATAL); | 52 exit(1); |
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(ERROR) << "Fatal error when communicating with the BattOr: " << error; | 62 LOG(FATAL) << "Fatal error when communicating with the BattOr: " << error; |
63 PLOG(FATAL); | |
Primiano Tucci (use gerrit)
2015/12/15 11:07:19
out of cusiosity why are you removing the P here?
charliea (OOO until 10-5)
2015/12/15 23:50:04
PLOG just appends the last system error to whateve
| |
64 } | |
65 } | 63 } |
66 | 64 |
67 // Prints an error message and exits due to a required thread failing to start. | 65 // Prints an error message and exits due to a required thread failing to start. |
68 void ExitFromThreadStartFailure(const std::string& thread_name) { | 66 void ExitFromThreadStartFailure(const std::string& thread_name) { |
69 LOG(ERROR) << "Failed to start " << thread_name; | 67 LOG(FATAL) << "Failed to start " << thread_name; |
70 PLOG(FATAL); | |
71 } | 68 } |
72 | 69 |
73 } // namespace | 70 } // namespace |
74 | 71 |
75 namespace battor { | 72 namespace battor { |
76 | 73 |
77 // Wrapper class containing all state necessary for an independent binary to | 74 // Wrapper class containing all state necessary for an independent binary to |
78 // use a BattOrAgent to communicate with a BattOr. | 75 // use a BattOrAgent to communicate with a BattOr. |
79 class BattOrAgentBin : public BattOrAgent::Listener { | 76 class BattOrAgentBin : public BattOrAgent::Listener { |
80 public: | 77 public: |
81 BattOrAgentBin() | 78 BattOrAgentBin() |
82 : done_(false, false), | 79 : done_(false, false), |
83 io_thread_(kIoThreadName), | 80 io_thread_(kIoThreadName), |
84 file_thread_(kFileThreadName), | 81 file_thread_(kFileThreadName), |
85 ui_thread_(kUiThreadName) {} | 82 ui_thread_(kUiThreadName) {} |
86 | 83 |
87 ~BattOrAgentBin() { | 84 ~BattOrAgentBin() { DCHECK(!agent_); } |
88 DCHECK(!agent_); | |
89 } | |
90 | 85 |
91 // Runs the BattOr binary and returns the exit code. | 86 // Runs the BattOr binary and returns the exit code. |
92 int Run(int argc, char* argv[]) { | 87 int Run(int argc, char* argv[]) { |
93 std::string cmd = GetArg(1, argc, argv); | 88 std::string cmd = GetArg(1, argc, argv); |
94 | 89 |
95 // SupportsExplicitClockSync doesn't need to use the serial connection, so | 90 // SupportsExplicitClockSync doesn't need to use the serial connection, so |
96 // handle it separately. | 91 // handle it separately. |
97 if (cmd == "SupportsExplicitClockSync") { | 92 if (cmd == "SupportsExplicitClockSync") { |
98 PrintSupportsExplicitClockSync(); | 93 PrintSupportsExplicitClockSync(); |
99 return 0; | 94 return 0; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 scoped_ptr<BattOrAgent> agent_; | 206 scoped_ptr<BattOrAgent> agent_; |
212 }; | 207 }; |
213 | 208 |
214 } // namespace battor | 209 } // namespace battor |
215 | 210 |
216 int main(int argc, char* argv[]) { | 211 int main(int argc, char* argv[]) { |
217 base::AtExitManager exit_manager; | 212 base::AtExitManager exit_manager; |
218 battor::BattOrAgentBin bin; | 213 battor::BattOrAgentBin bin; |
219 return bin.Run(argc, argv); | 214 return bin.Run(argc, argv); |
220 } | 215 } |
OLD | NEW |