Example #1
0
        /// <summary>
        /// Creates an procedure that can be called by a remote client
        /// </summary>
        /// <remarks>
        /// Note that this can only be called by a server.
        /// </remarks>
        /// <param name="name">The name for this Rpc</param>
        /// <param name="def">The definition for this Rpc</param>
        /// <param name="callback">The callback to use the the procedure is called from a remote</param>
        public static void CreateRpc(string name, IList <byte> def, RpcCallback callback)
        {
#if CORE
            CoreMethods.CreateRpc(name, def, callback);
#else
            Storage.Instance.CreateRpc(name, def, callback);
#endif
        }
Example #2
0
        /// <summary>
        /// Creates an procedure that can be called by a remote client
        /// </summary>
        /// <remarks>
        /// Note that this can only be called by a server.
        /// </remarks>
        /// <param name="name">The name for this Rpc</param>
        /// <param name="def">The definition for this Rpc</param>
        /// <param name="callback">The callback to use the the procedure is called from a remote</param>
        public static void CreateRpc(string name, RpcDefinition def, RpcCallback callback)
        {
#if CORE
            CreateRpc(name, PackRpcDefinition(def), callback);
#else
            Storage.Instance.CreateRpc(name, PackRpcDefinition(def), callback);
#endif
        }
Example #3
0
 public RpcCall(string name, Message msg, RpcCallback func, uint connId, SendMsgFunc sendResponse)
 {
     Name         = name;
     Msg          = msg;
     Func         = func;
     ConnId       = connId;
     SendResponse = sendResponse;
 }
Example #4
0
        public void Login(RpcCallback <DelTaskReply> callback)
        {
            var parameters = new PlayerLogin
            {
                token = 11010,
            };

            mInvoker.Call($"route,player", parameters, callback);
        }
Example #5
0
        /// <summary>
        /// list all task.
        /// </summary>
        public void ListTaskAsync(
            RpcCallback <ListTaskReply> callback
            )
        {
            var parameters = new ListTaskArgs {
            };

            ListTaskAsync(parameters, callback);
        }
Example #6
0
        /// <summary>
        /// get task with id.
        /// </summary>
        /// <param name="taskId">taskId</param>
        public void GetTaskAsync(
            int taskId,
            RpcCallback <GetTaskReply> callback
            )
        {
            var parameters = new GetTaskArgs {
                taskId = taskId,
            };

            GetTaskAsync(parameters, callback);
        }
Example #7
0
        /// <summary>
        /// delete task with id.
        /// </summary>
        /// <param name="taskId">taskId</param>
        public void DelTaskAsync(
            int taskId,
            RpcCallback <DelTaskReply> callback
            )
        {
            var parameters = new DelTaskArgs {
                taskId = taskId,
            };

            DelTaskAsync(parameters, callback);
        }
Example #8
0
        /// <summary>
        /// add new task.
        /// </summary>
        /// <param name="taskName">taskName</param>
        /// <param name="taskTime">taskTime</param>
        public void AddTaskAsync(
            string taskName,
            long taskTime,
            RpcCallback <AddTaskReply> callback
            )
        {
            var parameters = new AddTaskArgs {
                taskName = taskName,
                taskTime = taskTime,
            };

            AddTaskAsync(parameters, callback);
        }
Example #9
0
 public SampleRpc()
 {
     _rpcCallbackNum   = (int)EMsgType.MaxNum;
     _rpcCallbackArray = new RpcCallback[_rpcCallbackNum];
     _rpcCallbackArray[(int)EMsgType.voidReq]        = voidReqStub;
     _rpcCallbackArray[(int)EMsgType.voidAck]        = voidAckStub;
     _rpcCallbackArray[(int)EMsgType.sampleFuncReq]  = sampleFuncReqStub;
     _rpcCallbackArray[(int)EMsgType.sampleFuncAck]  = sampleFuncAckStub;
     _rpcCallbackArray[(int)EMsgType.sampleFuncPost] = sampleFuncPostStub;
     _rpcCallbackArray[(int)EMsgType.sampleFuncNtf]  = sampleFuncNtfStub;
     _rpcCallbackArray[(int)EMsgType.helloReq]       = helloReqStub;
     _rpcCallbackArray[(int)EMsgType.helloAck]       = helloAckStub;
     _rpcCallbackArray[(int)EMsgType.towParamReq]    = towParamReqStub;
     _rpcCallbackArray[(int)EMsgType.towParamAck]    = towParamAckStub;
 }
        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);
        }
Example #11
0
        /// <summary>
        /// Creates an procedure that can be called by a remote client
        /// </summary>
        /// <remarks>
        /// Note that this can only be called by a server.
        /// </remarks>
        /// <param name="name">The name for this Rpc</param>
        /// <param name="def">The definition for this Rpc</param>
        /// <param name="callback">The callback to use the the procedure is called from a remote</param>
        public static void CreateRpc(string name, byte[] def, RpcCallback callback)
        {
#if CORE
            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 nameLen;
            IntPtr  nameB = CoreMethods.CreateCachedUTF8String(name, out nameLen);
            Interop.NT_CreateRpc(nameB, nameLen, def, (UIntPtr)def.Length, IntPtr.Zero, modCallback);
            s_rpcCallbacks.Add(modCallback);
#else
            Storage.Instance.CreateRpc(name, def, callback);
#endif
        }
Example #12
0
        internal static void CreateRpc(string name, IList <byte> def, RpcCallback callback)
        {
            Interop.NT_RPCCallback modCallback =
                (IntPtr data, IntPtr ptr, UIntPtr len, IntPtr intPtr, UIntPtr paramsLen, out UIntPtr resultsLen, ref NtConnectionInfo connInfo) =>
            {
                string       retName = ReadUTF8String(ptr, len);
                byte[]       param   = GetRawDataFromPtr(intPtr, paramsLen);
                IList <byte> cb      = callback(retName, param, connInfo.ToManaged());
                resultsLen = (UIntPtr)cb.Count;
                IntPtr retPtr = Interop.NT_AllocateCharArray(resultsLen);
                if (cb is byte[])
                {
                    Marshal.Copy((byte[])cb, 0, retPtr, cb.Count);
                }
                else
                {
                    for (int i = 0; i < cb.Count; i++)
                    {
                        // Must do a slow write if not a byte[]
                        Marshal.WriteByte(retPtr, i, cb[i]);
                    }
                }

                return(retPtr);
            };
            var nameB = CreateCachedUTF8String(name);

            if (def is byte[] bArr)
            {
                Interop.NT_CreateRpc(nameB.Buffer, nameB.Length, bArr, (UIntPtr)def.Count, IntPtr.Zero, modCallback);
            }
            else
            {
                Interop.NT_CreateRpc(nameB.Buffer, nameB.Length, def.ToArray(), (UIntPtr)def.Count, IntPtr.Zero, modCallback);
            }

            s_rpcCallbacks.Add(modCallback);
        }
Example #13
0
 public void ProcessRpc(string name, Message msg, RpcCallback func, uint connId, SendMsgFunc sendResponse)
 {
     using (m_lockObject.Lock())
     {
         if (func != null)
         {
             m_callQueue.Enqueue(new RpcCall(name, msg, func, connId, sendResponse));
         }
         else
         {
             // ReSharper disable once ExpressionIsAlwaysNull
             m_pollQueue.Enqueue(new RpcCall(name, msg, func, connId, sendResponse));
         }
         if (func != null)
         {
             m_callCond.NotifyAll();
         }
         else
         {
             m_pollCond.NotifyAll();
         }
     }
 }
        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);
        }
 /// <inheritdoc cref="RemoteProcedureCall.CreateRpc(string, byte[], RpcCallback)"/>
 public void CreateRpc(string name, byte[] def, RpcCallback callback)
 {
     m_ntCore.m_storage.CreateRpc(name, def, callback);
 }
 /// <inheritdoc cref="RemoteProcedureCall.CreateRpc(string, RpcDefinition, RpcCallback)"/>
 public void CreateRpc(string name, RpcDefinition def, RpcCallback callback)
 {
     m_ntCore.m_storage.CreateRpc(name, PackRpcDefinition(def), callback);
 }
Example #17
0
 /// <summary>
 /// add new task.
 /// </summary>
 public void AddTaskAsync(AddTaskArgs args, RpcCallback <AddTaskReply> callback)
 {
     mInvoker.Call($"player,route", args, callback);
 }
Example #18
0
        public void CreateRpc(string name, byte[] def, RpcCallback callback)
        {
            if (string.IsNullOrEmpty(name) || def == null || def.Length == 0 || callback == null)
            {
                return;
            }
            IDisposable monitor = null;

            try
            {
                monitor = m_monitor.Enter();
                IDisposable monitorToUnlock;
                if (!m_server)
                {
                    return;
                }

                Entry entry;
                if (!m_entries.TryGetValue(name, out entry))
                {
                    entry = new Entry(name);
                    m_entries.Add(name, entry);
                }

                var oldValue = entry.Value;
                var value    = Value.MakeRpc(def);
                entry.Value       = value;
                entry.RpcCallback = callback;
                m_rpcServer.Start();

                if (oldValue != null && oldValue == value)
                {
                    return;
                }

                if (entry.Id == 0xffff)
                {
                    int id = m_idMap.Count;
                    entry.Id = (uint)id;
                    m_idMap.Add(entry);
                }

                if (m_queueOutgoing == null)
                {
                    return;
                }
                var queueOutgoing = m_queueOutgoing;
                if (oldValue == null || oldValue.Type != value.Type)
                {
                    ++entry.SeqNum;
                    var msg = Message.EntryAssign(name, entry.Id, entry.SeqNum.Value, value, entry.Flags);
                    monitorToUnlock = Interlocked.Exchange(ref monitor, null);
                    monitorToUnlock.Dispose();
                    queueOutgoing(msg, null, null);
                }
                else
                {
                    ++entry.SeqNum;
                    var msg = Message.EntryUpdate(entry.Id, entry.SeqNum.Value, value);
                    monitorToUnlock = Interlocked.Exchange(ref monitor, null);
                    monitorToUnlock.Dispose();
                    queueOutgoing(msg, null, null);
                }
            }
            finally
            {
                monitor?.Dispose();
            }
        }