-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch Connections to use
ValueSet
s to initialize them (#10184)
####⚠️ targets #10051 ## Summary of the Pull Request This PR does one big, primary thing. It removes all the constructors from any TerminalConnections, and changes them to use an `Initialize` method that accepts a `ValueSet` of properties. Why? For the upcoming window/content process work, we'll need the content process to be able to initialize the connection _in the content process_. However, the window process will be the one that knows what type of connection to make. Enter `ConnectionInformation`. This class will let us specify the class name of the type we want to create, and a set of settings to use when initializing that connection. **IMPORTANT**: As a part of this, the constructor for a connection must have 0 arguments. `RoActivateInstance` lets you just conjure a WinRT type just by class name, but that class must have a 0 arg ctor. Hence the need for `Initialize`, to actually pass the settings. We're using a `ValueSet` here because it's basically a json blob, with more steps. In the future, when extension authors want to have custom connections, we can always deserialize the json into a `ValueSet`, pass it to their connection's `Initialize`, and let then get what they need out of it. ## References * Tear-out: #1256 * Megathread: #5000 * Project: https://github.com/microsoft/terminal/projects/5 ## PR Checklist * [x] Closes https://github.com/microsoft/terminal/projects/5#card-50760298 * [x] I work here * [n/a] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments `ConnectionInformation` was included as a part of this PR, to demonstrate how this will eventually be used. `ConnectionInformation` is not _currently_ used. ## Validation Steps Performed It still builds and runs.
- Loading branch information
1 parent
b05a557
commit 6e70c4a
Showing
24 changed files
with
304 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "pch.h" | ||
#include "ConnectionInformation.h" | ||
#include "ConnectionInformation.g.cpp" | ||
|
||
namespace winrt::Microsoft::Terminal::TerminalConnection::implementation | ||
{ | ||
ConnectionInformation::ConnectionInformation(hstring const& className, | ||
const Windows::Foundation::Collections::ValueSet& settings) : | ||
_ClassName{ className }, | ||
_Settings{ settings } | ||
{ | ||
} | ||
|
||
// Function Description: | ||
// - Create an instance of the connection specified in the | ||
// ConnectionInformation, and Initialize it. | ||
// - This static method allows the content process to create a connection | ||
// from information that lives in the window process. | ||
// Arguments: | ||
// - info: A ConnectionInformation object that possibly lives out-of-proc, | ||
// containing the name of the WinRT class we should activate for this | ||
// connection, and a bag of setting to use to initialize that object. | ||
// Return Value: | ||
// - <none> | ||
TerminalConnection::ITerminalConnection ConnectionInformation::CreateConnection(TerminalConnection::ConnectionInformation info) | ||
try | ||
{ | ||
Windows::Foundation::IInspectable inspectable{}; | ||
|
||
const auto name = static_cast<HSTRING>(winrt::get_abi(info.ClassName())); | ||
const auto pointer = winrt::put_abi(inspectable); | ||
|
||
#pragma warning(push) | ||
#pragma warning(disable : 26490) | ||
// C++/WinRT just loves it's void**, nothing we can do here _except_ reinterpret_cast | ||
::IInspectable** raw = reinterpret_cast<::IInspectable**>(pointer); | ||
#pragma warning(pop) | ||
|
||
// RoActivateInstance() will try to create an instance of the object, | ||
// who's fully qualified name is the string in Name(). | ||
// | ||
// The class has to be activatable. For the Terminal, this is easy | ||
// enough - we're not hosting anything that's not already in our | ||
// manifest, or living as a .dll & .winmd SxS. | ||
// | ||
// When we get to extensions (GH#4000), we may want to revisit. | ||
if (LOG_IF_FAILED(RoActivateInstance(name, raw))) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
// Now that thing we made, make sure it's actually a ITerminalConnection | ||
if (const auto connection{ inspectable.try_as<TerminalConnection::ITerminalConnection>() }) | ||
{ | ||
// Initialize it, and return it. | ||
connection.Initialize(info.Settings()); | ||
return connection; | ||
} | ||
return nullptr; | ||
} | ||
catch (...) | ||
{ | ||
LOG_CAUGHT_EXCEPTION(); | ||
return nullptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*++ | ||
Copyright (c) Microsoft Corporation | ||
Licensed under the MIT license. | ||
Class Name: | ||
- ConnectionInformation.h | ||
Abstract: | ||
- This is a helper object for storing both the name of a type of connection, and | ||
a bag of settings to use to initialize that connection. | ||
- This helper is used primarily in cross-proc scenarios, to allow the window | ||
process to tell the content process the name of the connection type it wants | ||
created, and how to set that connection up. This is done so the connection can | ||
live entirely in the content process, without having to go through the window | ||
process at all. | ||
--*/ | ||
|
||
#pragma once | ||
#include "../inc/cppwinrt_utils.h" | ||
#include "ConnectionInformation.g.h" | ||
|
||
namespace winrt::Microsoft::Terminal::TerminalConnection::implementation | ||
{ | ||
struct ConnectionInformation : ConnectionInformationT<ConnectionInformation> | ||
{ | ||
ConnectionInformation(hstring const& className, | ||
const Windows::Foundation::Collections::ValueSet& settings); | ||
|
||
static TerminalConnection::ITerminalConnection CreateConnection(TerminalConnection::ConnectionInformation info); | ||
|
||
winrt::hstring ClassName() const { return _ClassName; } | ||
void ClassName(const winrt::hstring& value) { _ClassName = value; } | ||
|
||
WINRT_PROPERTY(Windows::Foundation::Collections::ValueSet, Settings); | ||
|
||
private: | ||
winrt::hstring _ClassName{}; | ||
}; | ||
} | ||
namespace winrt::Microsoft::Terminal::TerminalConnection::factory_implementation | ||
{ | ||
BASIC_FACTORY(ConnectionInformation); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import "ITerminalConnection.idl"; | ||
|
||
namespace Microsoft.Terminal.TerminalConnection | ||
{ | ||
[default_interface] runtimeclass ConnectionInformation | ||
{ | ||
ConnectionInformation(String className, Windows.Foundation.Collections.ValueSet settings); | ||
String ClassName { get; }; | ||
Windows.Foundation.Collections.ValueSet Settings { get; }; | ||
|
||
static ITerminalConnection CreateConnection(ConnectionInformation info); | ||
} | ||
|
||
} |
Oops, something went wrong.