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.util.datalog;
006
007/** Log entry base class. */
008public class DataLogEntry {
009  /**
010   * Constructs a data log entry.
011   *
012   * @param log datalog
013   * @param name name of the entry
014   * @param type Data type
015   * @param metadata metadata
016   * @param timestamp entry creation timestamp (0=now)
017   */
018  protected DataLogEntry(DataLog log, String name, String type, String metadata, long timestamp) {
019    m_log = log;
020    m_entry = log.start(name, type, metadata, timestamp);
021  }
022
023  /**
024   * Constructs a data log entry.
025   *
026   * @param log datalog
027   * @param name name of the entry
028   * @param type Data type
029   * @param metadata metadata
030   */
031  protected DataLogEntry(DataLog log, String name, String type, String metadata) {
032    this(log, name, type, metadata, 0);
033  }
034
035  /**
036   * Constructs a data log entry.
037   *
038   * @param log datalog
039   * @param name name of the entry
040   * @param type Data type
041   */
042  protected DataLogEntry(DataLog log, String name, String type) {
043    this(log, name, type, "");
044  }
045
046  /**
047   * Updates the metadata for the entry.
048   *
049   * @param metadata New metadata for the entry
050   * @param timestamp Time stamp (0 to indicate now)
051   */
052  public void setMetadata(String metadata, long timestamp) {
053    m_log.setMetadata(m_entry, metadata, timestamp);
054  }
055
056  /**
057   * Updates the metadata for the entry.
058   *
059   * @param metadata New metadata for the entry
060   */
061  public void setMetadata(String metadata) {
062    setMetadata(metadata, 0);
063  }
064
065  /**
066   * Finishes the entry.
067   *
068   * @param timestamp Time stamp (0 to indicate now)
069   */
070  public void finish(long timestamp) {
071    m_log.finish(m_entry, timestamp);
072  }
073
074  /** Finishes the entry. */
075  public void finish() {
076    finish(0);
077  }
078
079  /** The data log instance associated with the entry. */
080  protected final DataLog m_log;
081
082  /** The data log entry index. */
083  protected final int m_entry;
084}