Skip to main content



      Home
Home » Modeling » Papyrus » [C++ Code Gen] Issue when triggering a state machine when a class has several instances
[C++ Code Gen] Issue when triggering a state machine when a class has several instances [message #1852356] Wed, 11 May 2022 11:19 Go to next message
Eclipse UserFriend
Hello,

I have a question about an issue I met these days. I create several instances of the same class which have their own state machine.

The instantiation enables the starting of the statemachines but when I try to trigger one of the state machines, the event seems to be injected in the queue of the statemachine but it is never consumed (and treated).

I made a simple example to reproduce the issue. I think the creation of my instances is ok but I don't understand why the state machine can not be stimulated.

Any idea? bug?

Thanks for reading.
Regards.
Yoann.
Re: [C++ Code Gen] Issue when triggering a state machine when a class has several instances [message #1852696 is a reply to message #1852356] Wed, 01 June 2022 05:46 Go to previous messageGo to next message
Eclipse UserFriend
Hi Yoann,

it took me some time, but I found the problem. With some test output I realized that the "this" pointer of MyInnerClass (with id 2) is different during start of behavior and during the "call" operation.

Your custom instantiator creates the instances, but then creates a copy during the push into the vector (with *myCompositeClass). The example works, if you store a pointer in the vector (of course, change the vector declaration accordingly), as shown below:

void MyCompositeInstantiator::create(::PrimitiveTypes::Integer /*in*/id) {
	std::cout << "create : " << id << std::endl;
	MyCompositeClass *myCompositeClass = new MyCompositeClass(id);
	myCompositeClasses.push_back(myCompositeClass);
	std::cout << myCompositeClasses[myCompositeClasses.size() - 1]->myClass.id
			<< std::endl;
}
..
void MyCompositeInstantiator::call(::PrimitiveTypes::Integer /*in*/id) {
	std::cout << "call : " << id << std::endl;

	for (unsigned int i = 0; i < myCompositeClasses.size(); i++) {
		std::cout << "call " << i << "   " << myCompositeClasses[i]->myClass.id
				<< std::endl;
		if (id == myCompositeClasses[i]->myClass.id) {
			myCompositeClasses[i]->myClass.call();
		}
	}

}
Re: [C++ Code Gen] Issue when triggering a state machine when a class has several instances [message #1852699 is a reply to message #1852696] Wed, 01 June 2022 07:30 Go to previous messageGo to next message
Eclipse UserFriend
As the error was caused by an accidental copy of a class with a state-machine, the question is how the code generator should handle the situation:
(1) delete the copy constructor to avoid copying
(2) provide a generated copy constructor that calls the startBehavior method (as the normal constructor does)
Re: [C++ Code Gen] Issue when triggering a state machine when a class has several instances [message #1852701 is a reply to message #1852699] Wed, 01 June 2022 09:10 Go to previous message
Eclipse UserFriend
Hi Ansgar,

Thank you for pointing this out!

Effectively it works with the change that you propose. Not a bug of software designer =)

For the subsequent question:
(1) This probably avoids using some common operations in C++ so I'm not sure about this solution.
(2) In this case, the current state of the state machine has to be retained in the copy but it could be the right solution in my opinion.

EDIT: What could be the best solution to change the way to generate the code for the vector in this case? ListHint should work but I think it should be set at the property level. Ptr stereotype enables to add the "*" but not at the good place.

[Updated on: Wed, 01 June 2022 09:22] by Moderator

Previous Topic:Is there any way to do api parsing for Sysml1.6?
Next Topic:Aligning Member End labels
Goto Forum:
  


Current Time: Wed Jul 16 18:50:43 EDT 2025

Powered by FUDForum. Page generated in 0.26067 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top