public RemoteAnswerCapability(PendingQuestion question, MemberAccessPath access) : base(question.RpcEndpoint)
        {
            _question = question ?? throw new ArgumentNullException(nameof(question));
            _access   = access ?? throw new ArgumentNullException(nameof(access));

            _ = AwaitWhenResolved();
        }
        /// <summary>
        /// Returns a promise-pipelined capability for a remote method invocation Task.
        /// </summary>
        /// <param name="task">remote method invocation task</param>
        /// <param name="access">path to the desired capability</param>
        /// <param name="proxyTask">task returning a proxy to the desired capability</param>
        /// <returns>Pipelined low-level capability</returns>
        public static ConsumedCapability Access(Task task, MemberAccessPath access, Task <IDisposable?> proxyTask)
        {
            var answer = TryGetAnswer(task);

            if (answer != null)
            {
                return(answer.Access(access, proxyTask));
            }
            return(new LazyCapability(proxyTask.AsProxyTask()));
        }
Example #3
0
        public void Chain(bool strictSync, PromisedAnswer.READER rd, Func <Task <Proxy>, Task> func)
        {
            Chain(strictSync, async t =>
            {
                async Task <Proxy> EvaluateProxy()
                {
                    var aorcq = await t;

                    if (aorcq.Answer != null)
                    {
                        DeserializerState cur = aorcq.Answer;

                        foreach (var op in rd.Transform)
                        {
                            switch (op.which)
                            {
                            case PromisedAnswer.Op.WHICH.GetPointerField:
                                try
                                {
                                    cur = cur.StructReadPointer(op.GetPointerField);
                                }
                                catch (System.Exception)
                                {
                                    throw new ArgumentOutOfRangeException("Illegal pointer field in transformation operation");
                                }
                                break;

                            case PromisedAnswer.Op.WHICH.Noop:
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("Unknown transformation operation");
                            }
                        }

                        Proxy proxy;

                        switch (cur.Kind)
                        {
                        case ObjectKind.Capability:
                            try
                            {
                                var cap = aorcq.Answer.Caps[(int)cur.CapabilityIndex];
                                proxy   = new Proxy(cap ?? LazyCapability.Null);
                            }
                            catch (ArgumentOutOfRangeException)
                            {
                                throw new ArgumentOutOfRangeException("Bad capability table in internal answer - internal error?");
                            }
                            return(proxy);

                        default:
                            throw new ArgumentOutOfRangeException("Transformation did not result in a capability");
                        }
                    }
                    else
                    {
                        var path = MemberAccessPath.Deserialize(rd);
                        var cap  = new RemoteAnswerCapability(aorcq.Counterquestion, path);
                        return(new Proxy(cap));
                    }
                }

                await func(EvaluateProxy());
            });
        }
Example #4
0
        static async Task <Proxy> TransferOwnershipToDummyProxy(StrictlyOrderedAwaitTask <DeserializerState> answer, MemberAccessPath access)
        {
            var result = await answer;
            var cap    = access.Eval(result);
            var proxy  = new Proxy(cap);

            cap?.Release();
            return(proxy);
        }
Example #5
0
 public LocalAnswerCapability(StrictlyOrderedAwaitTask <DeserializerState> answer, MemberAccessPath access) :
     this(TransferOwnershipToDummyProxy(answer, access))
 {
 }
Example #6
0
 public RemoteAnswerCapability(PendingQuestion question, MemberAccessPath access) : this(question, access, TransferOwnershipToDummyProxy(question, access))
 {
 }
Example #7
0
        static async Task <Proxy> TransferOwnershipToDummyProxy(PendingQuestion question, MemberAccessPath access)
        {
            var result = await question.WhenReturned;
            var cap    = access.Eval(result);
            var proxy  = new Proxy(cap);

            cap?.Release();
            return(proxy);
        }
Example #8
0
 public RemoteAnswerCapability(PendingQuestion question, MemberAccessPath access, Task <Proxy> proxyTask) : base(question.RpcEndpoint)
 {
     _question          = question ?? throw new ArgumentNullException(nameof(question));
     _access            = access ?? throw new ArgumentNullException(nameof(access));
     _whenResolvedProxy = (proxyTask ?? throw new ArgumentNullException(nameof(proxyTask))).EnforceAwaitOrder();
 }
Example #9
0
 public LocalAnswerCapability(Task <DeserializerState> answer, MemberAccessPath access)
 {
     _answer = answer;
     _access = access;
 }
 public ConsumedCapability Access(MemberAccessPath _, Task <IDisposable?> task)
 {
     return(new LocalAnswerCapability(task.AsProxyTask()));
 }
 public ConsumedCapability Access(MemberAccessPath access)
 {
     return(new LocalAnswerCapability(WhenReturned, access));
 }