Add device event sender

Create a separate component to send device events, managed by the
controller.
This commit is contained in:
Romain Vimont 2019-05-30 15:17:05 +02:00
parent 6112095e75
commit 3149e2cf4a
5 changed files with 103 additions and 6 deletions

View file

@ -19,8 +19,11 @@ public final class Server {
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate());
EventController controller = new EventController(device, connection);
// asynchronous
startEventController(device, connection);
startEventController(controller);
startEventSender(controller.getSender());
try {
// synchronous
@ -32,12 +35,12 @@ public final class Server {
}
}
private static void startEventController(final Device device, final DesktopConnection connection) {
private static void startEventController(final EventController controller) {
new Thread(new Runnable() {
@Override
public void run() {
try {
new EventController(device, connection).control();
controller.control();
} catch (IOException e) {
// this is expected on close
Ln.d("Event controller stopped");
@ -46,6 +49,20 @@ public final class Server {
}).start();
}
private static void startEventSender(final EventSender sender) {
new Thread(new Runnable() {
@Override
public void run() {
try {
sender.loop();
} catch (IOException | InterruptedException e) {
// this is expected on close
Ln.d("Event sender stopped");
}
}
}).start();
}
@SuppressWarnings("checkstyle:MagicNumber")
private static Options createOptions(String... args) {
if (args.length != 5) {