public static byte[] PackRpcDefinition(NtRpcDefinition def, out UIntPtr packedLen)
        {
            WireEncoder enc = new WireEncoder();
            enc.Write8((byte)def.Version);
            enc.WriteString(def.Name);

            int paramsSize = def.ParamsArray.Length;
            if (paramsSize > 0xff) paramsSize = 0xff;
            enc.Write8((byte)paramsSize);
            for (int i = 0; i < paramsSize; ++i)
            {
                enc.WriteType(def.ParamsArray[i].Value.Type);
                enc.WriteString(def.ParamsArray[i].Name);
                enc.WriteValue(def.ParamsArray[i].Value);
            }

            int resultsSize = def.ResultsArray.Length;
            if (resultsSize > 0xff) resultsSize = 0xff;
            enc.Write8((byte)resultsSize);
            for (int i = 0; i < resultsSize; ++i)
            {
                enc.WriteType(def.ResultsArray[i].Type);
                enc.WriteString(def.ResultsArray[i].Name);
            }
            packedLen = (UIntPtr)enc.Buffer.Length;
            return enc.Buffer;
        }
 public static void CreatePolledPrc(string name, NtRpcDefinition def)
 {
     UIntPtr packedLen;
     byte[] packed = PackRpcDefinition(def, out packedLen);
     UIntPtr nameLen;
     byte[] nameB = CoreMethods.CreateUTF8String(name, out nameLen);
     Interop.NT_CreatePolledRpc(nameB, nameLen, packed, packedLen);
 }
        public static void CreatePolledPrc(string name, NtRpcDefinition def)
        {
            UIntPtr packedLen;

            byte[]  packed = PackRpcDefinition(def, out packedLen);
            UIntPtr nameLen;

            byte[] nameB = CoreMethods.CreateUTF8String(name, out nameLen);
            Interop.NT_CreatePolledRpc(nameB, nameLen, packed, packedLen);
        }
Пример #4
0
        public void TestRpcAllTypes()
        {
            CoreMethods.SetLogger((level, file, line, message) =>
            {
                //Console.Error.WriteLine(message);
            }, 0);

            var def = new NtRpcDefinition(1, "myfunc1", new[]
            {
                new NtRpcParamDef("param1", RpcValue.MakeBoolean(true)),
                new NtRpcParamDef("param2", RpcValue.MakeBooleanArray(new[] { true, false })),
                new NtRpcParamDef("param3", RpcValue.MakeDouble(0.0)),
                new NtRpcParamDef("param4", RpcValue.MakeDoubleArray(new[] { 2.8, 6.87 })),
                new NtRpcParamDef("param5", RpcValue.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 })),
                new NtRpcParamDef("param6", RpcValue.MakeString("NewString")),
                new NtRpcParamDef("param7", RpcValue.MakeStringArray(new[] { "String1", "String2" })),
            }, new[]
            {
                new NtRpcResultDef("result1", NtType.Boolean),
                new NtRpcResultDef("result2", NtType.BooleanArray),
                new NtRpcResultDef("result3", NtType.Double),
                new NtRpcResultDef("result4", NtType.DoubleArray),
                new NtRpcResultDef("result5", NtType.Raw),
                new NtRpcResultDef("result6", NtType.String),
                new NtRpcResultDef("result7", NtType.StringArray),
            });

            RemoteProcedureCall.CreateRpc("func1", def, Callback2);

            Console.WriteLine("Calling RPC");

            uint call1Uid = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeBoolean(true), RpcValue.MakeBooleanArray(new[] { true, false }), RpcValue.MakeDouble(2.2), RpcValue.MakeDoubleArray(new[] { 2.8, 6.87 }),
                RpcValue.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 }), RpcValue.MakeString("NewString"), RpcValue.MakeStringArray(new[] { "String1", "String2" }));

            Console.WriteLine("Waiting for RPC Result");
            byte[] result = RemoteProcedureCall.GetRpcResult(true, call1Uid);
            var call1Result = RemoteProcedureCall.UnpackRpcValues(result, NtType.Boolean, NtType.BooleanArray, NtType.Double, NtType.DoubleArray, NtType.Raw, NtType.String, NtType.StringArray);
            Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty");

            Console.WriteLine(call1Result[0].ToString());
        }
        public static void CreateRpc(string name, NtRpcDefinition def, RpcCallback callback)
        {
            Interop.NT_RPCCallback modCallback =
                (IntPtr data, IntPtr ptr, UIntPtr len, IntPtr intPtr, UIntPtr paramsLen, out UIntPtr resultsLen) =>
                {
                    string retName = CoreMethods.ReadUTF8String(ptr, len);
                    byte[] param = CoreMethods.GetRawDataFromPtr(intPtr, paramsLen);
                    byte[] cb = callback(retName, param);
                    resultsLen = (UIntPtr)cb.Length;
                    IntPtr retPtr = Interop.NT_AllocateCharArray(resultsLen);
                    Marshal.Copy(cb, 0, retPtr, cb.Length);
                    return retPtr;
                };

            UIntPtr packedLen;
            byte[] packed = PackRpcDefinition(def, out packedLen);
            UIntPtr nameLen;
            byte[] nameB = CoreMethods.CreateUTF8String(name, out nameLen);
            Interop.NT_CreateRpc(nameB, nameLen, packed, packedLen, IntPtr.Zero, modCallback);
            s_rpcCallbacks.Add(modCallback);
        }
Пример #6
0
        public void TestRpcLocal()
        {
            CoreMethods.SetLogger((level, file, line, message) =>
            {
                //Console.Error.WriteLine(message);
            }, 0);

            var def = new NtRpcDefinition(1, "myfunc1", new[] { new NtRpcParamDef("param1", RpcValue.MakeDouble(0.0)) }, new[] { new NtRpcResultDef("result1", NtType.Double) });

            RemoteProcedureCall.CreateRpc("func1", def, Callback1);

            Console.WriteLine("Calling RPC");

            uint call1Uid = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeDouble(2.0));

            Console.WriteLine("Waiting for RPC Result");
            byte[] result = RemoteProcedureCall.GetRpcResult(true, call1Uid);
            var call1Result = RemoteProcedureCall.UnpackRpcValues(result, NtType.Double);
            Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty");

            Console.WriteLine(call1Result[0].ToString());
        }
        public static void CreateRpc(string name, NtRpcDefinition def, RpcCallback callback)
        {
            Interop.NT_RPCCallback modCallback =
                (IntPtr data, IntPtr ptr, UIntPtr len, IntPtr intPtr, UIntPtr paramsLen, out UIntPtr resultsLen) =>
            {
                string retName = CoreMethods.ReadUTF8String(ptr, len);
                byte[] param   = CoreMethods.GetRawDataFromPtr(intPtr, paramsLen);
                byte[] cb      = callback(retName, param);
                resultsLen = (UIntPtr)cb.Length;
                IntPtr retPtr = Interop.NT_AllocateCharArray(resultsLen);
                Marshal.Copy(cb, 0, retPtr, cb.Length);
                return(retPtr);
            };

            UIntPtr packedLen;

            byte[]  packed = PackRpcDefinition(def, out packedLen);
            UIntPtr nameLen;

            byte[] nameB = CoreMethods.CreateUTF8String(name, out nameLen);
            Interop.NT_CreateRpc(nameB, nameLen, packed, packedLen, IntPtr.Zero, modCallback);
            s_rpcCallbacks.Add(modCallback);
        }
Пример #8
0
        public void TestRpcSpeed()
        {
            CoreMethods.SetLogger((level, file, line, message) =>
            {
                //Console.Error.WriteLine(message);
            }, 0);

            var def = new NtRpcDefinition(1, "myfunc1", new[] { new NtRpcParamDef("param1", RpcValue.MakeDouble(0.0)) }, new[] { new NtRpcResultDef("result1", NtType.Double) });

            RemoteProcedureCall.CreateRpc("func1", def, Callback1);

            Stopwatch sw = new Stopwatch();
            sw.Start();

            for (int i = 0; i < 10000; ++i)
            {
                uint call1Uid = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeDouble(i));
                byte[] call1Result = RemoteProcedureCall.GetRpcResult(true, call1Uid);
                var res = RemoteProcedureCall.UnpackRpcValues(call1Result, NtType.Double);
                Assert.AreNotEqual(0, res.Count, "RPC Result empty");
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed);
        }
        public static byte[] PackRpcDefinition(NtRpcDefinition def, out UIntPtr packedLen)
        {
            WireEncoder enc = new WireEncoder();

            enc.Write8((byte)def.Version);
            enc.WriteString(def.Name);

            int paramsSize = def.ParamsArray.Length;

            if (paramsSize > 0xff)
            {
                paramsSize = 0xff;
            }
            enc.Write8((byte)paramsSize);
            for (int i = 0; i < paramsSize; ++i)
            {
                enc.WriteType(def.ParamsArray[i].Value.Type);
                enc.WriteString(def.ParamsArray[i].Name);
                enc.WriteValue(def.ParamsArray[i].Value);
            }

            int resultsSize = def.ResultsArray.Length;

            if (resultsSize > 0xff)
            {
                resultsSize = 0xff;
            }
            enc.Write8((byte)resultsSize);
            for (int i = 0; i < resultsSize; ++i)
            {
                enc.WriteType(def.ResultsArray[i].Type);
                enc.WriteString(def.ResultsArray[i].Name);
            }
            packedLen = (UIntPtr)enc.Buffer.Length;
            return(enc.Buffer);
        }