예제 #1
0
 public ReceiveStream(signals.EType type, signals.IEPRecvFrom recv)
 {
     m_type   = type;
     m_recv   = recv;
     m_thread = new Thread(new ThreadStart(start));
     m_thread.IsBackground = true;
     m_thread.Start();
 }
예제 #2
0
 public LinkTypeFailure(EndpointKey fromEP, signals.EType fromType, EndpointKey toEP, signals.EType toType)
 {
     this.fromEP   = fromEP;
     this.fromType = fromType;
     this.toEP     = toEP;
     this.toType   = toType;
     this.HResult  = unchecked ((int)0x80020005);
 }
예제 #3
0
 public ReceiveStream(signals.EType type, signals.IEPRecvFrom recv)
 {
     m_type = type;
     m_recv = recv;
     m_thread = new Thread(new ThreadStart(start));
     m_thread.IsBackground = true;
     m_thread.Start();
 }
예제 #4
0
        private static signals.IFunctionSpec findImplicitConversion(sharptest.ModLibrary library, signals.EType inpType, signals.EType outType)
        {
            List <signals.IFunctionSpec> idents = library.func("=");

            if (idents == null)
            {
                return(null);
            }
            foreach (signals.IFunctionSpec avail in idents)
            {
                signals.EType identInput  = avail.Fingerprint.inputs[0];
                signals.EType identOutput = avail.Fingerprint.outputs[0];
                if (inpType == identInput && outType == identOutput)
                {
                    return(avail);
                }
            }
            return(null);
        }
예제 #5
0
        private void interrogate()
        {
            m_name = Utilities.getString(m_native.Name());
            m_descr = Utilities.getString(m_native.Description());
            m_type = m_native.Type();
            m_typeInfo = ProxyTypes.getTypeInfo(m_type);
            m_readOnly = m_native.isReadOnly();

            m_callbackRef = false;
            CppNativeProxy.Callback callback = CppNativeProxy.CreateCallin(m_catcher, typeof(Native.IAttributeObserver));
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                m_callback = callback;
                m_callback.DangerousAddRef(ref m_callbackRef);
                m_native.Observe(m_callback.DangerousGetHandle());
            }
        }
예제 #6
0
 public Vector(signals.EType type, ITypeMarshaller inner)
 {
     enumType = type;
     innerType = inner;
 }
예제 #7
0
 public Complex(signals.EType type)
 {
     enumType = type;
 }
예제 #8
0
 public bool WriteOne(signals.EType type, object val, int msTimeout)
 {
     if (val == null) throw new ArgumentNullException("val");
     if (type != m_sendType || m_sendTypeInfo == null)
     {
         m_sendType = type;
         m_sendTypeInfo = ProxyTypes.getTypeInfo(type);
         if (m_sendTypeInfo == null) throw new NotSupportedException("Cannot retrieve value for this type.");
     }
     Array pinArray = m_sendTypeInfo.toPinnableArray(new object[] { val });
     GCHandle pin = GCHandle.Alloc(pinArray, GCHandleType.Pinned);
     try
     {
         return m_nativeSend.WriteOne(type, pin.AddrOfPinnedObject(), (uint)msTimeout);
     }
     finally
     {
         pin.Free();
     }
 }
예제 #9
0
 private void interrogate()
 {
     m_name = Utilities.getString(m_native.EPName());
     m_descr = Utilities.getString(m_native.EPDescr());
     m_type = m_native.Type();
 }
예제 #10
0
        public object ReadOne(signals.EType type, int msTimeout)
        {
            if (type != m_recvType || m_recvTypeInfo == null)
            {
                m_recvType = type;
                m_recvTypeInfo = ProxyTypes.getTypeInfo(type);
                if (m_recvTypeInfo == null) throw new NotSupportedException("Cannot retrieve value for this type.");
            }

            Array pinArray = m_recvTypeInfo.makePinnableArray(1);
            GCHandle pin = GCHandle.Alloc(pinArray, GCHandleType.Pinned);
            bool read;
            try
            {
                read = m_nativeRecv.ReadOne(type, pin.AddrOfPinnedObject(), (uint)msTimeout);
            }
            finally
            {
                pin.Free();
            }
            return read ? m_recvTypeInfo.fromPinnableArray(pinArray, 1).GetValue(0) : null;
        }
예제 #11
0
        public void Read(signals.EType type, out Array values, bool bReadAll, int msTimeout)
        {
            if (type != m_recvType || m_recvTypeInfo == null)
            {
                m_recvType = type;
                m_recvTypeInfo = ProxyTypes.getTypeInfo(type);
                if (m_recvTypeInfo == null) throw new NotSupportedException("Cannot retrieve value for this type.");
            }

            Array pinArray = m_recvTypeInfo.makePinnableArray(BufferSize);
            GCHandle pin = GCHandle.Alloc(pinArray, GCHandleType.Pinned);
            uint read;
            try
            {
                read = m_nativeRecv.Read(type, pin.AddrOfPinnedObject(), (uint)BufferSize, bReadAll, (uint)msTimeout);
            }
            finally
            {
                pin.Free();
            }
            values = m_recvTypeInfo.fromPinnableArray(pinArray, (int)read);
        }
예제 #12
0
        public int Write(signals.EType type, Array values, int msTimeout)
        {
            if (values == null) throw new ArgumentNullException("values");
            if (type != m_type || m_typeInfo == null)
            {
                m_type = type;
                m_typeInfo = ProxyTypes.getTypeInfo(type);
                if (m_typeInfo == null) throw new NotSupportedException("Cannot retrieve value for this type.");
            }

            Array pinArray = m_typeInfo.toPinnableArray(values);
            GCHandle pin = GCHandle.Alloc(pinArray, GCHandleType.Pinned);
            try
            {
                return (int)m_native.Write(type, pin.AddrOfPinnedObject(), (uint)values.Length, (uint)msTimeout);
            }
            finally
            {
                pin.Free();
            }
        }
예제 #13
0
 private void interrogate()
 {
     m_type = m_native.Type();
     m_typeInfo = ProxyTypes.getTypeInfo(m_type);
 }
예제 #14
0
        public static string TypeName(signals.EType typ)
        {
            switch (typ)
            {
            case signals.EType.None:
                return("none");

            case signals.EType.Event:
                return("event");

            case signals.EType.String:
                return("string");

            case signals.EType.WinHdl:
                return("HWND");

            case signals.EType.Boolean:
                return("bool");

            case signals.EType.Byte:
                return("byte");

            case signals.EType.Short:
                return("short");

            case signals.EType.Long:
                return("int");

            case signals.EType.Int64:
                return("long");

            case signals.EType.Single:
                return("float");

            case signals.EType.Double:
                return("double");

            case signals.EType.Complex:
                return("complex(float)");

            case signals.EType.CmplDbl:
                return("complex(double)");

            case signals.EType.LRSingle:
                return("left-right(float)");

            case signals.EType.VecBoolean:
                return("array(bool)");

            case signals.EType.VecByte:
                return("array(byte)");

            case signals.EType.VecShort:
                return("array(short)");

            case signals.EType.VecLong:
                return("array(int)");

            case signals.EType.VecInt64:
                return("array(long)");

            case signals.EType.VecSingle:
                return("array(float)");

            case signals.EType.VecDouble:
                return("array(double)");

            case signals.EType.VecComplex:
                return("array(complex(float))");

            case signals.EType.VecCmplDbl:
                return("array(complex(double))");

            case signals.EType.VecLRSingle:
                return("array(left-right(float))");

            default:
                return(String.Format("unknown({0})", typ));
            }
        }
예제 #15
0
        private void resolveNeighbors(sharptest.ModLibrary library, Element elm)
        {
            if (elm.availObjects.Count != 1)
            {
                throw new ApplicationException("elm should contain a single availObject by this point");
            }
            signals.ICircuitConnectible avail       = elm.availObjects[0];
            Dictionary <Element, bool>  recurseList = new Dictionary <Element, bool>();
            List <KeyValuePair <EndpointKey, EndpointKey> > tempCollect = new List <KeyValuePair <EndpointKey, EndpointKey> >();

            tempCollect.AddRange(connections);
            foreach (KeyValuePair <EndpointKey, EndpointKey> entry in tempCollect)
            {
                EndpointKey key   = entry.Key;
                EndpointKey value = entry.Value;
                if (key.elem == elm)
                {
                    Element       otherElm = value.elem;
                    signals.EType ourType  = key.OutputType(avail);
                    bool          changed  = false;
                    if (otherElm.availObjects.Count > 1)
                    {
                        // if we have more than one option here, just look for possible compatibility
                        List <signals.ICircuitConnectible> newAvail = new List <signals.ICircuitConnectible>();
                        foreach (signals.ICircuitConnectible otherAvail in otherElm.availObjects)
                        {
                            signals.EType otherType = value.InputType(otherAvail);
                            if (ourType != otherType && findImplicitConversion(library, ourType, otherType) == null)
                            {
                                changed = true;
                            }
                            else
                            {
                                newAvail.Add(otherAvail);
                            }
                        }
                        otherElm.availObjects = newAvail;
                    }
                    if (otherElm.availObjects.Count == 1)
                    {
                        // if we're on one-to-one terms, we might add compat connections
                        signals.ICircuitConnectible otherAvail = otherElm.availObjects[0];
                        signals.EType otherType = value.InputType(otherAvail);
                        if (ourType != otherType)
                        {
                            signals.IFunctionSpec func = findImplicitConversion(library, ourType, otherType);
                            if (func == null)
                            {
                                // only option isn't type-compatible? Looks like we broke a connection
                                throw new LinkTypeFailure(entry.Key, ourType, entry.Value, otherType);
                            }
                            else
                            {
                                AddImplicitConversion(key, value, func);
                            }
                        }
                    }
                    else if (otherElm.availObjects.Count == 0)
                    {
                        // ran out of possible connections? Looks like we broke a connection
                        throw new CannotResolveElement(otherElm);
                    }
                    if (changed)
                    {
                        recurseList.Add(value.elem, true);
                    }
                }
                if (value.elem == elm)
                {
                    Element       otherElm = key.elem;
                    signals.EType ourType  = value.InputType(avail);
                    bool          changed  = false;
                    if (otherElm.availObjects.Count > 1)
                    {
                        // if we have more than one option here, just look for possible compatibility
                        List <signals.ICircuitConnectible> newAvail = new List <signals.ICircuitConnectible>();
                        foreach (signals.ICircuitConnectible otherAvail in otherElm.availObjects)
                        {
                            signals.EType otherType = key.OutputType(otherAvail);
                            if (ourType != otherType && findImplicitConversion(library, otherType, ourType) == null)
                            {
                                changed = true;
                            }
                            else
                            {
                                newAvail.Add(otherAvail);
                            }
                        }
                        otherElm.availObjects = newAvail;
                    }
                    if (otherElm.availObjects.Count == 1)
                    {
                        // if we're on one-to-one terms, we might add compat connections
                        signals.ICircuitConnectible otherAvail = otherElm.availObjects[0];
                        signals.EType otherType = key.OutputType(otherAvail);
                        if (ourType != otherType)
                        {
                            signals.IFunctionSpec func = findImplicitConversion(library, otherType, ourType);
                            if (func == null)
                            {
                                // only option isn't type-compatible? Looks like we broke a connection
                                throw new LinkTypeFailure(entry.Key, otherType, entry.Value, ourType);
                            }
                            else
                            {
                                AddImplicitConversion(key, value, func);
                            }
                        }
                    }
                    else if (otherElm.availObjects.Count == 0)
                    {
                        // ran out of possible connections? Looks like we broke a connection
                        throw new CannotResolveElement(otherElm);
                    }
                    if (changed)
                    {
                        recurseList.Add(value.elem, true);
                    }
                }
            }
            foreach (KeyValuePair <Element, bool> entry in recurseList)
            {
                if (entry.Key.availObjects.Count == 1)
                {
                    resolveNeighbors(library, entry.Key);
                }
            }
        }