コード例 #1
0
        protected IPacketBroadcaster StartCommunicator()
        {
            if (_communicator != null)
            {
                throw new NotSupportedException("Can't start while already started.");
            }

            switch (_communicationType)
            {
            case BroadcasterTypeEnum.UDP:
                _communicator = new UdpPacketBroadcaster();
                break;

            case BroadcasterTypeEnum.TCP:
                //TODO: _communicator = new TcpBroadcaster();
                throw new NotSupportedException("TCP Not yet supported.");
                break;

            default:
                throw new NotSupportedException("Developer laziness not yet supported.");
            }

            _communicator.BroadcastPort = _broadcastPort;
            _communicator.Start();

            return(_communicator);
        }
コード例 #2
0
        private void BroadcastingThreadMethod()
        {
            try
            {
                using (_observer = new InputDeltaObserver())
                {
                    using (StartCommunicator())
                    {
                        _observer.StartCapturing();
                        LogExceptions(_observer.ProcessingExceptions);
                        _communicator.Start();

                        OnDriversReady();

                        while (_isRunning)
                        {
                            lock (this)
                            {
                                _observer.UpdateTick();
                                LogExceptions(_observer.ProcessingExceptions);

                                if (_observer.DirtiedDeltas.Count > 0)
                                {
                                    //Filter dirtied deltas
                                    //TODO

                                    //Serialize and send
                                    var dirtied = _observer.SerializeDirtied();
                                    _communicator.Broadcast(dirtied);
                                }
                            }

                            Thread.Sleep(_updateTick);
                        }

                        _communicator.Stop();
                        _communicator.Dispose();
                        _communicator = null;
                    }
                    _observer.StopCapturing();
                    _observer.Dispose();
                    LogExceptions(_observer.ProcessingExceptions);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
            }
        }