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 org.wpilib.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) { 018 case PubSubOption.Periodic p -> periodic = p.period(); 019 case PubSubOption.SendAll s -> sendAll = s.enabled(); 020 case PubSubOption.TopicsOnly t -> topicsOnly = t.enabled(); 021 case PubSubOption.PollStorage p -> pollStorage = p.depth(); 022 case PubSubOption.KeepDuplicates k -> keepDuplicates = k.enabled(); 023 case PubSubOption.DisableRemote d -> disableRemote = d.disabled(); 024 case PubSubOption.DisableLocal l -> disableLocal = l.disabled(); 025 case PubSubOption.ExcludePublisher e -> 026 excludePublisher = e.publisher() == null ? 0 : e.publisher().getHandle(); 027 case PubSubOption.ExcludePublisherHandle e -> excludePublisher = e.publisher(); 028 case PubSubOption.ExcludeSelf s -> excludeSelf = s.enabled(); 029 case PubSubOption.Hidden h -> hidden = h.enabled(); 030 } 031 } 032 } 033 034 PubSubOptions( 035 int pollStorage, 036 double periodic, 037 int excludePublisher, 038 boolean sendAll, 039 boolean topicsOnly, 040 boolean keepDuplicates, 041 boolean prefixMatch, 042 boolean disableRemote, 043 boolean disableLocal, 044 boolean excludeSelf, 045 boolean hidden) { 046 this.pollStorage = pollStorage; 047 this.periodic = periodic; 048 this.excludePublisher = excludePublisher; 049 this.sendAll = sendAll; 050 this.topicsOnly = topicsOnly; 051 this.keepDuplicates = keepDuplicates; 052 this.prefixMatch = prefixMatch; 053 this.disableRemote = disableRemote; 054 this.disableLocal = disableLocal; 055 this.excludeSelf = excludeSelf; 056 this.hidden = hidden; 057 } 058 059 /** Default value of periodic. */ 060 public static final double kDefaultPeriodic = 0.1; 061 062 /** 063 * Polling storage size for a subscription. Specifies the maximum number of updates NetworkTables 064 * should store between calls to the subscriber's readQueue() function. If zero, defaults to 1 if 065 * sendAll is false, 20 if sendAll is true. 066 */ 067 public int pollStorage; 068 069 /** 070 * How frequently changes will be sent over the network, in seconds. NetworkTables may send more 071 * frequently than this (e.g. use a combined minimum period for all values) or apply a restricted 072 * range to this value. The default is 100 ms. 073 */ 074 public double periodic = kDefaultPeriodic; 075 076 /** 077 * For subscriptions, if non-zero, value updates for readQueue() are not queued for this 078 * publisher. 079 */ 080 public int excludePublisher; 081 082 /** Send all value changes over the network. */ 083 public boolean sendAll; 084 085 /** For subscriptions, don't ask for value changes (only topic announcements). */ 086 public boolean topicsOnly; 087 088 /** Preserve duplicate value changes (rather than ignoring them). */ 089 public boolean keepDuplicates; 090 091 /** 092 * Perform prefix match on subscriber topic names. Is ignored/overridden by subscribe() functions; 093 * only present in struct for the purposes of getting information about subscriptions. 094 */ 095 public boolean prefixMatch; 096 097 /** 098 * For subscriptions, if remote value updates should not be queued for readQueue(). See also 099 * disableLocal. 100 */ 101 public boolean disableRemote; 102 103 /** 104 * For subscriptions, if local value updates should not be queued for readQueue(). See also 105 * disableRemote. 106 */ 107 public boolean disableLocal; 108 109 /** For entries, don't queue (for readQueue) value updates for the entry's internal publisher. */ 110 public boolean excludeSelf; 111 112 /** 113 * For subscriptions, don't share the existence of the subscription with the network. Note this 114 * means updates will not be received from the network unless another subscription overlaps with 115 * this one, and the subscription will not appear in metatopics. 116 */ 117 public boolean hidden; 118}