001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.net;
006
007import java.util.HashMap;
008import java.util.Map;
009
010/** Service data for MulticastServiceResolver. */
011public class ServiceData {
012  /**
013   * Constructs a ServiceData.
014   *
015   * @param ipv4Address ipv4Address
016   * @param port port
017   * @param serviceName found service name
018   * @param hostName found host name
019   * @param keys txt keys
020   * @param values txt values
021   */
022  public ServiceData(
023      long ipv4Address,
024      int port,
025      String serviceName,
026      String hostName,
027      String[] keys,
028      String[] values) {
029    this.m_serviceName = serviceName;
030    this.m_hostName = hostName;
031    this.m_port = port;
032    this.m_ipv4Address = ipv4Address;
033
034    m_txt = new HashMap<>();
035
036    for (int i = 0; i < keys.length; i++) {
037      m_txt.put(keys[i], values[i]);
038    }
039  }
040
041  /**
042   * Returns service data payload.
043   *
044   * @return Service data payload.
045   */
046  public Map<String, String> getTxt() {
047    return m_txt;
048  }
049
050  /**
051   * Returns host name.
052   *
053   * @return Host name.
054   */
055  public String getHostName() {
056    return m_hostName;
057  }
058
059  /**
060   * Returns service name.
061   *
062   * @return Service name.
063   */
064  public String getServiceName() {
065    return m_serviceName;
066  }
067
068  /**
069   * Returns port number.
070   *
071   * @return Port number.
072   */
073  public int getPort() {
074    return m_port;
075  }
076
077  /**
078   * Returns IPv4 address.
079   *
080   * @return IPv4 address.
081   */
082  public long getIpv4Address() {
083    return m_ipv4Address;
084  }
085
086  private final Map<String, String> m_txt;
087  private final long m_ipv4Address;
088  private final int m_port;
089  private final String m_serviceName;
090  private final String m_hostName;
091}