blob: 4ec411d1411ddf97e45433a26ab16165c69b2944 [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:
Oleksiy Vyalove7df5f52015-11-03 01:37:01 +000036 enum UnixSocketNamespace
37 {
38 UnixSocketNamespaceAbstract,
39 UnixSocketNamespaceFileSystem,
40 };
41
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000042 using DeviceIDList = std::list<std::string>;
43
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000044 static Error
Chaoren Lin3ea689b2015-05-01 16:49:28 +000045 CreateByDeviceID(const std::string &device_id, AdbClient &adb);
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000046
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000047 AdbClient () = default;
48 explicit AdbClient (const std::string &device_id);
49
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000050 const std::string&
51 GetDeviceID() const;
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000052
53 Error
54 GetDevices (DeviceIDList &device_list);
55
56 Error
Oleksiy Vyalove7eabbb2015-09-01 19:02:14 +000057 SetPortForwarding (const uint16_t local_port, const uint16_t remote_port);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000058
59 Error
Oleksiy Vyalove7df5f52015-11-03 01:37:01 +000060 SetPortForwarding (const uint16_t local_port,
61 const char* remote_socket_name,
62 const UnixSocketNamespace socket_namespace);
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +000063
64 Error
Oleksiy Vyalove7eabbb2015-09-01 19:02:14 +000065 DeletePortForwarding (const uint16_t local_port);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000066
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000067 Error
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +000068 PullFile (const FileSpec &remote_file, const FileSpec &local_file);
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000069
Robert Flack62efb1f2015-05-27 02:18:50 +000070 Error
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +000071 PushFile (const FileSpec &local_file, const FileSpec &remote_file);
Robert Flack62efb1f2015-05-27 02:18:50 +000072
Oleksiy Vyalov6002a312015-06-05 01:32:45 +000073 Error
74 Stat (const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime);
75
Tamas Berghammer9d8dde82015-09-29 11:04:18 +000076 Error
77 Shell (const char* command, uint32_t timeout_ms, std::string* output);
78
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000079private:
80 Error
81 Connect ();
82
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000083 void
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000084 SetDeviceID (const std::string &device_id);
Oleksiy Vyalov6f001062015-03-25 17:58:13 +000085
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000086 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000087 SendMessage (const std::string &packet, const bool reconnect = true);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +000088
89 Error
90 SendDeviceMessage (const std::string &packet);
91
92 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +000093 SendSyncRequest (const char *request_id, const uint32_t data_len, const void *data);
94
95 Error
96 ReadSyncHeader (std::string &response_id, uint32_t &data_len);
97
98 Error
99 ReadMessage (std::vector<char> &message);
100
101 Error
Tamas Berghammer9d8dde82015-09-29 11:04:18 +0000102 ReadMessageStream (std::vector<char> &message, uint32_t timeout_ms);
103
104 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +0000105 GetResponseError (const char *response_id);
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +0000106
107 Error
108 ReadResponseStatus ();
109
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +0000110 Error
111 SwitchDeviceTransport ();
112
113 Error
114 Sync ();
115
116 Error
Oleksiy Vyalov0b5ebef2015-05-28 17:42:48 +0000117 StartSync ();
118
119 Error
Oleksiy Vyalov09e9079d2015-05-18 23:44:06 +0000120 PullFileChunk (std::vector<char> &buffer, bool &eof);
121
122 Error
123 ReadAllBytes (void *buffer, size_t size);
124
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +0000125 std::string m_device_id;
126 ConnectionFileDescriptor m_conn;
127};
128
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000129} // namespace platform_android
Oleksiy Vyalov05a55de2015-03-23 21:03:02 +0000130} // namespace lldb_private
131
132#endif // liblldb_AdbClient_h_