brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 633ebeb Raw
86 lines · c
1//===-- FifoFiles.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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_TOOLS_LLDB_DAP_FIFOFILES_H10#define LLDB_TOOLS_LLDB_DAP_FIFOFILES_H11 12#include "llvm/Support/Error.h"13#include "llvm/Support/JSON.h"14 15#include <chrono>16 17namespace lldb_dap {18 19/// Struct that controls the life of a fifo file in the filesystem.20///21/// The file is destroyed when the destructor is invoked.22struct FifoFile {23  FifoFile(llvm::StringRef path);24 25  ~FifoFile();26 27  std::string m_path;28};29 30/// Create a fifo file in the filesystem.31///32/// \param[in] path33///     The path for the fifo file.34///35/// \return36///     A \a std::shared_ptr<FifoFile> if the file could be created, or an37///     \a llvm::Error in case of failures.38llvm::Expected<std::shared_ptr<FifoFile>> CreateFifoFile(llvm::StringRef path);39 40class FifoFileIO {41public:42  /// \param[in] fifo_file43  ///     The path to an input fifo file that exists in the file system.44  ///45  /// \param[in] other_endpoint_name46  ///     A human readable name for the other endpoint that will communicate47  ///     using this file. This is used for error messages.48  FifoFileIO(llvm::StringRef fifo_file, llvm::StringRef other_endpoint_name);49 50  /// Read the next JSON object from the underlying input fifo file.51  ///52  /// The JSON object is expected to be a single line delimited with \a53  /// std::endl.54  ///55  /// \return56  ///     An \a llvm::Error object indicating the success or failure of this57  ///     operation. Failures arise if the timeout is hit, the next line of text58  ///     from the fifo file is not a valid JSON object, or is it impossible to59  ///     read from the file.60  llvm::Expected<llvm::json::Value> ReadJSON(std::chrono::milliseconds timeout);61 62  /// Serialize a JSON object and write it to the underlying output fifo file.63  ///64  /// \param[in] json65  ///     The JSON object to send. It will be printed as a single line delimited66  ///     with \a std::endl.67  ///68  /// \param[in] timeout69  ///     A timeout for how long we should until for the data to be consumed.70  ///71  /// \return72  ///     An \a llvm::Error object indicating whether the data was consumed by73  ///     a reader or not.74  llvm::Error SendJSON(75      const llvm::json::Value &json,76      std::chrono::milliseconds timeout = std::chrono::milliseconds(20000));77 78private:79  std::string m_fifo_file;80  std::string m_other_endpoint_name;81};82 83} // namespace lldb_dap84 85#endif // LLDB_TOOLS_LLDB_DAP_FIFOFILES_H86