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>
19 #include <vector>
20 
21 // Other libraries and framework includes
22 // Project includes
23 
24 #include "lldb/Core/Error.h"
25 #include "lldb/Host/ConnectionFileDescriptor.h"
26 
27 namespace lldb_private {
28 
29 class FileSpec;
30 
31 namespace platform_android {
32 
33 class AdbClient
34 {
35 public:
36     using DeviceIDList = std::list<std::string>;
37 
38     static Error
39     CreateByDeviceID(const std::string &device_id, AdbClient &adb);
40 
41     AdbClient () = default;
42     explicit AdbClient (const std::string &device_id);
43 
44     const std::string&
45     GetDeviceID() const;
46 
47     Error
48     GetDevices (DeviceIDList &device_list);
49 
50     Error
51     SetPortForwarding (const uint16_t port);
52 
53     Error
54     DeletePortForwarding (const uint16_t port);
55 
56     Error
57     PullFile (const FileSpec &remote_file, const FileSpec &local_file);
58 
59     Error
60     PushFile (const FileSpec &local_file, const FileSpec &remote_file);
61 
62     Error
63     Stat (const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime);
64 
65 private:
66     Error
67     Connect ();
68 
69     void
70     SetDeviceID (const std::string &device_id);
71 
72     Error
73     SendMessage (const std::string &packet, const bool reconnect = true);
74 
75     Error
76     SendDeviceMessage (const std::string &packet);
77 
78     Error
79     SendSyncRequest (const char *request_id, const uint32_t data_len, const void *data);
80 
81     Error
82     ReadSyncHeader (std::string &response_id, uint32_t &data_len);
83 
84     Error
85     ReadMessage (std::vector<char> &message);
86 
87     Error
88     GetResponseError (const char *response_id);
89 
90     Error
91     ReadResponseStatus ();
92 
93     Error
94     SwitchDeviceTransport ();
95 
96     Error
97     Sync ();
98 
99     Error
100     StartSync ();
101 
102     Error
103     PullFileChunk (std::vector<char> &buffer, bool &eof);
104 
105     Error
106     ReadAllBytes (void *buffer, size_t size);
107 
108     std::string m_device_id;
109     ConnectionFileDescriptor m_conn;
110 };
111 
112 } // namespace platform_android
113 } // namespace lldb_private
114 
115 #endif  // liblldb_AdbClient_h_
116