Beispiel #1
0
        public void add(signals.IBlockDriver block)
        {
            ModuleKey key = new ModuleKey(block);
            List <signals.IBlockDriver> list;

            if (!blocks.TryGetValue(key, out list))
            {
                list = new List <signals.IBlockDriver>();
                blocks.Add(key, list);
            }
            list.Add(block);
        }
Beispiel #2
0
 public Element(signals.IBlockDriver realDriver)
 {
     if (realDriver == null)
     {
         throw new ArgumentNullException("realDriver");
     }
     type         = ElementType.Module;
     name         = realDriver.Name;
     nodeId       = null;
     circuitId    = 0;
     availObjects = new List <signals.ICircuitConnectible>();
     availObjects.Add(realDriver);
     explicitAvail = true;
 }
Beispiel #3
0
 public ModuleKey(signals.IBlockDriver blk)
 {
     name = blk.Name;
     signals.Fingerprint fgr = blk.Fingerprint;
     if (fgr == null)
     {
         numIn = numOut = -1;
     }
     else
     {
         numIn  = fgr.inputs.Length;
         numOut = fgr.outputs.Length;
     }
 }
Beispiel #4
0
 public CppProxyBlock(signals.IBlockDriver driver, signals.IBlock parent, IntPtr native)
 {
     if (driver == null) throw new ArgumentNullException("driver");
     if (native == IntPtr.Zero) throw new ArgumentNullException("native");
     m_nativeRef = native;
     m_driver = driver;
     m_parent = parent;
     Registration.storeObject(native, this);
     m_native = (Native.IBlock)CppNativeProxy.CreateCallout(native, typeof(Native.IBlock));
     interrogate();
 }
Beispiel #5
0
 public CppProxyEPSender(signals.IBlockDriver driver, IntPtr native)
 {
     if (driver == null) throw new ArgumentNullException("driver");
     if (native == IntPtr.Zero) throw new ArgumentNullException("native");
     m_driver = driver;
     m_nativeRef = native;
     Registration.storeObject(native, this);
     m_native = (Native.IEPSendTo)CppNativeProxy.CreateCallout(native, typeof(Native.IEPSendTo));
     m_native.AddRef(IntPtr.Zero);
 }
Beispiel #6
0
 public void add(signals.IBlockDriver realDriver)
 {
     add(new Element(realDriver));
 }
Beispiel #7
0
        public Circuit construct()
        {
            Dictionary <int, Circuit.Element> result    = new Dictionary <int, Circuit.Element>();
            Dictionary <Element, object>      elmResult = new Dictionary <Element, object>();

            foreach (KeyValuePair <int, Element> here in contents)
            {
                Element elm = here.Value;
                if (elm.availObjects.Count != 1)
                {
                    throw new ApplicationException("expecting all elements to have exactly one solution");
                }
                signals.ICircuitConnectible avail = elm.availObjects[0];
                signals.ICircuitElement     newOb = null;
                switch (elm.type)
                {
                case ElementType.Module:
                {
                    signals.IBlockDriver drv = avail as signals.IBlockDriver;
                    if (drv != null)
                    {
                        newOb = drv.Create();
                    }
                    else
                    {
                        newOb = (signals.IBlock)avail;
                    }
                    break;
                }

                case ElementType.Function:
                case ElementType.FunctionOnIn:
                case ElementType.FunctionOnOut:
                    newOb = ((signals.IFunctionSpec)avail).Create();
                    break;
                }
                result.Add(elm.circuitId, new Circuit.Element(new ElemKey(elm), elm.circuitId, newOb));
                elmResult.Add(elm, newOb);
            }

            foreach (KeyValuePair <EndpointKey, EndpointKey> conn in connections)
            {
                EndpointKey from    = conn.Key;
                EndpointKey to      = conn.Value;
                object      fromObj = elmResult[from.elem];
                object      toObj   = elmResult[to.elem];
                switch (from.elem.type)
                {
                case ElementType.Module:
                {
                    signals.IOutEndpoint outEP = from.OutputEP((signals.IBlock)fromObj);
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IEPBuffer   buff = outEP.CreateBuffer();
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        outEP.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IEPBuffer   buff = outEP.CreateBuffer();
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        outEP.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                    {
                        signals.IEPSendTo inEP = ((signals.IFunction)toObj).Output;
                        outEP.Connect(inEP);
                        break;
                    }
                    }
                    break;
                }

                case ElementType.Function:
                case ElementType.FunctionOnIn:
                {
                    signals.IInputFunction func = ((signals.IFunction)fromObj).Input;
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        inEP.Connect(func);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        inEP.Connect(func);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                        throw new ApplicationException("incompatible connection types");
                    }
                    break;
                }

                case ElementType.FunctionOnOut:
                {
                    signals.IOutputFunction func = ((signals.IFunction)fromObj).Output;
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IEPBuffer   buff = func.CreateBuffer();
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        func.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IEPBuffer   buff = func.CreateBuffer();
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        func.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                    {
                        signals.IOutEndpoint outEP = ((signals.IFunction)toObj).Output;
                        outEP.Connect(func);
                        break;
                    }
                    }
                    break;
                }
                }
            }
            return(new Circuit(result));
        }