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