Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Unity & Android #333

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CS0162: Unreachable code detected
dotnet_diagnostic.CS0162.severity = none
325 changes: 325 additions & 0 deletions Psi.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<AppxDefaultResourceQualifiers>Language=en</AppxDefaultResourceQualifiers>
<CodeAnalysisRuleSet>..\..\..\..\Build\Microsoft.Psi.ruleset</CodeAnalysisRuleSet>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down Expand Up @@ -131,6 +131,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="HoloLensCaptureApp_TemporaryKey.pfx" />
<None Include="Readme.md" />
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<Identity
Name="0e0b1c4d-d6a2-4761-8a1e-8fb7b914a071"
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, C=US"
Version="1.0.0.0" />
Publisher="CN=AurélienM"
Version="1.0.2.0" />

<mp:PhoneIdentity PhoneProductId="0e0b1c4d-d6a2-4761-8a1e-8fb7b914a071" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
12 changes: 12 additions & 0 deletions Sources/Runtime/Microsoft.Psi.Interop/Rendezvous/Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Psi.Interop.Rendezvous
using Microsoft.Psi.Interop.Serialization;
using Microsoft.Psi.Interop.Transport;
using Microsoft.Psi.Remoting;
using Microsoft.Psi.Serialization;

/// <summary>
/// Rendezvous related operators.
Expand Down Expand Up @@ -101,6 +102,17 @@ public static Rendezvous.Endpoint ToRendezvousEndpoint(this RemoteExporter expor
return endpoint;
}

/// <summary>
/// Create a <see cref="RemoteImporter"/> from a <see cref="Rendezvous.RemoteExporterEndpoint"/>.
/// </summary>
/// <param name="endpoint"><see cref="Rendezvous.RemoteExporterEndpoint"/> from which to create .</param>
/// <param name="pipeline">The pipeline to add the component to.</param>
/// <param name="storePath">Path for PsiStore.</param>
/// <param name="knownSerializers">Custom known serializers.</param>
/// <returns><see cref="RemoteImporter"/>.</returns>
public static RemoteImporter ToRemoteImporter(this Rendezvous.RemoteExporterEndpoint endpoint, Pipeline pipeline, string storePath, KnownSerializers knownSerializers)
=> new (pipeline, storePath, endpoint.Host, endpoint.Port, knownSerializers);

/// <summary>
/// Create a <see cref="RemoteImporter"/> from a <see cref="Rendezvous.RemoteExporterEndpoint"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Description>Provides APIs and components for interoperation with other data formats.</Description>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\netstandard2.0\Microsoft.Psi.Interop.xml</DocumentationFile>
<CodeAnalysisRuleSet>../../../Build/Microsoft.Psi.ruleset</CodeAnalysisRuleSet>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard2.0\Microsoft.Psi.Interop.xml</DocumentationFile>
<CodeAnalysisRuleSet>../../../Build/Microsoft.Psi.ruleset</CodeAnalysisRuleSet>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>

<ItemGroup>
<None Remove="stylecop.json" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Net.Security" Version="4.3.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Psi\Microsoft.Psi.csproj" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions Sources/Runtime/Microsoft.Psi.InteropAndroid/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Psi Interop Android

Reduced version of `Microsoft.Psi.Interop` for using RendezVous system and TCPSource/Writer in Unity for Quest headset.
Should be used with Microsoft.Psi dll from this branch to be compatible.
117 changes: 117 additions & 0 deletions Sources/Runtime/Microsoft.Psi.InteropAndroid/Rendezvous/Operators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

namespace Microsoft.Psi.Interop.Rendezvous
{
using System;
using Microsoft.Psi.Interop.Serialization;
using Microsoft.Psi.Interop.Transport;
using Microsoft.Psi.Remoting;

/// <summary>
/// Rendezvous related operators.
/// </summary>
public static class Operators
{
/// <summary>
/// Create a rendezvous endpoint from a <see cref="TcpWriter{T}"/>.
/// </summary>
/// <typeparam name="T">Type of data stream.</typeparam>
/// <param name="writer"><see cref="TcpWriter{T}"/> from which to create endpoint.</param>
/// <param name="address">Address with which to create endpoint.</param>
/// <param name="streamName">The name of the rendezvous stream.</param>
/// <returns>Rendezvous endpoint.</returns>
public static Rendezvous.Endpoint ToRendezvousEndpoint<T>(this TcpWriter<T> writer, string address, string streamName)
=> new Rendezvous.TcpSourceEndpoint(address, writer.Port, new Rendezvous.Stream(streamName, typeof(T)));

/// <summary>
/// Create a <see cref="TcpSource{T}"/> from a <see cref="Rendezvous.TcpSourceEndpoint"/>.
/// </summary>
/// <typeparam name="T">Type of data stream.</typeparam>
/// <param name="endpoint"><see cref="Rendezvous.TcpSourceEndpoint"/> from which to create .</param>
/// <param name="pipeline">The pipeline to add the component to.</param>
/// <param name="deserializer">The deserializer to use to deserialize messages.</param>
/// <param name="deallocator">An optional deallocator for the data.</param>
/// <param name="useSourceOriginatingTimes">An optional parameter indicating whether to use originating times received from the source over the network or to re-timestamp with the current pipeline time upon receiving.</param>
/// <param name="name">An optional name for the TCP source component.</param>
/// <returns><see cref="TcpSource{T}"/>.</returns>
public static TcpSource<T> ToTcpSource<T>(
this Rendezvous.TcpSourceEndpoint endpoint,
Pipeline pipeline,
IFormatDeserializer<T> deserializer,
Action<T> deallocator = null,
bool useSourceOriginatingTimes = true,
string name = nameof(TcpSource<T>))
=> new (pipeline, endpoint.Host, endpoint.Port, deserializer, deallocator, useSourceOriginatingTimes, name);

/// <summary>
/// Create a rendezvous endpoint from a <see cref="RemoteClockExporter"/>.
/// </summary>
/// <param name="exporter"><see cref="RemoteClockExporter"/> from which to create endpoint.</param>
/// <param name="host">Host address with which to create endpoint.</param>
/// <returns>Rendezvous endpoint.</returns>
public static Rendezvous.Endpoint ToRendezvousEndpoint(this RemoteClockExporter exporter, string host)
=> new Rendezvous.RemoteClockExporterEndpoint(host, exporter.Port);

/// <summary>
/// Create a rendezvous endpoint from a <see cref="RemoteExporter"/>.
/// </summary>
/// <param name="exporter"><see cref="RemoteExporter"/> from which to create endpoint.</param>
/// <param name="host">Host name with which to create endpoint.</param>
/// <returns>Rendezvous endpoint.</returns>
public static Rendezvous.Endpoint ToRendezvousEndpoint(this RemoteExporter exporter, string host)
{
// Each RemoteExporter is an endpoint emitting one or more streams.
var endpoint = new Rendezvous.RemoteExporterEndpoint(host, exporter.Port, exporter.TransportKind);
foreach (var m in exporter.Exporter.Metadata)
{
endpoint.AddStream(new Rendezvous.Stream(m.Name, m.TypeName));
}

return endpoint;
}

/// <summary>
/// Create a <see cref="RemoteImporter"/> from a <see cref="Rendezvous.RemoteExporterEndpoint"/>.
/// </summary>
/// <param name="endpoint"><see cref="Rendezvous.RemoteExporterEndpoint"/> from which to create .</param>
/// <param name="pipeline">The pipeline to add the component to.</param>
/// <returns><see cref="RemoteImporter"/>.</returns>
public static RemoteImporter ToRemoteImporter(this Rendezvous.RemoteExporterEndpoint endpoint, Pipeline pipeline)
=> new (pipeline, endpoint.Host, endpoint.Port);

/// <summary>
/// Create a <see cref="RemoteClockImporter"/> from a <see cref="Rendezvous.RemoteClockExporterEndpoint"/>.
/// </summary>
/// <param name="endpoint"><see cref="Rendezvous.RemoteClockExporterEndpoint"/> from which to create .</param>
/// <param name="pipeline">The pipeline to add the component to.</param>
/// <returns><see cref="RemoteClockImporter"/>.</returns>
public static RemoteClockImporter ToRemoteClockImporter(this Rendezvous.RemoteClockExporterEndpoint endpoint, Pipeline pipeline)
=> new (pipeline, endpoint.Host, endpoint.Port);

/// <summary>
/// Writes a stream to a specified rendezvous process.
/// </summary>
/// <typeparam name="T">The type of data in the stream.</typeparam>
/// <param name="source">The source stream to write.</param>
/// <param name="streamName">The name under which to write the stream to the rendezvous process.</param>
/// <param name="rendezvousProcess">The rendezvous process.</param>
/// <param name="address">The address to write the stream to.</param>
/// <param name="port">The port to write the stream to.</param>
/// <param name="serializer">The serializer to use when writing the stream.</param>
/// <param name="deliveryPolicy">An optional delivery policy.</param>
public static void WriteToRendezvousProcess<T>(
this IProducer<T> source,
string streamName,
Rendezvous.Process rendezvousProcess,
string address,
int port,
IFormatSerializer<T> serializer,
DeliveryPolicy deliveryPolicy = null)
{
var tcpWriter = new TcpWriter<T>(source.Out.Pipeline, port, serializer);
source.PipeTo(tcpWriter, deliveryPolicy);
rendezvousProcess.AddEndpoint(tcpWriter.ToRendezvousEndpoint(address, streamName));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Interop Rendezvous

A distributed \psi system may have many separate pipelines running in separate processes, on separate machines, publishing and subscribing to streams being conveyed using various protocols. The rendezvous system allows each pipeline process to advertise its available streams and to discover those of other pipelines. This is accomplished by a centralized "rendezvous point" which maintains and relays endpoint connection and stream information.

For more information, see [the Rendezvous System wiki page](https://github.com/microsoft/psi/wiki/Rendezvous-System).
Loading