Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: tools/battor_agent/battor_agent_bin.cc

Issue 1642763002: tools/battor_agent: Adds a tool to find connected BattOrs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/battor_agent/battor_agent.gyp ('k') | tools/battor_agent/battor_agent_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/battor_agent/battor_agent_bin.cc
diff --git a/tools/battor_agent/battor_agent_bin.cc b/tools/battor_agent/battor_agent_bin.cc
index 360146dd39d81771ec4d0d8779fa84e99147d973..93036e2fcb9b37a4be51a8cca2b97d2aea950f76 100644
--- a/tools/battor_agent/battor_agent_bin.cc
+++ b/tools/battor_agent/battor_agent_bin.cc
@@ -19,6 +19,7 @@
#include "base/threading/thread.h"
#include "tools/battor_agent/battor_agent.h"
#include "tools/battor_agent/battor_error.h"
+#include "tools/battor_agent/battor_finder.h"
using std::cout;
using std::endl;
@@ -47,12 +48,11 @@ void PrintSupportsExplicitClockSync() {
cout << battor::BattOrAgent::SupportsExplicitClockSync() << endl;
}
-// Retrieves argument argnum from the argument list, printing the usage
-// guidelines and exiting with an error code if the argument doesn't exist.
+// Retrieves argument argnum from the argument list, or an empty string if the
+// argument doesn't exist.
std::string GetArg(int argnum, int argc, char* argv[]) {
if (argnum >= argc) {
- PrintUsage();
- exit(1);
+ return std::string();
}
return argv[argnum];
@@ -89,6 +89,10 @@ class BattOrAgentBin : public BattOrAgent::Listener {
// Runs the BattOr binary and returns the exit code.
int Run(int argc, char* argv[]) {
std::string cmd = GetArg(1, argc, argv);
+ if (cmd.empty()) {
+ PrintUsage();
+ exit(1);
+ }
// SupportsExplicitClockSync doesn't need to use the serial connection, so
// handle it separately.
@@ -98,6 +102,18 @@ class BattOrAgentBin : public BattOrAgent::Listener {
}
std::string path = GetArg(2, argc, argv);
+ // If no path is specified, see if we can find a BattOr and use that.
+ if (path.empty())
+ path = BattOrFinder::FindBattOr();
+
+ // If we don't have any BattOr to use, exit.
+ if (path.empty()) {
+ cout << "Unable to find a BattOr, and no explicit BattOr path was "
+ "specified."
+ << endl;
+ exit(1);
+ }
+
SetUp(path);
if (cmd == "StartTracing") {
« no previous file with comments | « tools/battor_agent/battor_agent.gyp ('k') | tools/battor_agent/battor_agent_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698