예제 #1
0
        public static byte[] CreateInputCommand(CommandFrame frame)
        {
            var fbb = new FlatBufferBuilder(1024);

            var oFrame = CreateCommandFrameOffset(frame, fbb);

            var oInputCommand = Messages.InputCommand.CreateInputCommand(fbb, oFrame);

            Messages.InputCommand.FinishInputCommandBuffer(fbb, oInputCommand);

            return(fbb.ToProtocolMessage(MessageIds.InputCommand));
        }
예제 #2
0
        private void ProcessMessage(Message m)
        {
            var messageId = (DLNSchema.Messages.MessageIds)m.Id;

            switch (messageId)
            {
            case DLNSchema.Messages.MessageIds.AssignSessionId:
            {
                var message = (DLNSchema.Messages.AssignSessionId)m.Body;

                this.sessionId = message.SessionId;

                this.handler.OnConnect();
            }
            break;

            case DLNSchema.Messages.MessageIds.SyncFrame:
            {
                if (this.sessionId == 0)
                {
                    throw new InvalidOperationException("SessionId is not assigned yet");
                }

                var message = (DLNSchema.Messages.SyncFrame)m.Body;
                for (int i = 0; i < message.FramesLength; i++)
                {
                    var f = message.GetFrames(i);

                    var commands = new Command[f.CommandsLength];
                    for (int j = 0; j < f.CommandsLength; j++)
                    {
                        var c = f.GetCommands(j);

                        commands[j] = new Command(c.CommandId, c.SessionId);
                    }

                    var frame = new CommandFrame(f.Ticks, commands);

                    lock (this.framesLock)
                    {
                        this.frames.Add(frame);
                    }

                    this.handler.OnSync();
                }
            }
            break;

            default:
                throw new InvalidOperationException(string.Format("Unexpected message: {0}", messageId));
            }
        }
예제 #3
0
        private static Offset <Messages.CommandFrame> CreateCommandFrameOffset(CommandFrame frame, FlatBufferBuilder fbb)
        {
            Offset <Messages.Command>[] oCommands = null;
            if (frame.Commands != null && frame.Commands.Length > 0)
            {
                oCommands = new Offset <Messages.Command> [frame.Commands.Length];

                int j = 0;
                foreach (var c in frame.Commands)
                {
                    oCommands[j] = Messages.Command.CreateCommand(fbb, c.CommandId, c.SessionId);
                    j++;
                }
            }
            else
            {
                oCommands = new Offset <Messages.Command> [0];
            }

            var vCommand = Messages.CommandFrame.CreateCommandsVector(fbb, oCommands);

            return(Messages.CommandFrame.CreateCommandFrame(fbb, frame.Ticks, vCommand));
        }
        private void SynchronizeFrame(object state)
        {
            while (!isEnded)
            {
                Thread.Sleep(SyncInterval);

                this.currentTicks++;

                CommandFrame frame;
                lock (this.commandsLock)
                {
                    frame = new CommandFrame(this.currentTicks, this.commands.ToArray());

                    this.commands.Clear();
                }

                lock(this.totalFramesLock)
                {
                    this.totalFrames.Add(frame);
                }

                lock (this.sessionsLock)
                {
                    foreach (var session in this.sessions)
                    {
                        session.SynchronizeCommandFrame(frame);
                    }
                }
            }
        }
예제 #5
0
        public void SendCommand(uint ticks, Command command)
        {
            var frame = new CommandFrame(ticks, new Command[] { command });

            ThreadPool.QueueUserWorkItem(WriteThread, frame);
        }
        private void ProcessMessage(Message m)
        {
            var messageId = (DLNSchema.Messages.MessageIds)m.Id;

            switch (messageId)
            {
                case DLNSchema.Messages.MessageIds.AssignSessionId:
                    {
                        var message = (DLNSchema.Messages.AssignSessionId)m.Body;

                        this.sessionId = message.SessionId;

                        this.handler.OnConnect();
                    }
                    break;

                case DLNSchema.Messages.MessageIds.SyncFrame:
                    {
                        if (this.sessionId == 0)
                            throw new InvalidOperationException("SessionId is not assigned yet");

                        var message = (DLNSchema.Messages.SyncFrame)m.Body;
                        for (int i = 0; i < message.FramesLength; i++)
                        {
                            var f = message.GetFrames(i);

                            var commands = new Command[f.CommandsLength];
                            for (int j = 0; j < f.CommandsLength; j++)
                            {
                                var c = f.GetCommands(j);

                                commands[j] = new Command(c.CommandId, c.SessionId);
                            }

                            var frame = new CommandFrame(f.Ticks, commands);

                            lock (this.framesLock)
                            {
                                this.frames.Add(frame);
                            }

                            this.handler.OnSync();
                        }
                    }
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Unexpected message: {0}", messageId));
            }
        }
        public void SendCommand(uint ticks, Command command)
        {
            var frame = new CommandFrame(ticks, new Command[] { command });

            ThreadPool.QueueUserWorkItem(WriteThread, frame);
        }