2021-11-25 22:08:26 -08: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.
|
|
|
|
|
|
2022-05-07 10:54:14 -07:00
|
|
|
package edu.wpi.first.net;
|
2021-11-25 22:08:26 -08:00
|
|
|
|
2023-07-10 09:59:36 -07:00
|
|
|
import edu.wpi.first.util.WPICleaner;
|
|
|
|
|
import java.lang.ref.Cleaner.Cleanable;
|
|
|
|
|
|
2021-11-25 22:08:26 -08:00
|
|
|
/** Class to resolve a service over mDNS. */
|
|
|
|
|
public class MulticastServiceResolver implements AutoCloseable {
|
|
|
|
|
private final int m_handle;
|
2023-07-10 09:59:36 -07:00
|
|
|
private final Cleanable m_cleanable;
|
|
|
|
|
|
|
|
|
|
private static Runnable cleanupAction(int handle) {
|
|
|
|
|
return () -> WPINetJNI.freeMulticastServiceResolver(handle);
|
|
|
|
|
}
|
2021-11-25 22:08:26 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a MulticastServiceResolver.
|
|
|
|
|
*
|
|
|
|
|
* @param serviceType service type to look for
|
|
|
|
|
*/
|
|
|
|
|
public MulticastServiceResolver(String serviceType) {
|
2022-05-07 10:54:14 -07:00
|
|
|
m_handle = WPINetJNI.createMulticastServiceResolver(serviceType);
|
2023-07-10 09:59:36 -07:00
|
|
|
m_cleanable = WPICleaner.register(this, cleanupAction(m_handle));
|
2021-11-25 22:08:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void close() {
|
2023-07-10 09:59:36 -07:00
|
|
|
m_cleanable.clean();
|
2021-11-25 22:08:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void start() {
|
2022-05-07 10:54:14 -07:00
|
|
|
WPINetJNI.startMulticastServiceResolver(m_handle);
|
2021-11-25 22:08:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stop() {
|
2022-05-07 10:54:14 -07:00
|
|
|
WPINetJNI.stopMulticastServiceResolver(m_handle);
|
2021-11-25 22:08:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasImplementation() {
|
2022-05-07 10:54:14 -07:00
|
|
|
return WPINetJNI.getMulticastServiceResolverHasImplementation(m_handle);
|
2021-11-25 22:08:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getEventHandle() {
|
2022-05-07 10:54:14 -07:00
|
|
|
return WPINetJNI.getMulticastServiceResolverEventHandle(m_handle);
|
2021-11-25 22:08:26 -08:00
|
|
|
}
|
|
|
|
|
|
2021-11-27 11:16:24 -08:00
|
|
|
public ServiceData[] getData() {
|
2022-05-07 10:54:14 -07:00
|
|
|
return WPINetJNI.getMulticastServiceResolverData(m_handle);
|
2021-11-25 22:08:26 -08:00
|
|
|
}
|
|
|
|
|
}
|