blob: f192739ad08b8d9b9401cfd8f386c18476b3e4d0 [file] [log] [blame]
michaelt2fe9ac32017-04-20 06:56:27 -07001/*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <jni.h>
12#undef JNIEXPORT
13#define JNIEXPORT __attribute__((visibility("default")))
14#include <string>
15
Byoungchan Leec931f702022-07-03 17:20:17 +090016#include "rtc_base/logging.h"
17#include "rtc_base/thread.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_tools/network_tester/test_controller.h"
michaelt2fe9ac32017-04-20 06:56:27 -070019
20extern "C" JNIEXPORT jlong JNICALL
21Java_com_google_media_networktester_NetworkTester_CreateTestController(
22 JNIEnv* jni,
23 jclass) {
Byoungchan Leec931f702022-07-03 17:20:17 +090024 rtc::ThreadManager::Instance()->WrapCurrentThread();
michaelt2fe9ac32017-04-20 06:56:27 -070025 return reinterpret_cast<intptr_t>(new webrtc::TestController(
26 0, 0, "/mnt/sdcard/network_tester_client_config.dat",
27 "/mnt/sdcard/network_tester_client_packet_log.dat"));
28}
29
30extern "C" JNIEXPORT void JNICALL
31Java_com_google_media_networktester_NetworkTester_TestControllerConnect(
32 JNIEnv* jni,
33 jclass,
34 jlong native_pointer) {
35 reinterpret_cast<webrtc::TestController*>(native_pointer)
36 ->SendConnectTo("85.195.237.107", 9090);
37}
38
39extern "C" JNIEXPORT bool JNICALL
40Java_com_google_media_networktester_NetworkTester_TestControllerIsDone(
41 JNIEnv* jni,
42 jclass,
43 jlong native_pointer) {
44 return reinterpret_cast<webrtc::TestController*>(native_pointer)
45 ->IsTestDone();
46}
47
48extern "C" JNIEXPORT void JNICALL
49Java_com_google_media_networktester_NetworkTester_TestControllerRun(
50 JNIEnv* jni,
51 jclass,
52 jlong native_pointer) {
Byoungchan Leec931f702022-07-03 17:20:17 +090053 // 100 ms arbitrary chosen, but it works well.
54 rtc::Thread::Current()->ProcessMessages(/*cms=*/100);
michaelt2fe9ac32017-04-20 06:56:27 -070055}
56
57extern "C" JNIEXPORT void JNICALL
58Java_com_google_media_networktester_NetworkTester_DestroyTestController(
59 JNIEnv* jni,
60 jclass,
61 jlong native_pointer) {
62 webrtc::TestController* test_controller =
63 reinterpret_cast<webrtc::TestController*>(native_pointer);
64 if (test_controller) {
65 delete test_controller;
66 }
Byoungchan Leec931f702022-07-03 17:20:17 +090067 rtc::ThreadManager::Instance()->UnwrapCurrentThread();
michaelt2fe9ac32017-04-20 06:56:27 -070068}