コード例 #1
0
        private void HandleMessage(IPCMessage msg)
        {
            RPCMessage rpcmsg = msg.rpc;

            Debuger.Log("[{0}]-> {1}({2})", msg.src, rpcmsg.name, rpcmsg.args.ToListString());

            var helper = m_rpc.GetMethodHelper(rpcmsg.name);

            if (helper != null)
            {
                object[]         args      = new object[rpcmsg.args.Length + 1];
                List <RPCRawArg> raw_args  = rpcmsg.raw_args;
                ParameterInfo[]  paramInfo = helper.method.GetParameters();

                if (args.Length == paramInfo.Length)
                {
                    for (int i = 0; i < raw_args.Count; i++)
                    {
                        if (raw_args[i].type == RPCArgType.PBObject)
                        {
                            args[i + 1] = PBSerializer.NDeserialize(raw_args[i].raw_value, paramInfo[i + 1].ParameterType);
                        }
                        else
                        {
                            args[i + 1] = raw_args[i].value;
                        }
                    }

                    args[0] = msg.src;

                    m_currInvokingName = rpcmsg.name;
                    m_currInvokingSrc  = msg.src;

                    try
                    {
                        helper.method.Invoke(helper.listener, BindingFlags.NonPublic, null, args, null);
                    }
                    catch (Exception e)
                    {
                        Debuger.LogError("RPC调用出错:{0}\n{1}", e.Message, e.StackTrace);
                    }

                    m_currInvokingName = "";
                    m_currInvokingSrc  = 0;
                }
                else
                {
                    Debuger.LogWarning("参数数量不一致!");
                }
            }
            else
            {
                Debuger.LogWarning("RPC不存在!");
            }
        }
コード例 #2
0
        private void DoReceiveInMain()
        {
            lock (m_RecvBufferQueue)
            {
                if (m_RecvBufferQueue.Count > 0)
                {
                    byte[] buffer = m_RecvBufferQueue.Dequeue();

                    IPCMessage msg = PBSerializer.NDeserialize <IPCMessage>(buffer);

                    HandleMessage(msg);
                }
            }
        }
コード例 #3
0
        public void Invoke(int dst, string name, params object[] args)
        {
            Debuger.Log("->[{0}] {1}({2})", dst, name, args.ToListString());

            RPCMessage rpcmsg = new RPCMessage();

            rpcmsg.name = name;
            rpcmsg.args = args;

            IPCMessage msg = new IPCMessage();

            msg.src = m_id;
            msg.rpc = rpcmsg;

            byte[] temp = PBSerializer.NSerialize(msg);
            SendMessage(dst, temp, temp.Length);
        }
コード例 #4
0
        public void ReturnError(string errinfo, int errcode = 1)
        {
            var name = "On" + m_currInvokingName + "Error";

            Debuger.LogWarning("->[{0}] {1}({2},{3})", m_currInvokingSrc, name, errinfo, errcode);

            RPCMessage rpcmsg = new RPCMessage();

            rpcmsg.name = name;
            rpcmsg.args = new object[] { errinfo, errcode };

            IPCMessage msg = new IPCMessage();

            msg.src = m_id;
            msg.rpc = rpcmsg;

            byte[] temp = PBSerializer.NSerialize(msg);
            SendMessage(m_currInvokingSrc, temp, temp.Length);
        }
コード例 #5
0
        public void Return(params object[] args)
        {
            var name = "On" + m_currInvokingName;

            Debuger.Log("->[{0}] {1}({2})", m_currInvokingSrc, name, args.ToListString());

            RPCMessage rpcmsg = new RPCMessage();

            rpcmsg.name = name;
            rpcmsg.args = args;

            IPCMessage msg = new IPCMessage();

            msg.src = m_id;
            msg.rpc = rpcmsg;


            byte[] temp = PBSerializer.NSerialize(msg);
            SendMessage(m_currInvokingSrc, temp, temp.Length);
        }