2019-09-26 22:53:21 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-08-06 21:37:38 -07:00
|
|
|
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
2019-09-26 22:53:21 -07:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
|
|
|
|
#include "edu_wpi_first_wpiutil_WPIUtilJNI.h"
|
|
|
|
|
#include "wpi/PortForwarder.h"
|
|
|
|
|
#include "wpi/jni_util.h"
|
2020-08-06 21:37:38 -07:00
|
|
|
#include "wpi/timestamp.h"
|
2019-09-26 22:53:21 -07:00
|
|
|
|
|
|
|
|
using namespace wpi::java;
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
|
|
|
|
|
JNIEnv* env;
|
|
|
|
|
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
|
|
|
|
|
return JNI_ERR;
|
|
|
|
|
|
|
|
|
|
return JNI_VERSION_1_6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {}
|
|
|
|
|
|
2020-08-06 21:37:38 -07:00
|
|
|
/*
|
2020-08-16 19:40:11 -07:00
|
|
|
* Class: edu_wpi_first_wpiutil_WPIUtilJNI
|
2020-08-06 21:37:38 -07:00
|
|
|
* Method: now
|
|
|
|
|
* Signature: ()J
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jlong JNICALL
|
2020-08-16 19:40:11 -07:00
|
|
|
Java_edu_wpi_first_wpiutil_WPIUtilJNI_now
|
2020-08-06 21:37:38 -07:00
|
|
|
(JNIEnv*, jclass)
|
|
|
|
|
{
|
|
|
|
|
return wpi::Now();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 22:53:21 -07:00
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpiutil_WPIUtilJNI
|
|
|
|
|
* Method: addPortForwarder
|
|
|
|
|
* Signature: (ILjava/lang/String;I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpiutil_WPIUtilJNI_addPortForwarder
|
|
|
|
|
(JNIEnv* env, jclass, jint port, jstring remoteHost, jint remotePort)
|
|
|
|
|
{
|
|
|
|
|
wpi::PortForwarder::GetInstance().Add(static_cast<unsigned int>(port),
|
|
|
|
|
JStringRef{env, remoteHost}.str(),
|
|
|
|
|
static_cast<unsigned int>(remotePort));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Class: edu_wpi_first_wpiutil_WPIUtilJNI
|
|
|
|
|
* Method: removePortForwarder
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_edu_wpi_first_wpiutil_WPIUtilJNI_removePortForwarder
|
|
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
|
|
|
|
wpi::PortForwarder::GetInstance().Remove(port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // extern "C"
|