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 publish/subscribe options. */
008@SuppressWarnings("MemberName")
009public class PubSubOptions {
010  /**
011   * Construct from a list of options.
012   *
013   * @param options options
014   */
015  public PubSubOptions(PubSubOption... options) {
016    for (PubSubOption option : options) {
017      switch (option.m_kind) {
018        case periodic:
019          periodic = option.m_dValue;
020          break;
021        case sendAll:
022          sendAll = option.m_bValue;
023          break;
024        case topicsOnly:
025          topicsOnly = option.m_bValue;
026          break;
027        case pollStorage:
028          pollStorage = option.m_iValue;
029          break;
030        case keepDuplicates:
031          keepDuplicates = option.m_bValue;
032          break;
033        case disableRemote:
034          disableRemote = option.m_bValue;
035          break;
036        case disableLocal:
037          disableLocal = option.m_bValue;
038          break;
039        case excludePublisher:
040          excludePublisher = option.m_iValue;
041          break;
042        case excludeSelf:
043          excludeSelf = option.m_bValue;
044          break;
045        default:
046          break;
047      }
048    }
049  }
050
051  PubSubOptions(
052      int pollStorage,
053      double periodic,
054      int excludePublisher,
055      boolean sendAll,
056      boolean topicsOnly,
057      boolean keepDuplicates,
058      boolean prefixMatch,
059      boolean disableRemote,
060      boolean disableLocal,
061      boolean excludeSelf) {
062    this.pollStorage = pollStorage;
063    this.periodic = periodic;
064    this.excludePublisher = excludePublisher;
065    this.sendAll = sendAll;
066    this.topicsOnly = topicsOnly;
067    this.keepDuplicates = keepDuplicates;
068    this.prefixMatch = prefixMatch;
069    this.disableRemote = disableRemote;
070    this.disableLocal = disableLocal;
071    this.excludeSelf = excludeSelf;
072  }
073
074  /** Default value of periodic. */
075  public static final double kDefaultPeriodic = 0.1;
076
077  /**
078   * Polling storage size for a subscription. Specifies the maximum number of updates NetworkTables
079   * should store between calls to the subscriber's readQueue() function. If zero, defaults to 1 if
080   * sendAll is false, 20 if sendAll is true.
081   */
082  public int pollStorage;
083
084  /**
085   * How frequently changes will be sent over the network, in seconds. NetworkTables may send more
086   * frequently than this (e.g. use a combined minimum period for all values) or apply a restricted
087   * range to this value. The default is 100 ms.
088   */
089  public double periodic = kDefaultPeriodic;
090
091  /**
092   * For subscriptions, if non-zero, value updates for readQueue() are not queued for this
093   * publisher.
094   */
095  public int excludePublisher;
096
097  /** Send all value changes over the network. */
098  public boolean sendAll;
099
100  /** For subscriptions, don't ask for value changes (only topic announcements). */
101  public boolean topicsOnly;
102
103  /** Preserve duplicate value changes (rather than ignoring them). */
104  public boolean keepDuplicates;
105
106  /**
107   * Perform prefix match on subscriber topic names. Is ignored/overridden by subscribe() functions;
108   * only present in struct for the purposes of getting information about subscriptions.
109   */
110  public boolean prefixMatch;
111
112  /**
113   * For subscriptions, if remote value updates should not be queued for readQueue(). See also
114   * disableLocal.
115   */
116  public boolean disableRemote;
117
118  /**
119   * For subscriptions, if local value updates should not be queued for readQueue(). See also
120   * disableRemote.
121   */
122  public boolean disableLocal;
123
124  /** For entries, don't queue (for readQueue) value updates for the entry's internal publisher. */
125  public boolean excludeSelf;
126}