001/*----------------------------------------------------------------------------*/
002/* Copyright (c) FIRST 2017-2018. All Rights Reserved.                        */
003/* Open Source Software - may be modified and shared by FRC teams. The code   */
004/* must be accompanied by the FIRST BSD license file in the root directory of */
005/* the project.                                                               */
006/*----------------------------------------------------------------------------*/
007
008package edu.wpi.first.networktables;
009
010/**
011 * NetworkTables Entry notification.
012 */
013public final class EntryNotification {
014  /**
015   * Listener that was triggered.
016   */
017  public final int listener;
018
019  /**
020   * Entry handle.
021   */
022  public final int entry;
023
024  /**
025   * Entry name.
026   */
027  public final String name;
028
029  /**
030   * The new value.
031   */
032  public final NetworkTableValue value;
033
034  /**
035   * Update flags.  For example, {@link EntryListenerFlags#kNew} if the key did
036   * not previously exist.
037   */
038  public final int flags;
039
040  /** Constructor.
041   * This should generally only be used internally to NetworkTables.
042   * @param inst Instance
043   * @param listener Listener that was triggered
044   * @param entry Entry handle
045   * @param name Entry name
046   * @param value The new value
047   * @param flags Update flags
048   */
049  public EntryNotification(NetworkTableInstance inst, int listener, int entry, String name, NetworkTableValue value, int flags) {
050    this.inst = inst;
051    this.listener = listener;
052    this.entry = entry;
053    this.name = name;
054    this.value = value;
055    this.flags = flags;
056  }
057
058  /* Network table instance. */
059  private final NetworkTableInstance inst;
060
061  /* Cached entry object. */
062  NetworkTableEntry entryObject;
063
064  /**
065   * Get the entry as an object.
066   * @return NetworkTableEntry for this entry.
067   */
068  public NetworkTableEntry getEntry() {
069    if (entryObject == null) {
070      entryObject = new NetworkTableEntry(inst, entry);
071    }
072    return entryObject;
073  }
074}