... | ... | @@ -353,3 +353,40 @@ To finish, it is **highly recommended** to follow these guidelines to implement |
|
|
|
|
|
# Connect to the starter app
|
|
|
|
|
|
There are some use cases where it is interesting or even necessary to get a reference to the application that started *this* application.
|
|
|
Let's take the previous example where we defined the code of *App2*. We modify it to get an access to the *starter* app:
|
|
|
```java
|
|
|
import fr.ill.ics.cameo.base.This;
|
|
|
|
|
|
public class JavaApp {
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
// Initialise the Cameo application represented by This.
|
|
|
This.init(args);
|
|
|
|
|
|
// Get the starter app.
|
|
|
Instance starter = This.connectToStarter();
|
|
|
|
|
|
// Infinite printing loop.
|
|
|
int i = 0;
|
|
|
while (true) {
|
|
|
System.out.println("Printing " + i);
|
|
|
try {
|
|
|
Thread.sleep(100);
|
|
|
}
|
|
|
catch (InterruptedException e) {
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
|
|
|
This.terminate();
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
In our example, the *starter* app should be the running application *App1*. But warning, the application could have terminated since it sent the request to start *App2*.
|
|
|
|
|
|
In C++ and Python, the function is also *connectToStarter()* member of the *This* object.
|
|
|
|
|
|
Once you have a reference to the *starter* you can decide to stop it or use it to connect a communication object. |
|
|
\ No newline at end of file |