2019-05-03 00:29:04 +02:00
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "ConptyConnection.g.h"
|
2019-11-07 00:09:01 +01:00
|
|
|
|
|
|
|
|
|
namespace wil
|
|
|
|
|
{
|
|
|
|
|
// These belong in WIL upstream, so when we reingest the change that has them we'll get rid of ours.
|
|
|
|
|
using unique_pseudoconsole_handle = wil::unique_any<HPCON, decltype(&::ClosePseudoConsole), ::ClosePseudoConsole>;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
|
namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
|
|
|
|
{
|
|
|
|
|
struct ConptyConnection : ConptyConnectionT<ConptyConnection>
|
|
|
|
|
{
|
2019-11-07 00:09:01 +01:00
|
|
|
|
ConptyConnection(const hstring& cmdline, const hstring& startingDirectory, const hstring& startingTitle, const uint32_t rows, const uint32_t cols, const guid& guid);
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
|
|
winrt::event_token TerminalOutput(TerminalConnection::TerminalOutputEventArgs const& handler);
|
|
|
|
|
void TerminalOutput(winrt::event_token const& token) noexcept;
|
|
|
|
|
winrt::event_token TerminalDisconnected(TerminalConnection::TerminalDisconnectedEventArgs const& handler);
|
|
|
|
|
void TerminalDisconnected(winrt::event_token const& token) noexcept;
|
|
|
|
|
void Start();
|
|
|
|
|
void WriteInput(hstring const& data);
|
|
|
|
|
void Resize(uint32_t rows, uint32_t columns);
|
|
|
|
|
void Close();
|
|
|
|
|
|
2019-11-07 00:09:01 +01:00
|
|
|
|
winrt::guid Guid() const noexcept;
|
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
|
private:
|
2019-11-07 00:09:01 +01:00
|
|
|
|
HRESULT _LaunchAttachedClient() noexcept;
|
|
|
|
|
void _ClientTerminated() noexcept;
|
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
|
winrt::event<TerminalConnection::TerminalOutputEventArgs> _outputHandlers;
|
2019-11-07 00:09:01 +01:00
|
|
|
|
winrt::event<TerminalConnection::TerminalDisconnectedEventArgs> _disconnectHandlers;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
2019-11-07 00:09:01 +01:00
|
|
|
|
uint32_t _initialRows{};
|
|
|
|
|
uint32_t _initialCols{};
|
2019-05-03 00:29:04 +02:00
|
|
|
|
hstring _commandline;
|
2019-11-07 00:09:01 +01:00
|
|
|
|
hstring _startingDirectory;
|
|
|
|
|
hstring _startingTitle;
|
|
|
|
|
guid _guid{}; // A unique session identifier for connected client
|
|
|
|
|
|
|
|
|
|
bool _connected{};
|
|
|
|
|
std::atomic<bool> _closing{ false };
|
|
|
|
|
bool _recievedFirstByte{ false };
|
|
|
|
|
std::chrono::high_resolution_clock::time_point _startTime{};
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
2019-11-07 00:09:01 +01:00
|
|
|
|
wil::unique_hfile _inPipe; // The pipe for writing input to
|
|
|
|
|
wil::unique_hfile _outPipe; // The pipe for reading output from
|
|
|
|
|
wil::unique_handle _hOutputThread;
|
|
|
|
|
wil::unique_process_information _piClient;
|
|
|
|
|
wil::unique_pseudoconsole_handle _hPC;
|
|
|
|
|
wil::unique_threadpool_wait _clientExitWait;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
|
|
DWORD _OutputThread();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace winrt::Microsoft::Terminal::TerminalConnection::factory_implementation
|
|
|
|
|
{
|
|
|
|
|
struct ConptyConnection : ConptyConnectionT<ConptyConnection, implementation::ConptyConnection>
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
}
|