예제 #1
0
        private void FeedAction(Action action, SocketError socketError, int bytesTransferred)
        {
            this.Handle(action, socketError, bytesTransferred);

            while (this.m_actionsQueue.Count > 0)
            {
                StateMachineAction stateMachineAction = this.m_actionsQueue.Dequeue();
                this.Handle(stateMachineAction.Action, stateMachineAction.SocketError, stateMachineAction.BytesTransferred);
            }
        }
        private static StateMachineAction ReadAction(BinaryReader reader)
        {
            var newAction = new StateMachineAction
            {
                ParentEntryIndex     = reader.ReadInt32(),
                ParentConditionIndex = reader.ReadInt32(),
                Name  = reader.ReadNullTerminatedString(),
                Value = reader.ReadNullTerminatedString()
            };

            return(newAction);
        }
        /// <summary>
        /// Build telephone state configuration
        /// </summary>
        private void BuildConfig()
        {
            // Transitions and actions
            #region preparation of transitions and actions
            TelephoneActivities = new TelephoneActivities();

            // create actions and map action methods into the corresponding action object
            // Device actions
            var actionBellRings  = new StateMachineAction("ActionBellRings", this.TelephoneActivities.ActionBellRings);
            var actionBellSilent = new StateMachineAction("ActionBellSilent", this.TelephoneActivities.ActionBellSilent);
            var actionLineOff    = new StateMachineAction("ActionLineOff", this.TelephoneActivities.ActionLineOff);
            var actionLineActive = new StateMachineAction("ActionLineActive", this.TelephoneActivities.ActionLineActive);

            // View Actions
            var actionViewPhoneRings = new StateMachineAction("ActionViewPhoneRings", this.TelephoneActivities.ActionViewPhoneRings);
            var actionViewPhoneIdle  = new StateMachineAction("ActionViewPhoneIdle", this.TelephoneActivities.ActionViewPhoneIdle);
            var actionViewTalking    = new StateMachineAction("ActionViewTalking", this.TelephoneActivities.ActionViewTalking);

            // Error Actions
            var actionViewErrorPhoneRings = new StateMachineAction("ActionViewErrorPhoneRings", TelephoneActivities.ActionErrorPhoneRings);

            // Create transitions and corresponding triggers, states need to be added
            var emptyList = new List <StateMachineAction>(); // to avoid null reference exceptions, use an empty list
            // transition IncomingCall
            var IncomingCallActions = new List <StateMachineAction>();
            IncomingCallActions.Add(actionViewPhoneRings);
            var transIncomingCall = new Transition("TransitionIncomingCall", "StatePhoneIdle", "StatePhoneRings", emptyList, IncomingCallActions, "OnLineExternalActive");

            // transition CallBlocked
            var CallBlockedActions = new List <StateMachineAction>();
            CallBlockedActions.Add(actionViewPhoneIdle);
            var transCallBlocked = new Transition("TransitionCallBlocked", "StatePhoneRings", "StatePhoneIdle", emptyList, CallBlockedActions, "OnReceiverDown");

            // transition CallAccepted
            var CallAcceptedActions = new List <StateMachineAction>();
            CallAcceptedActions.Add(actionViewTalking);
            var transCallAccepted = new Transition("TransitionCallAccepted", "StatePhoneRings", "StateTalking", emptyList, CallAcceptedActions, "OnReceiverUp");

            // transition CallEnded
            var CallEndedActions = new List <StateMachineAction>();
            CallEndedActions.Add(actionViewPhoneIdle);
            var transCallEnded = new Transition("TransitionCallEnded", "StateTalking", "StatePhoneIdle", emptyList, CallEndedActions, "OnReceiverDown");

            // transition ErrorPhoneRings - self-transition on PhoneRings state
            var errorPhoneRingsActions = new List <StateMachineAction>();
            errorPhoneRingsActions.Add(actionViewErrorPhoneRings);
            var transErrorPhoneRings = new Transition("TransitionErrorPhoneRings", "StatePhoneRings", "StatePhoneRings", emptyList, errorPhoneRingsActions, "OnBellBroken");

            #endregion

            #region Assemble all states
            // create states
            // state: PhoneIdle
            var transitionsPhoneIdle  = new Dictionary <string, Transition>();
            var entryActionsPhoneIdle = new List <StateMachineAction>();
            var exitActionsPhoneIdle  = new List <StateMachineAction>();
            transitionsPhoneIdle.Add("TransitionIncomingCall", transIncomingCall);
            // Always specify all action lists, even empty ones, do not pass null into a state Lists are read via foreach, which will return an error
            var phoneIdle = new State("StatePhoneIdle", transitionsPhoneIdle, entryActionsPhoneIdle, exitActionsPhoneIdle, true);

            // state: PhoneRings
            var transitionsPhoneRings  = new Dictionary <string, Transition>();
            var entryActionsPhoneRings = new List <StateMachineAction>();
            entryActionsPhoneRings.Add(actionBellRings);
            var exitActionsPhoneRings = new List <StateMachineAction>();
            exitActionsPhoneRings.Add(actionBellSilent);
            transitionsPhoneRings.Add("TransitionCallBlocked", transCallBlocked);
            transitionsPhoneRings.Add("TransitionCallAccepted", transCallAccepted);
            transitionsPhoneRings.Add("TransitionErrorPhoneRings", transErrorPhoneRings);
            // Always specify all action lists, even empty ones, do not pass null into a state Lists are read via foreach, which will return an error
            var phoneRings = new State("StatePhoneRings", transitionsPhoneRings, entryActionsPhoneRings, exitActionsPhoneRings);

            // state: Talking
            var transitionsTalking  = new Dictionary <string, Transition>();
            var entryActionsTalking = new List <StateMachineAction>();
            entryActionsTalking.Add(actionLineActive);
            var exitActionsTalking = new List <StateMachineAction>();
            exitActionsTalking.Add(actionLineOff);
            transitionsTalking.Add("TransitionCallEnded", transCallEnded);
            // Always specify all action lists, even empty ones, do not pass null into a state Lists are read via foreach, which will return an error
            var talking = new State("StateTalking", transitionsTalking, entryActionsTalking, exitActionsTalking);

            this.TelephoneStateMachineStateList = new Dictionary <string, State>
            {
                { "StatePhoneIdle", phoneIdle },
                { "StatePhoneRings", phoneRings },
                { "StateTalking", talking }
            };

            #endregion

            // Application Services
            #region Appilcation Services
            // Get application services
            this.TelephoneEventManager  = EventManager.Instance;
            this.TelephoneViewManager   = ViewManager.Instance;
            this.TelephoneLogManager    = LogManager.Instance;
            this.TelephoneDeviceManager = DeviceManager.Instance;

            #endregion
        }
예제 #4
0
 public void Add(T state, StateMachineAction <T> action) /****************/
 {
     _actions.Add(state, action);
 }
 private static void WriteAction(BinaryWriter writer, int entryIndex, int conditionIndex, StateMachineAction action)
 {
     writer.Write(Magics.Action);
     writer.Write(entryIndex);
     writer.Write(conditionIndex);
     writer.WriteNullTerminatedString(action.Name);
     writer.WriteNullTerminatedString(action.Value);
 }