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 Raw topic. */
008public final class RawTopic extends Topic {
009  /**
010   * Construct from a generic topic.
011   *
012   * @param topic Topic
013   */
014  public RawTopic(Topic topic) {
015    super(topic.m_inst, topic.m_handle);
016  }
017
018  /**
019   * Constructor; use NetworkTableInstance.getRawTopic() instead.
020   *
021   * @param inst Instance
022   * @param handle Native handle
023   */
024  public RawTopic(NetworkTableInstance inst, int handle) {
025    super(inst, handle);
026  }
027
028  /**
029   * Create a new subscriber to the topic.
030   *
031   * <p>The subscriber is only active as long as the returned object
032   * is not closed.
033   *
034   * <p>Subscribers that do not match the published data type do not return
035   * any values. To determine if the data type matches, use the appropriate
036   * Topic functions.
037   *
038   * @param typeString type string
039
040   * @param defaultValue default value used when a default is not provided to a
041   *        getter function
042   * @param options subscribe options
043   * @return subscriber
044   */
045  public RawSubscriber subscribe(
046      String typeString,
047
048      byte[] defaultValue,
049      PubSubOption... options) {
050    return new RawEntryImpl(
051        this,
052        NetworkTablesJNI.subscribe(
053            m_handle, NetworkTableType.kRaw.getValue(),
054            typeString, options),
055        defaultValue);
056  }
057
058  /**
059   * Create a new publisher to the topic.
060   *
061   * <p>The publisher is only active as long as the returned object
062   * is not closed.
063   *
064   * <p>It is not possible to publish two different data types to the same
065   * topic. Conflicts between publishers are typically resolved by the server on
066   * a first-come, first-served basis. Any published values that do not match
067   * the topic's data type are dropped (ignored). To determine if the data type
068   * matches, use the appropriate Topic functions.
069   *
070   * @param typeString type string
071
072   * @param options publish options
073   * @return publisher
074   */
075  public RawPublisher publish(
076      String typeString,
077
078      PubSubOption... options) {
079    return new RawEntryImpl(
080        this,
081        NetworkTablesJNI.publish(
082            m_handle, NetworkTableType.kRaw.getValue(),
083            typeString, options),
084        new byte[] {});
085  }
086
087  /**
088   * Create a new publisher to the topic, with type string and initial properties.
089   *
090   * <p>The publisher is only active as long as the returned object
091   * is not closed.
092   *
093   * <p>It is not possible to publish two different data types to the same
094   * topic. Conflicts between publishers are typically resolved by the server on
095   * a first-come, first-served basis. Any published values that do not match
096   * the topic's data type are dropped (ignored). To determine if the data type
097   * matches, use the appropriate Topic functions.
098   *
099   * @param typeString type string
100   * @param properties JSON properties
101   * @param options publish options
102   * @return publisher
103   * @throws IllegalArgumentException if properties is not a JSON object
104   */
105  public RawPublisher publishEx(
106      String typeString,
107      String properties,
108      PubSubOption... options) {
109    return new RawEntryImpl(
110        this,
111        NetworkTablesJNI.publishEx(
112            m_handle, NetworkTableType.kRaw.getValue(),
113            typeString, properties, options),
114        new byte[] {});
115  }
116
117  /**
118   * Create a new entry for the topic.
119   *
120   * <p>Entries act as a combination of a subscriber and a weak publisher. The
121   * subscriber is active as long as the entry is not closed. The publisher is
122   * created when the entry is first written to, and remains active until either
123   * unpublish() is called or the entry is closed.
124   *
125   * <p>It is not possible to use two different data types with the same
126   * topic. Conflicts between publishers are typically resolved by the server on
127   * a first-come, first-served basis. Any published values that do not match
128   * the topic's data type are dropped (ignored), and the entry will show no new
129   * values if the data type does not match. To determine if the data type
130   * matches, use the appropriate Topic functions.
131   *
132   * @param typeString type string
133
134   * @param defaultValue default value used when a default is not provided to a
135   *        getter function
136   * @param options publish and/or subscribe options
137   * @return entry
138   */
139  public RawEntry getEntry(
140      String typeString,
141
142      byte[] defaultValue,
143      PubSubOption... options) {
144    return new RawEntryImpl(
145        this,
146        NetworkTablesJNI.getEntry(
147            m_handle, NetworkTableType.kRaw.getValue(),
148            typeString, options),
149        defaultValue);
150  }
151
152}