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