Example #1
0
        public override void Write(ulong memorypos, T[] buffer, ulong bufferpos, ulong count)
        {
            T[] buffer3;
            if ((ulong)buffer.Length == count)
            {
                buffer3 = buffer;
            }
            else
            {
                buffer3 = new T[count];
                Array.Copy(buffer, (long)bufferpos, buffer3, 0, (long)count);
            }

            RRBaseArray buffer2 = null;

            try
            {
                buffer2 = MessageElementDataUtil.ArrayToRRBaseArray(buffer3);
                WrappedArrayMemoryClientUtil.Write(innerarray, memorypos, buffer2, 0, count);
            }
            finally
            {
                if (buffer2 != null)
                {
                    buffer2.Dispose();
                }
            }
        }
Example #2
0
        public override void Write(ulong[] memorypos, MultiDimArray buffer, ulong[] bufferpos, ulong[] count)
        {
            RRMultiDimArrayUntyped dat2      = null;
            RRBaseArray            dat2Dims  = null;
            RRBaseArray            dat2Array = null;

            try
            {
                int elemcount = 1;
                foreach (ulong v in count)
                {
                    elemcount *= (int)v;
                }
                uint[] count2 = count.Select(x => (uint)x).ToArray();
                T[]    array  = new T[elemcount];


                MultiDimArray writedat1 = new MultiDimArray(count2, array);
                writedat1.AssignSubArray(new uint[count.Length], buffer, bufferpos.Select(x => (uint)x).ToArray(), count.Select(x => (uint)x).ToArray());

                dat2       = new RRMultiDimArrayUntyped();
                dat2Dims   = MessageElementDataUtil.ArrayToRRBaseArray(count2);
                dat2.Dims  = dat2Dims;
                dat2Array  = MessageElementDataUtil.ArrayToRRBaseArray(array);
                dat2.Array = dat2Array;

                vector_uint64_t memorypos3 = new vector_uint64_t();
                foreach (ulong val in memorypos)
                {
                    memorypos3.Add(val);
                }
                vector_uint64_t count3 = new vector_uint64_t();
                foreach (ulong val in count)
                {
                    count3.Add(val);
                }
                vector_uint64_t bufferpos3 = new vector_uint64_t();
                for (int i = 0; i < count.Length; i++)
                {
                    bufferpos3.Add(0);
                }
                WrappedMultiDimArrayMemoryClientUtil.Write(innermem, memorypos3, dat2, bufferpos3, count3);
            }
            finally
            {
                if (dat2 != null)
                {
                    if (dat2Dims != null)
                    {
                        dat2Dims.Dispose();
                    }
                    if (dat2Array != null)
                    {
                        dat2Array.Dispose();
                    }
                    dat2.Dispose();
                }
            }
        }
Example #3
0
        public override void Write(WrappedMultiDimArrayMemoryParams p)
        {
            RRMultiDimArrayUntyped pbuffer      = null;
            RRBaseArray            pbufferDims  = null;
            RRBaseArray            pbufferArray = null;

            try
            {
                ulong[] count     = p.count.ToArray();
                ulong[] bufferpos = p.bufferpos.ToArray();
                ulong[] memorypos = p.memorypos.ToArray();

                ulong elemcount = 1;
                foreach (ulong e in count)
                {
                    elemcount *= e;
                }

                pbuffer      = p.buffer;
                pbufferDims  = pbuffer.Dims;
                pbufferArray = pbuffer.Array;

                int[] dims  = (int[])MessageElementDataUtil.RRBaseArrayToArray(pbufferDims);
                T[]   array = (T[])MessageElementDataUtil.RRBaseArrayToArray(pbufferArray);

                MultiDimArray m = new MultiDimArray(count.Select(x => (uint)x).ToArray(), array);

                mem.Write(memorypos, m, bufferpos, count);
            }
            catch (Exception e)
            {
                using (MessageEntry merr = new MessageEntry())
                {
                    RobotRaconteurExceptionUtil.ExceptionToMessageEntry(e, merr);
                    RRDirectorExceptionHelper.SetError(merr, e.ToString());
                }
            }
            finally
            {
                if (p != null && pbuffer != null)
                {
                    if (pbufferDims != null)
                    {
                        pbufferDims.Dispose();
                    }
                    if (pbufferArray != null)
                    {
                        pbufferArray.Dispose();
                    }
                }
                if (p != null)
                {
                    p.Dispose();
                }
            }
        }
Example #4
0
        private object GetData()
        {
            using (MessageElementData val = _GetData())
            {
                if (val == null)
                {
                    return(null);
                }
                object a = null;
                a = MessageElementDataUtil.ToRRBaseArray(val);
                if (a != null)
                {
                    if (DataTypeUtil.IsNumber(val.GetTypeID()))
                    {
                        RRBaseArray ra = (RRBaseArray)a;
                        try
                        {
                            return(MessageElementDataUtil.RRBaseArrayToArray(ra));
                        }
                        finally
                        {
                            ra.Dispose();
                        }
                    }
                    if (val.GetTypeID() == DataTypes.string_t)
                    {
                        RRBaseArray ra = (RRBaseArray)a;
                        try
                        {
                            return(MessageElementDataUtil.RRBaseArrayToString(ra));
                        }
                        finally
                        {
                            ra.Dispose();
                        }
                    }
                    IDisposable ad = a as IDisposable;
                    if (ad != null)
                    {
                        ad.Dispose();
                    }
                    throw new DataTypeException("Unknown RRArray type");
                }
                a = MessageElementDataUtil.ToMessageElementNestedElementList(val);
                if (a != null)
                {
                    return(a);
                }
                throw new ApplicationException("Unknown data type");
            }

            throw new ApplicationException("Unknown data type");
        }
Example #5
0
        private void SetData(object dat)
        {
            if (dat == null)
            {
                _SetData(null);
                return;
            }
            if (dat is Array)
            {
                using (RRBaseArray rb = MessageElementDataUtil.ArrayToRRBaseArray((Array)dat))
                {
                    _SetData(rb);
                }
                return;
            }

            if (dat is string)
            {
                using (RRBaseArray rb = MessageElementDataUtil.stringToRRBaseArray((string)dat))
                {
                    _SetData(rb);
                }

                return;
            }

            if (dat is MessageElementData)
            {
                _SetData((MessageElementData)dat);
                return;
            }

            string    datatype    = datatype = RobotRaconteurNode.GetTypeString(dat.GetType());
            DataTypes elementtype = DataTypeUtil.TypeIDFromString(datatype);

            if (elementtype != DataTypes.void_t && (elementtype < DataTypes.uint64_t || elementtype == DataTypes.bool_t) &&
                !(dat is Array))
            {
                object dat2 = DataTypeUtil.ArrayFromScalar(dat);

                using (RRBaseArray rb = MessageElementDataUtil.ArrayToRRBaseArray((Array)dat2))
                {
                    _SetData(rb);
                }

                return;
            }

            throw new DataTypeException("Invalid MessageElement data type");
        }
Example #6
0
        public override void Read(ulong[] memorypos, MultiDimArray buffer, ulong[] bufferpos, ulong[] count)
        {
            RRMultiDimArrayUntyped dat      = null;
            RRBaseArray            datDims  = null;
            RRBaseArray            datArray = null;

            try
            {
                vector_uint64_t memorypos2 = new vector_uint64_t();
                foreach (ulong val in memorypos)
                {
                    memorypos2.Add(val);
                }
                vector_uint64_t count2 = new vector_uint64_t();
                foreach (ulong val in count)
                {
                    count2.Add(val);
                }

                dat = WrappedMultiDimArrayMemoryClientUtil.Read(innermem, memorypos2, count2);

                datDims  = dat.Dims;
                datArray = dat.Array;
                uint[] dims  = (uint[])MessageElementDataUtil.RRBaseArrayToArray(datDims);
                T[]    array = (T[])MessageElementDataUtil.RRBaseArrayToArray(datArray);

                MultiDimArray dat2 = new MultiDimArray(dims, array);
                buffer.AssignSubArray(bufferpos.Select(x => (uint)x).ToArray(), dat2, new uint[count.Length],
                                      count.Select(x => (uint)x).ToArray());
            }
            finally
            {
                if (dat != null)
                {
                    if (datDims != null)
                    {
                        datDims.Dispose();
                    }
                    if (datArray != null)
                    {
                        datArray.Dispose();
                    }
                    dat.Dispose();
                }
            }
        }
Example #7
0
        public override void Read(ulong memorypos, T[] buffer, ulong bufferpos, ulong count)
        {
            RRBaseArray dat = null;

            try
            {
                dat = WrappedArrayMemoryClientUtil.Read(innerarray, memorypos, count);
                T[] dat2 = (T[])MessageElementDataUtil.RRBaseArrayToArray(dat);
                Array.Copy(dat2, 0, buffer, (long)bufferpos, (long)count);
            }
            finally
            {
                if (dat != null)
                {
                    dat.Dispose();
                }
            }
        }
Example #8
0
 public override void Write(ulong memorypos, RRBaseArray buffer, ulong bufferpos, ulong count)
 {
     try
     {
         using (buffer)
         {
             T[] buffer2 = (T[])MessageElementDataUtil.RRBaseArrayToArray(buffer);
             mem.Write(memorypos, buffer2, bufferpos, count);
         }
     }
     catch (Exception e)
     {
         using (MessageEntry merr = new MessageEntry())
         {
             RobotRaconteurExceptionUtil.ExceptionToMessageEntry(e, merr);
             RRDirectorExceptionHelper.SetError(merr, e.ToString());
         }
     }
 }
Example #9
0
        public override void Read(ulong memorypos, RRBaseArray buffer, ulong bufferpos, ulong count)
        {
            try
            {
                using (buffer)
                {
                    T[] buffer3 = new T[count];
                    mem.Read(memorypos, buffer3, 0, count);

                    MessageElementDataUtil.ArrayToRRBaseArray(buffer3, buffer);
                }
            }
            catch (Exception e)
            {
                using (MessageEntry merr = new MessageEntry())
                {
                    RobotRaconteurExceptionUtil.ExceptionToMessageEntry(e, merr);
                    RRDirectorExceptionHelper.SetError(merr, e.ToString());
                }
            }
        }
Example #10
0
        public static RRBaseArray ArrayToRRBaseArray(Array i, RRBaseArray o)
        {
            if (i == null)
            {
                return(null);
            }
            DataTypes type = DataTypeUtil.TypeIDFromString(RobotRaconteurNode.GetTypeString(i.GetType().GetElementType()));

            if (i.Length != o.size())
            {
                throw new Exception("Length mismatch");
            }
            if (o.GetTypeID() != type)
            {
                throw new Exception("Type mismatch");
            }

            /*GCHandle h = GCHandle.Alloc(i, GCHandleType.Pinned);
             * rr_memcpy.memcpy(o.void_ptr(), h.AddrOfPinnedObject(), i.Length * o.ElementSize());
             * h.Free();*/

            switch (type)
            {
            case DataTypes.double_t: {
                var a = (double[])i;
                MessageElementDataUtil.DoublesToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.single_t: {
                var a = (float[])i;
                MessageElementDataUtil.FloatsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.int8_t: {
                var a = (sbyte[])i;
                MessageElementDataUtil.BytesToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.uint8_t: {
                var a = (byte[])i;
                MessageElementDataUtil.BytesToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.int16_t: {
                var a = (short[])i;
                MessageElementDataUtil.ShortsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.uint16_t: {
                var a = (ushort[])i;
                MessageElementDataUtil.ShortsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.int32_t: {
                var a = (int[])i;
                MessageElementDataUtil.IntsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.uint32_t: {
                var a = (uint[])i;
                MessageElementDataUtil.IntsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.int64_t: {
                var a = (long[])i;
                MessageElementDataUtil.LongsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.uint64_t: {
                var a = (ulong[])i;
                MessageElementDataUtil.LongsToRRBaseArray(a, a.Length, o);
                return(o);
            }

            case DataTypes.cdouble_t: {
                var a = (CDouble[])i;
                var b = new double[a.Length * 2];
                for (int j = 0; j < a.Length; j++)
                {
                    b[j * 2]     = a[j].Real;
                    b[j * 2 + 1] = a[j].Imag;
                }
                MessageElementDataUtil.DoublesToComplexRRBaseArray(b, b.Length, o);
                return(o);
            }

            case DataTypes.csingle_t: {
                var a = (CSingle[])i;
                var b = new float[a.Length * 2];
                for (int j = 0; j < a.Length; j++)
                {
                    b[j * 2]     = a[j].Real;
                    b[j * 2 + 1] = a[j].Imag;
                }
                MessageElementDataUtil.FloatsToComplexRRBaseArray(b, b.Length, o);
                return(o);
            }

            case DataTypes.bool_t: {
                var a = (bool[])i;
                var b = new byte[a.Length];
                for (int j = 0; j < a.Length; j++)
                {
                    b[j] = a[j] ? (byte)1 : (byte)0;
                }
                MessageElementDataUtil.BytesToBoolRRBaseArray(b, b.Length, o);
                return(o);
            }

            default:
                throw new DataTypeException("Invalid RRBaseArray type");
            }

            return(o);
        }
Example #11
0
        public static Array RRBaseArrayToArray(RRBaseArray i)
        {
            if (i == null)
            {
                return(null);
            }
            DataTypes type = i.GetTypeID();
            Array     o    = null;

            switch (type)
            {
            case DataTypes.double_t: {
                var o2 = new double[i.size()];
                MessageElementDataUtil.RRBaseArrayToDoubles(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.single_t: {
                var o2 = new float[i.size()];
                MessageElementDataUtil.RRBaseArrayToFloats(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.int8_t: {
                var o2 = new sbyte[i.size()];
                MessageElementDataUtil.RRBaseArrayToBytes(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.uint8_t: {
                var o2 = new byte[i.size()];
                MessageElementDataUtil.RRBaseArrayToBytes(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.int16_t: {
                var o2 = new short[i.size()];
                MessageElementDataUtil.RRBaseArrayToShorts(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.uint16_t: {
                var o2 = new ushort[i.size()];
                MessageElementDataUtil.RRBaseArrayToShorts(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.int32_t: {
                var o2 = new int[i.size()];
                MessageElementDataUtil.RRBaseArrayToInts(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.uint32_t: {
                var o2 = new uint[i.size()];
                MessageElementDataUtil.RRBaseArrayToInts(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.int64_t: {
                var o2 = new long[i.size()];
                MessageElementDataUtil.RRBaseArrayToLongs(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.uint64_t: {
                var o2 = new ulong[i.size()];
                MessageElementDataUtil.RRBaseArrayToLongs(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.cdouble_t: {
                var o2 = new double[i.size() * 2];
                MessageElementDataUtil.RRBaseArrayComplexToDoubles(i, o2, o2.Length);
                var o3 = new CDouble[i.size()];
                for (int j = 0; j < o3.Length; j++)
                {
                    o3[j] = new CDouble(o2[j * 2], o2[j * 2 + 1]);
                }
                return(o3);
            }

            case DataTypes.csingle_t: {
                var o2 = new float[i.size() * 2];
                MessageElementDataUtil.RRBaseArrayComplexToFloats(i, o2, o2.Length);
                var o3 = new CSingle[i.size()];
                for (int j = 0; j < o3.Length; j++)
                {
                    o3[j] = new CSingle(o2[j * 2], o2[j * 2 + 1]);
                }
                return(o3);
            }

            case DataTypes.bool_t: {
                var o2 = new byte[i.size()];
                MessageElementDataUtil.RRBaseArrayBoolToBytes(i, o2, o2.Length);
                var o3 = new bool[o2.Length];
                for (int j = 0; j < o3.Length; j++)
                {
                    o3[j] = o2[j] != 0;
                }
                return(o3);
            }

            default:
                throw new DataTypeException("Invalid RRBaseArray type");
            }
        }