コード例 #1
0
        public TR InObjectStreamOutObjectStream <TR>(int type, Action <IBinaryStream> writeAction,
                                                     Func <IBinaryStream, IPlatformTargetInternal, TR> readAction, IPlatformTargetInternal arg)
        {
            PlatformMemoryStream outStream = null;
            long outPtr = 0;

            PlatformMemoryStream inStream = null;
            long inPtr = 0;

            try
            {
                if (writeAction != null)
                {
                    outStream = IgniteManager.Memory.Allocate().GetStream();
                    writeAction(outStream);
                    outPtr = outStream.SynchronizeOutput();
                }

                if (readAction != null)
                {
                    inStream = IgniteManager.Memory.Allocate().GetStream();
                    inPtr    = inStream.MemoryPointer;
                }

                var res = UU.TargetInObjectStreamOutObjectStream(_target, type,
                                                                 ((PlatformJniTarget)arg).Target, outPtr, inPtr);

                if (readAction == null)
                {
                    return(default(TR));
                }

                inStream.SynchronizeInput();

                var target = res == null ? null : new PlatformJniTarget(res, _marsh);

                return(readAction(inStream, target));
            }
            catch (JavaException jex)
            {
                throw ConvertException(jex);
            }
            finally
            {
                try
                {
                    if (inStream != null)
                    {
                        inStream.Dispose();
                    }
                }
                finally
                {
                    if (outStream != null)
                    {
                        outStream.Dispose();
                    }
                }
            }
        }
コード例 #2
0
        /** <inheritdoc /> */
        public T InObjectStreamOutObjectStream <T>(int type, IPlatformTarget arg,
                                                   Action <IBinaryRawWriter> writeAction, Func <IBinaryRawReader, IPlatformTarget, T> readAction)
        {
            PlatformMemoryStream outStream = null;
            long outPtr = 0;

            PlatformMemoryStream inStream = null;
            long inPtr = 0;

            try
            {
                if (writeAction != null)
                {
                    outStream = IgniteManager.Memory.Allocate().GetStream();
                    var writer = _marsh.StartMarshal(outStream);
                    writeAction(writer);
                    FinishMarshal(writer);
                    outPtr = outStream.SynchronizeOutput();
                }

                if (readAction != null)
                {
                    inStream = IgniteManager.Memory.Allocate().GetStream();
                    inPtr    = inStream.MemoryPointer;
                }

                var res = UU.TargetInObjectStreamOutObjectStream(_target, type, GetTargetPtr(arg), outPtr, inPtr);

                if (readAction == null)
                {
                    return(default(T));
                }

                inStream.SynchronizeInput();

                return(readAction(_marsh.StartUnmarshal(inStream), GetPlatformTarget(res)));
            }
            catch (JavaException jex)
            {
                throw ConvertException(jex);
            }
            finally
            {
                try
                {
                    if (inStream != null)
                    {
                        inStream.Dispose();
                    }
                }
                finally
                {
                    if (outStream != null)
                    {
                        outStream.Dispose();
                    }
                }
            }
        }
コード例 #3
0
ファイル: PlatformTarget.cs プロジェクト: xestyle/ignite
        /// <summary>
        /// Perform out-in operation.
        /// </summary>
        /// <param name="type">Operation type.</param>
        /// <param name="outAction">Out action.</param>
        /// <param name="inAction">In action.</param>
        /// <param name="arg">Argument.</param>
        /// <returns>Result.</returns>
        protected unsafe TR DoOutInOp <TR>(int type, Action <BinaryWriter> outAction,
                                           Func <IBinaryStream, IUnmanagedTarget, TR> inAction, void *arg)
        {
            PlatformMemoryStream outStream = null;
            long outPtr = 0;

            PlatformMemoryStream inStream = null;
            long inPtr = 0;

            try
            {
                if (outAction != null)
                {
                    outStream = IgniteManager.Memory.Allocate().GetStream();
                    var writer = _marsh.StartMarshal(outStream);
                    outAction(writer);
                    FinishMarshal(writer);
                    outPtr = outStream.SynchronizeOutput();
                }

                if (inAction != null)
                {
                    inStream = IgniteManager.Memory.Allocate().GetStream();
                    inPtr    = inStream.MemoryPointer;
                }

                var res = UU.TargetInObjectStreamOutObjectStream(_target, type, arg, outPtr, inPtr);

                if (inAction == null)
                {
                    return(default(TR));
                }

                inStream.SynchronizeInput();

                return(inAction(inStream, res));
            }
            finally
            {
                try
                {
                    if (inStream != null)
                    {
                        inStream.Dispose();
                    }
                }
                finally
                {
                    if (outStream != null)
                    {
                        outStream.Dispose();
                    }
                }
            }
        }