blob: 25a72640c6ca97abe5ca4077395efab52881e188 [file] [log] [blame]
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +00001//===-- AdbClient.h ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_AdbClient_h_
11#define liblldb_AdbClient_h_
12
13// C Includes
14
15// C++ Includes
16
17#include <list>
18#include <string>
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000019#include <vector>
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000020
21// Other libraries and framework includes
22// Project includes
23
24#include "lldb/Core/Error.h"
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000025#include "lldb/Host/ConnectionFileDescriptor.h"
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000026
27namespace lldb_private {
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +000028
29class FileSpec;
30
Tamas Berghammerdb264a62015-03-31 09:52:22 +000031namespace platform_android {
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000032
33class AdbClient
34{
35public:
36 using DeviceIDList = std::list<std::string>;
37
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000038 static Error
Chaoren Lin3ea689b2015-05-01 16:49:28 +000039 CreateByDeviceID(const std::string &device_id, AdbClient &adb);
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000040
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000041 AdbClient () = default;
42 explicit AdbClient (const std::string &device_id);
43
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000044 const std::string&
45 GetDeviceID() const;
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000046
47 Error
48 GetDevices (DeviceIDList &device_list);
49
50 Error
Oleksiy Vyalove7eabbb2015-09-01 19:02:14 +000051 SetPortForwarding (const uint16_t local_port, const uint16_t remote_port);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000052
53 Error
Oleksiy Vyalove7eabbb2015-09-01 19:02:14 +000054 DeletePortForwarding (const uint16_t local_port);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000055
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000056 Error
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +000057 PullFile (const FileSpec &remote_file, const FileSpec &local_file);
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000058
Robert Flack62efb1f2015-05-27 02:18:50 +000059 Error
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +000060 PushFile (const FileSpec &local_file, const FileSpec &remote_file);
Robert Flack62efb1f2015-05-27 02:18:50 +000061
Oleksiy Vyalov6002a312015-06-05 01:32:45 +000062 Error
63 Stat (const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime);
64
Tamas Berghammer9d8dde82015-09-29 11:04:18 +000065 Error
66 Shell (const char* command, uint32_t timeout_ms, std::string* output);
67
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000068private:
69 Error
70 Connect ();
71
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000072 void
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000073 SetDeviceID (const std::string &device_id);
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000074
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000075 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000076 SendMessage (const std::string &packet, const bool reconnect = true);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000077
78 Error
79 SendDeviceMessage (const std::string &packet);
80
81 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000082 SendSyncRequest (const char *request_id, const uint32_t data_len, const void *data);
83
84 Error
85 ReadSyncHeader (std::string &response_id, uint32_t &data_len);
86
87 Error
88 ReadMessage (std::vector<char> &message);
89
90 Error
Tamas Berghammer9d8dde82015-09-29 11:04:18 +000091 ReadMessageStream (std::vector<char> &message, uint32_t timeout_ms);
92
93 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000094 GetResponseError (const char *response_id);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000095
96 Error
97 ReadResponseStatus ();
98
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000099 Error
100 SwitchDeviceTransport ();
101
102 Error
103 Sync ();
104
105 Error
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +0000106 StartSync ();
107
108 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +0000109 PullFileChunk (std::vector<char> &buffer, bool &eof);
110
111 Error
112 ReadAllBytes (void *buffer, size_t size);
113
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +0000114 std::string m_device_id;
115 ConnectionFileDescriptor m_conn;
116};
117
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000118} // namespace platform_android
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +0000119} // namespace lldb_private
120
121#endif // liblldb_AdbClient_h_