Esempio n. 1
0
        /// <summary>
        /// Constructs a DssHostRoot object.
        /// </summary>
        public DssHostRoot(ISimulator simulatorIface, IDssHostSetup setupIface, int opCount)
            : base(simulatorIface)
        {
            this.setupSteps           = new SetupStep[opCount - 1];
            this.connReqTimeoutClocks = new AlarmClock[opCount - 1];
            for (int i = 0; i < this.setupSteps.Length; i++)
            {
                this.setupSteps[i]           = new SetupStep(DssMode.HOST_SIDE);
                this.connReqTimeoutClocks[i] = null;
            }

            this.setupStepAwTimeoutClock = null;
            this.setupStepClock          = null;

            this.leftGuests = new List <int>();
            this.lostGuests = new List <int>();

            this.setupIface = setupIface;
            this.lobby      = null;
            this.dssManager = new DssManagerSM(opCount - 1, this);
            TraceManager.WriteAllTrace("DssHostRoot created", DssTraceFilters.SETUP_STAGE_INFO);
        }
Esempio n. 2
0
        /// <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();
            }
        }