Beispiel #1
0
        /// <summary>
        /// Constructs a DssGuestSessionSM object.
        /// </summary>
        /// <param name="smc">The SM-controller that is used to construct the underlying state machine.</param>
        public DssGuestSessionSM(DssGuestRoot guestRoot)
        {
            ///this.indexOfThisGuest = -1;     /// We don't know the index currently.
            this.guestRoot    = guestRoot;
            this.channelProxy = new DssChannelProxy(DssMode.GUEST_SIDE);
            this.opFlagsTmp   = null;

            /// Creating the state machine
            this.controller = new StateMachineController();
            this.sm         = this.controller.AddStateMachine("Session");

            /// Creating the states
            this.Start = this.sm.AddState("Start", null);
            this.WaitingConnectionACK = this.sm.AddState("WaitingConnectionACK", null);
            this.WaitingSetupStepRQ   = this.sm.AddState("WaitingSetupStepRQ", null);
            this.SendingSetupStepAW   = this.sm.AddState("SendingSetupStepAW", this.CallClientModuleSetupIface);
            this.Simulating           = this.sm.AddState("Simulating", this.BeginSimulationStage);

            /// Setting the initial state
            this.sm.SetInitialState(this.Start);

            /// Creating the external triggers
            this.Start_WaitingConnectionACK = this.Start.AddExternalTrigger(this.WaitingConnectionACK, this.StartConnAckTimeout);
            this.WaitingConnectionACK_WaitingSetupStepRQ = this.WaitingConnectionACK.AddExternalTrigger(this.WaitingSetupStepRQ,
                                                                                                        this.StopConnAckTimeoutStartSetupStepReqTimeout);
            this.WaitingSetupStepRQ_SendingSetupStepAW = this.WaitingSetupStepRQ.AddExternalTrigger(this.SendingSetupStepAW, this.StopSetupStepReqTimeout);
            this.WaitingSetupStepRQ_Simulating         = this.WaitingSetupStepRQ.AddExternalTrigger(this.Simulating, this.StopSetupStepReqTimeout);
            this.SendingSetupStepAW_WaitingSetupStepRQ = this.SendingSetupStepAW.AddExternalTrigger(this.WaitingSetupStepRQ, this.StartSetupStepReqTimeout);

            this.controller.CommissionController();
        }
        /// <summary>
        /// Connects to an existing DSS-lobby on the network.
        /// </summary>
        /// <param name="dssLobby">The information package of the lobby that contains data for the connection.</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 while the peer is connected to the DSS.</remarks>
        public static void ConnectDSS(LobbyInfo dssLobby, INetwork network, ISimulator simulatorIface, IDssGuestSetup setupIface)
        {
            if (dssLobby == null)
            {
                throw new ArgumentNullException("dssLobby");
            }
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }
            if (simulatorIface == null)
            {
                throw new ArgumentNullException("simulatorIface");
            }
            if (setupIface == null)
            {
                throw new ArgumentNullException("setupIface");
            }

            //throw new Exception("Test exception");
            dssActive.WaitOne();

            try
            {
                DssGuestRoot      guestRoot = new DssGuestRoot(simulatorIface, setupIface);
                GuestEventHandler eventHdl  = new GuestEventHandler(guestRoot);
                guestRoot.EventQueue.RegisterHandler(eventHdl);

                ILobbyClient client = network.JoinLobby(dssLobby, guestRoot.EventQueue);
                if (client == null)
                {
                    throw new DssException("Cannot join to the lobby under the DSS!");
                }
                guestRoot.Lobby = client;
                guestRoot.EventQueue.EventLoop();
                client.Disconnect();

                guestRoot.Dispose();
            }
            catch (Exception ex)
            {
                TraceManager.WriteExceptionAllTrace(ex, false);
            }
            finally
            {
                dssActive.Release();
            }
        }
 /// <summary>
 /// Constructs a GuestEventHandler object.
 /// </summary>
 public GuestEventHandler(DssGuestRoot root)
     : base(root)
 {
     this.root = root;
 }