[UWP] Basic console panel

This commit is contained in:
Paul Rouget 2020-06-17 11:36:04 +02:00 committed by Josh Matthews
parent 2560e78f11
commit bd8c7d6f4d
9 changed files with 400 additions and 33 deletions

View file

@ -0,0 +1,57 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#pragma once
#include "pch.h"
namespace winrt::servo {
using namespace winrt::Windows::Storage::Streams;
using namespace winrt::Windows::Data::Json;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Networking::Sockets;
class DevtoolsDelegate;
enum DevtoolsMessageLevel { Error, Warn, None };
class DevtoolsClient {
public:
DevtoolsClient(hstring hostname, hstring port, DevtoolsDelegate &d)
: mDelegate(d), mHostname(hostname), mPort(port){};
~DevtoolsClient() { Stop(); }
void Run();
void Stop();
void Send(JsonObject);
private:
hstring mPort;
hstring mHostname;
DevtoolsDelegate &mDelegate;
std::optional<DataReader> mDataReader;
std::optional<DataWriter> mDataWriter;
std::optional<IAsyncAction> mReceiveOp;
std::vector<JsonObject> mPendingObjects;
IAsyncOperation<unsigned int> mReaderOp;
bool mSending = false;
bool mReceiving = false;
void SendPendingObjects();
IAsyncAction Loop();
DevtoolsMessageLevel ParseLevel(JsonObject);
hstring ParseSource(JsonObject);
void HandleMessage(JsonObject);
void HandlePageError(JsonObject);
void HandleConsoleMessage(JsonObject);
void HandleNonHandledMessage(JsonObject);
};
class DevtoolsDelegate {
public:
virtual void OnDevtoolsMessage(DevtoolsMessageLevel, hstring, hstring) = 0;
virtual void OnDevtoolsDetached() = 0;
};
} // namespace winrt::servo