Esempio n. 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();
                }
            }
        }
Esempio n. 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();
                }
            }
        }
Esempio n. 3
0
        public override void Read(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;

                T[] array = new T[elemcount];

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

                mem.Read(memorypos, m, bufferpos, count);
                MessageElementDataUtil.ArrayToRRBaseArray(array, pbufferArray);
            }
            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();
                }
            }
        }
Esempio n. 4
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");
        }
Esempio n. 5
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());
                }
            }
        }