Esempio n. 1
0
#pragma warning disable CS0162 // Disabled since the flag can be set while debugging
        /// <summary>
        /// Dynamic handler changes are communicated from a GraphStageLogic by this method.
        /// </summary>
        /// <param name="connection">TBD</param>
        /// <param name="handler">TBD</param>
        public void SetHandler(Connection connection, IInHandler handler)
        {
            if (IsDebug)
            {
                Console.WriteLine($"{Name} SETHANDLER {OutOwnerName(connection)} (in) {handler}");
            }
            connection.InHandler = handler;
        }
Esempio n. 2
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="id">Identifier of the connection. Corresponds to the array slot in the <see cref="GraphAssembly"/></param>
 /// <param name="inOwnerId">Identifier of the owner of the input side of the connection. Corresponds to the array slot in the <see cref="GraphAssembly"/></param>
 /// <param name="inOwner">The stage logic that corresponds to the input side of the connection.</param>
 /// <param name="outOwnerId">Identifier of the owner of the output side of the connection. Corresponds to the array slot in the <see cref="GraphAssembly"/></param>
 /// <param name="outOwner">The stage logic that corresponds to the output side of the connection.</param>
 /// <param name="inHandler">The handler that contains the callback for input events.</param>
 /// <param name="outHandler">The handler that contains the callback for output events.</param>
 public Connection(int id, int inOwnerId, GraphStageLogic inOwner, int outOwnerId, GraphStageLogic outOwner,
                   IInHandler inHandler, IOutHandler outHandler)
 {
     Id         = id;
     InOwnerId  = inOwnerId;
     InOwner    = inOwner;
     OutOwnerId = outOwnerId;
     OutOwner   = outOwner;
     InHandler  = inHandler;
     OutHandler = outHandler;
 }
Esempio n. 3
0
 /// <summary>
 /// Dynamic handler changes are communicated from a GraphStageLogic by this method.
 /// </summary>
 public void SetHandler(int connection, IInHandler handler)
 {
     if (IsDebug) Console.WriteLine($"{Name} SETHANDLER {OutOwnerName(connection)} (in) {handler}");
     InHandlers[connection] = handler;
 }
Esempio n. 4
0
        public GraphInterpreter(
            GraphAssembly assembly,
            IMaterializer materializer,
            ILoggingAdapter log,
            IInHandler[] inHandlers,
            IOutHandler[] outHandlers,
            GraphStageLogic[] logics,
            Action<GraphStageLogic, object, Action<object>> onAsyncInput,
            bool fuzzingMode)
        {
            Logics = logics;
            Assembly = assembly;
            Materializer = materializer;
            Log = log;
            InHandlers = inHandlers;
            OutHandlers = outHandlers;
            OnAsyncInput = onAsyncInput;
            FuzzingMode = fuzzingMode;

            ConnectionSlots = new object[assembly.ConnectionCount];
            for (var i = 0; i < ConnectionSlots.Length; i++)
                ConnectionSlots[i] = Empty.Instance;

            PortStates = new int[assembly.ConnectionCount];
            for (var i = 0; i < PortStates.Length; i++)
                PortStates[i] = InReady;

            RunningStagesCount = Assembly.Stages.Length;

            _shutdownCounter = new int[assembly.Stages.Length];
            for (var i = 0; i < _shutdownCounter.Length; i++)
            {
                var shape = assembly.Stages[i].Shape;
                _shutdownCounter[i] = shape.Inlets.Count() + shape.Outlets.Count();
            }

            _eventQueue = new int[1 << (32 - (assembly.ConnectionCount - 1).NumberOfLeadingZeros())];
            _mask = _eventQueue.Length - 1;
        }
Esempio n. 5
0
        /// <summary>
        /// Takes an interpreter and returns three arrays required by the interpreter containing the input, output port
        /// handlers and the stage logic instances.
        ///
        /// <para>Returns a tuple of</para>
        /// <para/> - lookup table for InHandlers
        /// <para/> - lookup table for OutHandlers
        /// <para/> - array of the logics
        /// <para/> - materialized value
        /// </summary>
        public Tuple <IInHandler[], IOutHandler[], GraphStageLogic[]> Materialize(
            Attributes inheritedAttributes,
            IModule[] copiedModules,
            IDictionary <IModule, object> materializedValues,
            Action <IMaterializedValueSource> register)
        {
            var logics = new GraphStageLogic[Stages.Length];

            for (var i = 0; i < Stages.Length; i++)
            {
                // Port initialization loops, these must come first
                var shape = Stages[i].Shape;

                var idx             = 0;
                var inletEnumerator = shape.Inlets.GetEnumerator();
                while (inletEnumerator.MoveNext())
                {
                    var inlet = inletEnumerator.Current;
                    if (inlet.Id != -1 && inlet.Id != idx)
                    {
                        throw new ArgumentException($"Inlet {inlet} was shared among multiple stages. That is illegal.");
                    }
                    inlet.Id = idx;
                    idx++;
                }

                idx = 0;
                var outletEnumerator = shape.Outlets.GetEnumerator();
                while (outletEnumerator.MoveNext())
                {
                    var outlet = outletEnumerator.Current;
                    if (outlet.Id != -1 && outlet.Id != idx)
                    {
                        throw new ArgumentException($"Outlet {outlet} was shared among multiple stages. That is illegal.");
                    }
                    outlet.Id = idx;
                    idx++;
                }

                var stage = Stages[i];
                if (stage is IMaterializedValueSource)
                {
                    var copy = ((IMaterializedValueSource)stage).CopySource();
                    register(copy);
                    stage = (IGraphStageWithMaterializedValue <Shape, object>)copy;
                }

                var logicAndMaterialized = stage.CreateLogicAndMaterializedValue(inheritedAttributes.And(OriginalAttributes[i]));
                materializedValues[copiedModules[i]] = logicAndMaterialized.MaterializedValue;
                logics[i] = logicAndMaterialized.Logic;
            }

            var inHandlers  = new IInHandler[ConnectionCount];
            var outHandlers = new IOutHandler[ConnectionCount];

            for (var i = 0; i < ConnectionCount; i++)
            {
                var inlet = Inlets[i];
                if (inlet != null)
                {
                    var owner = InletOwners[i];
                    var logic = logics[owner];
                    var h     = logic.Handlers[inlet.Id] as InHandler;

                    if (h == null)
                    {
                        throw new IllegalStateException($"No handler defined in stage {logic} for port {inlet}");
                    }
                    inHandlers[i] = h;

                    logic.PortToConn[inlet.Id] = i;
                }

                var outlet = Outlets[i];
                if (outlet != null)
                {
                    var owner   = OutletOwners[i];
                    var logic   = logics[owner];
                    var inCount = logic.InCount;
                    var h       = logic.Handlers[outlet.Id + inCount] as OutHandler;

                    if (h == null)
                    {
                        throw new IllegalStateException($"No handler defined in stage {logic} for port {outlet}");
                    }
                    outHandlers[i] = h;

                    logic.PortToConn[outlet.Id + inCount] = i;
                }
            }

            return(Tuple.Create(inHandlers, outHandlers, logics));
        }