Use more chrono in AdbClient

This refactors AdbClient interface in terms of std::chrono.

llvm-svn: 287880
This commit is contained in:
Pavel Labath 2016-11-24 14:11:47 +00:00
parent 818dd516da
commit ce255ff26a
3 changed files with 13 additions and 11 deletions

View File

@ -383,10 +383,10 @@ Error AdbClient::internalShell(const char *command, milliseconds timeout,
return Error();
}
Error AdbClient::Shell(const char *command, uint32_t timeout_ms,
Error AdbClient::Shell(const char *command, milliseconds timeout,
std::string *output) {
std::vector<char> output_buffer;
auto error = internalShell(command, milliseconds(timeout_ms), output_buffer);
auto error = internalShell(command, timeout, output_buffer);
if (error.Fail())
return error;
@ -395,10 +395,10 @@ Error AdbClient::Shell(const char *command, uint32_t timeout_ms,
return error;
}
Error AdbClient::ShellToFile(const char *command, uint32_t timeout_ms,
Error AdbClient::ShellToFile(const char *command, milliseconds timeout,
const FileSpec &output_file_spec) {
std::vector<char> output_buffer;
auto error = internalShell(command, milliseconds(timeout_ms), output_buffer);
auto error = internalShell(command, timeout, output_buffer);
if (error.Fail())
return error;

View File

@ -94,9 +94,10 @@ public:
Error DeletePortForwarding(const uint16_t local_port);
Error Shell(const char *command, uint32_t timeout_ms, std::string *output);
Error Shell(const char *command, std::chrono::milliseconds timeout,
std::string *output);
Error ShellToFile(const char *command, uint32_t timeout_ms,
Error ShellToFile(const char *command, std::chrono::milliseconds timeout,
const FileSpec &output_file_spec);
std::unique_ptr<SyncService> GetSyncService(Error &error);

View File

@ -28,6 +28,7 @@
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::platform_android;
using namespace std::chrono;
static uint32_t g_initialize_count = 0;
static const unsigned int g_android_default_cache_size =
@ -230,7 +231,7 @@ Error PlatformAndroid::GetFile(const FileSpec &source,
char cmd[PATH_MAX];
snprintf(cmd, sizeof(cmd), "cat '%s'", source_file);
return adb.ShellToFile(cmd, 60000 /* ms */, destination);
return adb.ShellToFile(cmd, minutes(1), destination);
}
Error PlatformAndroid::PutFile(const FileSpec &source,
@ -288,7 +289,7 @@ uint32_t PlatformAndroid::GetSdkVersion() {
std::string version_string;
AdbClient adb(m_device_id);
Error error =
adb.Shell("getprop ro.build.version.sdk", 5000 /* ms */, &version_string);
adb.Shell("getprop ro.build.version.sdk", seconds(5), &version_string);
version_string = llvm::StringRef(version_string).trim().str();
if (error.Fail() || version_string.empty()) {
@ -327,7 +328,7 @@ Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
AdbClient adb(m_device_id);
std::string tmpdir;
Error error = adb.Shell("mktemp --directory --tmpdir /data/local/tmp",
5000 /* ms */, &tmpdir);
seconds(5), &tmpdir);
if (error.Fail() || tmpdir.empty())
return Error("Failed to generate temporary directory on the device (%s)",
error.AsCString());
@ -338,7 +339,7 @@ Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
tmpdir_remover(&tmpdir, [this, &adb](std::string *s) {
StreamString command;
command.Printf("rm -rf %s", s->c_str());
Error error = adb.Shell(command.GetData(), 5000 /* ms */, nullptr);
Error error = adb.Shell(command.GetData(), seconds(5), nullptr);
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (log && error.Fail())
@ -353,7 +354,7 @@ Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
command.Printf("oatdump --symbolize=%s --output=%s",
module_sp->GetPlatformFileSpec().GetCString(false),
symfile_platform_filespec.GetCString(false));
error = adb.Shell(command.GetData(), 60000 /* ms */, nullptr);
error = adb.Shell(command.GetData(), minutes(1), nullptr);
if (error.Fail())
return Error("Oatdump failed: %s", error.AsCString());