180814287SRaphael Isemann //===-- StreamAsynchronousIO.cpp ------------------------------------------===//
2969ed3d1SCaroline Tice //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6969ed3d1SCaroline Tice //
7969ed3d1SCaroline Tice //===----------------------------------------------------------------------===//
8969ed3d1SCaroline Tice 
94446487dSPavel Labath #include "lldb/Core/StreamAsynchronousIO.h"
10969ed3d1SCaroline Tice 
114446487dSPavel Labath #include "lldb/Core/Debugger.h"
12672d2c12SJonas Devlieghere #include "lldb/lldb-enumerations.h"
13969ed3d1SCaroline Tice 
14969ed3d1SCaroline Tice using namespace lldb;
15969ed3d1SCaroline Tice using namespace lldb_private;
16969ed3d1SCaroline Tice 
StreamAsynchronousIO(Debugger & debugger,bool for_stdout,bool colors)17*990d0c71SJonas Devlieghere StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout,
18*990d0c71SJonas Devlieghere                                            bool colors)
19*990d0c71SJonas Devlieghere     : Stream(0, 4, eByteOrderBig, colors), m_debugger(debugger), m_data(),
20b9c1b51eSKate Stone       m_for_stdout(for_stdout) {}
21969ed3d1SCaroline Tice 
~StreamAsynchronousIO()22b9c1b51eSKate Stone StreamAsynchronousIO::~StreamAsynchronousIO() {
2344d93782SGreg Clayton   // Flush when we destroy to make sure we display the data
2444d93782SGreg Clayton   Flush();
25969ed3d1SCaroline Tice }
26969ed3d1SCaroline Tice 
Flush()27b9c1b51eSKate Stone void StreamAsynchronousIO::Flush() {
28b9c1b51eSKate Stone   if (!m_data.empty()) {
294446487dSPavel Labath     m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout);
303a29f8b9SPavel Labath     m_data = std::string();
31969ed3d1SCaroline Tice   }
32969ed3d1SCaroline Tice }
33969ed3d1SCaroline Tice 
WriteImpl(const void * s,size_t length)3492b16738SRaphael Isemann size_t StreamAsynchronousIO::WriteImpl(const void *s, size_t length) {
354446487dSPavel Labath   m_data.append((const char *)s, length);
36969ed3d1SCaroline Tice   return length;
37969ed3d1SCaroline Tice }
38