예제 #1
0
        public Task<RPCData> DispatchCall(int callId, RPCData data)
        {
            var tcs = new TaskCompletionSource<RPCData>();
            pendingCalls.Add(callId, tcs);

            data.Peer.Dispatch(data);

            return tcs.Task;
        }
예제 #2
0
        internal void SetResult(int callId, RPCData data)
        {
            if (!pendingCalls.ContainsKey(callId))
            {
                Log.Error("Received unexpected reply.");
                return;
            }

            pendingCalls[callId].SetResult(data);
        }
예제 #3
0
        public override void Dispatch(RPCData data)
        {
            var bytes = data.Serializer.Buffer.ReadAllBytes();

            var packet = new Packet(0);
            packet.Write(new List<byte>(bytes));
            packet.Flags = ConvertFlags(data.Flags);

            Session.Peer.QueuePacket(packet, 0);
        }
예제 #4
0
파일: RPCImpl.cs 프로젝트: chartly/flood
        internal void ProcessEventSubscribe(RPCData data)
        {
            var eventId = data.Serializer.ReadI32();
            var remoteDelegateId = data.Serializer.ReadI32();

            var subscribe = processors[eventId].Subscribe;
            if (subscribe == null)
                throw new Exception();

            subscribe(data.Peer, remoteDelegateId);
        }
예제 #5
0
파일: RPCImpl.cs 프로젝트: chartly/flood
 public void ProcessCall(RPCData.Call call)
 {
     var processCall = processors[call.MethodId].Call;
     if (processCall != null)
     {
         processCall(call);
     }
     else
     {
         SerializerUtil.Skip(call.Data.Serializer, TType.DataObject);
         var response = new RPCData(call.Data, RPCDataType.Exception);
         RPCException x = new RPCException(RPCException.ExceptionType.UnknownMethod, "Invalid method id: '" + call.MethodId + "'");
         response.Serializer.WriteI32(call.Id);
         x.Write(response.Serializer);
         response.Dispatch();
     }
 }
예제 #6
0
        public void ProcessCall(RPCData.Call call)
        {
            var processCall = processors[call.MethodId].Call;

            if (processCall != null)
            {
                processCall(call);
            }
            else
            {
                SerializerUtil.Skip(call.Data.Serializer, TType.DataObject);
                var          response = RPCData.Create(call.Data, RPCDataType.Exception);
                RPCException x        = new RPCException(RPCException.ExceptionType.UnknownMethod, "Invalid method id: '" + call.MethodId + "'");
                response.Serializer.WriteI32(call.Id);
                x.Write(response.Serializer);
                response.Dispatch();
            }
        }
예제 #7
0
        public unsafe void DispatchChanges()
        {
            foreach (var reference in referencesChanged)
            {
                var bitFieldsCount = reference.DataObject.BaseDataObjectCount + 1;
                var bitFields = stackalloc BitField[bitFieldsCount];

                reference.DataObject.GetResetChanges(bitFields);

                foreach (var peer in reference.Subscribers)
                {
                    var peerData = new RPCData(peer, RPCManager, reference.LocalId, 0, RPCDataType.ReferenceChanges);
                    // TODO: Optimize this. Dont't serialize again for each peer.
                    reference.DataObject.Write(peerData, bitFields, bitFieldsCount);
                    peerData.Dispatch();
                }
            }
        }
예제 #8
0
 public void Process(RPCData data)
 {
     switch (data.Header.CallType)
     {
         case RPCDataType.ReferenceChanges:
             ProcessChanges(data);
             return;
         case RPCDataType.ReferenceSubscribe:
             ProcessSubscribe(data);
             return;
         case RPCDataType.ReferenceUnsubscribe:
             ProcessUnsubscribe(data);
             return;
         default:
             Debug.Assert(false);
             return;
     }
 }
예제 #9
0
        private void ProcessUnsubscribe(RPCData data)
        {
            var localId = data.Header.LocalId;

            Reference reference;
            if (!localIdToReference.TryGetValue(localId, out reference))
                throw new Exception("No reference to subscribe to.");

            reference.Subscribers.Remove(data.Peer);
        }
예제 #10
0
        private void ProcessSubscribe(RPCData data)
        {
            var localId = data.Header.LocalId;

            Reference reference;
            if (!localIdToReference.TryGetValue(localId, out reference))
                throw new Exception("No reference to subscribe to.");

            if (reference.Subscribers == null)
                reference.Subscribers = new HashSet<RPCPeer>();

            reference.Subscribers.Add(data.Peer);
            //TODO send complete serialization
        }
예제 #11
0
        private void ProcessChanges(RPCData data)
        {
            var subscription = new Subscription(data.Peer, data.Header.RemoteId);
            Reference reference;
            if (!subscriptionToReference.TryGetValue(subscription, out reference))
                throw new Exception("Reference not found.");

            reference.DataObject.Read(data);
        }
예제 #12
0
파일: RPCData.cs 프로젝트: chartly/flood
            internal static DelegateCall Create(RPCData data)
            {
                var call = new DelegateCall();
                call.Data = data;

                call.Id = data.Serializer.ReadI32();

                return call;
            }
예제 #13
0
 public abstract void Invoke(RPCData.DelegateCall call);
예제 #14
0
 public abstract void Dispatch(RPCData data);
예제 #15
0
파일: RPCData.cs 프로젝트: chartly/flood
            internal Call(int id, int methodId, RPCPeer peer, RPCManager rpcManager, int localId, int remoteId)
            {
                Id = id;
                MethodId = methodId;
                Data = new RPCData(peer, rpcManager, localId, remoteId, RPCDataType.Call);

                Data.Serializer.WriteI32(id);
                Data.Serializer.WriteI32(methodId);

                if (remoteId == 0)
                {
                    GlobalServiceId = rpcManager.ServiceManager.GetGlobalServiceId(localId);
                    GlobalServiceId.Write(Data);
                }
                else
                {
                    GlobalServiceId = default(GlobalServiceId);
                }
            }
예제 #16
0
파일: RPCData.cs 프로젝트: chartly/flood
            internal static Call Create(RPCData data)
            {
                var call = new Call();
                call.Data = data;

                call.Id = data.Serializer.ReadI32();
                call.MethodId = data.Serializer.ReadI32();

                if (data.Header.LocalId == 0)
                    call.GlobalServiceId = GlobalServiceId.Read(data);

                return call;
            }
예제 #17
0
파일: RPCData.cs 프로젝트: chartly/flood
 public RPCData(RPCData call, RPCDataType type, RPCFlags flags = RPCFlags.None)
     : this(call.Peer, call.RPCManager ,call.Header.LocalId, call.Header.RemoteId, type, flags)
 {
 }
예제 #18
0
파일: RPCData.cs 프로젝트: chartly/flood
            internal static Reply Create(RPCData data)
            {
                var reply = new Reply();
                reply.Data = data;

                reply.Id = data.Serializer.ReadI32();
                reply.MethodId = data.Serializer.ReadI32();

                return reply;
            }
예제 #19
0
파일: RPCData.cs 프로젝트: chartly/flood
            public Reply(Call call)
            {
                Id = call.Id;
                MethodId = call.MethodId;
                Data = new RPCData(call.Data, RPCDataType.Reply);

                Data.Serializer.WriteI32(Id);
                Data.Serializer.WriteI32(MethodId);
            }
예제 #20
0
파일: RPCData.cs 프로젝트: chartly/flood
            internal static DelegateReply Create(RPCData data)
            {
                var reply = new DelegateReply();
                reply.Data = data;

                reply.Id = data.Serializer.ReadI32();

                return reply;
            }
예제 #21
0
파일: RPCData.cs 프로젝트: chartly/flood
            public DelegateReply(DelegateCall call)
            {
                Id = call.Id;

                Data = new RPCData(call.Data, RPCDataType.DelegateReply);

                Data.Serializer.WriteI32(Id);
            }
예제 #22
0
 public static RPCData Create(RPCData call, RPCDataType type, RPCFlags flags = RPCFlags.None)
 {
     return(Create(call.Peer, call.Header.LocalId, call.Header.RemoteId, type, flags));
 }
예제 #23
0
파일: RPCPeer.cs 프로젝트: chartly/flood
 public abstract void Dispatch(RPCData data);
예제 #24
0
 internal void ProcessEventUnsubscribe(RPCData data)
 {
     throw new System.NotImplementedException();
 }
예제 #25
0
파일: RPCImpl.cs 프로젝트: chartly/flood
 internal void ProcessEventUnsubscribe(RPCData data)
 {
     throw new System.NotImplementedException();
 }
예제 #26
0
 internal void ProcessReply(RPCData.DelegateReply reply)
 {
     callProcessor.SetResult(reply.Id, reply.Data);
 }
예제 #27
0
        public void Subscribe(IObservableDataObject dataObject, RPCPeer peer, int remoteId)
        {
            Reference reference;
            if (!dataObjectToReference.TryGetValue(dataObject, out reference))
                reference = CreateReference(dataObject);

            reference.Subscription = new Subscription(peer, remoteId);

            subscriptionToReference.Add(reference.Subscription, reference);

            var data = new RPCData(peer, RPCManager, reference.LocalId, remoteId, RPCDataType.ReferenceSubscribe);
            data.Dispatch();
        }
예제 #28
0
 public Task<RPCData> DispatchCall(RPCData.DelegateCall call)
 {
     return callProcessor.DispatchCall(call.Id, call.Data);
 }
예제 #29
0
파일: RPCData.cs 프로젝트: chartly/flood
            internal DelegateCall(int id, RPCPeer peer, RPCManager rpcManager, int localId, int remoteId)
            {
                Id = id;
                Data = new RPCData(peer, rpcManager, localId, remoteId, RPCDataType.DelegateCall);

                Data.Serializer.WriteI32(id);
            }