blob: 43aa1db678fae2e34cee10d75f13504c38e3dae5 [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 Vyalov9fe526c2015-10-21 19:34:26 +000054 SetPortForwarding (const uint16_t local_port, const char* remote_socket_name);
55
56 Error
Oleksiy Vyalove7eabbb2015-09-01 19:02:14 +000057 DeletePortForwarding (const uint16_t local_port);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000058
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000059 Error
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +000060 PullFile (const FileSpec &remote_file, const FileSpec &local_file);
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000061
Robert Flack62efb1f2015-05-27 02:18:50 +000062 Error
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +000063 PushFile (const FileSpec &local_file, const FileSpec &remote_file);
Robert Flack62efb1f2015-05-27 02:18:50 +000064
Oleksiy Vyalov6002a312015-06-05 01:32:45 +000065 Error
66 Stat (const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime);
67
Tamas Berghammer9d8dde82015-09-29 11:04:18 +000068 Error
69 Shell (const char* command, uint32_t timeout_ms, std::string* output);
70
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000071private:
72 Error
73 Connect ();
74
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000075 void
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000076 SetDeviceID (const std::string &device_id);
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000077
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000078 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000079 SendMessage (const std::string &packet, const bool reconnect = true);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000080
81 Error
82 SendDeviceMessage (const std::string &packet);
83
84 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000085 SendSyncRequest (const char *request_id, const uint32_t data_len, const void *data);
86
87 Error
88 ReadSyncHeader (std::string &response_id, uint32_t &data_len);
89
90 Error
91 ReadMessage (std::vector<char> &message);
92
93 Error
Tamas Berghammer9d8dde82015-09-29 11:04:18 +000094 ReadMessageStream (std::vector<char> &message, uint32_t timeout_ms);
95
96 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000097 GetResponseError (const char *response_id);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000098
99 Error
100 ReadResponseStatus ();
101
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +0000102 Error
103 SwitchDeviceTransport ();
104
105 Error
106 Sync ();
107
108 Error
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +0000109 StartSync ();
110
111 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +0000112 PullFileChunk (std::vector<char> &buffer, bool &eof);
113
114 Error
115 ReadAllBytes (void *buffer, size_t size);
116
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +0000117 std::string m_device_id;
118 ConnectionFileDescriptor m_conn;
119};
120
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000121} // namespace platform_android
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +0000122} // namespace lldb_private
123
124#endif // liblldb_AdbClient_h_