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 Float topic. */ 008public final class FloatTopic extends Topic { 009 /** The default type string for this topic type. */ 010 public static final String kTypeString = "float"; 011 012 /** 013 * Construct from a generic topic. 014 * 015 * @param topic Topic 016 */ 017 public FloatTopic(Topic topic) { 018 super(topic.m_inst, topic.m_handle); 019 } 020 021 /** 022 * Constructor; use NetworkTableInstance.getFloatTopic() instead. 023 * 024 * @param inst Instance 025 * @param handle Native handle 026 */ 027 public FloatTopic(NetworkTableInstance inst, int handle) { 028 super(inst, handle); 029 } 030 031 /** 032 * Create a new subscriber to the topic. 033 * 034 * <p>The subscriber is only active as long as the returned object 035 * is not closed. 036 * 037 * <p>Subscribers that do not match the published data type do not return 038 * any values. To determine if the data type matches, use the appropriate 039 * Topic functions. 040 * 041 * @param defaultValue default value used when a default is not provided to a 042 * getter function 043 * @param options subscribe options 044 * @return subscriber 045 */ 046 public FloatSubscriber subscribe( 047 float defaultValue, 048 PubSubOption... options) { 049 return new FloatEntryImpl( 050 this, 051 NetworkTablesJNI.subscribe( 052 m_handle, NetworkTableType.kFloat.getValue(), 053 "float", options), 054 defaultValue); 055 } 056 057 /** 058 * Create a new subscriber to the topic, with specified type string. 059 * 060 * <p>The subscriber is only active as long as the returned object 061 * is not closed. 062 * 063 * <p>Subscribers that do not match the published data type do not return 064 * any values. To determine if the data type matches, use the appropriate 065 * Topic functions. 066 * 067 * @param typeString type string 068 * @param defaultValue default value used when a default is not provided to a 069 * getter function 070 * @param options subscribe options 071 * @return subscriber 072 */ 073 public FloatSubscriber subscribeEx( 074 String typeString, 075 float defaultValue, 076 PubSubOption... options) { 077 return new FloatEntryImpl( 078 this, 079 NetworkTablesJNI.subscribe( 080 m_handle, NetworkTableType.kFloat.getValue(), 081 typeString, options), 082 defaultValue); 083 } 084 085 /** 086 * Create a new publisher to the topic. 087 * 088 * <p>The publisher is only active as long as the returned object 089 * is not closed. 090 * 091 * <p>It is not possible to publish two different data types to the same 092 * topic. Conflicts between publishers are typically resolved by the server on 093 * a first-come, first-served basis. Any published values that do not match 094 * the topic's data type are dropped (ignored). To determine if the data type 095 * matches, use the appropriate Topic functions. 096 * 097 * @param options publish options 098 * @return publisher 099 */ 100 public FloatPublisher publish( 101 PubSubOption... options) { 102 return new FloatEntryImpl( 103 this, 104 NetworkTablesJNI.publish( 105 m_handle, NetworkTableType.kFloat.getValue(), 106 "float", options), 107 0); 108 } 109 110 /** 111 * Create a new publisher to the topic, with type string and initial properties. 112 * 113 * <p>The publisher is only active as long as the returned object 114 * is not closed. 115 * 116 * <p>It is not possible to publish two different data types to the same 117 * topic. Conflicts between publishers are typically resolved by the server on 118 * a first-come, first-served basis. Any published values that do not match 119 * the topic's data type are dropped (ignored). To determine if the data type 120 * matches, use the appropriate Topic functions. 121 * 122 * @param typeString type string 123 * @param properties JSON properties 124 * @param options publish options 125 * @return publisher 126 * @throws IllegalArgumentException if properties is not a JSON object 127 */ 128 public FloatPublisher publishEx( 129 String typeString, 130 String properties, 131 PubSubOption... options) { 132 return new FloatEntryImpl( 133 this, 134 NetworkTablesJNI.publishEx( 135 m_handle, NetworkTableType.kFloat.getValue(), 136 typeString, properties, options), 137 0); 138 } 139 140 /** 141 * Create a new entry for the topic. 142 * 143 * <p>Entries act as a combination of a subscriber and a weak publisher. The 144 * subscriber is active as long as the entry is not closed. The publisher is 145 * created when the entry is first written to, and remains active until either 146 * unpublish() is called or the entry is closed. 147 * 148 * <p>It is not possible to use two different data types with the same 149 * topic. Conflicts between publishers are typically resolved by the server on 150 * a first-come, first-served basis. Any published values that do not match 151 * the topic's data type are dropped (ignored), and the entry will show no new 152 * values if the data type does not match. To determine if the data type 153 * matches, use the appropriate Topic functions. 154 * 155 * @param defaultValue default value used when a default is not provided to a 156 * getter function 157 * @param options publish and/or subscribe options 158 * @return entry 159 */ 160 public FloatEntry getEntry( 161 float defaultValue, 162 PubSubOption... options) { 163 return new FloatEntryImpl( 164 this, 165 NetworkTablesJNI.getEntry( 166 m_handle, NetworkTableType.kFloat.getValue(), 167 "float", options), 168 defaultValue); 169 } 170 171 /** 172 * Create a new entry for the topic, with specified type string. 173 * 174 * <p>Entries act as a combination of a subscriber and a weak publisher. The 175 * subscriber is active as long as the entry is not closed. The publisher is 176 * created when the entry is first written to, and remains active until either 177 * unpublish() is called or the entry is closed. 178 * 179 * <p>It is not possible to use two different data types with the same 180 * topic. Conflicts between publishers are typically resolved by the server on 181 * a first-come, first-served basis. Any published values that do not match 182 * the topic's data type are dropped (ignored), and the entry will show no new 183 * values if the data type does not match. To determine if the data type 184 * matches, use the appropriate Topic functions. 185 * 186 * @param typeString type string 187 * @param defaultValue default value used when a default is not provided to a 188 * getter function 189 * @param options publish and/or subscribe options 190 * @return entry 191 */ 192 public FloatEntry getEntryEx( 193 String typeString, 194 float defaultValue, 195 PubSubOption... options) { 196 return new FloatEntryImpl( 197 this, 198 NetworkTablesJNI.getEntry( 199 m_handle, NetworkTableType.kFloat.getValue(), 200 typeString, options), 201 defaultValue); 202 } 203 204}