2020-03-21 13:27:46 +01:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
2019-06-12 21:56:55 +02:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Capnp.Rpc
|
|
|
|
|
{
|
2020-04-10 18:29:06 +02:00
|
|
|
|
|
2019-06-12 21:56:55 +02:00
|
|
|
|
class Vine : Skeleton
|
|
|
|
|
{
|
2020-04-10 18:29:06 +02:00
|
|
|
|
public Vine(ConsumedCapability consumedCap)
|
2019-06-12 21:56:55 +02:00
|
|
|
|
{
|
2020-04-10 18:29:06 +02:00
|
|
|
|
Cap = consumedCap;
|
2019-06-12 21:56:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-10 18:29:06 +02:00
|
|
|
|
public ConsumedCapability Cap { get; }
|
2020-03-21 13:27:46 +01:00
|
|
|
|
|
2020-04-10 18:29:06 +02:00
|
|
|
|
internal override ConsumedCapability AsCapability() => Cap;
|
2020-03-21 13:27:46 +01:00
|
|
|
|
|
2020-04-10 18:29:06 +02:00
|
|
|
|
internal override void Claim()
|
2020-03-21 13:27:46 +01:00
|
|
|
|
{
|
2020-04-10 18:29:06 +02:00
|
|
|
|
Cap.AddRef();
|
2019-06-12 21:56:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-10 18:29:06 +02:00
|
|
|
|
internal override void Relinquish()
|
2019-06-12 21:56:55 +02:00
|
|
|
|
{
|
2020-04-10 18:29:06 +02:00
|
|
|
|
Cap.Release();
|
2019-06-12 21:56:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async override Task<AnswerOrCounterquestion> Invoke(
|
|
|
|
|
ulong interfaceId, ushort methodId, DeserializerState args,
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
2020-04-10 18:29:06 +02:00
|
|
|
|
using var proxy = new Proxy(Cap);
|
|
|
|
|
var promisedAnswer = proxy.Call(interfaceId, methodId, (DynamicSerializerState)args, false, cancellationToken);
|
2019-06-12 21:56:55 +02:00
|
|
|
|
|
|
|
|
|
if (promisedAnswer is PendingQuestion pendingQuestion && pendingQuestion.RpcEndpoint == Impatient.AskingEndpoint)
|
|
|
|
|
{
|
|
|
|
|
return pendingQuestion;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-10 21:55:34 +01:00
|
|
|
|
using var registration = cancellationToken.Register(promisedAnswer.Dispose);
|
|
|
|
|
return (DynamicSerializerState)await promisedAnswer.WhenReturned;
|
2019-06-12 21:56:55 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-11 17:56:12 +01:00
|
|
|
|
}
|