[statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Gurcan Gulesir

Hi,

 

I am trying to implement an asynchronous state machine whose states contain substates. Since my compilation errors seem to be related to the statechart library (instead of directly to the code I wrote myself), I started to suspect that the statechart library does not support the nesting of states in an asynchronous state machine. Am I right or am I missing something?

 

Upon trying any combination of boost::statechart::state and boost::statechart::simple_state as the super class of the top-level states and sub states, the typical compilation errors I received are like the following:

 

‘deep_construct’ is not a member of ‘boost::statechart::simple_state<MostDerived, Context, InnerInitial, historyMode>::deep_construct_inner_impl_non_empty::deep_construct_inner_impl(const boost::intrusive_ptr<T>&, typename Context::inner_context_type::outermost_context_base_type&) [with InnerList = boost::mpl::list<robot::RobotSM::SCOUTING, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, MostDerived = robot::RobotSM::CONNECTED_WITH_OPERATOR, Context = robot::RobotSM::RobotSM, InnerInitial = robot::RobotSM::SCOUTING, boost::statechart::history_mode historyMode = (boost::statechart::history_mode)0u]::current_inner’ RobotBehavior                 line 894, external location: /usr/include/boost/statechart/simple_state.hpp           C/C++ Problem

 

‘class boost::statechart::simple_state<robot::RobotSM::SAFE_TO_MOVE, robot::RobotSM::CONNECTED_WITH_OPERATOR, boost::mpl::list<mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, (boost::statechart::history_mode)0u>’ has no member named ‘deferred_events’                RobotBehavior                 line 360, external location: /usr/include/boost/statechart/simple_state.hpp    C/C++ Problem

 

‘class boost::statechart::state<robot::RobotSM::SAFE_TO_MOVE, robot::RobotSM::CONNECTED_WITH_OPERATOR, boost::mpl::list<mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, (boost::statechart::history_mode)0u>’ has no member named ‘set_context’ RobotBehavior                 line 50, external location: /usr/include/boost/statechart/state.hpp        C/C++ Problem

 

If nested states are intentionally not supported in current Boost.Statechart, is there a fundamental reason for this restriction? Or is it just not yet implemented as a feature of asynchronous state machines?

 

Many thanks for your response, in advance.

 

Best regards,

Gurcan


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Andreas Huber-3
Hi

[snip]
> I started to
> suspect that the statechart library does not support the  
> nesting of states
> in an asynchronous state machine. Am I right or am I missing  
> something?

Probably the latter: Asynchronous state machines should be able  
to deal with nested states just like synchronous ones.

Please post a small but complete program that demonstrates the  
issue.

Thanks & Regards,

--
Andreas Huber

When replying by private email, please remove the words spam and  
trap from the address shown in the header.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Gurcan Gulesir
In reply to this post by Gurcan Gulesir
Hi Andreas,

Many thanks for your help first of all!

Upon your request, I wrote a small but complete program that demonstrates
the issue. This program consists of 5 source code files:

1) main.cpp
2) StateMachine.hpp
3) StateMachine.cpp
4) SuperState.hpp
5) SubState.hpp

The contents of these files are listed at the end of this e-mail. You should
be able to compile these listings and then run the executable successfully.
Depending on your compiler flags, you may receive one warning that says "/*
within comment". This is intentional, so please ignore the warning.

To reproduce my problem regarding the nesting of states, please modify the
listings in three locations, as explained in the comments in SuperState.hpp
and SubState.hpp, and then re-compile. You should receive multiple errors
pointing to the Boost Statechart library.

Looking forward to your feedback.

Thanks & Regards,
Gurcan

----------------------------------------
1) main.cpp
----------------------------------------

#include <iostream>

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/thread/thread.hpp>
#include <boost/statechart/asynchronous_state_machine.hpp>
#include <boost/statechart/fifo_worker.hpp>

#include "StateMachine.hpp"

int main() {
    std::cout<<"\n\nPress any key and then <CR> to exit\n\n"<<std::endl;
    char key;

    boost::statechart::fifo_scheduler<> scheduler(true);
    boost::statechart::fifo_scheduler<>::processor_handle handle =
scheduler.create_processor<StateMachine> ();
    scheduler.initiate_processor(handle);
    boost::thread
aThread(boost::bind(&boost::statechart::fifo_scheduler<>::operator(),&schedu
ler, 0));

    std::cin >> key;

    scheduler.destroy_processor(handle);
    scheduler.terminate();
    aThread.join();

    return 0;
}

----------------------------------------
2) StateMachine.hpp
----------------------------------------

#ifndef StateMachine_hpp
#define StateMachine_hpp

#include <boost/statechart/asynchronous_state_machine.hpp>

class StateMachine;

class SuperState;

namespace boost {
namespace statechart {
template<>
inline void asynchronous_state_machine<StateMachine,
SuperState>::initiate_impl() {}
}}

class StateMachine: public
boost::statechart::asynchronous_state_machine<StateMachine, SuperState> {

public:
    StateMachine(my_context ctx) : my_base(ctx) {}

private:
    virtual void initiate_impl();
};

#endif

----------------------------------------
3) StateMachine.cpp
----------------------------------------

#include <boost/statechart/state_machine.hpp>

#include "StateMachine.hpp"
#include "SuperState.hpp"

void StateMachine::initiate_impl() {
    boost::statechart::state_machine<StateMachine, SuperState>::initiate();
}

----------------------------------------
4) SuperState.hpp
----------------------------------------

#ifndef SuperState_hpp
#define SuperState_hpp

#include <iostream>
#include <boost/statechart/simple_state.hpp>

#include "StateMachine.hpp"
#include "SubState.hpp"

class StateMachine;

class SubState;

//MODIFICATION 1 of 3: UNCOMMENT THE FOLLOWING LINE
//class SuperState: public boost::statechart::simple_state<SuperState,
StateMachine, SubState> {

//MODIFICATION 2 of 3: COMMENT OUT THE FOLLOWING LINE
class SuperState: public boost::statechart::simple_state<SuperState,
StateMachine> {

public:

    SuperState(){
        std::cout<<"Entered into SuperState."<<std::endl;
    }

};

#endif

----------------------------------------
5) SubState.hpp
----------------------------------------

//MODIFICATION 3 of 3: COMMENT OUT THE FOLLOWING LINE
/*

#ifndef SubState_hpp
#define SubState_hpp

#include <iostream>
#include <boost/statechart/simple_state.hpp>

#include "SuperState.hpp"

class SuperState;

class SubState: public boost::statechart::simple_state<SubState, SuperState>
{

public:

    SubState(){
        std::cout<<"Enteres into SubState."<<std::endl;
    }

};

#endif
/**/

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Igor R.
In reply to this post by Gurcan Gulesir
> Upon your request, I wrote a small but complete program that demonstrates
> the issue. This program consists of 5 source code files:
>
> 1) main.cpp
> 2) StateMachine.hpp
> 3) StateMachine.cpp
> 4) SuperState.hpp
> 5) SubState.hpp


You've got a compiler error, not a linker one, right? If so, why do
you need 2 translation units and 5 files to reproduce it?
I belive, you can reproduce it in one single file, which we could just
copy&paste into an empty file, and try to compile.
It should go like this:

// states definition...
// machine definition...
int main()
{
  // machine instantiation
}
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Gurcan Gulesir
In reply to this post by Gurcan Gulesir
Hi Andreas,

I realized that some lines in my previously posted listings were wrapped by
my e-mail client. Since this may cause compilation problems for you, I
hereby attach the source code files for your convenience.

Thanks & Regards,
Gurcan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

main.cpp (825 bytes) Download Attachment
StateMachine.hpp (542 bytes) Download Attachment
StateMachine.cpp (225 bytes) Download Attachment
SuperState.hpp (615 bytes) Download Attachment
SubState.hpp (417 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Gurcan Gulesir
In reply to this post by Gurcan Gulesir
> I belive, you can reproduce it in one single file,
> which we could just copy&paste into an empty file, and try to compile.
> It should go like this:
>
> // states definition...
> // machine definition...
> int main()
>{
>   // machine instantiation
>}

Ok. Please see the attached file in which I put the whole source code.

Putting everything into one file, surprisingly for me, solved my problem of
not being able to nest a sub-state under a super state. Now I need to figure
out why the previous implementation (i.e., the one distributed over multiple
files) does not compile. Ultimately, I should be able to distribute my
actual state machine implementation to multiple files for better
scalability, readability, maintainability, etc. I will investigate further
and announce the outcome. Needless to say, I would also very much appreciate
if you would be willing to quickly point out where I went wrong in the
previous implementation.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

main.cpp (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Igor R.
In reply to this post by Gurcan Gulesir
> Putting everything into one file, surprisingly for me, solved my problem of
> not being able to nest a sub-state under a super state. Now I need to figure
> out why the previous implementation (i.e., the one distributed over multiple
> files) does not compile.

I guess you try to use undefined (forward-declared) types in contexts
where they cannot be used.
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Gurcan Gulesir
In reply to this post by Gurcan Gulesir
Thanks for the recommendation. The problem turned out to be indeed with
forward declarations. I wish the compilation errors were somewhat more
informative, so that I could find the root cause of the problem easily.

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Igor R
Sent: donderdag 9 juni 2011 18:33
To: [hidden email]
Subject: Re: [Boost-users] [statechart] Is it possible to have nested
(sub)states in an asynchronous state machine?

> Putting everything into one file, surprisingly for me, solved my problem
of
> not being able to nest a sub-state under a super state. Now I need to
figure
> out why the previous implementation (i.e., the one distributed over
multiple
> files) does not compile.

I guess you try to use undefined (forward-declared) types in contexts
where they cannot be used.
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Igor R.
In reply to this post by Gurcan Gulesir
> Thanks for the recommendation. The problem turned out to be indeed with
> forward declarations. I wish the compilation errors were somewhat more
> informative, so that I could find the root cause of the problem easily.


I don't know what compiler you used and what your real code looked
like, but when I tried to compile some portions of your sample code
with VC10, I got a lot of "use of undefined type" errors.
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] Is it possible to have nested (sub)states in an asynchronous state machine?

Gurcan Gulesir
In reply to this post by Gurcan Gulesir
> I don't know what compiler you used and what your real code looked
> like, but when I tried to compile some portions of your sample code
> with VC10, I got a lot of "use of undefined type" errors.

I am using Eclipse IDE for C/C++ Helios Service Release 2 and Ubuntu 10.04
LTS with its built-in GCC C++ compiler and linker. My software uses
Linux-specific libraries, so VC10 is currently not an option for me. If I
encounter any additional problems, then I will first compile the "skeleton
code" of my state machines in VC10, find and solve the problem there, and
then port the solution to Eclipse in Ubuntu. So, thanks for the tip!

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users