cancel
Showing results for 
Search instead for 
Did you mean: 

Can I get Instance of Model? Or How can I call the function of Model in other C code?

Wrend.1
Senior

Often I call the C function from the hardware in Model::tick() function.

But how can I call the function of Model outside.

If I add a member variable to get the Instance(this) of Model, is there any risk? I mean if Model writed by Singleton mode.

1 ACCEPTED SOLUTION

Accepted Solutions

What exactly do you want to accomplish? There might be another way. It could be that you simply want to have a task running and send a message through a queue to the Model which will then handle it in its ::tick() function.

View solution in original post

4 REPLIES 4
Martin KJELDSEN
Chief III

What is it exactly you want to do?

You probably either want to 1) Call a C++ function from C code 2) Have the Model react to something

/Martin

1) Call a C++ function from C code

And now, I write a static pointer of Model​ and make it = this. To make it work. I am afraid it is not safe.😅

What exactly do you want to accomplish? There might be another way. It could be that you simply want to have a task running and send a message through a queue to the Model which will then handle it in its ::tick() function.

Yes, you are right, but sometimes I want to trigger an action one times. If I use the tick() function, I need maintain two flags to realize it. The touchGFX give the trigger function like 'static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent(1);', So I want to find If the Model have the same interface. It is not a problem for me, just a advice.=)