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.networktables;
006
007/** NetworkTables value event data. */
008@SuppressWarnings("MemberName")
009public final class ValueEventData {
010  /** Topic handle. Topic.getHandle() can be used to map this to the corresponding Topic object. */
011  public final int topic;
012
013  /**
014   * Subscriber/entry handle. Subscriber.getHandle() or entry.getHandle() can be used to map this to
015   * the corresponding Subscriber or Entry object.
016   */
017  public final int subentry;
018
019  /** The new value. */
020  public final NetworkTableValue value;
021
022  /**
023   * Constructor. This should generally only be used internally to NetworkTables.
024   *
025   * @param inst Instance
026   * @param topic Topic handle
027   * @param subentry Subscriber/entry handle
028   * @param value The new value
029   */
030  public ValueEventData(
031      NetworkTableInstance inst, int topic, int subentry, NetworkTableValue value) {
032    this.m_inst = inst;
033    this.topic = topic;
034    this.subentry = subentry;
035    this.value = value;
036  }
037
038  /* Cached topic object. */
039  private Topic m_topicObject;
040
041  private final NetworkTableInstance m_inst;
042
043  /**
044   * Get the topic as an object.
045   *
046   * @return Topic for this notification.
047   */
048  public Topic getTopic() {
049    if (m_topicObject == null) {
050      m_topicObject = new Topic(m_inst, topic);
051    }
052    return m_topicObject;
053  }
054}