Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 1 | //===-- 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 Vyalov | 09e9079d | 2015-05-18 23:44:06 +0000 | [diff] [blame] | 19 | #include <vector> |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 20 | |
| 21 | // Other libraries and framework includes |
| 22 | // Project includes |
| 23 | |
| 24 | #include "lldb/Core/Error.h" |
Oleksiy Vyalov | 6f00106 | 2015-03-25 17:58:13 +0000 | [diff] [blame] | 25 | #include "lldb/Host/ConnectionFileDescriptor.h" |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 26 | |
| 27 | namespace lldb_private { |
Oleksiy Vyalov | 0b5ebef | 2015-05-28 17:42:48 +0000 | [diff] [blame] | 28 | |
| 29 | class FileSpec; |
| 30 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 31 | namespace platform_android { |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 32 | |
| 33 | class AdbClient |
| 34 | { |
| 35 | public: |
Oleksiy Vyalov | e7df5f5 | 2015-11-03 01:37:01 +0000 | [diff] [blame] | 36 | enum UnixSocketNamespace |
| 37 | { |
| 38 | UnixSocketNamespaceAbstract, |
| 39 | UnixSocketNamespaceFileSystem, |
| 40 | }; |
| 41 | |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 42 | using DeviceIDList = std::list<std::string>; |
| 43 | |
Oleksiy Vyalov | 6f00106 | 2015-03-25 17:58:13 +0000 | [diff] [blame] | 44 | static Error |
Chaoren Lin | 3ea689b | 2015-05-01 16:49:28 +0000 | [diff] [blame] | 45 | CreateByDeviceID(const std::string &device_id, AdbClient &adb); |
Oleksiy Vyalov | 6f00106 | 2015-03-25 17:58:13 +0000 | [diff] [blame] | 46 | |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 47 | AdbClient () = default; |
| 48 | explicit AdbClient (const std::string &device_id); |
| 49 | |
Oleksiy Vyalov | 6f00106 | 2015-03-25 17:58:13 +0000 | [diff] [blame] | 50 | const std::string& |
| 51 | GetDeviceID() const; |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 52 | |
| 53 | Error |
| 54 | GetDevices (DeviceIDList &device_list); |
| 55 | |
| 56 | Error |
Oleksiy Vyalov | e7eabbb | 2015-09-01 19:02:14 +0000 | [diff] [blame] | 57 | SetPortForwarding (const uint16_t local_port, const uint16_t remote_port); |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 58 | |
| 59 | Error |
Oleksiy Vyalov | e7df5f5 | 2015-11-03 01:37:01 +0000 | [diff] [blame] | 60 | SetPortForwarding (const uint16_t local_port, |
| 61 | const char* remote_socket_name, |
| 62 | const UnixSocketNamespace socket_namespace); |
Oleksiy Vyalov | 9fe526c | 2015-10-21 19:34:26 +0000 | [diff] [blame] | 63 | |
| 64 | Error |
Oleksiy Vyalov | e7eabbb | 2015-09-01 19:02:14 +0000 | [diff] [blame] | 65 | DeletePortForwarding (const uint16_t local_port); |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 66 | |
Oleksiy Vyalov | 09e9079d | 2015-05-18 23:44:06 +0000 | [diff] [blame] | 67 | Error |
Oleksiy Vyalov | 0b5ebef | 2015-05-28 17:42:48 +0000 | [diff] [blame] | 68 | PullFile (const FileSpec &remote_file, const FileSpec &local_file); |
Oleksiy Vyalov | 09e9079d | 2015-05-18 23:44:06 +0000 | [diff] [blame] | 69 | |
Robert Flack | 62efb1f | 2015-05-27 02:18:50 +0000 | [diff] [blame] | 70 | Error |
Oleksiy Vyalov | 0b5ebef | 2015-05-28 17:42:48 +0000 | [diff] [blame] | 71 | PushFile (const FileSpec &local_file, const FileSpec &remote_file); |
Robert Flack | 62efb1f | 2015-05-27 02:18:50 +0000 | [diff] [blame] | 72 | |
Oleksiy Vyalov | 6002a31 | 2015-06-05 01:32:45 +0000 | [diff] [blame] | 73 | Error |
| 74 | Stat (const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime); |
| 75 | |
Tamas Berghammer | 9d8dde8 | 2015-09-29 11:04:18 +0000 | [diff] [blame] | 76 | Error |
| 77 | Shell (const char* command, uint32_t timeout_ms, std::string* output); |
| 78 | |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 79 | private: |
| 80 | Error |
| 81 | Connect (); |
| 82 | |
Oleksiy Vyalov | 6f00106 | 2015-03-25 17:58:13 +0000 | [diff] [blame] | 83 | void |
Oleksiy Vyalov | 09e9079d | 2015-05-18 23:44:06 +0000 | [diff] [blame] | 84 | SetDeviceID (const std::string &device_id); |
Oleksiy Vyalov | 6f00106 | 2015-03-25 17:58:13 +0000 | [diff] [blame] | 85 | |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 86 | Error |
Oleksiy Vyalov | 09e9079d | 2015-05-18 23:44:06 +0000 | [diff] [blame] | 87 | SendMessage (const std::string &packet, const bool reconnect = true); |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 88 | |
| 89 | Error |
| 90 | SendDeviceMessage (const std::string &packet); |
| 91 | |
| 92 | Error |
Oleksiy Vyalov | 09e9079d | 2015-05-18 23:44:06 +0000 | [diff] [blame] | 93 | 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 Berghammer | 9d8dde8 | 2015-09-29 11:04:18 +0000 | [diff] [blame] | 102 | ReadMessageStream (std::vector<char> &message, uint32_t timeout_ms); |
| 103 | |
| 104 | Error |
Oleksiy Vyalov | 09e9079d | 2015-05-18 23:44:06 +0000 | [diff] [blame] | 105 | GetResponseError (const char *response_id); |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 106 | |
| 107 | Error |
| 108 | ReadResponseStatus (); |
| 109 | |
Oleksiy Vyalov | 09e9079d | 2015-05-18 23:44:06 +0000 | [diff] [blame] | 110 | Error |
| 111 | SwitchDeviceTransport (); |
| 112 | |
| 113 | Error |
| 114 | Sync (); |
| 115 | |
| 116 | Error |
Oleksiy Vyalov | 0b5ebef | 2015-05-28 17:42:48 +0000 | [diff] [blame] | 117 | StartSync (); |
| 118 | |
| 119 | Error |
Oleksiy Vyalov | 09e9079d | 2015-05-18 23:44:06 +0000 | [diff] [blame] | 120 | PullFileChunk (std::vector<char> &buffer, bool &eof); |
| 121 | |
| 122 | Error |
| 123 | ReadAllBytes (void *buffer, size_t size); |
| 124 | |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 125 | std::string m_device_id; |
| 126 | ConnectionFileDescriptor m_conn; |
| 127 | }; |
| 128 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 129 | } // namespace platform_android |
Oleksiy Vyalov | 05a55de | 2015-03-23 21:03:02 +0000 | [diff] [blame] | 130 | } // namespace lldb_private |
| 131 | |
| 132 | #endif // liblldb_AdbClient_h_ |