LLDB mainline
File.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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_HOST_FILE_H
10#define LLDB_HOST_FILE_H
11
12#include "lldb/Host/FileBase.h"
13#include "lldb/Host/Terminal.h"
14
15#include <memory>
16#include <optional>
17
18#if defined(_WIN32)
20#else
22#endif
23
24namespace lldb_private {
25
26#if defined(_WIN32)
28#else
30#endif
31
32class SerialPort : public NativeFile {
33public:
34 struct Options {
35 std::optional<unsigned int> BaudRate;
36 std::optional<Terminal::Parity> Parity;
37 std::optional<Terminal::ParityCheck> ParityCheck;
38 std::optional<unsigned int> StopBits;
39 };
40
41 // Obtain Options corresponding to the passed URL query string
42 // (i.e. the part after '?').
43 static llvm::Expected<Options> OptionsFromURL(llvm::StringRef urlqs);
44
45 static llvm::Expected<std::unique_ptr<SerialPort>>
46 Create(int fd, OpenOptions options, Options serial_options,
47 bool transfer_ownership);
48
49 bool IsValid() const override {
51 }
52
53 Status Close() override;
54
55 static char ID;
56 bool isA(const void *classID) const override {
57 return classID == &ID || NativeFile::isA(classID);
58 }
59 static bool classof(const File *file) { return file->isA(&ID); }
60
61private:
62 SerialPort(int fd, OpenOptions options, Options serial_options,
63 bool transfer_ownership);
64
65 SerialPort(const SerialPort &) = delete;
66 const SerialPort &operator=(const SerialPort &) = delete;
67
69};
70
71} // namespace lldb_private
72
73#endif // LLDB_HOST_FILE_H
An abstract base class for files.
Definition FileBase.h:34
virtual bool isA(const void *classID) const
Definition FileBase.h:363
LazyBool m_is_interactive
Definition FileBase.h:367
bool IsValid() const override
IsValid.
Definition File.cpp:106
POSIX implementation of NativeFile.
Definition FilePosix.h:18
bool isA(const void *classID) const override
Definition FilePosix.h:38
Windows implementation of NativeFile.
Definition FileWindows.h:18
A command line option parsing protocol class.
Definition Options.h:58
SerialPort(const SerialPort &)=delete
static llvm::Expected< std::unique_ptr< SerialPort > > Create(int fd, OpenOptions options, Options serial_options, bool transfer_ownership)
Definition File.cpp:695
TerminalState m_state
Definition File.h:68
SerialPort(int fd, OpenOptions options, Options serial_options, bool transfer_ownership)
Definition File.cpp:727
const SerialPort & operator=(const SerialPort &)=delete
Status Close() override
Flush any buffers and release any resources owned by the file.
Definition File.cpp:732
bool IsValid() const override
IsValid.
Definition File.h:49
static bool classof(const File *file)
Definition File.h:59
static char ID
Definition File.h:55
bool isA(const void *classID) const override
Definition File.h:56
static llvm::Expected< Options > OptionsFromURL(llvm::StringRef urlqs)
Definition File.cpp:640
An error handling class.
Definition Status.h:118
A RAII-friendly terminal state saving/restoring class.
Definition Terminal.h:99
A class that represents a running process on the host machine.
NativeFilePosix NativeFile
Definition File.h:29
std::optional< Terminal::ParityCheck > ParityCheck
Definition File.h:37
std::optional< unsigned int > StopBits
Definition File.h:38
std::optional< Terminal::Parity > Parity
Definition File.h:36
std::optional< unsigned int > BaudRate
Definition File.h:35