Exemplo n.º 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;
        }
Exemplo n.º 2
0
        internal void SetResult(int callId, RPCData data)
        {
            if (!pendingCalls.ContainsKey(callId))
            {
                Log.Error("Received unexpected reply.");
                return;
            }

            pendingCalls[callId].SetResult(data);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
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 = 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();
     }
 }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 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;
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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
        }
Exemplo n.º 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);
        }
Exemplo n.º 12
0
            internal static DelegateCall Create(RPCData data)
            {
                var call = new DelegateCall();
                call.Data = data;

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

                return call;
            }
Exemplo n.º 13
0
 public abstract void Invoke(RPCData.DelegateCall call);
Exemplo n.º 14
0
 public abstract void Dispatch(RPCData data);
Exemplo n.º 15
0
            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);
                }
            }
Exemplo n.º 16
0
            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;
            }
Exemplo n.º 17
0
 public RPCData(RPCData call, RPCDataType type, RPCFlags flags = RPCFlags.None)
     : this(call.Peer, call.RPCManager ,call.Header.LocalId, call.Header.RemoteId, type, flags)
 {
 }
Exemplo n.º 18
0
            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;
            }
Exemplo n.º 19
0
            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);
            }
Exemplo n.º 20
0
            internal static DelegateReply Create(RPCData data)
            {
                var reply = new DelegateReply();
                reply.Data = data;

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

                return reply;
            }
Exemplo n.º 21
0
            public DelegateReply(DelegateCall call)
            {
                Id = call.Id;

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

                Data.Serializer.WriteI32(Id);
            }
Exemplo n.º 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));
 }
Exemplo n.º 23
0
 public abstract void Dispatch(RPCData data);
Exemplo n.º 24
0
 internal void ProcessEventUnsubscribe(RPCData data)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 25
0
 internal void ProcessEventUnsubscribe(RPCData data)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 26
0
 internal void ProcessReply(RPCData.DelegateReply reply)
 {
     callProcessor.SetResult(reply.Id, reply.Data);
 }
Exemplo n.º 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();
        }
Exemplo n.º 28
0
 public Task<RPCData> DispatchCall(RPCData.DelegateCall call)
 {
     return callProcessor.DispatchCall(call.Id, call.Data);
 }
Exemplo n.º 29
0
            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);
            }