2022-05-07 10:54:14 -07:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
2024-09-20 17:43:39 -07:00
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "../MulticastHandleManager.hpp"
|
2025-11-07 19:55:43 -05:00
|
|
|
#include "org_wpilib_net_WPINetJNI.h"
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/net/MulticastServiceAnnouncer.h"
|
|
|
|
|
#include "wpi/net/MulticastServiceResolver.h"
|
|
|
|
|
#include "wpi/net/PortForwarder.hpp"
|
|
|
|
|
#include "wpi/net/WebServer.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/util/jni_util.hpp"
|
2022-05-07 10:54:14 -07:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
using namespace wpi::util::java;
|
2022-05-07 10:54:14 -07:00
|
|
|
|
|
|
|
|
static JClass serviceDataCls;
|
|
|
|
|
static JGlobal<jobjectArray> serviceDataEmptyArray;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 19:55:43 -05:00
|
|
|
serviceDataCls = JClass{env, "org/wpilib/net/ServiceData"};
|
2022-05-07 10:54:14 -07:00
|
|
|
if (!serviceDataCls) {
|
|
|
|
|
return JNI_ERR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serviceDataEmptyArray = JGlobal<jobjectArray>{
|
|
|
|
|
env, env->NewObjectArray(0, serviceDataCls, nullptr)};
|
|
|
|
|
if (serviceDataEmptyArray == nullptr) {
|
|
|
|
|
return JNI_ERR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JNI_VERSION_1_6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
|
|
|
|
|
JNIEnv* env;
|
|
|
|
|
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serviceDataEmptyArray.free(env);
|
|
|
|
|
serviceDataCls.free(env);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: addPortForwarder
|
|
|
|
|
* Signature: (ILjava/lang/String;I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_addPortForwarder
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jstring remoteHost, jint remotePort)
|
|
|
|
|
{
|
2025-11-07 20:01:58 -05:00
|
|
|
wpi::net::PortForwarder::GetInstance().Add(
|
|
|
|
|
static_cast<unsigned int>(port), JStringRef{env, remoteHost}.str(),
|
|
|
|
|
static_cast<unsigned int>(remotePort));
|
2022-05-07 10:54:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: removePortForwarder
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_removePortForwarder
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::net::PortForwarder::GetInstance().Remove(port);
|
2022-05-07 10:54:14 -07:00
|
|
|
}
|
|
|
|
|
|
2024-12-14 12:51:21 -07:00
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2024-12-14 12:51:21 -07:00
|
|
|
* Method: startWebServer
|
|
|
|
|
* Signature: (ILjava/lang/String;)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_startWebServer
|
2024-12-14 12:51:21 -07:00
|
|
|
(JNIEnv* env, jclass, jint port, jstring path)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::net::WebServer::GetInstance().Start(static_cast<unsigned int>(port),
|
2025-11-07 20:01:58 -05:00
|
|
|
JStringRef{env, path}.str());
|
2024-12-14 12:51:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2024-12-14 12:51:21 -07:00
|
|
|
* Method: stopWebServer
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_stopWebServer
|
2024-12-14 12:51:21 -07:00
|
|
|
(JNIEnv* env, jclass, jint port)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::net::WebServer::GetInstance().Stop(port);
|
2024-12-14 12:51:21 -07:00
|
|
|
}
|
|
|
|
|
|
2022-05-07 10:54:14 -07:00
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: createMulticastServiceAnnouncer
|
|
|
|
|
* Signature: (Ljava/lang/String;Ljava/lang/String;I[Ljava/lang/Object;[Ljava/lang/Object;)I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_createMulticastServiceAnnouncer
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jstring serviceName, jstring serviceType, jint port,
|
|
|
|
|
jobjectArray keys, jobjectArray values)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
|
|
|
|
|
JStringRef serviceNameRef{env, serviceName};
|
|
|
|
|
JStringRef serviceTypeRef{env, serviceType};
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::SmallVector<std::pair<std::string, std::string>, 8> txtVec;
|
2022-08-03 11:15:56 -07:00
|
|
|
|
|
|
|
|
if (keys != nullptr && values != nullptr) {
|
|
|
|
|
size_t keysLen = env->GetArrayLength(keys);
|
|
|
|
|
|
|
|
|
|
txtVec.reserve(keysLen);
|
|
|
|
|
for (size_t i = 0; i < keysLen; i++) {
|
|
|
|
|
JLocal<jstring> key{
|
|
|
|
|
env, static_cast<jstring>(env->GetObjectArrayElement(keys, i))};
|
|
|
|
|
JLocal<jstring> value{
|
|
|
|
|
env, static_cast<jstring>(env->GetObjectArrayElement(values, i))};
|
|
|
|
|
|
|
|
|
|
txtVec.emplace_back(std::pair<std::string, std::string>{
|
|
|
|
|
JStringRef{env, key}.str(), JStringRef{env, value}.str()});
|
|
|
|
|
}
|
2022-05-07 10:54:14 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
auto announcer = std::make_unique<wpi::net::MulticastServiceAnnouncer>(
|
2022-05-07 10:54:14 -07:00
|
|
|
serviceNameRef.str(), serviceTypeRef.str(), port, txtVec);
|
|
|
|
|
|
|
|
|
|
size_t index = manager.handleIds.emplace_back(1);
|
|
|
|
|
|
|
|
|
|
manager.announcers[index] = std::move(announcer);
|
|
|
|
|
|
|
|
|
|
return static_cast<jint>(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: freeMulticastServiceAnnouncer
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_freeMulticastServiceAnnouncer
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
manager.announcers[handle] = nullptr;
|
|
|
|
|
manager.handleIds.erase(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: startMulticastServiceAnnouncer
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_startMulticastServiceAnnouncer
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
auto& announcer = manager.announcers[handle];
|
|
|
|
|
announcer->Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: stopMulticastServiceAnnouncer
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_stopMulticastServiceAnnouncer
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
auto& announcer = manager.announcers[handle];
|
|
|
|
|
announcer->Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: getMulticastServiceAnnouncerHasImplementation
|
|
|
|
|
* Signature: (I)Z
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_getMulticastServiceAnnouncerHasImplementation
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
auto& announcer = manager.announcers[handle];
|
|
|
|
|
return announcer->HasImplementation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: createMulticastServiceResolver
|
|
|
|
|
* Signature: (Ljava/lang/String;)I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_createMulticastServiceResolver
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jstring serviceType)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
JStringRef serviceTypeRef{env, serviceType};
|
|
|
|
|
|
2025-11-07 20:01:58 -05:00
|
|
|
auto resolver = std::make_unique<wpi::net::MulticastServiceResolver>(
|
|
|
|
|
serviceTypeRef.str());
|
2022-05-07 10:54:14 -07:00
|
|
|
|
|
|
|
|
size_t index = manager.handleIds.emplace_back(2);
|
|
|
|
|
|
|
|
|
|
manager.resolvers[index] = std::move(resolver);
|
|
|
|
|
|
|
|
|
|
return static_cast<jint>(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: freeMulticastServiceResolver
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_freeMulticastServiceResolver
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
manager.resolvers[handle] = nullptr;
|
|
|
|
|
manager.handleIds.erase(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: startMulticastServiceResolver
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_startMulticastServiceResolver
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
auto& resolver = manager.resolvers[handle];
|
|
|
|
|
resolver->Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: stopMulticastServiceResolver
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_stopMulticastServiceResolver
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
auto& resolver = manager.resolvers[handle];
|
|
|
|
|
resolver->Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: getMulticastServiceResolverHasImplementation
|
|
|
|
|
* Signature: (I)Z
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_getMulticastServiceResolverHasImplementation
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
auto& resolver = manager.resolvers[handle];
|
|
|
|
|
return resolver->HasImplementation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: getMulticastServiceResolverEventHandle
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_getMulticastServiceResolverEventHandle
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
2022-05-07 10:54:14 -07:00
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
auto& resolver = manager.resolvers[handle];
|
|
|
|
|
return resolver->GetEventHandle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_net_WPINetJNI
|
2022-05-07 10:54:14 -07:00
|
|
|
* Method: getMulticastServiceResolverData
|
|
|
|
|
* Signature: (I)[Ljava/lang/Object;
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jobjectArray JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_net_WPINetJNI_getMulticastServiceResolverData
|
2022-05-07 10:54:14 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
static jmethodID constructor =
|
|
|
|
|
env->GetMethodID(serviceDataCls, "<init>",
|
|
|
|
|
"(JILjava/lang/String;Ljava/lang/String;[Ljava/lang/"
|
|
|
|
|
"String;[Ljava/lang/String;)V");
|
2025-11-07 20:00:05 -05:00
|
|
|
auto& manager = wpi::net::GetMulticastManager();
|
|
|
|
|
std::vector<wpi::net::MulticastServiceResolver::ServiceData> allData;
|
2022-05-07 10:54:14 -07:00
|
|
|
{
|
|
|
|
|
std::scoped_lock lock{manager.mutex};
|
|
|
|
|
auto& resolver = manager.resolvers[handle];
|
|
|
|
|
allData = resolver->GetData();
|
|
|
|
|
}
|
|
|
|
|
if (allData.empty()) {
|
|
|
|
|
return serviceDataEmptyArray;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 20:41:32 -07:00
|
|
|
jobjectArray returnData =
|
|
|
|
|
env->NewObjectArray(allData.size(), serviceDataCls, nullptr);
|
2022-05-07 10:54:14 -07:00
|
|
|
|
2026-03-29 20:41:32 -07:00
|
|
|
size_t index = 0;
|
2022-05-07 10:54:14 -07:00
|
|
|
for (auto&& data : allData) {
|
|
|
|
|
JLocal<jstring> serviceName{env, MakeJString(env, data.serviceName)};
|
|
|
|
|
JLocal<jstring> hostName{env, MakeJString(env, data.hostName)};
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::SmallVector<std::string_view, 8> keysRef;
|
|
|
|
|
wpi::util::SmallVector<std::string_view, 8> valuesRef;
|
2022-05-07 10:54:14 -07:00
|
|
|
|
|
|
|
|
for (auto&& txt : data.txt) {
|
|
|
|
|
keysRef.emplace_back(txt.first);
|
|
|
|
|
valuesRef.emplace_back(txt.second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JLocal<jobjectArray> keys{env, MakeJStringArray(env, keysRef)};
|
|
|
|
|
JLocal<jobjectArray> values{env, MakeJStringArray(env, valuesRef)};
|
|
|
|
|
|
|
|
|
|
JLocal<jobject> dataItem{
|
|
|
|
|
env, env->NewObject(serviceDataCls, constructor,
|
|
|
|
|
static_cast<jlong>(data.ipv4Address),
|
|
|
|
|
static_cast<jint>(data.port), serviceName.obj(),
|
|
|
|
|
hostName.obj(), keys.obj(), values.obj())};
|
|
|
|
|
|
|
|
|
|
env->SetObjectArrayElement(returnData, index, dataItem);
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // extern "C"
|