Skip to content

Commit

Permalink
dispose correctly of the plugin channels
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVautherin committed Sep 13, 2019
1 parent ea81bde commit 0803505
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void onPause() {
disposable.dispose();
}

// TODO: 4/10/19 close these channels properly
drone.dispose();
drone = null;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ private void updateVehiclePosition(@Nullable LatLng newLatLng) {
*
* @param latLngs current mission waypoints
*/
private void updateMarkers(@Nullable List<LatLng> latLngs) {
private void updateMarkers(@NonNull List<LatLng> latLngs) {
if (circleManager != null) {
circleManager.delete(waypoints);
waypoints.clear();
Expand Down
138 changes: 82 additions & 56 deletions sdk/mavsdk/src/main/java/io/mavsdk/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,97 @@
import io.mavsdk.telemetry.Telemetry;

public class System {
private Action action;
private Calibration calibration;
private Camera camera;
private Core core;
private Gimbal gimbal;
private Info info;
private Mission mission;
private Offboard offboard;
private Param param;
private Telemetry telemetry;
private Action action;
private Calibration calibration;
private Camera camera;
private Core core;
private Gimbal gimbal;
private Info info;
private Mission mission;
private Offboard offboard;
private Param param;
private Telemetry telemetry;

public System() {
this("localhost", 50051);
}
/**
* Create a System object, initializing the plugins and connecting them to mavsdk_server.
*
* This defaults to a mavsdk_server running on localhost:50051.
*/
public System() {
this("localhost", 50051);
}

public System(String host, int port) {
this.action = new Action(host, port);
this.calibration = new Calibration(host, port);
this.camera = new Camera(host, port);
this.core = new Core(host, port);
this.gimbal = new Gimbal(host, port);
this.info = new Info(host, port);
this.mission = new Mission(host, port);
this.offboard = new Offboard(host, port);
this.param = new Param(host, port);
this.telemetry = new Telemetry(host, port);
}
/**
* Create a System object, initializing the plugins and connecting them to mavsdk_server.
* @param host the address of mavsdk_server
* @param port the port of mavsdk_server
*/
public System(String host, int port) {
this.action = new Action(host, port);
this.calibration = new Calibration(host, port);
this.camera = new Camera(host, port);
this.core = new Core(host, port);
this.gimbal = new Gimbal(host, port);
this.info = new Info(host, port);
this.mission = new Mission(host, port);
this.offboard = new Offboard(host, port);
this.param = new Param(host, port);
this.telemetry = new Telemetry(host, port);
}

public Action getAction() {
return action;
}
public Action getAction() {
return action;
}

public Calibration getCalibration() {
return calibration;
}
public Calibration getCalibration() {
return calibration;
}

public Camera getCamera() {
return camera;
}
public Camera getCamera() {
return camera;
}

public Core getCore() {
return core;
}
public Core getCore() {
return core;
}

public Gimbal getGimbal() {
return gimbal;
}
public Gimbal getGimbal() {
return gimbal;
}

public Info getInfo() {
return info;
}
public Info getInfo() {
return info;
}

public Mission getMission() {
return mission;
}
public Mission getMission() {
return mission;
}

public Offboard getOffboard() {
return offboard;
}
public Offboard getOffboard() {
return offboard;
}

public Param getParam() {
return param;
}
public Param getParam() {
return param;
}

public Telemetry getTelemetry() {
return telemetry;
}
}
public Telemetry getTelemetry() {
return telemetry;
}

/**
* Dispose of all the plugins.
*/
public void dispose() {
this.action.dispose();
this.calibration.dispose();
this.camera.dispose();
this.core.dispose();
this.gimbal.dispose();
this.info.dispose();
this.mission.dispose();
this.offboard.dispose();
this.param.dispose();
this.telemetry.dispose();
}
}
9 changes: 5 additions & 4 deletions sdk/mavsdk/src/test/java/io/mavsdk/MavsdkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class MavsdkTest {
public void testStream() throws InterruptedException {
System system = new System();
system.getTelemetry().getPosition()
.doOnNext(next -> java.lang.System.out.println(next))
.test()
.await(5, TimeUnit.SECONDS);
.doOnNext(next -> java.lang.System.out.println(next))
.test()
.await(5, TimeUnit.SECONDS);
}

@Test
Expand All @@ -28,6 +28,7 @@ public void testCall() throws InterruptedException {
@Test
public void testRequest() throws InterruptedException {
System system = new System();
system.getAction().getTakeoffAltitude().doOnSuccess(result -> java.lang.System.out.println(result)).test().await();
system.getAction().getTakeoffAltitude()
.doOnSuccess(result -> java.lang.System.out.println(result)).test().await();
}
}
4 changes: 4 additions & 0 deletions sdk/templates/file.j2
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public class {{ plugin_name.upper_camel_case }} {
scheduler = Schedulers.trampoline();
}

public void dispose() {
this.channel.shutdown();
}

{% if has_result %}
public class {{ plugin_name.upper_camel_case }}Exception extends Exception {
private {{ plugin_name.upper_camel_case }}Result.Result code;
Expand Down

0 comments on commit 0803505

Please sign in to comment.