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

fix for issue #33 #34

Merged
merged 1 commit into from
Dec 12, 2019
Merged
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
3 changes: 2 additions & 1 deletion Capnp.Net.Runtime/Capnp.Net.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
<PackageTags>capnp "Cap'n Proto" RPC serialization cerealization</PackageTags>
<Version>1.2-local$([System.DateTime]::UtcNow.ToString(yyMMddHHmm))</Version>
<Configurations>Debug;Release</Configurations>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions Capnp.Net.Runtime/FramePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public void Run()
}
}

/// <summary>
/// Attaches an observer for tracing RPC traffic
/// </summary>
/// <param name="tracer">observer implementation</param>
public void AttachTracer(IFrameTracer tracer)
{
_tracers.Add(tracer);
Expand Down
20 changes: 18 additions & 2 deletions Capnp.Net.Runtime/FrameTracing/IFrameTracer.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Capnp.FrameTracing
{
/// <summary>
/// Send or receive
/// </summary>
public enum FrameDirection
{
/// <summary>
/// Receive direction
/// </summary>
Rx,

/// <summary>
/// Send direction
/// </summary>
Tx
}

/// <summary>
/// Client interface for observing RPC traffic
/// </summary>
public interface IFrameTracer: IDisposable
{
/// <summary>
/// Called whenever an RPC frame was sent or received
/// </summary>
/// <param name="direction">frame direction</param>
/// <param name="frame">actual frame</param>
void TraceFrame(FrameDirection direction, WireFrame frame);
}
}
15 changes: 15 additions & 0 deletions Capnp.Net.Runtime/FrameTracing/RpcFrameTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

namespace Capnp.FrameTracing
{
/// <summary>
/// Default implementation of an RPC observer
/// </summary>
public class RpcFrameTracer : IFrameTracer
{
const string Header = "Ticks | Thread | Dir | Message";
Expand All @@ -16,12 +19,19 @@ public class RpcFrameTracer : IFrameTracer
readonly Stopwatch _timer = new Stopwatch();
readonly TextWriter _traceWriter;

/// <summary>
/// Constructs an instance
/// </summary>
/// <param name="traceWriter">textual logging target</param>
public RpcFrameTracer(TextWriter traceWriter)
{
_traceWriter = traceWriter ?? throw new ArgumentNullException(nameof(traceWriter));
_traceWriter.WriteLine(Header);
}

/// <summary>
/// Dispose pattern implementation
/// </summary>
public void Dispose()
{
_traceWriter.WriteLine("<end of trace>");
Expand Down Expand Up @@ -91,6 +101,11 @@ void RenderCapTable(IEnumerable<CapDescriptor.READER> caps, FrameDirection dir)
}
}

/// <summary>
/// Processes a sent or received RPC frame
/// </summary>
/// <param name="dir">frame direction</param>
/// <param name="frame">actual frame</param>
public void TraceFrame(FrameDirection dir, WireFrame frame)
{
if (!_timer.IsRunning)
Expand Down
1 change: 0 additions & 1 deletion Capnp.Net.Runtime/Rpc/BareProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public BareProxy(ConsumedCapability cap): base(cap)
/// <param name="interfaceId">Target interface ID</param>
/// <param name="methodId">Target method ID</param>
/// <param name="args">Method arguments</param>
/// <param name="tailCall">Whether it is a tail call</param>
/// <returns>Answer promise</returns>
public IPromisedAnswer Call(ulong interfaceId, ushort methodId, DynamicSerializerState args)
{
Expand Down
1 change: 0 additions & 1 deletion Capnp.Net.Runtime/Rpc/Interception/CallContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ public void UninterceptOutCaps(IInterceptionPolicy policyOverride = null)
/// <summary>
/// Forwards this intercepted call to the target capability ("Bob").
/// </summary>
/// <param name="cancellationToken">Optional cancellation token, requesting Bob to cancel the call</param>
public void ForwardToBob()
{
if (Bob == null)
Expand Down
12 changes: 10 additions & 2 deletions Capnp.Net.Runtime/Rpc/TcpRpcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Capnp.Rpc
{
/// <summary>
/// Carries information on RPC connection state changes.
/// </summary>
public class ConnectionEventArgs: EventArgs
{
/// <summary>
/// Affected connection
/// </summary>
public IConnection Connection { get; }

/// <summary>
/// Constructs an instance
/// </summary>
/// <param name="connection">RPC connection object</param>
public ConnectionEventArgs(IConnection connection)
{
Connection = connection;
Expand Down
4 changes: 2 additions & 2 deletions CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9015,7 +9015,7 @@ Task<AnswerOrCounterquestion> Call<TT, TU>(DeserializerState d_, CancellationTok
where TT : class where TU : class
{
var in_ = CapnpSerializable.Create<Capnproto_test.Capnp.Test.TestImplicitMethodParams.Params_call<TT, TU>>(d_);
return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ =>
return Impatient.MaybeTailCall(Impl.Call<TT, TU>(in_.Foo, in_.Bar, cancellationToken_), r_ =>
{
var s_ = SerializerState.CreateForRpc<Capnproto_test.Capnp.Test.TestGenerics<TT, TU>.WRITER>();
r_.serialize(s_);
Expand Down Expand Up @@ -9142,7 +9142,7 @@ Task<AnswerOrCounterquestion> Call<TT, TU>(DeserializerState d_, CancellationTok
where TT : class where TU : class
{
var in_ = CapnpSerializable.Create<Capnproto_test.Capnp.Test.TestImplicitMethodParamsInGeneric<TV>.Params_call<TT, TU>>(d_);
return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ =>
return Impatient.MaybeTailCall(Impl.Call<TT, TU>(in_.Foo, in_.Bar, cancellationToken_), r_ =>
{
var s_ = SerializerState.CreateForRpc<Capnproto_test.Capnp.Test.TestGenerics<TT, TU>.WRITER>();
r_.serialize(s_);
Expand Down
17 changes: 16 additions & 1 deletion CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,26 @@ CSharpSyntaxNode MakeMaybeTailCallLambdaBody(Method method)

IEnumerable<StatementSyntax> MakeSkeletonMethodBody(Method method)
{
SimpleNameSyntax methodName;

if (method.GenericParameters.Count == 0)
{
methodName = _names.GetCodeIdentifier(method).IdentifierName;
}
else
{
methodName = GenericName(_names.GetCodeIdentifier(method).Identifier)
.AddTypeArgumentListArguments(
method.GenericParameters.Select(
p => _names.GetGenericTypeParameter(p).IdentifierName)
.ToArray());
}

var call = InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName(SkeletonWorder.ImplName),
_names.GetCodeIdentifier(method).IdentifierName));
methodName));

if (method.Params.Count > 0)
{
Expand Down
11 changes: 11 additions & 0 deletions MsBuildGenerationTest/Issue33.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@0xaa62d76b329585e5;

interface Frobnicator(T)
{
frobnicate @0 (value: T);
}

interface FrobnicatorFactory
{
createFrobnicator @0 [T] (id: Text) -> (result: Frobnicator(T));
}