/// <summary>
        /// Creates a new DSS-lobby with the given maximum number of operators.
        /// </summary>
        /// <param name="opCount">The maximum number of operators in the DSS (including the host itself).</param>
        /// <param name="network">The network interface that is used to connect.</param>
        /// <param name="simulatorIface">Interface of the local simulator implemented by the client module.</param>
        /// <param name="setupIface">Interface of the setup manager object implemented by the client module.</param>
        /// <remarks>The caller thread will be blocked during the whole lifetime of the DSS.</remarks>
        public static void CreateDSS(int opCount, INetwork network, ISimulator simulatorIface, IDssHostSetup setupIface)
        {
            if (opCount < 2)
            {
                throw new ArgumentOutOfRangeException("opCount");
            }
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }
            if (simulatorIface == null)
            {
                throw new ArgumentNullException("simulatorIface");
            }
            if (setupIface == null)
            {
                throw new ArgumentNullException("setupIface");
            }

            dssActive.WaitOne();

            try
            {
                DssHostRoot      hostRoot = new DssHostRoot(simulatorIface, setupIface, opCount);
                HostEventHandler eventHdl = new HostEventHandler(hostRoot);
                hostRoot.EventQueue.RegisterHandler(eventHdl);

                ILobbyServer server = network.CreateLobby(opCount, hostRoot.EventQueue);
                if (server == null)
                {
                    throw new DssException("Cannot create the lobby under the DSS!");
                }
                server.StartAnnouncing(); /// TODO: add ILobbyCustomDataProvider if necessary
                hostRoot.Lobby = server;
                hostRoot.EventQueue.EventLoop();
                server.Shutdown();

                hostRoot.Dispose();
            }
            catch (Exception ex)
            {
                TraceManager.WriteExceptionAllTrace(ex, false);
            }
            finally
            {
                dssActive.Release();
            }
        }
Exemple #2
0
 /// <summary>
 /// Constructs a HostEventHandler object.
 /// </summary>
 public HostEventHandler(DssHostRoot root)
     : base(root)
 {
     this.root = root;
 }
Exemple #3
0
        /// <summary>
        /// Contructs a DssManagerSM object.
        /// </summary>
        /// <param name="channelCount">The number of the channels.</param>
        public DssManagerSM(int channelCount, DssHostRoot hostRoot)
        {
            if (channelCount < 1)
            {
                throw new ArgumentOutOfRangeException("channelCount");
            }
            if (hostRoot == null)
            {
                throw new ArgumentNullException("hostRoot");
            }

            this.controller = new StateMachineController();
            this.hostRoot   = hostRoot;
            this.channels   = new DssChannelSM[channelCount];
            this.sessions   = new DssHostSessionSM[channelCount];
            this.externalTriggersCreated = false;
            this.internalTriggersCreated = false;
            this.channelProxies          = new DssChannelProxy[channelCount];

            /// Creating the underlying state machines
            this.managerSM                 = this.controller.AddStateMachine("DSS-manager");
            this.setupStepTimerSM          = this.controller.AddStateMachine("SetupStepTimer");
            this.channelStabilityMonitorSM = this.controller.AddStateMachine("ChannelMonitor");

            /// Creating the states of the DSS-manager
            this.Start               = this.managerSM.AddState("Start", null);
            this.LobbyCreated        = this.managerSM.AddState("LobbyCreated", null);
            this.SendingSetupStepRQs = this.managerSM.AddState("SendingSetupStepRQs", this.CallClientModuleSetupIface);
            this.WaitingSetupStepAWs = this.managerSM.AddState("WaitingSetupStepAWs", null);
            this.SimulationStage     = this.managerSM.AddState("SimulationStage", null);
            this.managerSM.SetInitialState(this.Start);

            /// Creating the states of the setup step timer
            this.SetupStepTimerInactive = this.setupStepTimerSM.AddState("SetupStepTimerInactive", null);
            this.SetupStepTimerRunning  = this.setupStepTimerSM.AddState("SetupStepTimerRunning", this.StartSetupStepTimer);
            this.setupStepTimerSM.SetInitialState(this.SetupStepTimerInactive);

            /// Creating the states of the channel stability monitor
            this.TransientChannelStates = this.channelStabilityMonitorSM.AddState("TransientChannelStates", null);
            this.PermanentChannelStates = this.channelStabilityMonitorSM.AddState("PermanentChannelStates", null);
            this.channelStabilityMonitorSM.SetInitialState(this.TransientChannelStates);

            for (int i = 0; i < channelCount; i++)
            {
                this.channelProxies[i] = new DssChannelProxy(DssMode.HOST_SIDE);//, i);
                IStateMachine channelSM = this.controller.AddStateMachine("Channel-" + i);
                IStateMachine sessionSM = this.controller.AddStateMachine("Session-" + i);
                this.sessions[i] = new DssHostSessionSM(sessionSM, this);
                this.sessions[i].CreateExternalTriggers();
                this.channels[i] = new DssChannelSM(channelSM, this, this.sessions[i], i);
                this.channels[i].CreateExternalTriggers();
                this.sessions[i].Channel = this.channels[i];
            }
            CreateExternalTriggers();

            for (int i = 0; i < channelCount; i++)
            {
                this.sessions[i].CreateInternalTriggers();
                this.channels[i].CreateInternalTriggers();
            }
            CreateInternalTriggers();

            this.controller.CommissionController();

            TraceManager.WriteAllTrace("DSS-manager created", DssTraceFilters.SETUP_STAGE_INFO);
        }