mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 23:01:44 +01:00
56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using System.Threading.Tasks;
|
|
|
|
#nullable enable
|
|
namespace Capnp.Rpc
|
|
{
|
|
/// <summary>
|
|
/// Low-level capability which as imported from a remote peer.
|
|
/// </summary>
|
|
class ImportedCapability : RemoteCapability
|
|
{
|
|
readonly uint _remoteId;
|
|
|
|
public ImportedCapability(IRpcEndpoint ep, uint remoteId): base(ep)
|
|
{
|
|
_remoteId = remoteId;
|
|
}
|
|
|
|
protected override void ReleaseRemotely()
|
|
{
|
|
_ep.ReleaseImport(_remoteId);
|
|
}
|
|
|
|
protected override Call.WRITER SetupMessage(DynamicSerializerState args, ulong interfaceId, ushort methodId)
|
|
{
|
|
var call = base.SetupMessage(args, interfaceId, methodId);
|
|
call.Target.which = MessageTarget.WHICH.ImportedCap;
|
|
call.Target.ImportedCap = _remoteId;
|
|
|
|
return call;
|
|
}
|
|
|
|
internal override void Freeze(out IRpcEndpoint boundEndpoint)
|
|
{
|
|
boundEndpoint = _ep;
|
|
}
|
|
|
|
internal override void Unfreeze()
|
|
{
|
|
}
|
|
|
|
internal override void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER capDesc)
|
|
{
|
|
if (endpoint == _ep)
|
|
{
|
|
capDesc.which = CapDescriptor.WHICH.ReceiverHosted;
|
|
capDesc.ReceiverHosted = _remoteId;
|
|
}
|
|
else
|
|
{
|
|
capDesc.which = CapDescriptor.WHICH.SenderHosted;
|
|
capDesc.SenderHosted = endpoint.AllocateExport(Vine.Create(this), out var _);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#nullable restore |