| |||
| Home > Communication with C++ Code > Accessing C++ constructs from LISA+ > LISA+ example | |||
Example 3.1 demonstrates the LISA+ language features used to communicate with C++ code.
Example 3.1. Communicating with C++
component MyComponent{
includes
{
// make C++ declaration visible in behaviors and resources
#include "MyCPPComponent.h"
}
resources
{
MyCPPComponent *mycomp; // declare a pointer to a C++ class
}
// this internal port is used to allow the C++ code to talk to us
internal port<MyInterface> callback
{
behavior signal()
{
// this behavior may be called by the C++ code
}
}
behavior init
{
// create instance of C++ class. We pass a pointer to the 'callback'
// port to allow the C++ code to call us back
mycomp = new MyCPPComponent(callback.getAbstractInterface());
}
behavior reset(int level)
{
// C++ code can be directly called from LISA+ without any special
// syntax
mycomp->reset();
}
behavior terminate
{
delete mycomp; // delete instance of C++ class
}
}
// this protocol is used to allow the C++ code to call the LISA codeprotocol MyInterface{
behavior signal();
}