Пример #1
0
        public void ResolveTo(ConsumedCapability resolvedCap)
        {
            bool release = false;

            lock (_reentrancyBlocker)
            {
#if DebugFinalizers
                if (resolvedCap != null)
                {
                    resolvedCap.ResolvingCap = this;
                }
#endif
                _resolvedCap.SetResult(resolvedCap !);

                if (_pendingCallsOnPromise == 0)
                {
                    release   = true;
                    _released = true;
                }
            }

            if (release)
            {
                _ep.ReleaseImport(_remoteId);
            }
        }
Пример #2
0
 public static Skeleton Create(ConsumedCapability cap)
 {
     if (cap is LocalCapability lcap)
     {
         return(lcap.ProvidedCap);
     }
     else
     {
         return(new Vine(cap));
     }
 }
Пример #3
0
        public static async Task <ConsumedCapability> Unwrap(this ConsumedCapability cap)
        {
            while (cap is IResolvingCapability resolving)
            {
                await resolving.WhenResolved;
                using var proxy = resolving.GetResolvedCapability <BareProxy>() !;
                cap             = proxy.ConsumedCap;
            }

            return(cap);
        }
        internal PendingQuestion(IRpcEndpoint ep, uint id, ConsumedCapability target, SerializerState?inParams)
        {
            RpcEndpoint   = ep ?? throw new ArgumentNullException(nameof(ep));
            _questionId   = id;
            _target       = target;
            _inParams     = inParams;
            _whenReturned = _tcs.Task.EnforceAwaitOrder();

            StateFlags = inParams == null ? State.Sent : State.None;

            if (target != null)
            {
                target.AddRef();
            }
        }
Пример #5
0
        internal void Bind(ConsumedCapability cap)
        {
            if (ConsumedCap != null)
            {
                throw new InvalidOperationException("Proxy was already bound");
            }

            if (cap == null)
            {
                return;
            }

            ConsumedCap = cap;
            cap.AddRef();
        }
        public void ResolveTo(ConsumedCapability resolvedCap)
        {
            bool release = false;

            lock (_reentrancyBlocker)
            {
                _resolvedCap.SetResult(new Proxy(resolvedCap));

                if (_pendingCallsOnPromise == 0)
                {
                    release   = true;
                    _released = true;
                }
            }

            if (release)
            {
                _ep.ReleaseImport(_remoteId);
            }
        }
        internal PendingQuestion(IRpcEndpoint ep, uint id, ConsumedCapability target, SerializerState inParams)
        {
            RpcEndpoint = ep ?? throw new ArgumentNullException(nameof(ep));
            _questionId = id;
            _target     = target;
            _inParams   = inParams;
            StateFlags  = inParams == null ? State.Sent : State.None;

            if (inParams != null)
            {
                foreach (var cap in inParams.Caps)
                {
                    cap?.AddRef();
                }
            }

            if (target != null)
            {
                target.AddRef();
            }
        }
Пример #8
0
        /// <summary>
        /// Constructs a Proxy for given capability interface and wraps it around given low-level capability.
        /// </summary>
        /// <typeparam name="TInterface">Capability interface. Must be annotated with <see cref="ProxyAttribute"/>.</typeparam>
        /// <param name="cap">low-level capability</param>
        /// <param name="memberName">debugging aid</param>
        /// <param name="sourceFilePath">debugging aid</param>
        /// <param name="sourceLineNumber">debugging aid</param>
        /// <returns>The Proxy instance which implements <typeparamref name="TInterface"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="cap"/> is null.</exception>
        /// <exception cref="InvalidCapabilityInterfaceException"><typeparamref name="TInterface"/> did not qualify as capability interface.</exception>
        /// <exception cref="InvalidOperationException">Mismatch between generic type arguments (if capability interface is generic).</exception>
        /// <exception cref="ArgumentException">Mismatch between generic type arguments (if capability interface is generic).</exception>
        /// <exception cref="System.Reflection.TargetInvocationException">Problem with instatiating the Proxy (constructor threw exception).</exception>
        /// <exception cref="MemberAccessException">Caller does not have permission to invoke the Proxy constructor.</exception>
        /// <exception cref="TypeLoadException">Problem with building the Proxy type, or problem with loading some dependent class.</exception>
        public static Proxy CreateProxy <TInterface>(ConsumedCapability cap,
                                                     [System.Runtime.CompilerServices.CallerMemberName] string memberName    = "",
                                                     [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath  = "",
                                                     [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
        {
            var factory = GetProxyFactory(typeof(TInterface));
            var proxy   = factory.NewProxy();

            proxy.Bind(cap);
#if DebugFinalizers
            proxy.CreatorMemberName = memberName;
            proxy.CreatorFilePath   = sourceFilePath;
            proxy.CreatorLineNumber = sourceLineNumber;
            if (cap != null)
            {
                cap.CreatorFilePath   = proxy.CreatorFilePath;
                cap.CreatorLineNumber = proxy.CreatorLineNumber;
                cap.CreatorMemberName = proxy.CreatorMemberName;
            }
#endif
            return(proxy);
        }
Пример #9
0
 Vine(ConsumedCapability consumedCap)
 {
     Proxy = new Proxy(consumedCap ?? throw new ArgumentNullException(nameof(consumedCap)));
 }
Пример #10
0
 public Vine(ConsumedCapability consumedCap)
 {
     Cap = consumedCap;
 }
Пример #11
0
 internal Proxy(ConsumedCapability cap)
 {
     Bind(cap);
 }