1//===-- SBPlatform.h --------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SBPlatform_h_
10#define LLDB_SBPlatform_h_
11
12#include "lldb/API/SBDefines.h"
13
14#include <functional>
15
16struct PlatformConnectOptions;
17struct PlatformShellCommand;
18
19namespace lldb {
20
21class SBLaunchInfo;
22
23class LLDB_API SBPlatformConnectOptions {
24public:
25  SBPlatformConnectOptions(const char *url);
26
27  SBPlatformConnectOptions(const SBPlatformConnectOptions &rhs);
28
29  ~SBPlatformConnectOptions();
30
31  void operator=(const SBPlatformConnectOptions &rhs);
32
33  const char *GetURL();
34
35  void SetURL(const char *url);
36
37  bool GetRsyncEnabled();
38
39  void EnableRsync(const char *options, const char *remote_path_prefix,
40                   bool omit_remote_hostname);
41
42  void DisableRsync();
43
44  const char *GetLocalCacheDirectory();
45
46  void SetLocalCacheDirectory(const char *path);
47
48protected:
49  PlatformConnectOptions *m_opaque_ptr;
50};
51
52class LLDB_API SBPlatformShellCommand {
53public:
54  SBPlatformShellCommand(const char *shell_command);
55
56  SBPlatformShellCommand(const SBPlatformShellCommand &rhs);
57
58  ~SBPlatformShellCommand();
59
60  void Clear();
61
62  const char *GetCommand();
63
64  void SetCommand(const char *shell_command);
65
66  const char *GetWorkingDirectory();
67
68  void SetWorkingDirectory(const char *path);
69
70  uint32_t GetTimeoutSeconds();
71
72  void SetTimeoutSeconds(uint32_t sec);
73
74  int GetSignal();
75
76  int GetStatus();
77
78  const char *GetOutput();
79
80protected:
81  friend class SBPlatform;
82
83  PlatformShellCommand *m_opaque_ptr;
84};
85
86class LLDB_API SBPlatform {
87public:
88  SBPlatform();
89
90  SBPlatform(const char *platform_name);
91
92  ~SBPlatform();
93
94  explicit operator bool() const;
95
96  bool IsValid() const;
97
98  void Clear();
99
100  const char *GetWorkingDirectory();
101
102  bool SetWorkingDirectory(const char *path);
103
104  const char *GetName();
105
106  SBError ConnectRemote(SBPlatformConnectOptions &connect_options);
107
108  void DisconnectRemote();
109
110  bool IsConnected();
111
112  // The following functions will work if the platform is connected
113  const char *GetTriple();
114
115  const char *GetHostname();
116
117  const char *GetOSBuild();
118
119  const char *GetOSDescription();
120
121  uint32_t GetOSMajorVersion();
122
123  uint32_t GetOSMinorVersion();
124
125  uint32_t GetOSUpdateVersion();
126
127  SBError Put(SBFileSpec &src, SBFileSpec &dst);
128
129  SBError Get(SBFileSpec &src, SBFileSpec &dst);
130
131  SBError Install(SBFileSpec &src, SBFileSpec &dst);
132
133  SBError Run(SBPlatformShellCommand &shell_command);
134
135  SBError Launch(SBLaunchInfo &launch_info);
136
137  SBError Kill(const lldb::pid_t pid);
138
139  SBError
140  MakeDirectory(const char *path,
141                uint32_t file_permissions = eFilePermissionsDirectoryDefault);
142
143  uint32_t GetFilePermissions(const char *path);
144
145  SBError SetFilePermissions(const char *path, uint32_t file_permissions);
146
147  SBUnixSignals GetUnixSignals() const;
148
149protected:
150  friend class SBDebugger;
151  friend class SBTarget;
152
153  lldb::PlatformSP GetSP() const;
154
155  void SetSP(const lldb::PlatformSP &platform_sp);
156
157  SBError ExecuteConnected(
158      const std::function<lldb_private::Status(const lldb::PlatformSP &)>
159          &func);
160
161  lldb::PlatformSP m_opaque_sp;
162};
163
164} // namespace lldb
165
166#endif // LLDB_SBPlatform_h_
167