Opened 9 years ago

Closed 9 years ago

#9280 closed Bugs (fixed)

handling deferred events

Reported by: Dmitry Banschikov <me@…> Owned by: Christophe Henry
Milestone: To Be Determined Component: msm
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

My FSM has two states(connected, disconnected). One of the states is submachine with number of other substates. One of this substates has deferred events specified.

When my root machine goes from state with submachine(connected) to disconnected, should any deferred events be cleared? If no, then why when we enter back in st_connected, deferred events are not handled immediately? MSM process them only after processing normal event(I think that after processing events MSM check if there are any deferred events).

In test case I expect either no output after string 'On cmd with reply: 5' (when right behaviour is to clear deferred events), or 'On cmd with reply: 1' (when right behaviour is to process all deferred events on entry into st_connected state).

Tested on 1.51, 1.53, trunk.

Attachments (1)

main.cc (5.1 KB ) - added by Dmitry Banschikov <me@…> 9 years ago.
Processing of deferred events for submachine

Download all attachments as: .zip

Change History (5)

by Dmitry Banschikov <me@…>, 9 years ago

Attachment: main.cc added

Processing of deferred events for submachine

comment:1 by Christophe Henry, 9 years ago

Status: newassigned

Correct, this is a bug, precisely, entering the submachine does not check for waiting deferred events. This would be solved by adding inside do_entry inside state_machine.hpp:

handle_defer_helper<library_sm> defer_helper(m_deferred_events_queue); defer_helper.do_post_handle_deferred(HANDLED_TRUE);

before : process_message_queue(this);

This will have for effect that MSM will process ev_async_send_cmd_with_reply(1) when entering, and ev_async_send_cmd_with_reply(2) will be the last displayed text.

But frankly, after seeing this, I'm unsure whether it's a great idea to keep deferred events while leaving the submachine, I need to think about it.

To check if it solves your problem, I committed this fix in trunk rev. 86759.

comment:2 by Dmitry Banschikov <me@…>, 9 years ago

Yes, with rev. 86759 output of test case is more expected. Actually, I need all deferred events be cleared on exit from state. For such behaviour I use this workaround:

        template <class Event, class Fsm>
        void on_exit(Event const&, Fsm& fsm)
        {   
            std::cout << "On exit" << std::endl;
            op_.reset();
            fsm.template get_state<test_machine_front_t::st_connected&>().get_deferred_queue().clear();
        }

comment:3 by Christophe Henry, 9 years ago

Ok, next possible solution, should make most happy: the decision of throwing away the deferred events upon exit is made by the history policy:

I committed to trunk, rev. 86799 (let's see if I get the last commit to svn ever ;-) ). Hope it solves your problem.

comment:4 by Christophe Henry, 9 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.